Fix static stack in recursion

Fix static stack allocation and placement for non recursive sub trees in a recursive call tree
This commit is contained in:
drmortalwombat 2024-08-09 16:18:38 +02:00
parent e4e997fef2
commit 932c7ec222
4 changed files with 34 additions and 1 deletions

View File

@ -13663,6 +13663,23 @@ void InterCodeBasicBlock::ApplyStaticStack(InterOperand & iop, const GrowingVari
}
}
void InterCodeBasicBlock::CollectStaticStackDependencies(LinkerObject* lobj)
{
if (!mVisited)
{
mVisited = true;
for (int i = 0; i < mInstructions.Size(); i++)
{
if ((mInstructions[i]->mCode == IC_CALL || mInstructions[i]->mCode == IC_CALL_NATIVE) && mInstructions[i]->mSrc[0].mLinkerObject && mInstructions[i]->mSrc[0].mLinkerObject->mStackSection)
lobj->mStackSection->mSections.Push(mInstructions[i]->mSrc[0].mLinkerObject->mStackSection);
}
if (mTrueJump) mTrueJump->CollectStaticStackDependencies(lobj);
if (mFalseJump) mFalseJump->CollectStaticStackDependencies(lobj);
}
}
void InterCodeBasicBlock::CollectStaticStack(LinkerObject* lobj, const GrowingVariableArray& localVars)
{
if (!mVisited)
@ -22498,6 +22515,15 @@ void InterCodeProcedure::Close(void)
DisassembleDebug("Rebuilt traces");
#endif
}
else if (!mInterruptCalled && mNativeProcedure)
{
// mLinkerObject->mFlags |= LOBJF_STATIC_STACK;
mLinkerObject->mStackSection = mModule->mLinker->AddSection(mIdent->Mangle("@stack"), LST_STATIC_STACK);
mLinkerObject->mStackSection->mSections.Push(mModule->mParamLinkerSection);
ResetVisited();
mEntryBlock->CollectStaticStackDependencies(mLinkerObject);
}
#endif
DisassembleDebug("PreLoopTemp");

View File

@ -637,6 +637,7 @@ public:
bool CheckStaticStack(void);
void ApplyStaticStack(InterOperand& iop, const GrowingVariableArray& localVars);
void CollectStaticStack(LinkerObject * lobj, const GrowingVariableArray& localVars);
void CollectStaticStackDependencies(LinkerObject* lobj);
void PromoteStaticStackParams(LinkerObject* paramlobj);
bool SameExitCode(const InterCodeBasicBlock* block) const;

View File

@ -731,15 +731,20 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge, boo
void LinkerRegion::PlaceStackSection(LinkerSection* stackSection, LinkerSection* section)
{
if (!section->mEnd)
if (!section->mEnd && !(section->mFlags & LSECF_PLACED))
{
section->mFlags |= LSECF_PLACED;
int start = stackSection->mEnd;
for (int i = 0; i < section->mSections.Size(); i++)
{
PlaceStackSection(stackSection, section->mSections[i]);
if (section->mSections[i]->mStart < start)
{
start = section->mSections[i]->mStart;
section->mStart = start;
}
}
section->mStart = start;

View File

@ -124,6 +124,7 @@ public:
};
static const uint32 LSECF_PACKED = 0x00000001;
static const uint32 LSECF_PLACED = 0x00000002;
class LinkerSection
{