1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 22:34:09 +02:00

More Fail info, better fail on OperandToAddr

This commit is contained in:
Brian Fiete 2020-08-03 10:00:32 -07:00
parent 99c7a9fe1f
commit 7e843bb402
2 changed files with 5783 additions and 5768 deletions

View file

@ -1906,6 +1906,7 @@ BeMCContext::BeMCContext(BeCOFFObject* coffObject) : mOut(coffObject->mTextSect.
mBeFunction = NULL; mBeFunction = NULL;
mActiveBeBlock = NULL; mActiveBeBlock = NULL;
mActiveBlock = NULL; mActiveBlock = NULL;
mActiveInst = NULL;
mDbgFunction = NULL; mDbgFunction = NULL;
mCompositeRetVRegIdx = -1; mCompositeRetVRegIdx = -1;
mTLSVRegIdx = -1; mTLSVRegIdx = -1;
@ -1933,6 +1934,16 @@ void BeMCContext::NotImpl()
void BeMCContext::Fail(const StringImpl& str) void BeMCContext::Fail(const StringImpl& str)
{ {
String errStr = StrFormat("Failure during codegen of %s in %s: %s", mBeFunction->mName.c_str(), mModule->mModuleName.c_str(), str.c_str()); String errStr = StrFormat("Failure during codegen of %s in %s: %s", mBeFunction->mName.c_str(), mModule->mModuleName.c_str(), str.c_str());
if (mActiveBlock != NULL)
errStr += StrFormat("\n MCBlock: %s", mActiveBlock->mName);
if ((mActiveInst != NULL) && (mActiveInst->mDbgLoc != NULL))
{
BeDumpContext dumpCtx;
errStr += "\n DbgLoc : ";
dumpCtx.ToString(errStr, mActiveInst->mDbgLoc);
}
BfpSystem_FatalError(errStr.c_str(), "FATAL ERROR"); BfpSystem_FatalError(errStr.c_str(), "FATAL ERROR");
} }
@ -3621,6 +3632,20 @@ BeMCOperand BeMCContext::GetImmediate(int64 val)
return operand; return operand;
} }
BeMCOperand BeMCContext::OperandToAddr(const BeMCOperand& operand)
{
BeMCOperand loadedOperand = operand;
if (loadedOperand.mKind == BeMCOperandKind_VRegLoad)
loadedOperand.mKind = BeMCOperandKind_VReg;
else if (loadedOperand.mKind == BeMCOperandKind_VReg)
loadedOperand.mKind = BeMCOperandKind_VRegAddr;
else if (loadedOperand.mKind == BeMCOperandKind_Symbol)
loadedOperand.mKind = BeMCOperandKind_SymbolAddr;
else
Fail("Invalid operand in OperandToAddr");
return loadedOperand;
}
BeMCOperand BeMCContext::GetVReg(int regNum) BeMCOperand BeMCContext::GetVReg(int regNum)
{ {
auto vregInfo = mVRegInfo[regNum]; auto vregInfo = mVRegInfo[regNum];
@ -3877,7 +3902,7 @@ BeMCOperand BeMCContext::ReplaceWithNewVReg(BeMCOperand& operand, int& instIdx,
{ {
if ((isInput) && (operand.mKind == BeMCOperandKind_VRegLoad) && (preserveDeref)) if ((isInput) && (operand.mKind == BeMCOperandKind_VRegLoad) && (preserveDeref))
{ {
BeMCOperand addrOperand = BeMCOperand::ToAddr(operand); BeMCOperand addrOperand = OperandToAddr(operand);
BeMCOperand scratchReg = AllocVirtualReg(GetType(addrOperand), 2, mustBeReg); BeMCOperand scratchReg = AllocVirtualReg(GetType(addrOperand), 2, mustBeReg);
CreateDefineVReg(scratchReg, instIdx++); CreateDefineVReg(scratchReg, instIdx++);
AllocInst(BeMCInstKind_Mov, scratchReg, addrOperand, instIdx++); AllocInst(BeMCInstKind_Mov, scratchReg, addrOperand, instIdx++);
@ -5127,7 +5152,7 @@ void BeMCContext::FixOperand(BeMCOperand& operand)
{ {
if (checkOperand.mKind == BeMCOperandKind_VRegAddr) if (checkOperand.mKind == BeMCOperandKind_VRegAddr)
{ {
operand = BeMCOperand::ToAddr(checkOperand); operand = OperandToAddr(checkOperand);
} }
else else
operand = checkOperand; operand = checkOperand;
@ -5458,12 +5483,12 @@ void BeMCContext::GetRMParams(const BeMCOperand& operand, BeRMParamsInfo& rmInfo
return ValidateRMResult(operand, rmInfo, doValidate); return ValidateRMResult(operand, rmInfo, doValidate);
} }
GetRMParams(BeMCOperand::ToAddr(operand), rmInfo, doValidate); GetRMParams(OperandToAddr(operand), rmInfo, doValidate);
if (rmInfo.mMode == BeMCRMMode_Invalid) if (rmInfo.mMode == BeMCRMMode_Invalid)
return; return;
BF_ASSERT(rmInfo.mMode == BeMCRMMode_Direct); BF_ASSERT(rmInfo.mMode == BeMCRMMode_Direct);
rmInfo.mMode = BeMCRMMode_Deref; rmInfo.mMode = BeMCRMMode_Deref;
return ValidateRMResult(BeMCOperand::ToAddr(operand), rmInfo, doValidate); return ValidateRMResult(OperandToAddr(operand), rmInfo, doValidate);
} }
// Fall through // Fall through
} }
@ -7921,7 +7946,7 @@ void BeMCContext::DoInstCombinePass()
if (operand->mKind == BeMCOperandKind_VReg) if (operand->mKind == BeMCOperandKind_VReg)
*operand = vregInfo->mRelTo; *operand = vregInfo->mRelTo;
else if (operand->mKind == BeMCOperandKind_VRegAddr) else if (operand->mKind == BeMCOperandKind_VRegAddr)
*operand = BeMCOperand::ToAddr(vregInfo->mRelTo); *operand = OperandToAddr(vregInfo->mRelTo);
} }
} }
}; };
@ -8440,6 +8465,7 @@ bool BeMCContext::DoLegalization()
auto inst = mcBlock->mInstructions[instIdx]; auto inst = mcBlock->mInstructions[instIdx];
SetCurrentInst(inst); SetCurrentInst(inst);
mActiveInst = inst;
if (inst->mKind == BeMCInstKind_Mov) if (inst->mKind == BeMCInstKind_Mov)
{ {
@ -9909,7 +9935,7 @@ bool BeMCContext::DoLegalization()
BF_ASSERT(arg1.mImmediate == 0); BF_ASSERT(arg1.mImmediate == 0);
SetAndRestoreValue<int*> insertPtr(mInsertInstIdxRef, &instIdx); SetAndRestoreValue<int*> insertPtr(mInsertInstIdxRef, &instIdx);
RemoveInst(mcBlock, instIdx); RemoveInst(mcBlock, instIdx);
CreateMemSet(BeMCOperand::ToAddr(arg0), 0, arg0Type->mSize, arg0Type->mAlign); CreateMemSet(OperandToAddr(arg0), 0, arg0Type->mSize, arg0Type->mAlign);
instIdx--; instIdx--;
isFinalRun = false; isFinalRun = false;
if (debugging) if (debugging)
@ -9985,8 +10011,8 @@ bool BeMCContext::DoLegalization()
// Struct = Struct // Struct = Struct
else //if (arg1.mKind == BeMCOperandKind_VReg) else //if (arg1.mKind == BeMCOperandKind_VReg)
{ {
auto arg0Addr = BeMCOperand::ToAddr(arg0); auto arg0Addr = OperandToAddr(arg0);
auto arg1Addr = BeMCOperand::ToAddr(arg1); auto arg1Addr = OperandToAddr(arg1);
SetAndRestoreValue<int*> insertPtr(mInsertInstIdxRef, &instIdx); SetAndRestoreValue<int*> insertPtr(mInsertInstIdxRef, &instIdx);
RemoveInst(mcBlock, instIdx); RemoveInst(mcBlock, instIdx);
CreateMemCpy(arg0Addr, arg1Addr, BF_MIN(arg0Type->mSize, arg1Type->mSize), BF_MIN(arg0Type->mAlign, arg1Type->mAlign)); CreateMemCpy(arg0Addr, arg1Addr, BF_MIN(arg0Type->mSize, arg1Type->mSize), BF_MIN(arg0Type->mAlign, arg1Type->mAlign));
@ -10174,7 +10200,7 @@ bool BeMCContext::DoLegalization()
auto origType = GetType(origOperand); auto origType = GetType(origOperand);
BeMCOperand scratchReg = AllocVirtualReg(mModule->mContext->GetPointerTo(origType), 2, false); BeMCOperand scratchReg = AllocVirtualReg(mModule->mContext->GetPointerTo(origType), 2, false);
CreateDefineVReg(scratchReg, safeIdx++); CreateDefineVReg(scratchReg, safeIdx++);
AllocInst(BeMCInstKind_Mov, scratchReg, BeMCOperand::ToAddr(origOperand), safeIdx++); AllocInst(BeMCInstKind_Mov, scratchReg, OperandToAddr(origOperand), safeIdx++);
auto newVRegInfo = GetVRegInfo(scratchReg); auto newVRegInfo = GetVRegInfo(scratchReg);
newVRegInfo->mDisableRAX = true; newVRegInfo->mDisableRAX = true;
@ -10305,6 +10331,7 @@ bool BeMCContext::DoLegalization()
dbgVar->mPendingInitType = BfIRInitType_NotNeeded;*/ dbgVar->mPendingInitType = BfIRInitType_NotNeeded;*/
} }
} }
mActiveInst = NULL;
} }
BF_ASSERT(regPreserveDepth == 0); BF_ASSERT(regPreserveDepth == 0);

View file

@ -388,20 +388,6 @@ public:
return loadedOperand; return loadedOperand;
} }
static BeMCOperand ToAddr(const BeMCOperand& operand)
{
BeMCOperand loadedOperand = operand;
if (loadedOperand.mKind == BeMCOperandKind_VRegLoad)
loadedOperand.mKind = BeMCOperandKind_VReg;
else if (loadedOperand.mKind == BeMCOperandKind_VReg)
loadedOperand.mKind = BeMCOperandKind_VRegAddr;
else if (loadedOperand.mKind == BeMCOperandKind_Symbol)
loadedOperand.mKind = BeMCOperandKind_SymbolAddr;
else
BF_FATAL("Bad");
return loadedOperand;
}
static BeMCOperand FromVReg(int vregIdx) static BeMCOperand FromVReg(int vregIdx)
{ {
BeMCOperand operand; BeMCOperand operand;
@ -1322,6 +1308,7 @@ public:
BeType* mNativeIntType; BeType* mNativeIntType;
BeModule* mModule; BeModule* mModule;
BeMCBlock* mActiveBlock; BeMCBlock* mActiveBlock;
BeMCInst* mActiveInst;
int* mInsertInstIdxRef; int* mInsertInstIdxRef;
BeBlock* mActiveBeBlock; BeBlock* mActiveBeBlock;
BeFunction* mBeFunction; BeFunction* mBeFunction;
@ -1383,6 +1370,7 @@ public:
void CreateCondBr(BeMCBlock* mcBlock, BeMCOperand& testVal, const BeMCOperand& trueBlock, const BeMCOperand& falseBlock); void CreateCondBr(BeMCBlock* mcBlock, BeMCOperand& testVal, const BeMCOperand& trueBlock, const BeMCOperand& falseBlock);
void CreatePhiAssign(BeMCBlock* mcBlock, const BeMCOperand& testVal, const BeMCOperand& result, const BeMCOperand& doneLabel); void CreatePhiAssign(BeMCBlock* mcBlock, const BeMCOperand& testVal, const BeMCOperand& result, const BeMCOperand& doneLabel);
BeMCOperand GetImmediate(int64 val); BeMCOperand GetImmediate(int64 val);
BeMCOperand OperandToAddr(const BeMCOperand& operand);
BeMCOperand GetVReg(int regNum); BeMCOperand GetVReg(int regNum);
BeMCOperand AllocVirtualReg(BeType* type, int refCount = -1, bool mustBeReg = false); BeMCOperand AllocVirtualReg(BeType* type, int refCount = -1, bool mustBeReg = false);
int GetUnderlyingVReg(int vregIdx); int GetUnderlyingVReg(int vregIdx);