Force some inline calls in vdc

This commit is contained in:
drmortalwombat 2024-02-14 15:24:01 +01:00
parent 806539a2d6
commit 18cfbc713a
5 changed files with 102 additions and 39 deletions

View File

@ -34,8 +34,11 @@ byte vdc_reg_read(VDCRegister reg)
void vdc_mem_addr(unsigned addr) void vdc_mem_addr(unsigned addr)
{ {
#pragma callinline()
vdc_reg_write(VDCR_ADDRH, addr >> 8); vdc_reg_write(VDCR_ADDRH, addr >> 8);
#pragma callinline()
vdc_reg_write(VDCR_ADDRL, addr); vdc_reg_write(VDCR_ADDRL, addr);
#pragma callinline()
vdc_reg(VDCR_DATA); vdc_reg(VDCR_DATA);
} }
@ -52,12 +55,14 @@ inline char vdc_mem_read(void)
void vdc_mem_write_at(unsigned addr, char data) void vdc_mem_write_at(unsigned addr, char data)
{ {
#pragma callinline()
vdc_mem_addr(addr); vdc_mem_addr(addr);
vdc_write(data); vdc_write(data);
} }
char vdc_mem_read_at(unsigned addr) char vdc_mem_read_at(unsigned addr)
{ {
#pragma callinline()
vdc_mem_addr(addr); vdc_mem_addr(addr);
return vdc_read(); return vdc_read();
} }

View File

@ -866,7 +866,13 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo
} }
else else
{ {
RegisterCall(procDec, ldec); if (exp->mType == EX_INLINE)
{
for (int i = 0; i < ldec->mCalled.Size(); i++)
RegisterCall(procDec, ldec->mCalled[i]);
}
else
RegisterCall(procDec, ldec);
if (!(GetProcFlags(ldec) & (DTF_FUNC_INTRSAVE | DTF_INTERRUPT))) if (!(GetProcFlags(ldec) & (DTF_FUNC_INTRSAVE | DTF_INTERRUPT)))
{ {
procDec->mFlags &= ~DTF_FUNC_INTRSAVE; procDec->mFlags &= ~DTF_FUNC_INTRSAVE;

View File

@ -19923,7 +19923,7 @@ void InterCodeProcedure::Close(void)
{ {
GrowingTypeArray tstack(IT_NONE); GrowingTypeArray tstack(IT_NONE);
CheckFunc = !strcmp(mIdent->mString, "main"); CheckFunc = !strcmp(mIdent->mString, "clear");
CheckCase = false; CheckCase = false;
mEntryBlock = mBlocks[0]; mEntryBlock = mBlocks[0];

View File

@ -21442,7 +21442,7 @@ void NativeCodeBasicBlock::ChangeTailZPStoreToY(int addr)
assert(false); assert(false);
} }
bool NativeCodeBasicBlock::IsExitYRegZP(int addr, int& index) const bool NativeCodeBasicBlock::IsExitYRegZP(int addr, int& index, NativeCodeBasicBlock*& block)
{ {
int i = mIns.Size() - 1; int i = mIns.Size() - 1;
while (i >= 0) while (i >= 0)
@ -21451,6 +21451,7 @@ bool NativeCodeBasicBlock::IsExitYRegZP(int addr, int& index) const
{ {
if (addr == mIns[i].mAddress) if (addr == mIns[i].mAddress)
{ {
block = this;
index = i; index = i;
return true; return true;
} }
@ -21464,10 +21465,13 @@ bool NativeCodeBasicBlock::IsExitYRegZP(int addr, int& index) const
i--; i--;
} }
if (mEntryBlocks.Size() == 1)
return mEntryBlocks[0]->IsExitYRegZP(addr, index, block);
return false; return false;
} }
bool NativeCodeBasicBlock::IsExitXRegZP(int addr, int& index) const bool NativeCodeBasicBlock::IsExitXRegZP(int addr, int& index, NativeCodeBasicBlock*& block)
{ {
int i = mIns.Size() - 1; int i = mIns.Size() - 1;
while (i >= 0) while (i >= 0)
@ -21476,6 +21480,7 @@ bool NativeCodeBasicBlock::IsExitXRegZP(int addr, int& index) const
{ {
if (addr == mIns[i].mAddress) if (addr == mIns[i].mAddress)
{ {
block = this;
index = i; index = i;
return true; return true;
} }
@ -21489,10 +21494,13 @@ bool NativeCodeBasicBlock::IsExitXRegZP(int addr, int& index) const
i--; i--;
} }
if (mEntryBlocks.Size() == 1)
return mEntryBlocks[0]->IsExitXRegZP(addr, index, block);
return false; return false;
} }
bool NativeCodeBasicBlock::IsExitARegZP(int addr, int& index) const bool NativeCodeBasicBlock::IsExitARegZP(int addr, int& index, NativeCodeBasicBlock*& block)
{ {
int i = mIns.Size() - 1; int i = mIns.Size() - 1;
while (i >= 0) while (i >= 0)
@ -21501,6 +21509,7 @@ bool NativeCodeBasicBlock::IsExitARegZP(int addr, int& index) const
{ {
if (addr == mIns[i].mAddress) if (addr == mIns[i].mAddress)
{ {
block = this;
index = i; index = i;
return true; return true;
} }
@ -21514,9 +21523,29 @@ bool NativeCodeBasicBlock::IsExitARegZP(int addr, int& index) const
i--; i--;
} }
if (mEntryBlocks.Size() == 1)
return mEntryBlocks[0]->IsExitARegZP(addr, index, block);
return false; return false;
} }
void NativeCodeBasicBlock::MarkLiveBlockChain(int index, NativeCodeBasicBlock* block, uint32 live, uint32 reg)
{
mExitRequiredRegs += reg;
if (this == block)
{
for (int i = index; i < mIns.Size(); i++)
mIns[i].mLive |= live;
}
else
{
for (int i = 0; i < mIns.Size(); i++)
mIns[i].mLive |= live;
mEntryRequiredRegs += reg;
mEntryBlocks[0]->MarkLiveBlockChain(index, block, live, reg);
}
}
bool NativeCodeBasicBlock::CanJoinEntryLoadStoreZP(int saddr, int daddr) bool NativeCodeBasicBlock::CanJoinEntryLoadStoreZP(int saddr, int daddr)
{ {
if (mFalseJump && mExitRequiredRegs[daddr]) if (mFalseJump && mExitRequiredRegs[daddr])
@ -23072,10 +23101,11 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
int ei = 0; int ei = 0;
int index; int index;
bool found = false, fail = false; bool found = false, fail = false;
NativeCodeBasicBlock* block;
for (int i = 0; i < mEntryBlocks.Size(); i++) for (int i = 0; i < mEntryBlocks.Size(); i++)
{ {
if (mEntryBlocks[i]->IsExitYRegZP(mIns[0].mAddress, index)) if (mEntryBlocks[i]->IsExitYRegZP(mIns[0].mAddress, index, block))
found = true; found = true;
else if (mEntryBlocks[i]->mFalseJump) else if (mEntryBlocks[i]->mFalseJump)
fail = true; fail = true;
@ -23085,15 +23115,14 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
{ {
for (int i = 0; i < mEntryBlocks.Size(); i++) for (int i = 0; i < mEntryBlocks.Size(); i++)
{ {
if (mEntryBlocks[i]->IsExitYRegZP(mIns[0].mAddress, index)) if (mEntryBlocks[i]->IsExitYRegZP(mIns[0].mAddress, index, block))
{ {
while (index < mEntryBlocks[i]->mIns.Size()) mEntryBlocks[i]->MarkLiveBlockChain(index, block, LIVE_CPU_REG_Y, CPU_REG_Y);
mEntryBlocks[i]->mIns[index++].mLive |= LIVE_CPU_REG_Y;
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_Y;
} }
else else
{ {
mEntryBlocks[i]->mIns.Push(mIns[0]); mEntryBlocks[i]->mIns.Push(mIns[0]);
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_Y;
} }
} }
@ -23107,10 +23136,11 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
int ei = 0; int ei = 0;
int index; int index;
bool found = false, fail = false; bool found = false, fail = false;
NativeCodeBasicBlock* block;
for (int i = 0; i < mEntryBlocks.Size(); i++) for (int i = 0; i < mEntryBlocks.Size(); i++)
{ {
if (mEntryBlocks[i]->IsExitXRegZP(mIns[0].mAddress, index)) if (mEntryBlocks[i]->IsExitXRegZP(mIns[0].mAddress, index, block))
found = true; found = true;
else if (mEntryBlocks[i]->mFalseJump) else if (mEntryBlocks[i]->mFalseJump)
fail = true; fail = true;
@ -23120,15 +23150,14 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
{ {
for (int i = 0; i < mEntryBlocks.Size(); i++) for (int i = 0; i < mEntryBlocks.Size(); i++)
{ {
if (mEntryBlocks[i]->IsExitXRegZP(mIns[0].mAddress, index)) if (mEntryBlocks[i]->IsExitXRegZP(mIns[0].mAddress, index, block))
{ {
while (index < mEntryBlocks[i]->mIns.Size()) mEntryBlocks[i]->MarkLiveBlockChain(index, block, LIVE_CPU_REG_X, CPU_REG_X);
mEntryBlocks[i]->mIns[index++].mLive |= LIVE_CPU_REG_X;
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_X;
} }
else else
{ {
mEntryBlocks[i]->mIns.Push(mIns[0]); mEntryBlocks[i]->mIns.Push(mIns[0]);
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_X;
} }
} }
@ -23142,10 +23171,11 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
int ei = 0; int ei = 0;
int index; int index;
bool found = false, fail = false; bool found = false, fail = false;
NativeCodeBasicBlock* block;
for (int i = 0; i < mEntryBlocks.Size(); i++) for (int i = 0; i < mEntryBlocks.Size(); i++)
{ {
if (mEntryBlocks[i]->IsExitARegZP(mIns[0].mAddress, index)) if (mEntryBlocks[i]->IsExitARegZP(mIns[0].mAddress, index, block))
found = true; found = true;
else if (mEntryBlocks[i]->mFalseJump) else if (mEntryBlocks[i]->mFalseJump)
fail = true; fail = true;
@ -23155,15 +23185,14 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool
{ {
for (int i = 0; i < mEntryBlocks.Size(); i++) for (int i = 0; i < mEntryBlocks.Size(); i++)
{ {
if (mEntryBlocks[i]->IsExitARegZP(mIns[0].mAddress, index)) if (mEntryBlocks[i]->IsExitARegZP(mIns[0].mAddress, index, block))
{ {
while (index < mEntryBlocks[i]->mIns.Size()) mEntryBlocks[i]->MarkLiveBlockChain(index, block, LIVE_CPU_REG_A, CPU_REG_A);
mEntryBlocks[i]->mIns[index++].mLive |= LIVE_CPU_REG_A;
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_A;
} }
else else
{ {
mEntryBlocks[i]->mIns.Push(mIns[0]); mEntryBlocks[i]->mIns.Push(mIns[0]);
mEntryBlocks[i]->mExitRequiredRegs += CPU_REG_A;
} }
} }
@ -23703,7 +23732,7 @@ bool NativeCodeBasicBlock::CrossBlockRegisterAlias(bool sameAX, bool sameAY)
return changed; return changed;
} }
bool NativeCodeBasicBlock::CrossBlockYAliasProgpagation(const int* yalias, int yoffset) bool NativeCodeBasicBlock::CrossBlockYAliasProgpagation(const int* yalias)
{ {
bool changed = false; bool changed = false;
@ -23718,21 +23747,14 @@ bool NativeCodeBasicBlock::CrossBlockYAliasProgpagation(const int* yalias, int y
{ {
if (mNumEntered == 0) if (mNumEntered == 0)
{ {
mYOffset = yoffset;
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
mYAlias[i] = yalias[i]; mYAlias[i] = yalias[i];
} }
else if (mYOffset == yoffset)
{
for (int i = 0; i < 256; i++)
if (mYAlias[i] != yalias[i])
mYAlias[i] = -1;
}
else else
{ {
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
mYAlias[i] = -1; if (mYAlias[i] != yalias[i])
yoffset = -1; mYAlias[i] = -1;
} }
mNumEntered++; mNumEntered++;
@ -23742,6 +23764,7 @@ bool NativeCodeBasicBlock::CrossBlockYAliasProgpagation(const int* yalias, int y
mVisited = true; mVisited = true;
int yoffset = 0;
for (int i = 0; i < mIns.Size(); i++) for (int i = 0; i < mIns.Size(); i++)
{ {
NativeCodeInstruction& ins(mIns[i]); NativeCodeInstruction& ins(mIns[i]);
@ -23788,6 +23811,23 @@ bool NativeCodeBasicBlock::CrossBlockYAliasProgpagation(const int* yalias, int y
mYAlias[ins.mAddress] = yoffset; mYAlias[ins.mAddress] = yoffset;
} }
} }
else if (ins.mType == ASMIT_TAY && i > 0 && (mIns[i - 1].mType == ASMIT_STA || mIns[i - 1].mType == ASMIT_LDA) && mIns[i - 1].mMode == ASMIM_ZERO_PAGE)
{
for (int i = 0; i < 256; i++)
mYAlias[i] = -1;
yoffset = 0;
mYAlias[mIns[i - 1].mAddress] = yoffset;
}
else if (ins.mType == ASMIT_LDA && ins.mMode == ASMIM_ZERO_PAGE && mYAlias[ins.mAddress] != -1 && i + 1 < mIns.Size())
{
if (mIns[i + 1].mType == ASMIT_ADC && mIns[i + 1].mMode == ASMIM_IMMEDIATE)
{
ins.mType = ASMIT_TYA;
ins.mMode = ASMIM_IMPLIED;
mIns[i + 1].mAddress = (mIns[i + 1].mAddress + mYAlias[ins.mAddress] - yoffset) & 0xff;
changed = true;
}
}
else if (ins.ChangesYReg()) else if (ins.ChangesYReg())
{ {
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
@ -23796,9 +23836,19 @@ bool NativeCodeBasicBlock::CrossBlockYAliasProgpagation(const int* yalias, int y
} }
} }
if (mTrueJump && mTrueJump->CrossBlockYAliasProgpagation(mYAlias, yoffset)) if (yoffset > 0)
{
for (int i = 0; i < 256; i++)
{
if (mYAlias[i] >= 0)
mYAlias[i] = (mYAlias[i] - yoffset) & 0xff;
}
}
if (mTrueJump && mTrueJump->CrossBlockYAliasProgpagation(mYAlias))
changed = true; changed = true;
if (mFalseJump && mFalseJump->CrossBlockYAliasProgpagation(mYAlias, yoffset)) if (mFalseJump && mFalseJump->CrossBlockYAliasProgpagation(mYAlias))
changed = true; changed = true;
} }
@ -46297,7 +46347,7 @@ void NativeCodeProcedure::Optimize(void)
if (step >= 6) if (step >= 6)
{ {
ResetVisited(); ResetVisited();
mEntryBlock->CrossBlockYAliasProgpagation(nullptr, -1); mEntryBlock->CrossBlockYAliasProgpagation(nullptr);
} }
RebuildEntry(); RebuildEntry();

View File

@ -247,7 +247,7 @@ public:
NativeRegisterDataSet mDataSet, mNDataSet, mFDataSet; NativeRegisterDataSet mDataSet, mNDataSet, mFDataSet;
ValueNumberingDataSet mNumDataSet, mNNumDataSet, mFNumDataSet; ValueNumberingDataSet mNumDataSet, mNNumDataSet, mFNumDataSet;
int mYAlias[256], mYOffset; int mYAlias[256];
ExpandingArray<NativeRegisterSum16Info> mRSumInfos; ExpandingArray<NativeRegisterSum16Info> mRSumInfos;
@ -536,9 +536,11 @@ public:
bool DoJoinEntryLoadStoreZP(int saddr, int daddr); bool DoJoinEntryLoadStoreZP(int saddr, int daddr);
bool JoinEntryLoadStoreZP(void); bool JoinEntryLoadStoreZP(void);
bool IsExitYRegZP(int addr, int& index) const; bool IsExitYRegZP(int addr, int& index, NativeCodeBasicBlock * & block);
bool IsExitXRegZP(int addr, int& index) const; bool IsExitXRegZP(int addr, int& index, NativeCodeBasicBlock * & block);
bool IsExitARegZP(int addr, int& index) const; bool IsExitARegZP(int addr, int& index, NativeCodeBasicBlock * & block);
void MarkLiveBlockChain(int index, NativeCodeBasicBlock* block, uint32 live, uint32 reg);
bool ShortcutBlockExit(void); bool ShortcutBlockExit(void);
bool PropagateSinglePath(void); bool PropagateSinglePath(void);
@ -559,7 +561,7 @@ public:
bool CrossBlockXYShortcut(void); bool CrossBlockXYShortcut(void);
bool CrossBlockYAliasProgpagation(const int * yalias, int yoffset); bool CrossBlockYAliasProgpagation(const int * yalias);
bool CrossBlockRegisterAlias(bool sameAX, bool sameAY); bool CrossBlockRegisterAlias(bool sameAX, bool sameAY);