Add object placement retry if page locking does not fit

This commit is contained in:
drmortalwombat 2024-05-23 09:54:07 +02:00
parent 375307822e
commit 9fa8b644a7
3 changed files with 21 additions and 15 deletions

View File

@ -561,7 +561,7 @@ bool LinkerRegion::AllocateAppend(Linker* linker, LinkerObject* lobj)
if (lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) if (lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED))
{ {
if (!Allocate(linker, lobj->mSuffix, true)) if (!Allocate(linker, lobj->mSuffix, true, false))
return false; return false;
} }
@ -598,7 +598,7 @@ bool LinkerRegion::AllocateAppend(Linker* linker, LinkerObject* lobj)
if (lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) if (lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED))
{ {
if (!Allocate(linker, lobj->mSuffix, true)) if (!Allocate(linker, lobj->mSuffix, true, false))
return false; return false;
} }
@ -610,13 +610,13 @@ bool LinkerRegion::AllocateAppend(Linker* linker, LinkerObject* lobj)
return false; return false;
} }
bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge) bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge, bool retry)
{ {
if (merge && lobj->mPrefix) if (merge && lobj->mPrefix)
{ {
if (!(lobj->mPrefix->mFlags & LOBJF_PLACED)) if (!(lobj->mPrefix->mFlags & LOBJF_PLACED))
{ {
if (!Allocate(linker, lobj->mPrefix, true)) if (!Allocate(linker, lobj->mPrefix, true, false))
return false; return false;
if (lobj->mFlags & LOBJF_PLACED) if (lobj->mFlags & LOBJF_PLACED)
@ -673,7 +673,7 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge)
if (merge && lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) if (merge && lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED))
{ {
if (!Allocate(linker, lobj->mSuffix, true)) if (!Allocate(linker, lobj->mSuffix, true, false))
return false; return false;
} }
@ -685,7 +685,7 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge)
int start = (mStart + mUsed + lobj->mAlignment - 1) & ~(lobj->mAlignment - 1); int start = (mStart + mUsed + lobj->mAlignment - 1) & ~(lobj->mAlignment - 1);
int end = start + lobj->mSize; int end = start + lobj->mSize;
if (!(linker->mCompilerOptions & COPT_OPTIMIZE_CODE_SIZE) && (lobj->mFlags & LOBJF_NO_CROSS) && !(lobj->mFlags & LOBJF_FORCE_ALIGN) && lobj->mSize <= 256 && (start & 0xff00) != ((end - 1) & 0xff00) && !(lobj->mSection->mFlags & LSECF_PACKED)) if (!(linker->mCompilerOptions & COPT_OPTIMIZE_CODE_SIZE) && !retry && (lobj->mFlags & LOBJF_NO_CROSS) && !(lobj->mFlags & LOBJF_FORCE_ALIGN) && lobj->mSize <= 256 && (start & 0xff00) != ((end - 1) & 0xff00) && !(lobj->mSection->mFlags & LSECF_PACKED))
{ {
start = (start + 0x00ff) & 0xff00; start = (start + 0x00ff) & 0xff00;
end = start + lobj->mSize; end = start + lobj->mSize;
@ -719,7 +719,7 @@ bool LinkerRegion::Allocate(Linker * linker, LinkerObject* lobj, bool merge)
if (merge && lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED)) if (merge && lobj->mSuffix && !(lobj->mSuffix->mFlags & LOBJF_PLACED))
{ {
if (!Allocate(linker, lobj->mSuffix, true)) if (!Allocate(linker, lobj->mSuffix, true, false))
return false; return false;
} }
@ -924,7 +924,7 @@ void Linker::PatchReferences(bool inlays)
} }
} }
void Linker::PlaceObjects(void) void Linker::PlaceObjects(bool retry)
{ {
for (int i = 0; i < mRegions.Size(); i++) for (int i = 0; i < mRegions.Size(); i++)
{ {
@ -935,7 +935,7 @@ void Linker::PlaceObjects(void)
for (int k = 0; k < lsec->mObjects.Size(); k++) for (int k = 0; k < lsec->mObjects.Size(); k++)
{ {
LinkerObject* lobj = lsec->mObjects[k]; LinkerObject* lobj = lsec->mObjects[k];
if (lobj->mType != LOT_INLAY && (lobj->mFlags & LOBJF_REFERENCED) && !(lobj->mFlags & LOBJF_PLACED) && lrgn->Allocate(this, lobj, mCompilerOptions & COPT_OPTIMIZE_MERGE_CALLS)) if (lobj->mType != LOT_INLAY && (lobj->mFlags & LOBJF_REFERENCED) && !(lobj->mFlags & LOBJF_PLACED) && lrgn->Allocate(this, lobj, mCompilerOptions & COPT_OPTIMIZE_MERGE_CALLS, retry))
{ {
if (lobj->mIdent && lobj->mIdent->mString && (mCompilerOptions & COPT_VERBOSE2)) if (lobj->mIdent && lobj->mIdent->mString && (mCompilerOptions & COPT_VERBOSE2))
printf("Placed object <%s> $%04x - $%04x\n", lobj->mIdent->mString, lobj->mAddress, lobj->mAddress + lobj->mSize); printf("Placed object <%s> $%04x - $%04x\n", lobj->mIdent->mString, lobj->mAddress, lobj->mAddress + lobj->mSize);
@ -996,7 +996,10 @@ void Linker::Link(void)
} }
// Move objects into regions // Move objects into regions
PlaceObjects(); PlaceObjects(false);
// Retry for alignment
PlaceObjects(true);
// Place stack segment // Place stack segment
@ -1051,7 +1054,7 @@ void Linker::Link(void)
} }
} }
PlaceObjects(); PlaceObjects(false);
// Calculate BSS storage // Calculate BSS storage

View File

@ -100,7 +100,7 @@ public:
LinkerObject * mLastObject; LinkerObject * mLastObject;
bool AllocateAppend(Linker* linker, LinkerObject* obj); bool AllocateAppend(Linker* linker, LinkerObject* obj);
bool Allocate(Linker * linker, LinkerObject* obj, bool merge); bool Allocate(Linker * linker, LinkerObject* obj, bool merge, bool retry);
void PlaceStackSection(LinkerSection* stackSection, LinkerSection* section); void PlaceStackSection(LinkerSection* stackSection, LinkerSection* section);
}; };
@ -307,7 +307,7 @@ public:
void InlineSimpleJumps(void); void InlineSimpleJumps(void);
void PatchReferences(bool inlays); void PatchReferences(bool inlays);
void CopyObjects(bool inlays); void CopyObjects(bool inlays);
void PlaceObjects(void); void PlaceObjects(bool retry);
void Link(void); void Link(void);
protected: protected:
NativeCodeDisassembler mNativeDisassembler; NativeCodeDisassembler mNativeDisassembler;

View File

@ -24180,9 +24180,11 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
{ {
mEntryBlocks[i]->mIns.Push(mIns[0]); mEntryBlocks[i]->mIns.Push(mIns[0]);
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_X; mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_X;
mEntryBlocks[i]->mExitRequiredRegs -= CPU_REG_Z;
} }
} }
mEntryRequiredRegs -= CPU_REG_Z;
mEntryRequiredRegs += CPU_REG_X; mEntryRequiredRegs += CPU_REG_X;
mIns.Remove(0); mIns.Remove(0);
changed = true; changed = true;
@ -42746,7 +42748,8 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
else if ( else if (
mIns[i + 0].mType == ASMIT_STA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && mIns[i + 0].mType == ASMIT_STA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE &&
!mIns[i + 1].ChangesZeroPage(mIns[i + 0].mAddress) && !mIns[i + 1].RequiresYReg() && !mIns[i + 1].ChangesYReg() && !mIns[i + 1].ChangesZeroPage(mIns[i + 0].mAddress) && !mIns[i + 1].RequiresYReg() && !mIns[i + 1].ChangesYReg() &&
mIns[i + 2].mType == ASMIT_LDY && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && !(mIns[i + 2].mLive & LIVE_MEM)) mIns[i + 2].mType == ASMIT_LDY && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && !(mIns[i + 2].mLive & LIVE_MEM) &&
(!mIns[i + 1].ChangesZFlag() || !(mIns[i + 2].mLive & LIVE_CPU_REG_Z)))
{ {
mIns[i + 0].mType = ASMIT_TAY; mIns[i + 0].mMode = ASMIM_IMPLIED; mIns[i + 0].mType = ASMIT_TAY; mIns[i + 0].mMode = ASMIM_IMPLIED;
mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED; mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED;
@ -48062,7 +48065,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
{ {
mInterProc = proc; mInterProc = proc;
CheckFunc = !strcmp(mInterProc->mIdent->mString, "Actor::setupFrame"); CheckFunc = !strcmp(mInterProc->mIdent->mString, "buildRamTiles");
int nblocks = proc->mBlocks.Size(); int nblocks = proc->mBlocks.Size();
tblocks = new NativeCodeBasicBlock * [nblocks]; tblocks = new NativeCodeBasicBlock * [nblocks];