mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Improved null conditional lhs cast location
This commit is contained in:
parent
4ef6723ac2
commit
096dc0aaa3
4 changed files with 40 additions and 16 deletions
|
@ -20555,10 +20555,12 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
{
|
{
|
||||||
leftValue = mModule->LoadValue(leftValue);
|
leftValue = mModule->LoadValue(leftValue);
|
||||||
|
|
||||||
auto prevBB = mModule->mBfIRBuilder->GetInsertBlock();
|
auto prevBB = mModule->mBfIRBuilder->GetInsertBlock();
|
||||||
|
|
||||||
auto rhsBB = mModule->mBfIRBuilder->CreateBlock("nullc.rhs");
|
auto rhsBB = mModule->mBfIRBuilder->CreateBlock("nullc.rhs");
|
||||||
auto endBB = mModule->mBfIRBuilder->CreateBlock("nullc.end");
|
auto endBB = mModule->mBfIRBuilder->CreateBlock("nullc.end");
|
||||||
|
auto lhsBB = endBB;
|
||||||
|
|
||||||
|
auto endLhsBB = prevBB;
|
||||||
|
|
||||||
BfIRValue isNull;
|
BfIRValue isNull;
|
||||||
if (leftValue.mType->IsFunction())
|
if (leftValue.mType->IsFunction())
|
||||||
|
@ -20567,7 +20569,6 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
else
|
else
|
||||||
isNull = mModule->mBfIRBuilder->CreateIsNull(leftValue.mValue);
|
isNull = mModule->mBfIRBuilder->CreateIsNull(leftValue.mValue);
|
||||||
|
|
||||||
|
|
||||||
mModule->AddBasicBlock(rhsBB);
|
mModule->AddBasicBlock(rhsBB);
|
||||||
BfTypedValue rightValue;
|
BfTypedValue rightValue;
|
||||||
if (assignTo != NULL)
|
if (assignTo != NULL)
|
||||||
|
@ -20583,7 +20584,7 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
rightValue = mModule->LoadValue(rightValue);
|
rightValue = mModule->LoadValue(rightValue);
|
||||||
|
|
||||||
if (assignTo == NULL)
|
if (assignTo == NULL)
|
||||||
{
|
{
|
||||||
auto rightToLeftValue = mModule->CastToValue(rightExpression, rightValue, leftValue.mType, BfCastFlags_SilentFail);
|
auto rightToLeftValue = mModule->CastToValue(rightExpression, rightValue, leftValue.mType, BfCastFlags_SilentFail);
|
||||||
if (rightToLeftValue)
|
if (rightToLeftValue)
|
||||||
{
|
{
|
||||||
|
@ -20591,7 +20592,8 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mModule->mBfIRBuilder->SetInsertPoint(prevBB);
|
lhsBB = mModule->mBfIRBuilder->CreateBlock("nullc.lhs", true);
|
||||||
|
mModule->mBfIRBuilder->SetInsertPoint(lhsBB);
|
||||||
|
|
||||||
auto leftToRightValue = mModule->CastToValue(leftExpression, leftValue, rightValue.mType, BfCastFlags_SilentFail);
|
auto leftToRightValue = mModule->CastToValue(leftExpression, leftValue, rightValue.mType, BfCastFlags_SilentFail);
|
||||||
if (leftToRightValue)
|
if (leftToRightValue)
|
||||||
|
@ -20605,7 +20607,9 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()), opToken);
|
mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()), opToken);
|
||||||
leftValue = mModule->GetDefaultTypedValue(rightValue.mType);
|
leftValue = mModule->GetDefaultTypedValue(rightValue.mType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mModule->mBfIRBuilder->CreateBr(endBB);
|
||||||
|
endLhsBB = mModule->mBfIRBuilder->GetInsertBlock();
|
||||||
mModule->mBfIRBuilder->SetInsertPoint(rhsBB);
|
mModule->mBfIRBuilder->SetInsertPoint(rhsBB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20615,10 +20619,10 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
|
|
||||||
mModule->mBfIRBuilder->CreateBr(endBB);
|
mModule->mBfIRBuilder->CreateBr(endBB);
|
||||||
auto endRhsBB = mModule->mBfIRBuilder->GetInsertBlock();
|
auto endRhsBB = mModule->mBfIRBuilder->GetInsertBlock();
|
||||||
|
|
||||||
// Actually add CondBr at start
|
// Actually add CondBr at start
|
||||||
mModule->mBfIRBuilder->SetInsertPoint(prevBB);
|
mModule->mBfIRBuilder->SetInsertPoint(prevBB);
|
||||||
mModule->mBfIRBuilder->CreateCondBr(isNull, rhsBB, endBB);
|
mModule->mBfIRBuilder->CreateCondBr(isNull, rhsBB, lhsBB);
|
||||||
|
|
||||||
mModule->AddBasicBlock(endBB);
|
mModule->AddBasicBlock(endBB);
|
||||||
|
|
||||||
|
@ -20629,7 +20633,7 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto phi = mModule->mBfIRBuilder->CreatePhi(mModule->mBfIRBuilder->MapType(leftValue.mType), 2);
|
auto phi = mModule->mBfIRBuilder->CreatePhi(mModule->mBfIRBuilder->MapType(leftValue.mType), 2);
|
||||||
mModule->mBfIRBuilder->AddPhiIncoming(phi, leftValue.mValue, prevBB);
|
mModule->mBfIRBuilder->AddPhiIncoming(phi, leftValue.mValue, endLhsBB);
|
||||||
mModule->mBfIRBuilder->AddPhiIncoming(phi, rightValue.mValue, endRhsBB);
|
mModule->mBfIRBuilder->AddPhiIncoming(phi, rightValue.mValue, endRhsBB);
|
||||||
mResult = BfTypedValue(phi, leftValue.mType);
|
mResult = BfTypedValue(phi, leftValue.mType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1915,7 +1915,7 @@ BfIRValue BfModule::CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime,
|
||||||
return allocaInst;
|
return allocaInst;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scopeData, bool condAlloca, bool mayEscape)
|
void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scopeData, bool condAlloca, bool mayEscape, BfIRBlock valBlock)
|
||||||
{
|
{
|
||||||
//This was removed because we want the alloc to be added to the __deferred list if it's actually a "stack"
|
//This was removed because we want the alloc to be added to the __deferred list if it's actually a "stack"
|
||||||
// 'stack' in a head scopeData is really the same as 'scopeData', so use the simpler scopeData handling
|
// 'stack' in a head scopeData is really the same as 'scopeData', so use the simpler scopeData handling
|
||||||
|
@ -1939,7 +1939,15 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
|
||||||
{
|
{
|
||||||
bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData));
|
bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData));
|
||||||
BfIRValue useVal = val.mValue;
|
BfIRValue useVal = val.mValue;
|
||||||
useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType));
|
|
||||||
|
BfIRBlock prevBlock = mBfIRBuilder->GetInsertBlock();
|
||||||
|
if (valBlock)
|
||||||
|
mBfIRBuilder->SetInsertPoint(valBlock);
|
||||||
|
useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType));
|
||||||
|
if (!useVal.IsConst())
|
||||||
|
mBfIRBuilder->ClearDebugLocation(useVal);
|
||||||
|
if (valBlock)
|
||||||
|
mBfIRBuilder->SetInsertPoint(prevBlock);
|
||||||
|
|
||||||
if (isDynAlloc)
|
if (isDynAlloc)
|
||||||
{
|
{
|
||||||
|
@ -1950,7 +1958,9 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
|
||||||
BF_ASSERT(!IsTargetingBeefBackend());
|
BF_ASSERT(!IsTargetingBeefBackend());
|
||||||
BF_ASSERT(!isDynAlloc);
|
BF_ASSERT(!isDynAlloc);
|
||||||
auto valPtr = CreateAlloca(checkBaseType);
|
auto valPtr = CreateAlloca(checkBaseType);
|
||||||
|
mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
mBfIRBuilder->CreateStore(useVal, valPtr);
|
mBfIRBuilder->CreateStore(useVal, valPtr);
|
||||||
|
mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
useVal = valPtr;
|
useVal = valPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1994,7 +2004,10 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
|
||||||
{
|
{
|
||||||
SizedArray<BfIRValue, 1> llvmArgs;
|
SizedArray<BfIRValue, 1> llvmArgs;
|
||||||
if (IsTargetingBeefBackend())
|
if (IsTargetingBeefBackend())
|
||||||
|
{
|
||||||
llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(nullPtrType)));
|
llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(nullPtrType)));
|
||||||
|
//mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
llvmArgs.push_back(val.mValue);
|
llvmArgs.push_back(val.mValue);
|
||||||
llvmArgs.push_back(GetConstValue(val.mType->mSize));
|
llvmArgs.push_back(GetConstValue(val.mType->mSize));
|
||||||
|
@ -2023,6 +2036,7 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
|
||||||
{
|
{
|
||||||
SizedArray<BfIRValue, 1> llvmArgs;
|
SizedArray<BfIRValue, 1> llvmArgs;
|
||||||
llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(nullPtrType)));
|
llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(nullPtrType)));
|
||||||
|
//mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
llvmArgs.push_back(clearSize);
|
llvmArgs.push_back(clearSize);
|
||||||
AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true);
|
AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true);
|
||||||
}
|
}
|
||||||
|
@ -2052,6 +2066,7 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
|
||||||
{
|
{
|
||||||
SizedArray<BfIRValue, 1> llvmArgs;
|
SizedArray<BfIRValue, 1> llvmArgs;
|
||||||
llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(nullPtrType)));
|
llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(nullPtrType)));
|
||||||
|
//mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true);
|
AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8829,13 +8844,14 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
||||||
auto allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(byteType), sizeValue);
|
auto allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(byteType), sizeValue);
|
||||||
if (!isDynAlloc)
|
if (!isDynAlloc)
|
||||||
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
||||||
|
auto allocaBlock = mBfIRBuilder->GetInsertBlock();
|
||||||
mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign);
|
mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign);
|
||||||
if (!isDynAlloc)
|
|
||||||
mBfIRBuilder->SetInsertPoint(prevBlock);
|
|
||||||
auto typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType);
|
auto typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType);
|
||||||
mBfIRBuilder->ClearDebugLocation_Last();
|
mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
|
if (!isDynAlloc)
|
||||||
|
mBfIRBuilder->SetInsertPoint(prevBlock);
|
||||||
if (!noDtorCall)
|
if (!noDtorCall)
|
||||||
AddStackAlloc(typedVal, BfIRValue(), NULL, scopeData, false, true);
|
AddStackAlloc(typedVal, BfIRValue(), NULL, scopeData, false, true, allocaBlock);
|
||||||
InitTypeInst(typedVal, scopeData, zeroMemory, sizeValue);
|
InitTypeInst(typedVal, scopeData, zeroMemory, sizeValue);
|
||||||
return typedVal.mValue;
|
return typedVal.mValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1573,7 +1573,7 @@ public:
|
||||||
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 CreateAlloca(BfType* type, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue());
|
||||||
BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL);
|
BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL);
|
||||||
void AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false);
|
void AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false, BfIRBlock valBlock = BfIRBlock());
|
||||||
void RestoreScoreState_LocalVariables();
|
void RestoreScoreState_LocalVariables();
|
||||||
void RestoreScopeState();
|
void RestoreScopeState();
|
||||||
void MarkDynStack(BfScopeData* scope);
|
void MarkDynStack(BfScopeData* scope);
|
||||||
|
|
|
@ -83,11 +83,15 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
||||||
mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock);
|
mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock);
|
||||||
auto allocaInst = mBfIRBuilder->CreateAlloca(origParamTypes[paramIdx]);
|
auto allocaInst = mBfIRBuilder->CreateAlloca(origParamTypes[paramIdx]);
|
||||||
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||||
if (WantsLifetimes())
|
if (WantsLifetimes())
|
||||||
|
{
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
|
mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
|
}
|
||||||
mBfIRBuilder->CreateStore(scopeArg, allocaInst);
|
mBfIRBuilder->CreateStore(scopeArg, allocaInst);
|
||||||
|
mBfIRBuilder->ClearDebugLocation_Last();
|
||||||
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst;
|
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst;
|
||||||
if (WantsLifetimes())
|
if (WantsLifetimes())
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue