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:
parent
99c7a9fe1f
commit
7e843bb402
2 changed files with 5783 additions and 5768 deletions
|
@ -21,7 +21,7 @@ USING_NS_BF;
|
||||||
const int BF_REP_MOV_LIMIT = 128;
|
const int BF_REP_MOV_LIMIT = 128;
|
||||||
|
|
||||||
static const X64CPURegister gVolatileRegs[] = { X64Reg_RAX, X64Reg_RCX, X64Reg_RDX, X64Reg_R8, X64Reg_R9, X64Reg_R10, X64Reg_R11,
|
static const X64CPURegister gVolatileRegs[] = { X64Reg_RAX, X64Reg_RCX, X64Reg_RDX, X64Reg_R8, X64Reg_R9, X64Reg_R10, X64Reg_R11,
|
||||||
X64Reg_XMM0_f64, X64Reg_XMM1_f64, X64Reg_XMM2_f64, X64Reg_XMM3_f64, X64Reg_XMM4_f64, X64Reg_XMM5_f64};
|
X64Reg_XMM0_f64, X64Reg_XMM1_f64, X64Reg_XMM2_f64, X64Reg_XMM3_f64, X64Reg_XMM4_f64, X64Reg_XMM5_f64 };
|
||||||
|
|
||||||
static const char* gOpName[] =
|
static const char* gOpName[] =
|
||||||
{
|
{
|
||||||
|
@ -153,7 +153,7 @@ int BeVTrackingContext::GetBitsBytes()
|
||||||
|
|
||||||
int BeVTrackingContext::GetIdx(int baseIdx, BeTrackKind liveKind)
|
int BeVTrackingContext::GetIdx(int baseIdx, BeTrackKind liveKind)
|
||||||
{
|
{
|
||||||
return baseIdx + mNumItems*(int)liveKind;
|
return baseIdx + mNumItems * (int)liveKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeVTrackingContext::Print(BeVTrackingList* list)
|
void BeVTrackingContext::Print(BeVTrackingList* list)
|
||||||
|
@ -900,8 +900,8 @@ void BeMCColorizer::Prepare()
|
||||||
(!vregInfo->mIsExpr) && (!vregInfo->mForceMem) && (vregInfo->mFrameOffset == INT_MIN));
|
(!vregInfo->mIsExpr) && (!vregInfo->mForceMem) && (vregInfo->mFrameOffset == INT_MIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (vregInfo->mIsRetVal)
|
// if (vregInfo->mIsRetVal)
|
||||||
// node->mWantsReg = true;
|
// node->mWantsReg = true;
|
||||||
if (!node->mWantsReg)
|
if (!node->mWantsReg)
|
||||||
vregInfo->mReg = X64Reg_None;
|
vregInfo->mReg = X64Reg_None;
|
||||||
vregInfo->mVRegAffinity = -1;
|
vregInfo->mVRegAffinity = -1;
|
||||||
|
@ -1352,21 +1352,21 @@ void BeMCColorizer::AssignRegs(RegKind regKind)
|
||||||
{
|
{
|
||||||
bool hadNewStackItem = false;
|
bool hadNewStackItem = false;
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// for (int graphIdx = 0; graphIdx < (int)vregGraph.size(); graphIdx++)
|
// for (int graphIdx = 0; graphIdx < (int)vregGraph.size(); graphIdx++)
|
||||||
// {
|
// {
|
||||||
// int validatedCount = 0;
|
// int validatedCount = 0;
|
||||||
// int vregIdx = vregGraph[graphIdx];
|
// int vregIdx = vregGraph[graphIdx];
|
||||||
// if (vregIdx == -1)
|
// if (vregIdx == -1)
|
||||||
// continue;
|
// continue;
|
||||||
// Node* node = &mNodes[vregIdx];
|
// Node* node = &mNodes[vregIdx];
|
||||||
// for (auto connNodeIdx : node->mEdges)
|
// for (auto connNodeIdx : node->mEdges)
|
||||||
// {
|
// {
|
||||||
// Node* connNode = &mNodes[connNodeIdx];
|
// Node* connNode = &mNodes[connNodeIdx];
|
||||||
// if (connNode->mInGraph)
|
// if (connNode->mInGraph)
|
||||||
// validatedCount++;
|
// validatedCount++;
|
||||||
// }
|
// }
|
||||||
// BF_ASSERT(validatedCount == node->mGraphEdgeCount);
|
// BF_ASSERT(validatedCount == node->mGraphEdgeCount);
|
||||||
// }
|
// }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int graphIdx = 0; graphIdx < (int)vregGraph.size(); graphIdx++)
|
for (int graphIdx = 0; graphIdx < (int)vregGraph.size(); graphIdx++)
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2916,7 +2927,7 @@ BeMCOperand BeMCContext::CreateCall(const BeMCOperand& func, const SizedArrayImp
|
||||||
}
|
}
|
||||||
|
|
||||||
bool didPreserveRegs = false;
|
bool didPreserveRegs = false;
|
||||||
auto _AddPreserveRegs = [&] ()
|
auto _AddPreserveRegs = [&]()
|
||||||
{
|
{
|
||||||
if (noReturn)
|
if (noReturn)
|
||||||
AllocInst(BeMCInstKind_PreserveVolatiles, BeMCOperand::FromPreserveFlag(BeMCPreserveFlag_NoRestore));
|
AllocInst(BeMCInstKind_PreserveVolatiles, BeMCOperand::FromPreserveFlag(BeMCPreserveFlag_NoRestore));
|
||||||
|
@ -2991,7 +3002,7 @@ BeMCOperand BeMCContext::CreateCall(const BeMCOperand& func, const SizedArrayImp
|
||||||
|
|
||||||
if ((shadowReg != X64Reg_None) && (useReg != X64Reg_None))
|
if ((shadowReg != X64Reg_None) && (useReg != X64Reg_None))
|
||||||
{
|
{
|
||||||
shadowRegs.push_back(_ShadowReg { useReg, shadowReg} );
|
shadowRegs.push_back(_ShadowReg{ useReg, shadowReg });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3065,7 +3076,7 @@ BeMCOperand BeMCContext::CreateCall(const BeMCOperand& func, const SizedArrayImp
|
||||||
|
|
||||||
auto mcFunc = func;
|
auto mcFunc = func;
|
||||||
|
|
||||||
for (auto& shadowReg : shadowRegs ) // Do float shadowing
|
for (auto& shadowReg : shadowRegs) // Do float shadowing
|
||||||
{
|
{
|
||||||
AllocInst(BeMCInstKind_MovRaw, BeMCOperand::FromReg(shadowReg.mIReg), BeMCOperand::FromReg(shadowReg.mFReg));
|
AllocInst(BeMCInstKind_MovRaw, BeMCOperand::FromReg(shadowReg.mIReg), BeMCOperand::FromReg(shadowReg.mFReg));
|
||||||
}
|
}
|
||||||
|
@ -3449,7 +3460,7 @@ void BeMCContext::CreateCondBr(BeMCBlock* mcBlock, BeMCOperand& testVal, const B
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
auto _CheckBlock = [&] (BeMCBlock* block)
|
auto _CheckBlock = [&](BeMCBlock* block)
|
||||||
{
|
{
|
||||||
for (int checkIdx = (int)block->mInstructions.size() - 1; checkIdx >= 0; checkIdx--)
|
for (int checkIdx = (int)block->mInstructions.size() - 1; checkIdx >= 0; checkIdx--)
|
||||||
{
|
{
|
||||||
|
@ -3562,7 +3573,7 @@ void BeMCContext::CreatePhiAssign(BeMCBlock* mcBlock, const BeMCOperand& testVal
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
auto _CheckBlock = [&] (BeMCBlock* block)
|
auto _CheckBlock = [&](BeMCBlock* block)
|
||||||
{
|
{
|
||||||
SetAndRestoreValue<BeMCBlock*> prevActiveBlock(mActiveBlock, block);
|
SetAndRestoreValue<BeMCBlock*> prevActiveBlock(mActiveBlock, block);
|
||||||
for (int checkIdx = (int)block->mInstructions.size() - 1; checkIdx >= 0; checkIdx--)
|
for (int checkIdx = (int)block->mInstructions.size() - 1; checkIdx >= 0; checkIdx--)
|
||||||
|
@ -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++);
|
||||||
|
@ -4274,7 +4299,7 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC
|
||||||
|
|
||||||
if ((inst->mVRegsInitialized != NULL) && (inst->mVRegsInitialized != vregsInitialized))
|
if ((inst->mVRegsInitialized != NULL) && (inst->mVRegsInitialized != vregsInitialized))
|
||||||
{
|
{
|
||||||
auto _VRegUninit = [&] (int vregIdxEx)
|
auto _VRegUninit = [&](int vregIdxEx)
|
||||||
{
|
{
|
||||||
int vregIdx = vregIdxEx % mVRegInitializedContext.mNumItems;
|
int vregIdx = vregIdxEx % mVRegInitializedContext.mNumItems;
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -5941,7 +5966,7 @@ void BeMCContext::EmitModRM(int rx, BeMCOperand rm, int relocOfs)
|
||||||
if (sym->mIsTLS)
|
if (sym->mIsTLS)
|
||||||
{
|
{
|
||||||
auto vregInfo = mVRegInfo[mTLSVRegIdx];
|
auto vregInfo = mVRegInfo[mTLSVRegIdx];
|
||||||
modRM |= (2<<6) | EncodeRegNum(vregInfo->mReg);
|
modRM |= (2 << 6) | EncodeRegNum(vregInfo->mReg);
|
||||||
reloc.mKind = BeMCRelocationKind_SECREL;
|
reloc.mKind = BeMCRelocationKind_SECREL;
|
||||||
relocOfs = 0;
|
relocOfs = 0;
|
||||||
}
|
}
|
||||||
|
@ -6265,7 +6290,7 @@ void BeMCContext::InitializedPassHelper(BeMCBlock* mcBlock, BeVTrackingGenContex
|
||||||
int listIdx = mVRegInitializedContext.FindIndex(vregsInitialized, startVRegIdx);
|
int listIdx = mVRegInitializedContext.FindIndex(vregsInitialized, startVRegIdx);
|
||||||
if (listIdx < 0)
|
if (listIdx < 0)
|
||||||
listIdx = ~listIdx;
|
listIdx = ~listIdx;
|
||||||
for ( ; listIdx < vregsInitialized->mSize; listIdx++)
|
for (; listIdx < vregsInitialized->mSize; listIdx++)
|
||||||
{
|
{
|
||||||
int vregIdx = vregsInitialized->mEntries[listIdx];
|
int vregIdx = vregsInitialized->mEntries[listIdx];
|
||||||
if (vregIdx >= endVRegIdx)
|
if (vregIdx >= endVRegIdx)
|
||||||
|
@ -6701,14 +6726,14 @@ bool BeMCContext::DoInitializedPass()
|
||||||
{
|
{
|
||||||
// Unused block - clear almost all instructions
|
// Unused block - clear almost all instructions
|
||||||
int newIdx = 0;
|
int newIdx = 0;
|
||||||
// for (int instIdx = 0; instIdx < (int)mcBlock->mInstructions.size(); instIdx++)
|
// for (int instIdx = 0; instIdx < (int)mcBlock->mInstructions.size(); instIdx++)
|
||||||
// {
|
// {
|
||||||
// auto inst = mcBlock->mInstructions[instIdx];
|
// auto inst = mcBlock->mInstructions[instIdx];
|
||||||
// if (inst->mKind == BeMCInstKind_ValueScopeHardEnd)
|
// if (inst->mKind == BeMCInstKind_ValueScopeHardEnd)
|
||||||
// {
|
// {
|
||||||
// mcBlock->mInstructions[newIdx++] = inst;
|
// mcBlock->mInstructions[newIdx++] = inst;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
mcBlock->mInstructions.mSize = newIdx;
|
mcBlock->mInstructions.mSize = newIdx;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -6883,7 +6908,7 @@ void BeMCContext::DoSplitLargeBlocks()
|
||||||
Dictionary<int, int> blockEndRemap;
|
Dictionary<int, int> blockEndRemap;
|
||||||
|
|
||||||
int splitSize = 4096;
|
int splitSize = 4096;
|
||||||
int maxBlockSize = splitSize + splitSize/4;
|
int maxBlockSize = splitSize + splitSize / 4;
|
||||||
bool hadSplits = false;
|
bool hadSplits = false;
|
||||||
|
|
||||||
for (int blockIdx = 0; blockIdx < mBlocks.size(); blockIdx++)
|
for (int blockIdx = 0; blockIdx < mBlocks.size(); blockIdx++)
|
||||||
|
@ -6948,17 +6973,17 @@ void BeMCContext::DoSplitLargeBlocks()
|
||||||
if (!hadSplits)
|
if (!hadSplits)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// for (int blockIdx = 0; blockIdx < mBlocks.size(); blockIdx++)
|
// for (int blockIdx = 0; blockIdx < mBlocks.size(); blockIdx++)
|
||||||
// {
|
// {
|
||||||
// auto mcBlock = mBlocks[blockIdx];
|
// auto mcBlock = mBlocks[blockIdx];
|
||||||
// for (auto inst : mcBlock->mInstructions)
|
// for (auto inst : mcBlock->mInstructions)
|
||||||
// {
|
// {
|
||||||
// if (inst->mResult.mKind == BeMCOperandKind_Phi)
|
// if (inst->mResult.mKind == BeMCOperandKind_Phi)
|
||||||
// {
|
// {
|
||||||
// inst->mResult.mP
|
// inst->mResult.mP
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
for (int blockIdx = 0; blockIdx < mBlocks.size(); blockIdx++)
|
for (int blockIdx = 0; blockIdx < mBlocks.size(); blockIdx++)
|
||||||
mBlocks[blockIdx]->mBlockIdx = blockIdx;
|
mBlocks[blockIdx]->mBlockIdx = blockIdx;
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -8519,13 +8545,13 @@ bool BeMCContext::DoLegalization()
|
||||||
badOperand = true;
|
badOperand = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool isSimple = (rmForm == BeMCRMMode_Direct) && (regB == X64Reg_None) && (bScale == 1) && (disp == 0);
|
// bool isSimple = (rmForm == BeMCRMMode_Direct) && (regB == X64Reg_None) && (bScale == 1) && (disp == 0);
|
||||||
// if ((!isSimple) && (oprIdx == 1) && (!arg0isSimple))
|
// if ((!isSimple) && (oprIdx == 1) && (!arg0isSimple))
|
||||||
// {
|
// {
|
||||||
// NOP;
|
// NOP;
|
||||||
// }
|
// }
|
||||||
// if (oprIdx == 0)
|
// if (oprIdx == 0)
|
||||||
// arg0isSimple = isSimple;
|
// arg0isSimple = isSimple;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (badOperand)
|
if (badOperand)
|
||||||
|
@ -9666,16 +9692,16 @@ bool BeMCContext::DoLegalization()
|
||||||
bool isLegal = true;
|
bool isLegal = true;
|
||||||
int64 immediateInt = inst->mArg1.GetImmediateInt();
|
int64 immediateInt = inst->mArg1.GetImmediateInt();
|
||||||
|
|
||||||
// if (inst->mKind == BeMCInstKind_Mul)
|
// if (inst->mKind == BeMCInstKind_Mul)
|
||||||
// {
|
// {
|
||||||
// if (immediateInt > 0xFFFFFFFFLL)
|
// if (immediateInt > 0xFFFFFFFFLL)
|
||||||
// isLegal = false;
|
// isLegal = false;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// if ((immediateInt < -0x80000000LL) || (immediateInt > 0x7FFFFFFF))
|
// if ((immediateInt < -0x80000000LL) || (immediateInt > 0x7FFFFFFF))
|
||||||
// isLegal = false;
|
// isLegal = false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!GetFixedOperand(inst->mResult).IsNativeReg())
|
if (!GetFixedOperand(inst->mResult).IsNativeReg())
|
||||||
{
|
{
|
||||||
|
@ -9803,7 +9829,7 @@ bool BeMCContext::DoLegalization()
|
||||||
int checkInstIdx = instIdx + 1;
|
int checkInstIdx = instIdx + 1;
|
||||||
auto checkBlock = mcBlock;
|
auto checkBlock = mcBlock;
|
||||||
|
|
||||||
for ( ; checkInstIdx < (int)checkBlock->mInstructions.size(); checkInstIdx++)
|
for (; checkInstIdx < (int)checkBlock->mInstructions.size(); checkInstIdx++)
|
||||||
{
|
{
|
||||||
auto checkInst = checkBlock->mInstructions[checkInstIdx];
|
auto checkInst = checkBlock->mInstructions[checkInstIdx];
|
||||||
if ((checkInst->mKind == BeMCInstKind_CondBr) || (checkInst->mKind == BeMCInstKind_CmpToBool))
|
if ((checkInst->mKind == BeMCInstKind_CondBr) || (checkInst->mKind == BeMCInstKind_CmpToBool))
|
||||||
|
@ -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);
|
||||||
|
@ -12464,7 +12491,7 @@ void BeMCContext::DoCodeEmission()
|
||||||
{
|
{
|
||||||
int frameReg = 5;
|
int frameReg = 5;
|
||||||
int offset = 0; // scaled by 16
|
int offset = 0; // scaled by 16
|
||||||
xdata.Write((uint8)(frameReg + (offset<<4))); // frame register
|
xdata.Write((uint8)(frameReg + (offset << 4))); // frame register
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
xdata.Write((uint8)0); // frame register
|
xdata.Write((uint8)0); // frame register
|
||||||
|
@ -12976,7 +13003,7 @@ void BeMCContext::DoCodeEmission()
|
||||||
if ((srcReg == destReg) && (srcOfs == destOfs))
|
if ((srcReg == destReg) && (srcOfs == destOfs))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for ( ; curOfs <= memSize - 8 ; curOfs += 8)
|
for (; curOfs <= memSize - 8; curOfs += 8)
|
||||||
{
|
{
|
||||||
EmitREX(BeMCOperand::FromReg(X64Reg_R11), BeMCOperand::FromReg(srcReg), true);
|
EmitREX(BeMCOperand::FromReg(X64Reg_R11), BeMCOperand::FromReg(srcReg), true);
|
||||||
Emit(0x8B);
|
Emit(0x8B);
|
||||||
|
@ -13003,7 +13030,7 @@ void BeMCContext::DoCodeEmission()
|
||||||
curOfs = memSize;
|
curOfs = memSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; curOfs <= memSize - 4; curOfs += 4)
|
for (; curOfs <= memSize - 4; curOfs += 4)
|
||||||
{
|
{
|
||||||
EmitREX(BeMCOperand::FromReg(X64Reg_R11D), BeMCOperand::FromReg(srcReg), false);
|
EmitREX(BeMCOperand::FromReg(X64Reg_R11D), BeMCOperand::FromReg(srcReg), false);
|
||||||
Emit(0x8B);
|
Emit(0x8B);
|
||||||
|
@ -13014,7 +13041,7 @@ void BeMCContext::DoCodeEmission()
|
||||||
EmitModRMRel(EncodeRegNum(X64Reg_R11D), destReg, X64Reg_None, 1, curOfs + destOfs);
|
EmitModRMRel(EncodeRegNum(X64Reg_R11D), destReg, X64Reg_None, 1, curOfs + destOfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; curOfs <= memSize - 2; curOfs += 2)
|
for (; curOfs <= memSize - 2; curOfs += 2)
|
||||||
{
|
{
|
||||||
Emit(0x66); EmitREX(BeMCOperand::FromReg(X64Reg_R11W), BeMCOperand::FromReg(srcReg), false);
|
Emit(0x66); EmitREX(BeMCOperand::FromReg(X64Reg_R11W), BeMCOperand::FromReg(srcReg), false);
|
||||||
Emit(0x8B);
|
Emit(0x8B);
|
||||||
|
@ -13025,7 +13052,7 @@ void BeMCContext::DoCodeEmission()
|
||||||
EmitModRMRel(EncodeRegNum(X64Reg_R11W), destReg, X64Reg_None, 1, curOfs + destOfs);
|
EmitModRMRel(EncodeRegNum(X64Reg_R11W), destReg, X64Reg_None, 1, curOfs + destOfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; curOfs <= memSize - 1; curOfs += 1)
|
for (; curOfs <= memSize - 1; curOfs += 1)
|
||||||
{
|
{
|
||||||
EmitREX(BeMCOperand::FromReg(X64Reg_R11B), BeMCOperand::FromReg(srcReg), false);
|
EmitREX(BeMCOperand::FromReg(X64Reg_R11B), BeMCOperand::FromReg(srcReg), false);
|
||||||
Emit(0x8B - 1);
|
Emit(0x8B - 1);
|
||||||
|
@ -13145,8 +13172,8 @@ void BeMCContext::DoCodeEmission()
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
BeDbgVariableRange gapRange = range;
|
BeDbgVariableRange gapRange = range;
|
||||||
// gapRange.mOffset++;
|
// gapRange.mOffset++;
|
||||||
// gapRange.mLength--;
|
// gapRange.mLength--;
|
||||||
vregInfo->mDbgVariable->mGaps.push_back(gapRange);
|
vregInfo->mDbgVariable->mGaps.push_back(gapRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15534,9 +15561,9 @@ void BeMCContext::Generate(BeFunction* function)
|
||||||
|
|
||||||
//mDbgPreferredRegs[8] = X64Reg_RAX;
|
//mDbgPreferredRegs[8] = X64Reg_RAX;
|
||||||
mDebugging = (function->mName == "?Main@Program@Mintest2@bf@@SAXXZ");
|
mDebugging = (function->mName == "?Main@Program@Mintest2@bf@@SAXXZ");
|
||||||
// || (function->mName == "?__BfStaticCtor@roboto_font@Drawing@ClassicUO_assistant@bf@@SAXXZ")
|
// || (function->mName == "?__BfStaticCtor@roboto_font@Drawing@ClassicUO_assistant@bf@@SAXXZ")
|
||||||
// || (function->mName == "?Hey@Blurg@bf@@SAXXZ")
|
// || (function->mName == "?Hey@Blurg@bf@@SAXXZ")
|
||||||
// ;
|
// ;
|
||||||
//"?ColorizeCodeString@IDEUtils@IDE@bf@@SAXPEAVString@System@3@W4CodeKind@123@@Z";
|
//"?ColorizeCodeString@IDEUtils@IDE@bf@@SAXPEAVString@System@3@W4CodeKind@123@@Z";
|
||||||
//"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z";
|
//"?Main@Program@bf@@CAHPEAV?$Array1@PEAVString@System@bf@@@System@2@@Z";
|
||||||
|
|
||||||
|
@ -15663,14 +15690,14 @@ void BeMCContext::Generate(BeFunction* function)
|
||||||
auto mcInst = AllocInst();
|
auto mcInst = AllocInst();
|
||||||
mcInst->mKind = BeMCInstKind_Unreachable;
|
mcInst->mKind = BeMCInstKind_Unreachable;
|
||||||
|
|
||||||
// if (instIdx == beBlock->mInstructions.size() - 1)
|
// if (instIdx == beBlock->mInstructions.size() - 1)
|
||||||
// {
|
// {
|
||||||
// // Fake branch to exit
|
// // Fake branch to exit
|
||||||
// mcInst = AllocInst();
|
// mcInst = AllocInst();
|
||||||
// mcInst->mKind = BeMCInstKind_Br;
|
// mcInst->mKind = BeMCInstKind_Br;
|
||||||
// mcInst->mArg0 = BeMCOperand::FromBlock(mBlocks.back());
|
// mcInst->mArg0 = BeMCOperand::FromBlock(mBlocks.back());
|
||||||
// mcInst->mArg0.mBlock->AddPred(mcBlock);
|
// mcInst->mArg0.mBlock->AddPred(mcBlock);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BeEnsureInstructionAtInst::TypeId:
|
case BeEnsureInstructionAtInst::TypeId:
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue