1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

MemCpy fix for reg composite sret

This commit is contained in:
Brian Fiete 2021-10-25 08:45:34 -07:00
parent 4b7ad7036c
commit 076be19488
2 changed files with 60 additions and 43 deletions

View file

@ -1261,11 +1261,6 @@ void BeMCColorizer::AssignRegs(RegKind regKind)
int totalRegs32 = 0; int totalRegs32 = 0;
int totalRegs16 = 0; int totalRegs16 = 0;
if (mContext->mDebugging)
{
NOP;
}
SizedArray<X64CPURegister, 32> validRegs; SizedArray<X64CPURegister, 32> validRegs;
if (regKind == BeMCColorizer::RegKind_Ints) if (regKind == BeMCColorizer::RegKind_Ints)
{ {
@ -1621,11 +1616,6 @@ void BeMCColorizer::AssignRegs(RegKind regKind)
} }
} }
if (vregInfo->mType->IsVector())
{
NOP;
}
if (vregInfo->mSpilled) if (vregInfo->mSpilled)
{ {
if (bestReg != X64Reg_None) if (bestReg != X64Reg_None)
@ -3785,7 +3775,7 @@ BeMCOperand BeMCContext::AllocVirtualReg(BeType* type, int refCount, bool mustBe
if (mDebugging) if (mDebugging)
{ {
if (mcOperand.mVRegIdx == 7) if (mcOperand.mVRegIdx == 8)
{ {
NOP; NOP;
} }
@ -4183,6 +4173,33 @@ bool BeMCContext::CouldBeReg(const BeMCOperand& operand)
return true; return true;
} }
// bool BeMCContext::CouldBeReg(const BeMCOperand& operand)
// {
// if (operand.mKind != BeMCOperandKind_VReg)
// return false;
//
// auto vregInfo = GetVRegInfo(operand);
// if ((vregInfo->mIsRetVal) && (mCompositeRetVRegIdx != -1) && (mCompositeRetVRegIdx != operand.mVRegIdx))
// {
// return CouldBeReg(BeMCOperand::FromVReg(mCompositeRetVRegIdx));
// }
//
// if (vregInfo->mReg != X64Reg_None)
// return true;
//
// if (vregInfo->mForceMem)
// return false;
//
// if (vregInfo->mIsExpr)
// {
// if (vregInfo->mRelOffset)
// return false;
// return CouldBeReg(vregInfo->mRelTo);
// }
//
// return !vregInfo->mType->IsNonVectorComposite();
// }
bool BeMCContext::CheckForce(BeMCVRegInfo* vregInfo) bool BeMCContext::CheckForce(BeMCVRegInfo* vregInfo)
{ {
if (!vregInfo->mIsRetVal) if (!vregInfo->mIsRetVal)
@ -6052,6 +6069,12 @@ void BeMCContext::GetValAddr(const BeMCOperand& operand, X64CPURegister& reg, in
vregInfo = GetVRegInfo(vregInfo->mRelTo); vregInfo = GetVRegInfo(vregInfo->mRelTo);
} }
if ((mCompositeRetVRegIdx == operand.mVRegIdx) && (vregInfo->mReg != X64Reg_None))
{
reg = vregInfo->mReg;
return;
}
reg = mUseBP ? X64Reg_RBP : X64Reg_RSP; reg = mUseBP ? X64Reg_RBP : X64Reg_RSP;
offset = mStackSize + vregInfo->mFrameOffset; offset = mStackSize + vregInfo->mFrameOffset;
} }
@ -8391,11 +8414,6 @@ void BeMCContext::DoFrameObjPass()
{ {
BF_ASSERT(mBlocks.size() == 1); BF_ASSERT(mBlocks.size() == 1);
if (mDebugging)
{
NOP;
}
SetCurrentInst(NULL); SetCurrentInst(NULL);
// MS x64 ABI requires a "home address" of 4 intptrs when we call a function, plus whatever // MS x64 ABI requires a "home address" of 4 intptrs when we call a function, plus whatever
@ -9797,7 +9815,6 @@ bool BeMCContext::DoLegalization()
for (int* argIdxPtr : vregIndices) for (int* argIdxPtr : vregIndices)
{ {
auto mcArg = BeMCOperand::FromEncoded(*argIdxPtr); auto mcArg = BeMCOperand::FromEncoded(*argIdxPtr);
BeRMParamsInfo rmInfo; BeRMParamsInfo rmInfo;
GetRMParams(mcArg, rmInfo); GetRMParams(mcArg, rmInfo);
if ((rmInfo.mMode != BeMCRMMode_Direct) || (rmInfo.mRegB != X64Reg_None) || (rmInfo.mRegA == X64Reg_R11)) if ((rmInfo.mMode != BeMCRMMode_Direct) || (rmInfo.mRegB != X64Reg_None) || (rmInfo.mRegA == X64Reg_R11))
@ -10465,8 +10482,7 @@ bool BeMCContext::DoLegalization()
} }
continue; continue;
} }
// Struct = Struct else // Struct = Struct
else //if (arg1.mKind == BeMCOperandKind_VReg)
{ {
auto arg0Addr = OperandToAddr(arg0); auto arg0Addr = OperandToAddr(arg0);
auto arg1Addr = OperandToAddr(arg1); auto arg1Addr = OperandToAddr(arg1);
@ -11335,11 +11351,6 @@ void BeMCContext::DoRegFinalization()
if (inst->IsMov()) if (inst->IsMov())
{ {
if (mDebugging)
{
NOP;
}
bool removeInst = false; bool removeInst = false;
if (GetFixedOperand(inst->mArg0) == GetFixedOperand(inst->mArg1)) if (GetFixedOperand(inst->mArg0) == GetFixedOperand(inst->mArg1))
@ -11369,11 +11380,6 @@ void BeMCContext::DoRegFinalization()
{ {
case BeMCInstKind_PreserveVolatiles: case BeMCInstKind_PreserveVolatiles:
{ {
if (mDebugging)
{
NOP;
}
int preserveIdx; int preserveIdx;
BeMCInst* preserveInst; BeMCInst* preserveInst;
BeMCInst* restoreInst; BeMCInst* restoreInst;
@ -13447,18 +13453,8 @@ void BeMCContext::DoCodeEmission()
break; break;
case BeMCInstKind_Mov: case BeMCInstKind_Mov:
{ {
if (mDebugging)
{
NOP;
}
if (inst->mArg1.mKind == BeMCOperandKind_ConstAgg) if (inst->mArg1.mKind == BeMCOperandKind_ConstAgg)
{ {
if (mDebugging)
{
NOP;
}
EmitAggMov(inst->mArg0, inst->mArg1); EmitAggMov(inst->mArg0, inst->mArg1);
break; break;
} }
@ -15934,7 +15930,7 @@ void BeMCContext::Generate(BeFunction* function)
mDbgPreferredRegs[32] = X64Reg_R8;*/ mDbgPreferredRegs[32] = X64Reg_R8;*/
//mDbgPreferredRegs[8] = X64Reg_RAX; //mDbgPreferredRegs[8] = X64Reg_RAX;
mDebugging = (function->mName == "?PopulateComboBox$ny@PropertyPanel@Editor@Cobalt@bf@@QEAAXPEAVMenu@widgets@Beefy@4@@Z"); mDebugging = (function->mName == "?Load@TestProgram@BeefTest@bf@@SA?AUHandle@23@XZ");
// || (function->mName == "?MethodA@TestProgram@BeefTest@bf@@CAXXZ"); // || (function->mName == "?MethodA@TestProgram@BeefTest@bf@@CAXXZ");
// || (function->mName == "?Hey@Blurg@bf@@SAXXZ") // || (function->mName == "?Hey@Blurg@bf@@SAXXZ")
// ; // ;

View file

@ -135,6 +135,24 @@ namespace Tests
} }
} }
public struct StructN
{
public int mA = 123;
}
public struct StructO
{
public StructN mA;
}
public static StructN GetStructN()
{
var sn = StructN();
var so = scope StructO();
so.mA = sn;
return sn;
}
[Test] [Test]
static void TestBasics() static void TestBasics()
{ {
@ -168,6 +186,9 @@ namespace Tests
Test.Assert(sm.a == 12); Test.Assert(sm.a == 12);
Test.Assert(sm.b == 23); Test.Assert(sm.b == 23);
Test.Assert(sm.c == 200); Test.Assert(sm.c == 200);
StructN sn = GetStructN();
Test.Assert(sn.mA == 123);
} }
[Test] [Test]