Optimize native code XY index register usage
This commit is contained in:
parent
640477f88d
commit
b9cbf525e9
|
@ -314,6 +314,42 @@ static void ConversionConstantFold(InterInstruction * ins, InterInstruction * ci
|
|||
}
|
||||
}
|
||||
|
||||
static void LoadConstantFold(InterInstruction* ins, InterInstruction* ains)
|
||||
{
|
||||
const uint8* data;
|
||||
|
||||
if (ains)
|
||||
data = ains->mConst.mLinkerObject->mData + ains->mConst.mIntConst;
|
||||
else
|
||||
data = ins->mSrc[0].mLinkerObject->mData + ins->mSrc[0].mIntConst;
|
||||
|
||||
switch (ins->mDst.mType)
|
||||
{
|
||||
case IT_BOOL:
|
||||
ins->mConst.mIntConst = data[0] ? 1 : 0;
|
||||
case IT_INT8:
|
||||
ins->mConst.mIntConst = data[0];
|
||||
break;
|
||||
case IT_INT16:
|
||||
case IT_POINTER:
|
||||
ins->mConst.mIntConst = data[0] | (data[1] << 8);
|
||||
break;
|
||||
case IT_INT32:
|
||||
ins->mConst.mIntConst = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
break;
|
||||
case IT_FLOAT:
|
||||
{
|
||||
union { float f; unsigned int v; } cc;
|
||||
cc.v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
ins->mConst.mFloatConst = cc.v;
|
||||
} break;
|
||||
}
|
||||
|
||||
ins->mCode = IC_CONSTANT;
|
||||
ins->mConst.mType = ins->mDst.mType;
|
||||
ins->mSrc[0].mTemp = -1;
|
||||
}
|
||||
|
||||
void ValueSet::InsertValue(InterInstruction * ins)
|
||||
{
|
||||
InterInstructionPtr* nins;
|
||||
|
@ -556,6 +592,11 @@ void ValueSet::UpdateValue(InterInstruction * ins, const GrowingInstructionPtrAr
|
|||
assert(ins->mSrc[0].mTemp >= 0);
|
||||
}
|
||||
}
|
||||
else if (ins->mSrc[0].mTemp >= 0 && tvalue[ins->mSrc[0].mTemp] && tvalue[ins->mSrc[0].mTemp]->mCode == IC_CONSTANT && tvalue[ins->mSrc[0].mTemp]->mConst.mMemory == IM_GLOBAL && (tvalue[ins->mSrc[0].mTemp]->mConst.mLinkerObject->mFlags & LOBJF_CONST))
|
||||
{
|
||||
LoadConstantFold(ins, tvalue[ins->mSrc[0].mTemp]);
|
||||
InsertValue(ins);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ins->mVolatile)
|
||||
|
@ -2100,6 +2141,10 @@ void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingI
|
|||
|
||||
case IC_LOAD:
|
||||
OptimizeAddress(ins, tvalue, 0);
|
||||
|
||||
if (ins->mSrc[0].mTemp < 0 && ins->mSrc[0].mMemory == IM_GLOBAL && (ins->mSrc[0].mLinkerObject->mFlags & LOBJF_CONST))
|
||||
LoadConstantFold(ins, nullptr);
|
||||
|
||||
break;
|
||||
case IC_STORE:
|
||||
if (ins->mSrc[0].mTemp >= 0 && tvalue[ins->mSrc[0].mTemp] && tvalue[ins->mSrc[0].mTemp]->mCode == IC_CONSTANT)
|
||||
|
@ -2205,6 +2250,14 @@ void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingI
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IC_CONVERSION_OPERATOR:
|
||||
if (ins->mSrc[0].mTemp >= 0 && tvalue[ins->mSrc[0].mTemp] && tvalue[ins->mSrc[0].mTemp]->mCode == IC_CONSTANT)
|
||||
{
|
||||
ConversionConstantFold(ins, tvalue[ins->mSrc[0].mTemp]);
|
||||
}
|
||||
break;
|
||||
|
||||
case IC_RETURN_VALUE:
|
||||
if (ins->mSrc[0].mTemp >= 0 && tvalue[ins->mSrc[0].mTemp] && tvalue[ins->mSrc[0].mTemp]->mCode == IC_CONSTANT)
|
||||
{
|
||||
|
|
|
@ -217,6 +217,12 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration*
|
|||
var->mLinkerObject = mLinker->AddObject(dec->mLocation, dec->mIdent, dec->mSection, LOT_DATA);
|
||||
var->mIdent = dec->mIdent;
|
||||
|
||||
Declaration* type = dec->mBase;
|
||||
while (type->mType == DT_TYPE_ARRAY)
|
||||
type = type->mBase;
|
||||
if (type->mFlags & DTF_CONST)
|
||||
var->mLinkerObject->mFlags |= LOBJF_CONST;
|
||||
|
||||
var->mIndex = mod->mGlobalVars.Size();
|
||||
mod->mGlobalVars.Push(var);
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ static const uint32 LOBJF_REFERENCED = 0x00000001;
|
|||
static const uint32 LOBJF_PLACED = 0x00000002;
|
||||
static const uint32 LOBJF_NO_FRAME = 0x00000004;
|
||||
static const uint32 LOBJF_INLINE = 0x00000008;
|
||||
static const uint32 LOBJF_CONST = 0x00000010;
|
||||
|
||||
class LinkerObject
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -175,7 +175,7 @@ public:
|
|||
bool MoveLoadAddImmStoreUp(int at);
|
||||
bool FindAddressSumY(int at, int reg, int & apos, int& breg, int& ireg);
|
||||
bool FindGlobalAddress(int at, int reg, int& apos);
|
||||
bool FindGlobalAddressSumY(int at, int reg, bool direct, int& apos, const NativeCodeInstruction * & ains, int& ireg);
|
||||
bool FindGlobalAddressSumY(int at, int reg, bool direct, int& apos, const NativeCodeInstruction * & ains, const NativeCodeInstruction*& iins, uint32 & flags);
|
||||
bool MoveStoreXUp(int at);
|
||||
|
||||
bool ValueForwarding(const NativeRegisterDataSet& data);
|
||||
|
@ -192,6 +192,10 @@ public:
|
|||
|
||||
void CollectZeroPageUsage(NumberSet& used);
|
||||
void RemapZeroPage(const uint8* remap);
|
||||
|
||||
void GlobalRegisterXYCheck(int* xregs, int * yregs);
|
||||
void GlobalRegisterXMap(int reg);
|
||||
bool LocalRegisterXYMap(void);
|
||||
};
|
||||
|
||||
class NativeCodeProcedure
|
||||
|
|
Loading…
Reference in New Issue