Avoid frame pointer in native code if simple stack frame
This commit is contained in:
parent
4aa82d539b
commit
9dfbe405a5
|
@ -2966,7 +2966,7 @@ void InterCodeBasicBlock::MapVariables(GrowingVariableArray& globalVars, Growing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterCodeBasicBlock::CollectOuterFrame(int level, int& size)
|
void InterCodeBasicBlock::CollectOuterFrame(int level, int& size, bool &inner, bool &inlineAssembler)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -2985,6 +2985,8 @@ void InterCodeBasicBlock::CollectOuterFrame(int level, int& size)
|
||||||
size = mInstructions[i]->mIntValue;
|
size = mInstructions[i]->mIntValue;
|
||||||
mInstructions[i]->mCode = IC_NONE;
|
mInstructions[i]->mCode = IC_NONE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
inner = true;
|
||||||
}
|
}
|
||||||
else if (mInstructions[i]->mCode == IC_POP_FRAME)
|
else if (mInstructions[i]->mCode == IC_POP_FRAME)
|
||||||
{
|
{
|
||||||
|
@ -2994,10 +2996,12 @@ void InterCodeBasicBlock::CollectOuterFrame(int level, int& size)
|
||||||
}
|
}
|
||||||
level--;
|
level--;
|
||||||
}
|
}
|
||||||
|
else if (mInstructions[i]->mCode == IC_ASSEMBLER)
|
||||||
|
inlineAssembler = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTrueJump) mTrueJump->CollectOuterFrame(level, size);
|
if (mTrueJump) mTrueJump->CollectOuterFrame(level, size, inner, inlineAssembler);
|
||||||
if (mFalseJump) mFalseJump->CollectOuterFrame(level, size);
|
if (mFalseJump) mFalseJump->CollectOuterFrame(level, size, inner, inlineAssembler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3809,12 +3813,14 @@ void InterCodeProcedure::Close(void)
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
mLeafProcedure = mEntryBlock->IsLeafProcedure();
|
mLeafProcedure = mEntryBlock->IsLeafProcedure();
|
||||||
|
|
||||||
|
mHasDynamicStack = false;
|
||||||
|
mHasInlineAssembler = false;
|
||||||
if (!mLeafProcedure)
|
if (!mLeafProcedure)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
mEntryBlock->CollectOuterFrame(0, size);
|
mEntryBlock->CollectOuterFrame(0, size, mHasDynamicStack, mHasInlineAssembler);
|
||||||
mCommonFrameSize = size;
|
mCommonFrameSize = size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -459,7 +459,7 @@ public:
|
||||||
void CollectVariables(GrowingVariableArray & globalVars, GrowingVariableArray & localVars);
|
void CollectVariables(GrowingVariableArray & globalVars, GrowingVariableArray & localVars);
|
||||||
void MapVariables(GrowingVariableArray& globalVars, GrowingVariableArray& localVars);
|
void MapVariables(GrowingVariableArray& globalVars, GrowingVariableArray& localVars);
|
||||||
|
|
||||||
void CollectOuterFrame(int level, int& size);
|
void CollectOuterFrame(int level, int& size, bool& inner, bool& inlineAssembler);
|
||||||
|
|
||||||
bool IsLeafProcedure(void);
|
bool IsLeafProcedure(void);
|
||||||
|
|
||||||
|
@ -487,7 +487,7 @@ public:
|
||||||
GrowingTypeArray mTemporaries;
|
GrowingTypeArray mTemporaries;
|
||||||
GrowingIntArray mTempOffset, mTempSizes;
|
GrowingIntArray mTempOffset, mTempSizes;
|
||||||
int mTempSize, mCommonFrameSize, mCallerSavedTemps;
|
int mTempSize, mCommonFrameSize, mCallerSavedTemps;
|
||||||
bool mLeafProcedure, mNativeProcedure, mCallsFunctionPointer;
|
bool mLeafProcedure, mNativeProcedure, mCallsFunctionPointer, mHasDynamicStack, mHasInlineAssembler;
|
||||||
GrowingInterCodeProcedurePtrArray mCalledFunctions;
|
GrowingInterCodeProcedurePtrArray mCalledFunctions;
|
||||||
|
|
||||||
InterCodeModule * mModule;
|
InterCodeModule * mModule;
|
||||||
|
|
|
@ -2133,6 +2133,7 @@ void NativeCodeBasicBlock::LoadConstantToReg(InterCodeProcedure * proc, const In
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(areg, index, 2);
|
CheckFrameIndex(areg, index, 2);
|
||||||
|
|
||||||
if (index != 0)
|
if (index != 0)
|
||||||
|
@ -2232,6 +2233,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 4);
|
CheckFrameIndex(reg, index, 4);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2306,6 +2308,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 4);
|
CheckFrameIndex(reg, index, 4);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2408,6 +2411,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 2);
|
CheckFrameIndex(reg, index, 2);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2453,6 +2457,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 2);
|
CheckFrameIndex(reg, index, 2);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2529,6 +2534,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 1);
|
CheckFrameIndex(reg, index, 1);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2568,6 +2574,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 2);
|
CheckFrameIndex(reg, index, 2);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2612,6 +2619,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 1);
|
CheckFrameIndex(reg, index, 1);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2652,6 +2660,7 @@ void NativeCodeBasicBlock::StoreValue(InterCodeProcedure* proc, const InterInstr
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(reg, index, 2);
|
CheckFrameIndex(reg, index, 2);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2748,7 +2757,8 @@ void NativeCodeBasicBlock::LoadStoreValue(InterCodeProcedure* proc, const InterI
|
||||||
index += proc->mLocalVars[rins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[rins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += rins->mVarIndex + proc->mLocalSize + 2;
|
index += rins->mVarIndex + proc->mLocalSize + 2;
|
||||||
CheckFrameIndex(areg, index, 4);
|
index += mFrameOffset;
|
||||||
|
CheckFrameIndex(areg, index, 1);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_INDIRECT_Y, areg));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_INDIRECT_Y, areg));
|
||||||
|
@ -2781,6 +2791,7 @@ void NativeCodeBasicBlock::LoadStoreValue(InterCodeProcedure* proc, const InterI
|
||||||
index += proc->mLocalVars[wins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[wins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += wins->mVarIndex + proc->mLocalSize + 2;
|
index += wins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(areg, index, 1);
|
CheckFrameIndex(areg, index, 1);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2842,6 +2853,7 @@ void NativeCodeBasicBlock::LoadValueToReg(InterCodeProcedure* proc, const InterI
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(areg, index, 4);
|
CheckFrameIndex(areg, index, 4);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2921,6 +2933,7 @@ void NativeCodeBasicBlock::LoadValueToReg(InterCodeProcedure* proc, const InterI
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(areg, index, 2);
|
CheckFrameIndex(areg, index, 2);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -2990,7 +3003,8 @@ void NativeCodeBasicBlock::LoadValueToReg(InterCodeProcedure* proc, const InterI
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
CheckFrameIndex(areg, index, 2);
|
index += mFrameOffset;
|
||||||
|
CheckFrameIndex(areg, index, 1);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_INDIRECT_Y, areg));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_INDIRECT_Y, areg));
|
||||||
|
@ -3055,6 +3069,7 @@ void NativeCodeBasicBlock::LoadValueToReg(InterCodeProcedure* proc, const InterI
|
||||||
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
index += proc->mLocalVars[ins->mVarIndex]->mOffset;
|
||||||
else
|
else
|
||||||
index += ins->mVarIndex + proc->mLocalSize + 2;
|
index += ins->mVarIndex + proc->mLocalSize + 2;
|
||||||
|
index += mFrameOffset;
|
||||||
CheckFrameIndex(areg, index, 2);
|
CheckFrameIndex(areg, index, 2);
|
||||||
|
|
||||||
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
mIns.Push(NativeCodeInstruction(ASMIT_LDY, ASMIM_IMMEDIATE, index));
|
||||||
|
@ -6186,7 +6201,8 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
|
||||||
int tempSave = proc->mTempSize > 16 ? proc->mTempSize - 16 : 0;
|
int tempSave = proc->mTempSize > 16 ? proc->mTempSize - 16 : 0;
|
||||||
int stackExpand = tempSave + proc->mLocalSize + 2;
|
int stackExpand = tempSave + proc->mLocalSize + 2;
|
||||||
|
|
||||||
mNoFrame = proc->mLocalSize == 0 && tempSave == 0 && proc->mLeafProcedure;
|
mFrameOffset = 0;
|
||||||
|
mNoFrame = proc->mLocalSize == 0 && tempSave == 0 && !proc->mHasDynamicStack && !(proc->mHasInlineAssembler && !proc->mLeafProcedure);
|
||||||
|
|
||||||
if (mNoFrame)
|
if (mNoFrame)
|
||||||
proc->mLinkerObject->mFlags |= LOBJF_NO_FRAME;
|
proc->mLinkerObject->mFlags |= LOBJF_NO_FRAME;
|
||||||
|
@ -6247,8 +6263,12 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
|
||||||
entryBlock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_STACK + 1));
|
entryBlock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_STACK + 1));
|
||||||
entryBlock->mIns.Push(NativeCodeInstruction(ASMIT_SBC, ASMIM_IMMEDIATE, ((proc->mCommonFrameSize + 2) >> 8) & 0xff));
|
entryBlock->mIns.Push(NativeCodeInstruction(ASMIT_SBC, ASMIM_IMMEDIATE, ((proc->mCommonFrameSize + 2) >> 8) & 0xff));
|
||||||
entryBlock->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_STACK + 1));
|
entryBlock->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_STACK + 1));
|
||||||
|
|
||||||
|
if (mNoFrame)
|
||||||
|
mFrameOffset = proc->mCommonFrameSize + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entryBlock->mFrameOffset = mFrameOffset;
|
||||||
|
|
||||||
tblocks[0] = entryBlock;
|
tblocks[0] = entryBlock;
|
||||||
|
|
||||||
|
@ -6412,6 +6432,7 @@ NativeCodeBasicBlock* NativeCodeProcedure::AllocateBlock(void)
|
||||||
{
|
{
|
||||||
NativeCodeBasicBlock* block = new NativeCodeBasicBlock();
|
NativeCodeBasicBlock* block = new NativeCodeBasicBlock();
|
||||||
block->mNoFrame = mNoFrame;
|
block->mNoFrame = mNoFrame;
|
||||||
|
block->mFrameOffset = mFrameOffset;
|
||||||
block->mIndex = mTempBlocks++;
|
block->mIndex = mTempBlocks++;
|
||||||
mBlocks.Push(block);
|
mBlocks.Push(block);
|
||||||
|
|
||||||
|
@ -6425,6 +6446,7 @@ NativeCodeBasicBlock* NativeCodeProcedure::CompileBlock(InterCodeProcedure* ipro
|
||||||
|
|
||||||
NativeCodeBasicBlock* block = new NativeCodeBasicBlock();
|
NativeCodeBasicBlock* block = new NativeCodeBasicBlock();
|
||||||
block->mNoFrame = mNoFrame;
|
block->mNoFrame = mNoFrame;
|
||||||
|
block->mFrameOffset = mFrameOffset;
|
||||||
mBlocks.Push(block);
|
mBlocks.Push(block);
|
||||||
|
|
||||||
tblocks[sblock->mIndex] = block;
|
tblocks[sblock->mIndex] = block;
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
|
|
||||||
GrowingArray<NativeCodeBasicBlock*> mEntryBlocks;
|
GrowingArray<NativeCodeBasicBlock*> mEntryBlocks;
|
||||||
|
|
||||||
int mOffset, mSize, mNumEntries;
|
int mOffset, mSize, mNumEntries, mFrameOffset;
|
||||||
bool mPlaced, mCopied, mKnownShortBranch, mBypassed, mAssembled, mNoFrame, mVisited;
|
bool mPlaced, mCopied, mKnownShortBranch, mBypassed, mAssembled, mNoFrame, mVisited;
|
||||||
|
|
||||||
int PutBranch(NativeCodeProcedure* proc, AsmInsType code, int offset);
|
int PutBranch(NativeCodeProcedure* proc, AsmInsType code, int offset);
|
||||||
|
@ -163,7 +163,7 @@ class NativeCodeProcedure
|
||||||
|
|
||||||
NativeCodeGenerator* mGenerator;
|
NativeCodeGenerator* mGenerator;
|
||||||
|
|
||||||
int mProgStart, mProgSize, mIndex;
|
int mProgStart, mProgSize, mIndex, mFrameOffset;
|
||||||
bool mNoFrame;
|
bool mNoFrame;
|
||||||
int mTempBlocks;
|
int mTempBlocks;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue