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

Use lifetime extension for mixin results

This commit is contained in:
Brian Fiete 2022-06-16 07:21:19 -07:00
parent 1639542fed
commit ccb1646990
12 changed files with 105 additions and 44 deletions

View file

@ -1754,6 +1754,14 @@ void BeIRCodeGen::HandleNextCmd()
SetResult(curId, inst);
}
break;
case BfIRCmd_LifetimeSoftEnd:
{
CMD_PARAM(BeValue*, val);
auto inst = mBeModule->AllocInst<BeLifetimeSoftEndInst>();
inst->mPtr = val;
SetResult(curId, inst);
}
break;
case BfIRCmd_LifetimeExtend:
{
CMD_PARAM(BeValue*, val);

View file

@ -34,11 +34,10 @@ static const char* gOpName[] =
"@DefLoad",
"@DefPhi",
"@DbgDecl",
"@DbgRangeStart",
"@DbgRangeEnd",
"@LifetimeExtend",
"@LifetimeStart",
"@LifetimeEnd",
"@LifetimeSoftEnd",
"@ValueScopeSoftEnd",
"@ValueScopeHardEnd",
"@Label",
@ -13234,29 +13233,25 @@ void BeMCContext::DoCodeEmission()
}
}
break;
case BeMCInstKind_DbgRangeStart:
{
}
break;
case BeMCInstKind_DbgRangeEnd:
{
auto vregInfo = GetVRegInfo(inst->mArg0);
if (vregInfo->mDbgVariable != NULL)
{
auto dbgVar = vregInfo->mDbgVariable;
dbgVar->mDeclEnd = funcCodePos;
dbgVar->mDeclLifetimeExtend = false;
BF_ASSERT((uint)dbgVar->mDeclEnd >= (uint)dbgVar->mDeclStart);
}
}
break;
case BeMCInstKind_LifetimeExtend:
break;
case BeMCInstKind_LifetimeStart:
break;
case BeMCInstKind_LifetimeEnd:
break;
case BeMCInstKind_LifetimeSoftEnd:
{
auto vregInfo = GetVRegInfo(inst->mArg0);
if ((vregInfo != NULL) && (vregInfo->mDbgVariable != NULL))
{
auto dbgVar = vregInfo->mDbgVariable;
dbgVar->mDeclEnd = funcCodePos;
dbgVar->mDeclLifetimeExtend = false;
dbgVar->mDbgLifeEnded = true;
BF_ASSERT((uint)dbgVar->mDeclEnd >= (uint)dbgVar->mDeclStart);
}
}
break;
case BeMCInstKind_ValueScopeSoftEnd:
break;
case BeMCInstKind_ValueScopeHardEnd:
@ -16143,7 +16138,7 @@ void BeMCContext::Generate(BeFunction* function)
mDbgPreferredRegs[32] = X64Reg_R8;*/
//mDbgPreferredRegs[8] = X64Reg_RAX;
//mDebugging = (function->mName == "?CreateEntity@ModelLoader@Content@GlitchyEngine@bf@@CA?AU?$__TUPLE_Entity_Transform@VEcsEntity@World@GlitchyEngine@bf@@PEA?AUTransformComponent@123@@4@PEAVEcsWorld@World@34@U?$Nullable@UStringView@System@bf@@@System@4@VEcsEntity@734@@Z");
mDebugging = (function->mName == "?NumberToString@NumberFormatter@System@bf@@SAXUStringView@23@HPEAVIFormatProvider@23@PEAVString@23@@Z");
// || (function->mName == "?MethodA@TestProgram@BeefTest@bf@@CAXXZ");
// || (function->mName == "?Hey@Blurg@bf@@SAXXZ")
// ;
@ -17002,6 +16997,16 @@ void BeMCContext::Generate(BeFunction* function)
}
}
break;
case BeLifetimeSoftEndInst::TypeId:
{
auto castedInst = (BeLifetimeSoftEndInst*)inst;
auto mcPtr = GetOperand(castedInst->mPtr, false, true, true);
if (mcPtr.IsVRegAny())
{
AllocInst(BeMCInstKind_LifetimeSoftEnd, mcPtr);
}
}
break;
case BeValueScopeStartInst::TypeId:
{
result = BeMCOperand::FromImmediate((int)mVRegInfo.size());

View file

@ -484,11 +484,10 @@ enum BeMCInstKind
BeMCInstKind_DefLoad,
BeMCInstKind_DefPhi,
BeMCInstKind_DbgDecl,
BeMCInstKind_DbgRangeStart,
BeMCInstKind_DbgRangeEnd, // Extends life of local variables/arguments to their lexical scope end
BeMCInstKind_LifetimeExtend,
BeMCInstKind_LifetimeStart,
BeMCInstKind_LifetimeEnd,
BeMCInstKind_LifetimeSoftEnd,
BeMCInstKind_ValueScopeSoftEnd,
BeMCInstKind_ValueScopeHardEnd,
BeMCInstKind_Label,

View file

@ -300,6 +300,12 @@ void BeInliner::Visit(BeLifetimeEndInst* lifetimeEndInst)
destlifetimeEndInst->mPtr = Remap(lifetimeEndInst->mPtr);
}
void BeInliner::Visit(BeLifetimeSoftEndInst* lifetimeEndInst)
{
auto destlifetimeEndInst = AllocInst(lifetimeEndInst);
destlifetimeEndInst->mPtr = Remap(lifetimeEndInst->mPtr);
}
void BeInliner::Visit(BeLifetimeFenceInst* lifetimeFenceInst)
{
auto destlifetimeFenceInst = AllocInst(lifetimeFenceInst);
@ -2344,6 +2350,7 @@ String BeModule::ToString(BeFunction* wantFunc)
DISPLAY_INST1(BeAliasValueInst, "aliasvalue", mPtr);
DISPLAY_INST1(BeLifetimeStartInst, "lifetime.start", mPtr);
DISPLAY_INST1(BeLifetimeEndInst, "lifetime.end", mPtr);
DISPLAY_INST1(BeLifetimeSoftEndInst, "lifetime.softEnd", mPtr);
DISPLAY_INST2(BeLifetimeFenceInst, "lifetime.fence", mFenceBlock, mPtr);
DISPLAY_INST0(BeValueScopeStartInst, "valueScope.start");
DISPLAY_INST1(BeValueScopeRetainInst, "valueScope.retain", mValue);

View file

@ -36,6 +36,7 @@ class BeLifetimeExtendInst;
class BeAliasValueInst;
class BeLifetimeStartInst;
class BeLifetimeEndInst;
class BeLifetimeSoftEndInst;
class BeLifetimeFenceInst;
class BeValueScopeStartInst;
class BeValueScopeRetainInst;
@ -90,6 +91,7 @@ public:
virtual void Visit(BeLifetimeExtendInst* lifetimeExtendInst) {}
virtual void Visit(BeLifetimeStartInst* lifetimeStartInst) {}
virtual void Visit(BeLifetimeEndInst* lifetimeEndInst) {}
virtual void Visit(BeLifetimeSoftEndInst* lifetimeEndInst) {}
virtual void Visit(BeLifetimeFenceInst* lifetimeFenceInst) {}
virtual void Visit(BeValueScopeStartInst* valueScopeStartInst) {}
virtual void Visit(BeValueScopeRetainInst* valueScopeRetainInst) {}
@ -183,6 +185,7 @@ public:
virtual void Visit(BeLifetimeStartInst* lifetimeStartInst) override;
virtual void Visit(BeLifetimeExtendInst* lifetimeExtendInst) override;
virtual void Visit(BeLifetimeEndInst* lifetimeEndInst) override;
virtual void Visit(BeLifetimeSoftEndInst* lifetimeEndInst) override;
virtual void Visit(BeLifetimeFenceInst* lifetimeFenceInst) override;
virtual void Visit(BeValueScopeStartInst* valueScopeStartInst) override;
virtual void Visit(BeValueScopeRetainInst* valueScopeRetainInst) override;
@ -978,6 +981,20 @@ public:
}
};
class BeLifetimeSoftEndInst : public BeInst
{
public:
BE_VALUE_TYPE(BeLifetimeSoftEndInst, BeInst);
BeValue* mPtr;
virtual void HashInst(BeHashContext& hashCtx) override
{
hashCtx.Mixin(TypeId);
mPtr->HashReference(hashCtx);
}
};
class BeLifetimeFenceInst : public BeInst
{
public: