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
|
@ -416,7 +416,7 @@ void Beefy::BFFatalError(const StringImpl& message, const StringImpl& file, int
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStrF("FATAL ERROR: %s\n", message.c_str());
|
OutputDebugStrF("FATAL ERROR: %s\n", message.c_str());
|
||||||
_wassert(UTF8Decode(message).c_str(), UTF8Decode(file).c_str(), line);
|
_wassert(UTF8Decode(message).c_str(), UTF8Decode(file).c_str(), line);
|
||||||
#else
|
#else
|
||||||
String error = StrFormat("%s in %s:%d", message.c_str(), file.c_str(), line);
|
String error = StrFormat("%s in %s:%d", message.c_str(), file.c_str(), line);
|
||||||
|
|
|
@ -7576,16 +7576,14 @@ void BeMCContext::DoInstCombinePass()
|
||||||
continue;
|
continue;
|
||||||
auto vregInfoFrom = mVRegInfo[remapFrom];
|
auto vregInfoFrom = mVRegInfo[remapFrom];
|
||||||
auto vregInfoTo = mVRegInfo[remapTo];
|
auto vregInfoTo = mVRegInfo[remapTo];
|
||||||
int bestVRegIdx = (vregInfoFrom->mDefOrderIdx < vregInfoTo->mDefOrderIdx) ? remapFrom : remapTo;
|
int bestVRegIdx = remapTo;
|
||||||
//auto itr = defMap.find(remapTo);
|
//auto itr = defMap.find(remapTo);
|
||||||
//if (itr != defMap.end())
|
//if (itr != defMap.end())
|
||||||
|
|
||||||
int* prevBestVRegIdxPtr = NULL;
|
int* prevBestVRegIdxPtr = NULL;
|
||||||
if (defMap.TryGetValue(remapTo, &prevBestVRegIdxPtr))
|
if (defMap.TryGetValue(remapTo, &prevBestVRegIdxPtr))
|
||||||
{
|
{
|
||||||
auto prevBestVRegIdx = *prevBestVRegIdxPtr;
|
|
||||||
if (mVRegInfo[bestVRegIdx]->mDefOrderIdx < mVRegInfo[prevBestVRegIdx]->mDefOrderIdx)
|
|
||||||
defMap[remapTo] = bestVRegIdx;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
defMap[remapTo] = bestVRegIdx;
|
defMap[remapTo] = bestVRegIdx;
|
||||||
|
|
|
@ -748,8 +748,7 @@ public:
|
||||||
bool mMustExist; // Regs we must be able to debug
|
bool mMustExist; // Regs we must be able to debug
|
||||||
// Must be refreshed with RefreshRefCounts
|
// Must be refreshed with RefreshRefCounts
|
||||||
int mRefCount;
|
int mRefCount;
|
||||||
int mAssignCount;
|
int mAssignCount;
|
||||||
int mDefOrderIdx; // Indicates instruction # in def assignment
|
|
||||||
|
|
||||||
BeMCBlock* mClosedBlock;
|
BeMCBlock* mClosedBlock;
|
||||||
int mClosedInstIdx;
|
int mClosedInstIdx;
|
||||||
|
@ -789,8 +788,7 @@ public:
|
||||||
mAssignCount = -1;
|
mAssignCount = -1;
|
||||||
mVolatileVRegSave = -1;
|
mVolatileVRegSave = -1;
|
||||||
mMustExist = false;
|
mMustExist = false;
|
||||||
mIsRetVal = false;
|
mIsRetVal = false;
|
||||||
mDefOrderIdx = -1;
|
|
||||||
|
|
||||||
mClosedBlock = NULL;
|
mClosedBlock = NULL;
|
||||||
mClosedInstIdx = -1;
|
mClosedInstIdx = -1;
|
||||||
|
|
|
@ -3264,11 +3264,15 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode)
|
||||||
{
|
{
|
||||||
auto nextNode = mVisitorPos.GetNext();
|
auto nextNode = mVisitorPos.GetNext();
|
||||||
whenToken = BfNodeDynCast<BfTokenNode>(nextNode);
|
whenToken = BfNodeDynCast<BfTokenNode>(nextNode);
|
||||||
if ((whenToken != NULL) && (whenToken->GetToken() != BfToken_When))
|
if ((whenToken != NULL) && (whenToken->GetToken() == BfToken_When))
|
||||||
|
{
|
||||||
|
mVisitorPos.MoveNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
whenToken = NULL;
|
whenToken = NULL;
|
||||||
}
|
}
|
||||||
if (whenToken != NULL)
|
if (whenToken != NULL)
|
||||||
{
|
{
|
||||||
auto whenExpr = mAlloc->Alloc<BfWhenExpression>();
|
auto whenExpr = mAlloc->Alloc<BfWhenExpression>();
|
||||||
whenExpr->mWhenToken = whenToken;
|
whenExpr->mWhenToken = whenToken;
|
||||||
ReplaceNode(whenToken, whenExpr);
|
ReplaceNode(whenToken, whenExpr);
|
||||||
|
|
|
@ -4397,6 +4397,20 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
||||||
lastDefaultBlock = notEqBB;
|
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)
|
if (lastDefaultBlock)
|
||||||
mBfIRBuilder->SetSwitchDefaultDest(switchStatement, lastDefaultBlock);
|
mBfIRBuilder->SetSwitchDefaultDest(switchStatement, lastDefaultBlock);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue