MCPcopy Create free account
hub / github.com/beefytech/Beef / AddStackAlloc

Method AddStackAlloc

IDEHelper/Compiler/BfModule.cpp:2147–2307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2145}
2146
2147BfDeferredCallEntry* BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scopeData, bool condAlloca, bool mayEscape, BfIRBlock valBlock)
2148{
2149 //This was removed because we want the alloc to be added to the __deferred list if it's actually a "stack"
2150 // 'stack' in a head scopeData is really the same as 'scopeData', so use the simpler scopeData handling
2151 /*if (mCurMethodState->mInHeadScope)
2152 isScopeAlloc = true;*/
2153
2154 if (scopeData == NULL)
2155 return NULL;
2156
2157 auto checkBaseType = val.mType->ToTypeInstance();
2158 if ((checkBaseType != NULL) && (checkBaseType->IsObject()) && (!arraySize))
2159 {
2160 bool hadDtorCall = false;
2161 while (checkBaseType != NULL)
2162 {
2163 BfMethodDef* dtorMethodDef = checkBaseType->mTypeDef->GetMethodByName("~this");
2164 if (dtorMethodDef != NULL)
2165 {
2166 auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector());
2167 if (dtorMethodInstance)
2168 {
2169 bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData));
2170 BfIRValue useVal = val.mValue;
2171
2172 BfIRBlock prevBlock = mBfIRBuilder->GetInsertBlock();
2173 if (valBlock)
2174 mBfIRBuilder->SetInsertPoint(valBlock);
2175 useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType));
2176 if (!useVal.IsConst())
2177 mBfIRBuilder->ClearDebugLocation(useVal);
2178 if (valBlock)
2179 mBfIRBuilder->SetInsertPoint(prevBlock);
2180
2181 if (isDynAlloc)
2182 {
2183 //
2184 }
2185 else if (condAlloca)
2186 {
2187 BF_ASSERT(!IsTargetingBeefBackend());
2188 BF_ASSERT(!isDynAlloc);
2189 auto valPtr = CreateAlloca(checkBaseType);
2190 mBfIRBuilder->ClearDebugLocation_Last();
2191 mBfIRBuilder->CreateAlignedStore(useVal, valPtr, checkBaseType->mAlign);
2192 mBfIRBuilder->ClearDebugLocation_Last();
2193 useVal = valPtr;
2194 }
2195
2196 SizedArray<BfIRValue, 1> llvmArgs;
2197 llvmArgs.push_back(useVal);
2198 auto deferredCall = AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true);
2199 if (deferredCall != NULL)
2200 {
2201 deferredCall->mCastThis = (val.mType != checkBaseType) && (!isDynAlloc);
2202 if (condAlloca)
2203 deferredCall->mArgsNeedLoad = true;
2204 }

Callers

nothing calls this directly

Calls 15

FailFunction · 0.85
IsDynMethod · 0.80
MapTypeInstPtrMethod · 0.80
ClearDebugLocationMethod · 0.80
MapTypeMethod · 0.80
CreateMulMethod · 0.80
ToTypeInstanceMethod · 0.45
IsObjectMethod · 0.45
GetMethodByNameMethod · 0.45
GetInsertBlockMethod · 0.45
SetInsertPointMethod · 0.45

Tested by

no test coverage detected