1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Improved large-method generation - simple vreg lives, block splits

This commit is contained in:
Brian Fiete 2020-06-13 04:56:56 -07:00
parent 52786e96ac
commit bb64d99ac4
2 changed files with 891 additions and 152 deletions

File diff suppressed because it is too large Load diff

View file

@ -566,6 +566,12 @@ struct BeMCVRegArray
int mVRegIndices[1];
};
struct BeVRegLastUseRecord
{
int mVRegIdx;
BeVRegLastUseRecord* mNext;
};
class BeMCInst
{
public:
@ -577,6 +583,7 @@ public:
BeVTrackingList* mLiveness;
BeVTrackingList* mVRegsInitialized;
BeVRegLastUseRecord* mVRegLastUseRecord;
BeDbgLoc* mDbgLoc;
bool IsDef()
@ -688,6 +695,67 @@ public:
int FindLabelInstIdx(int labelIdx);
};
class BeInstEnumerator
{
public:
BeMCBlock* mBlock;
int mReadIdx;
int mWriteIdx;
bool mRemoveCurrent;
public:
BeInstEnumerator(BeMCBlock* block)
{
mBlock = block;
mReadIdx = 0;
mWriteIdx = 0;
mRemoveCurrent = false;
}
~BeInstEnumerator()
{
if (mReadIdx >= mBlock->mInstructions.mSize)
{
mBlock->mInstructions.mSize = mWriteIdx;
}
}
void Next()
{
if (mRemoveCurrent)
{
mBlock->mInstructions[mReadIdx] = NULL;
mRemoveCurrent = false;
}
else
{
if (mWriteIdx != mReadIdx)
{
mBlock->mInstructions[mWriteIdx] = mBlock->mInstructions[mReadIdx];
mBlock->mInstructions[mReadIdx] = NULL;
}
mWriteIdx++;
}
mReadIdx++;
}
bool HasMore()
{
return mReadIdx < mBlock->mInstructions.mSize;
}
void RemoveCurrent()
{
mRemoveCurrent = true;
}
BeMCInst* Get()
{
return mBlock->mInstructions[mReadIdx];
}
};
class BeMCPhiValue
{
public:
@ -757,14 +825,12 @@ public:
int mVolatileVRegSave;
BeDbgVariable* mDbgVariable;
bool mFoundLastUse;
bool mMustExist; // Regs we must be able to debug
// Must be refreshed with RefreshRefCounts
int mRefCount;
int mAssignCount;
BeMCBlock* mClosedBlock;
int mClosedInstIdx;
public:
BeMCVRegInfo()
{
@ -801,9 +867,7 @@ public:
mVolatileVRegSave = -1;
mMustExist = false;
mIsRetVal = false;
mClosedBlock = NULL;
mClosedInstIdx = -1;
mFoundLastUse = false;
}
bool CanEliminate()
@ -961,7 +1025,7 @@ public:
BeVTrackingList* Add(BeVTrackingList* list, const SizedArrayImpl<int>& indices, bool perserveChangeList);
BeVTrackingList* Add(BeVTrackingList* list, int idx, bool perserveChangeList);
BeVTrackingList* ClearFiltered(BeVTrackingList* list, const SizedArrayImpl<int>& indices);
BeVTrackingList* Modify(BeVTrackingList* list, const SizedArrayImpl<int>& adds, const SizedArrayImpl<int>& removes, SizedArrayImpl<int>& filteredAdds, SizedArrayImpl<int>& filteredRemoves);
BeVTrackingList* Modify(BeVTrackingList* list, const SizedArrayImpl<int>& adds, const SizedArrayImpl<int>& removes, SizedArrayImpl<int>& filteredAdds, SizedArrayImpl<int>& filteredRemoves, bool preserveChanges = false);
int FindIndex(BeVTrackingList* entry, int val);
bool IsSet(BeVTrackingList* entry, int idx);
bool IsSet(BeVTrackingList* entry, int idx, BeTrackKind trackKind);
@ -1254,6 +1318,7 @@ public:
Array<BeCmpResult> mCmpResults;
int mCompositeRetVRegIdx;
int mTLSVRegIdx;
int mLegalizationIterations;
Array<int> mCallArgVRegs[BeMCNativeTypeCode_COUNT];
@ -1327,14 +1392,16 @@ public:
bool CouldBeReg(const BeMCOperand& operand);
bool CheckForce(BeMCVRegInfo* vregInfo);
void MarkLive(BeVTrackingList* liveRegs, SizedArrayImpl<int>& newRegs, BeVTrackingList* initRegs, const BeMCOperand& operand);
void MarkLive(BeVTrackingList* liveRegs, SizedArrayImpl<int>& newRegs, BeVTrackingList*& initRegs, const BeMCOperand& operand);
BeVTrackingList* MergeLiveRegs(BeVTrackingList* prevDestEntry, BeVTrackingList* mergeFrom);
void GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genCtx, bool& modifiedBlockBefore, bool& modifiedBlockAfter);
void GenerateLiveness();
void IntroduceVRegs(const BeMCOperand& newVReg, BeMCBlock* block, int startInstIdx, int lastInstIdx);
void VRegSetInitialized(BeMCBlock* mcBlock, BeMCInst* inst, const BeMCOperand& operand, SizedArrayImpl<int>& addVec, SizedArrayImpl<int>& removeVec, bool deepSet, bool doSet = true);
void VRegSetInitialized(BeMCBlock* mcBlock, BeMCInst* inst, const BeMCOperand& operand, SizedArrayImpl<int>& addVec, SizedArrayImpl<int>& removeVec, bool deepSet, bool doSet);
bool CheckVRegEqualityRange(BeMCBlock * mcBlock, int instIdx, const BeMCOperand & vreg0, const BeMCOperand & vreg1, BeMCRemapper& regRemaps, bool onlyCheckFirstLifetime = false);
BeMCInst* FindSafePreBranchInst(BeMCBlock* mcBlock);
void SimpleInitializedPass();
void DoLastUsePassHelper(BeMCInst* inst, const BeMCOperand& operand);
void InitializedPassHelper(BeMCBlock* block, BeVTrackingGenContext* genCtx, bool& modifiedBefore, bool& modifiedAfter);
void GenerateVRegInitFlags(BeVTrackingGenContext& genCtx);
void DoInitInjectionPass();
@ -1391,7 +1458,9 @@ public:
void DoTLSSetup();
void DoChainedBlockMerge();
void DoSplitLargeBlocks();
void DetectLoops();
void DoLastUsePass();
bool DoInitializedPass();
void RefreshRefCounts();
void DoInstCombinePass();