mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Added support for "case when" (valueless) switch cases
This commit is contained in:
parent
3fd81fc966
commit
857c1c384a
5 changed files with 25 additions and 11 deletions
|
@ -7576,16 +7576,14 @@ void BeMCContext::DoInstCombinePass()
|
|||
continue;
|
||||
auto vregInfoFrom = mVRegInfo[remapFrom];
|
||||
auto vregInfoTo = mVRegInfo[remapTo];
|
||||
int bestVRegIdx = (vregInfoFrom->mDefOrderIdx < vregInfoTo->mDefOrderIdx) ? remapFrom : remapTo;
|
||||
int bestVRegIdx = remapTo;
|
||||
//auto itr = defMap.find(remapTo);
|
||||
//if (itr != defMap.end())
|
||||
|
||||
int* prevBestVRegIdxPtr = NULL;
|
||||
if (defMap.TryGetValue(remapTo, &prevBestVRegIdxPtr))
|
||||
{
|
||||
auto prevBestVRegIdx = *prevBestVRegIdxPtr;
|
||||
if (mVRegInfo[bestVRegIdx]->mDefOrderIdx < mVRegInfo[prevBestVRegIdx]->mDefOrderIdx)
|
||||
defMap[remapTo] = bestVRegIdx;
|
||||
|
||||
}
|
||||
else
|
||||
defMap[remapTo] = bestVRegIdx;
|
||||
|
|
|
@ -749,7 +749,6 @@ public:
|
|||
// Must be refreshed with RefreshRefCounts
|
||||
int mRefCount;
|
||||
int mAssignCount;
|
||||
int mDefOrderIdx; // Indicates instruction # in def assignment
|
||||
|
||||
BeMCBlock* mClosedBlock;
|
||||
int mClosedInstIdx;
|
||||
|
@ -790,7 +789,6 @@ public:
|
|||
mVolatileVRegSave = -1;
|
||||
mMustExist = false;
|
||||
mIsRetVal = false;
|
||||
mDefOrderIdx = -1;
|
||||
|
||||
mClosedBlock = NULL;
|
||||
mClosedInstIdx = -1;
|
||||
|
|
|
@ -3264,7 +3264,11 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
|
|||
{
|
||||
auto nextNode = mVisitorPos.GetNext();
|
||||
whenToken = BfNodeDynCast<BfTokenNode>(nextNode);
|
||||
if ((whenToken != NULL) && (whenToken->GetToken() != BfToken_When))
|
||||
if ((whenToken != NULL) && (whenToken->GetToken() == BfToken_When))
|
||||
{
|
||||
mVisitorPos.MoveNext();
|
||||
}
|
||||
else
|
||||
whenToken = NULL;
|
||||
}
|
||||
if (whenToken != NULL)
|
||||
|
|
|
@ -4397,6 +4397,20 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
lastDefaultBlock = notEqBB;
|
||||
}
|
||||
|
||||
if ((whenExpr != NULL) && (switchCase->mCaseExpressions.size() == 1))
|
||||
{
|
||||
// This was a "case when" expression, always matches
|
||||
mayHaveMatch = true;
|
||||
|
||||
auto notEqBB = mBfIRBuilder->CreateBlock(StrFormat("switch.notEq_when.%d", blockIdx));
|
||||
|
||||
mBfIRBuilder->CreateBr(caseBlock);
|
||||
mBfIRBuilder->AddBlock(notEqBB);
|
||||
mBfIRBuilder->SetInsertPoint(notEqBB);
|
||||
|
||||
lastNotEqBlock = notEqBB;
|
||||
}
|
||||
|
||||
if (lastDefaultBlock)
|
||||
mBfIRBuilder->SetSwitchDefaultDest(switchStatement, lastDefaultBlock);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue