| 9847 | } |
| 9848 | |
| 9849 | BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget, BfIRValue appendSizeValue, BfIRValue arraySize, int arrayDim, BfAllocFlags allocFlags, int alignOverride) |
| 9850 | { |
| 9851 | BP_ZONE("AllocFromType"); |
| 9852 | |
| 9853 | BfScopeData* scopeData = allocTarget.mScopeData; |
| 9854 | |
| 9855 | BF_ASSERT(!type->IsVar()); |
| 9856 | |
| 9857 | auto typeInstance = type->ToTypeInstance(); |
| 9858 | if ((typeInstance == NULL) && (type->IsGenericParam())) |
| 9859 | typeInstance = mContext->mBfObjectType; |
| 9860 | |
| 9861 | bool isHeapAlloc = scopeData == NULL; |
| 9862 | bool isScopeAlloc = scopeData != NULL; |
| 9863 | bool isLoopedAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsLooped(scopeData)); |
| 9864 | bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData)); |
| 9865 | |
| 9866 | bool isRawArrayAlloc = (allocFlags & BfAllocFlags_RawArray) != 0; |
| 9867 | bool zeroMemory = (allocFlags & BfAllocFlags_ZeroMemory) != 0; |
| 9868 | bool noDtorCall = (allocFlags & BfAllocFlags_NoDtorCall) != 0; |
| 9869 | |
| 9870 | if ((type->IsValuelessType()) && ((!arraySize) || (isRawArrayAlloc))) |
| 9871 | { |
| 9872 | BfPointerType* ptrType = CreatePointerType(type); |
| 9873 | auto val = mBfIRBuilder->CreateIntToPtr(mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 1), mBfIRBuilder->MapType(ptrType)); |
| 9874 | return val; |
| 9875 | } |
| 9876 | |
| 9877 | if (typeInstance != NULL) |
| 9878 | mBfIRBuilder->PopulateType(typeInstance); |
| 9879 | |
| 9880 | bool hasCustomAllocator = (allocTarget.mCustomAllocator) || (allocTarget.mScopedInvocationTarget != NULL); |
| 9881 | |
| 9882 | if ((!hasCustomAllocator) && (mBfIRBuilder->mIgnoreWrites)) |
| 9883 | { |
| 9884 | return mBfIRBuilder->GetFakeVal(); |
| 9885 | } |
| 9886 | |
| 9887 | AddDependency(type, mCurTypeInstance, BfDependencyMap::DependencyFlag_Allocates); |
| 9888 | |
| 9889 | BfIRValue sizeValue; |
| 9890 | BfIRType allocType = mBfIRBuilder->MapType(type); |
| 9891 | int allocSize = type->mSize; |
| 9892 | int allocAlign = type->mAlign; |
| 9893 | if (typeInstance != NULL) |
| 9894 | { |
| 9895 | if ((!mBfIRBuilder->mIgnoreWrites) && (!mIsComptimeModule)) |
| 9896 | typeInstance->mHasBeenInstantiated = true; |
| 9897 | allocSize = typeInstance->mInstSize; |
| 9898 | allocAlign = typeInstance->mInstAlign; |
| 9899 | |
| 9900 | //if (typeInstance->IsEnum()) |
| 9901 | //allocType = typeInstance->mIRType; |
| 9902 | allocType = mBfIRBuilder->MapTypeInst(typeInstance); |
| 9903 | } |
| 9904 | |
| 9905 | if (alignOverride != -1) |
| 9906 | allocAlign = alignOverride; |
no test coverage detected