Reduce branches in short basic block sequences
This commit is contained in:
parent
ebc41560d9
commit
ea33f253d4
|
@ -631,8 +631,7 @@ bool NativeCodeInstruction::IsUsedResultInstructions(NumberSet& requiredTemps)
|
||||||
#if 1
|
#if 1
|
||||||
if (mFlags & NCIF_USE_CPU_REG_A)
|
if (mFlags & NCIF_USE_CPU_REG_A)
|
||||||
requiredTemps += CPU_REG_A;
|
requiredTemps += CPU_REG_A;
|
||||||
|
else if (mFlags & NCIF_LOWER)
|
||||||
if (mFlags & NCIF_LOWER)
|
|
||||||
{
|
{
|
||||||
requiredTemps += BC_REG_ACCU;
|
requiredTemps += BC_REG_ACCU;
|
||||||
if (mFlags & NCIF_UPPER)
|
if (mFlags & NCIF_UPPER)
|
||||||
|
@ -40318,7 +40317,10 @@ bool NativeCodeBasicBlock::OptimizeGenericLoop(NativeCodeProcedure* proc)
|
||||||
break;
|
break;
|
||||||
case ASMIT_TYA:
|
case ASMIT_TYA:
|
||||||
if (yoffset)
|
if (yoffset)
|
||||||
|
{
|
||||||
yreg = -2;
|
yreg = -2;
|
||||||
|
areg = -2;
|
||||||
|
}
|
||||||
else if ((areg == -1 || areg == CPU_REG_Y) && !(ins.mLive & LIVE_CPU_REG_Z))
|
else if ((areg == -1 || areg == CPU_REG_Y) && !(ins.mLive & LIVE_CPU_REG_Z))
|
||||||
areg = CPU_REG_Y;
|
areg = CPU_REG_Y;
|
||||||
else
|
else
|
||||||
|
@ -40326,7 +40328,10 @@ bool NativeCodeBasicBlock::OptimizeGenericLoop(NativeCodeProcedure* proc)
|
||||||
break;
|
break;
|
||||||
case ASMIT_TXA:
|
case ASMIT_TXA:
|
||||||
if (xoffset)
|
if (xoffset)
|
||||||
|
{
|
||||||
xreg = -2;
|
xreg = -2;
|
||||||
|
areg = -2;
|
||||||
|
}
|
||||||
else if ((areg == -1 || areg == CPU_REG_X) && !(ins.mLive & LIVE_CPU_REG_Z))
|
else if ((areg == -1 || areg == CPU_REG_X) && !(ins.mLive & LIVE_CPU_REG_Z))
|
||||||
areg = CPU_REG_X;
|
areg = CPU_REG_X;
|
||||||
else
|
else
|
||||||
|
@ -50846,6 +50851,19 @@ int NativeCodeBasicBlock::LeadsInto(NativeCodeBasicBlock* block, int dist)
|
||||||
return 1000;
|
return 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NativeCodeBasicBlock * NativeCodeBasicBlock::PlaceSequence(ExpandingArray<NativeCodeBasicBlock*>& placement, NativeCodeBasicBlock* block)
|
||||||
|
{
|
||||||
|
int size = 0;
|
||||||
|
do {
|
||||||
|
block->mPlaced = true;
|
||||||
|
block->mPlace = placement.Size();
|
||||||
|
placement.Push(block);
|
||||||
|
size += block->mCode.Size();
|
||||||
|
block = block->mTrueJump;
|
||||||
|
} while (block && !block->mFalseJump && !block->mPlaced && size + block->mCode.Size() < 32);
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeCodeBasicBlock::BuildPlacement(ExpandingArray<NativeCodeBasicBlock*>& placement)
|
void NativeCodeBasicBlock::BuildPlacement(ExpandingArray<NativeCodeBasicBlock*>& placement)
|
||||||
{
|
{
|
||||||
if (!mPlaced)
|
if (!mPlaced)
|
||||||
|
@ -50924,19 +50942,15 @@ void NativeCodeBasicBlock::BuildPlacement(ExpandingArray<NativeCodeBasicBlock*>&
|
||||||
}
|
}
|
||||||
else if (!mTrueJump->mFalseJump && mTrueJump->mTrueJump && mTrueJump->mCode.Size() < 100 && mFalseJump->LeadsInto(mTrueJump->mTrueJump, 0) < 100)
|
else if (!mTrueJump->mFalseJump && mTrueJump->mTrueJump && mTrueJump->mCode.Size() < 100 && mFalseJump->LeadsInto(mTrueJump->mTrueJump, 0) < 100)
|
||||||
{
|
{
|
||||||
mTrueJump->mPlaced = true;
|
NativeCodeBasicBlock * xblock = PlaceSequence(placement, mTrueJump);
|
||||||
mTrueJump->mPlace = placement.Size();
|
|
||||||
placement.Push(mTrueJump);
|
|
||||||
|
|
||||||
mFalseJump->BuildPlacement(placement);
|
mFalseJump->BuildPlacement(placement);
|
||||||
|
if (xblock) xblock->BuildPlacement(placement);
|
||||||
}
|
}
|
||||||
else if (!mFalseJump->mFalseJump && mFalseJump->mTrueJump && mFalseJump->mCode.Size() < 100 && mTrueJump->LeadsInto(mFalseJump->mTrueJump, 0) < 100)
|
else if (!mFalseJump->mFalseJump && mFalseJump->mTrueJump && mFalseJump->mCode.Size() < 100 && mTrueJump->LeadsInto(mFalseJump->mTrueJump, 0) < 100)
|
||||||
{
|
{
|
||||||
mFalseJump->mPlaced = true;
|
NativeCodeBasicBlock * xblock = PlaceSequence(placement, mFalseJump);
|
||||||
mFalseJump->mPlace = placement.Size();
|
|
||||||
placement.Push(mFalseJump);
|
|
||||||
|
|
||||||
mTrueJump->BuildPlacement(placement);
|
mTrueJump->BuildPlacement(placement);
|
||||||
|
if (xblock) xblock->BuildPlacement(placement);
|
||||||
}
|
}
|
||||||
else if (mTrueJump->mIns.Size() == 0 && mTrueJump->mFalseJump == mFalseJump->mFalseJump && mTrueJump->mTrueJump == mFalseJump->mTrueJump)
|
else if (mTrueJump->mIns.Size() == 0 && mTrueJump->mFalseJump == mFalseJump->mFalseJump && mTrueJump->mTrueJump == mFalseJump->mTrueJump)
|
||||||
{
|
{
|
||||||
|
@ -51492,7 +51506,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
|
||||||
mInterProc = proc;
|
mInterProc = proc;
|
||||||
mInterProc->mLinkerObject->mNativeProc = this;
|
mInterProc->mLinkerObject->mNativeProc = this;
|
||||||
|
|
||||||
CheckFunc = !strcmp(mInterProc->mIdent->mString, "fighter_input");
|
CheckFunc = !strcmp(mInterProc->mIdent->mString, "room_check_wall");
|
||||||
|
|
||||||
int nblocks = proc->mBlocks.Size();
|
int nblocks = proc->mBlocks.Size();
|
||||||
tblocks = new NativeCodeBasicBlock * [nblocks];
|
tblocks = new NativeCodeBasicBlock * [nblocks];
|
||||||
|
@ -52684,7 +52698,6 @@ void NativeCodeProcedure::Optimize(void)
|
||||||
if (!changed && mEntryBlock->LoopRegisterXYMap())
|
if (!changed && mEntryBlock->LoopRegisterXYMap())
|
||||||
changed = true;
|
changed = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
if (!changed && mEntryBlock->OptimizeGenericLoop(this))
|
if (!changed && mEntryBlock->OptimizeGenericLoop(this))
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
|
@ -274,6 +274,7 @@ public:
|
||||||
NativeCodeBasicBlock* BypassEmptyBlocks(void);
|
NativeCodeBasicBlock* BypassEmptyBlocks(void);
|
||||||
|
|
||||||
int LeadsInto(NativeCodeBasicBlock* block, int dist);
|
int LeadsInto(NativeCodeBasicBlock* block, int dist);
|
||||||
|
NativeCodeBasicBlock* PlaceSequence(ExpandingArray<NativeCodeBasicBlock*>& placement, NativeCodeBasicBlock* block);
|
||||||
void BuildPlacement(ExpandingArray<NativeCodeBasicBlock*>& placement);
|
void BuildPlacement(ExpandingArray<NativeCodeBasicBlock*>& placement);
|
||||||
void InitialOffset(int& total);
|
void InitialOffset(int& total);
|
||||||
bool CalculateOffset(int& total);
|
bool CalculateOffset(int& total);
|
||||||
|
|
Loading…
Reference in New Issue