1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Fixed append alignment with unaligned stomp allocator

This commit is contained in:
Brian Fiete 2022-07-16 06:03:35 -04:00
parent ce64d43b6a
commit b2b964489e
3 changed files with 18 additions and 13 deletions

View file

@ -9094,6 +9094,13 @@ void BfModule::InitTypeInst(BfTypedValue typedValue, BfScopeData* scopeData, boo
}
}
bool BfModule::IsAllocatorAligned()
{
if (mCompiler->mOptions.mMallocLinkName == "StompAlloc")
return false;
return true;
}
BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*, bool zeroMemory, bool defaultToMalloc*/)
{
BfIRValue result;
@ -10010,19 +10017,17 @@ void BfModule::ValidateAllocation(BfType* type, BfAstNode* refNode)
Fail(StrFormat("Unable to allocate opaque type '%s'", TypeToString(type).c_str()), refNode);
}
void BfModule::EmitAlign(BfIRValue& appendCurIdx, int align)
{
appendCurIdx = mBfIRBuilder->CreateAdd(appendCurIdx, GetConstValue(align - 1));
appendCurIdx = mBfIRBuilder->CreateAnd(appendCurIdx, GetConstValue(~(align - 1)));
}
void BfModule::EmitAppendAlign(int align, int sizeMultiple)
{
if (sizeMultiple == 0)
sizeMultiple = align;
if ((mCurMethodState->mCurAppendAlign != 0) && (mCurMethodState->mCurAppendAlign % align != 0))
{
if (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)
if (!IsAllocatorAligned())
{
// Don't align
}
else if (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)
{
auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1];
BF_ASSERT(localVar->mName == "appendIdx");

View file

@ -1662,7 +1662,7 @@ public:
BfVariant TypedValueToVariant(BfAstNode* refNode, const BfTypedValue& value, bool allowUndef = false);
BfTypedValue FlushNullConditional(BfTypedValue result, bool ignoreNullable = false);
void NewScopeState(bool createLexicalBlock = true, bool flushValueScope = true); // returns prev scope data
void NewScopeState(bool createLexicalBlock = true, bool flushValueScope = true); // returns prev scope data
BfIRValue CreateAlloca(BfType* type, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue());
BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL);
BfDeferredCallEntry* AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false, BfIRBlock valBlock = BfIRBlock());
@ -1707,13 +1707,13 @@ public:
void AssertErrorState();
void AssertParseErrorState();
void InitTypeInst(BfTypedValue typedValue, BfScopeData* scope, bool zeroMemory, BfIRValue dataSize);
bool IsAllocatorAligned();
BfIRValue AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*bool zeroMemory, bool defaultToMalloc*/);
BfIRValue GetMarkFuncPtr(BfType* type);
BfIRValue GetDbgRawAllocData(BfType* type);
BfIRValue AllocFromType(BfType* type, const BfAllocTarget& allocTarget, BfIRValue appendSizeValue = BfIRValue(), BfIRValue arraySize = BfIRValue(), int arrayDim = 0, /*bool isRawArrayAlloc = false, bool zeroMemory = true*/BfAllocFlags allocFlags = BfAllocFlags_ZeroMemory, int alignOverride = -1);
void ValidateAllocation(BfType* type, BfAstNode* refNode);
bool IsOptimized();
void EmitAlign(BfIRValue& appendCurIdx, int align);
bool IsOptimized();
void EmitAppendAlign(int align, int sizeMultiple = 0);
BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true);
bool IsTargetingBeefBackend();