| 10567 | } |
| 10568 | |
| 10569 | void BfModule::EmitAppendAlign(int align, int sizeMultiple) |
| 10570 | { |
| 10571 | if (align <= 1) |
| 10572 | return; |
| 10573 | |
| 10574 | if (sizeMultiple == 0) |
| 10575 | sizeMultiple = align; |
| 10576 | if ((mCurMethodState->mCurAppendAlign != 0) && (mCurMethodState->mCurAppendAlign % align != 0)) |
| 10577 | { |
| 10578 | if (!IsAllocatorAligned()) |
| 10579 | { |
| 10580 | // Don't align |
| 10581 | } |
| 10582 | else if (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor) |
| 10583 | { |
| 10584 | auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1]; |
| 10585 | BF_ASSERT(localVar->mName == "__appendIdx"); |
| 10586 | auto appendIdxVal = BfTypedValue(localVar->mValue, localVar->mResolvedType, true); |
| 10587 | BfIRValue appendCurIdx = mBfIRBuilder->CreateLoad(appendIdxVal.mValue); |
| 10588 | if (align > 1) |
| 10589 | { |
| 10590 | appendCurIdx = mBfIRBuilder->CreateAdd(appendCurIdx, GetConstValue(align - 1)); |
| 10591 | appendCurIdx = mBfIRBuilder->CreateAnd(appendCurIdx, GetConstValue(~(align - 1))); |
| 10592 | } |
| 10593 | mBfIRBuilder->CreateStore(appendCurIdx, appendIdxVal.mValue); |
| 10594 | } |
| 10595 | else |
| 10596 | { |
| 10597 | BF_ASSERT(mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_CtorCalcAppend); |
| 10598 | BfIRValue appendCurIdxPtr = mCurMethodState->mRetVal.mValue; |
| 10599 | BfIRValue appendCurIdx = mBfIRBuilder->CreateLoad(appendCurIdxPtr); |
| 10600 | appendCurIdx = mBfIRBuilder->CreateAdd(appendCurIdx, GetConstValue(align - 1)); |
| 10601 | appendCurIdx = mBfIRBuilder->CreateAnd(appendCurIdx, GetConstValue(~(align - 1))); |
| 10602 | mBfIRBuilder->CreateStore(appendCurIdx, appendCurIdxPtr); |
| 10603 | } |
| 10604 | } |
| 10605 | |
| 10606 | if (mCurMethodState->mCurAppendAlign == 0) |
| 10607 | mCurMethodState->mCurAppendAlign = sizeMultiple; |
| 10608 | else |
| 10609 | { |
| 10610 | if (sizeMultiple % align == 0) |
| 10611 | mCurMethodState->mCurAppendAlign = align; |
| 10612 | else |
| 10613 | mCurMethodState->mCurAppendAlign = sizeMultiple % align; |
| 10614 | } |
| 10615 | } |
| 10616 | |
| 10617 | BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, int appendAllocAlign, BfIRValue arraySize, int arrayDim, bool isRawArrayAlloc, bool zeroMemory) |
| 10618 | { |
no test coverage detected