[NFC][RDA] Break-up initialization code

Separate out the initialization code from the loop traversal so
that the analysis can be reset and re-run by a user.
This commit is contained in:
Sam Parker 2020-02-20 14:58:08 +00:00
parent 083717cf49
commit 659500c0c9
2 changed files with 39 additions and 23 deletions

View File

@ -37,6 +37,7 @@ class ReachingDefAnalysis : public MachineFunctionPass {
private:
MachineFunction *MF;
const TargetRegisterInfo *TRI;
LoopTraversal::TraversalOrder TraversedMBBOrder;
unsigned NumRegUnits;
/// Instruction that defined each register, relative to the beginning of the
/// current basic block. When a LiveRegsDefInfo is used to represent a
@ -93,6 +94,15 @@ public:
MachineFunctionProperties::Property::TracksLiveness);
}
/// Re-run the analysis.
void reset();
/// Initialize data structures.
void init();
/// Traverse the machine function, mapping definitions.
void traverse();
/// Provides the instruction id of the closest reaching def instruction of
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
int getReachingDef(MachineInstr *MI, int PhysReg) const;

View File

@ -136,30 +136,9 @@ void ReachingDefAnalysis::processBasicBlock(
bool ReachingDefAnalysis::runOnMachineFunction(MachineFunction &mf) {
MF = &mf;
TRI = MF->getSubtarget().getRegisterInfo();
LiveRegs.clear();
NumRegUnits = TRI->getNumRegUnits();
MBBReachingDefs.resize(mf.getNumBlockIDs());
LLVM_DEBUG(dbgs() << "********** REACHING DEFINITION ANALYSIS **********\n");
// Initialize the MBBOutRegsInfos
MBBOutRegsInfos.resize(mf.getNumBlockIDs());
// Traverse the basic blocks.
LoopTraversal Traversal;
LoopTraversal::TraversalOrder TraversedMBBOrder = Traversal.traverse(mf);
for (LoopTraversal::TraversedMBBInfo TraversedMBB : TraversedMBBOrder) {
processBasicBlock(TraversedMBB);
}
// Sorting all reaching defs found for a ceartin reg unit in a given BB.
for (MBBDefsInfo &MBBDefs : MBBReachingDefs) {
for (MBBRegUnitDefs &RegUnitDefs : MBBDefs)
llvm::sort(RegUnitDefs);
}
init();
traverse();
return false;
}
@ -168,6 +147,33 @@ void ReachingDefAnalysis::releaseMemory() {
MBBOutRegsInfos.clear();
MBBReachingDefs.clear();
InstIds.clear();
LiveRegs.clear();
}
void ReachingDefAnalysis::reset() {
releaseMemory();
init();
traverse();
}
void ReachingDefAnalysis::init() {
NumRegUnits = TRI->getNumRegUnits();
MBBReachingDefs.resize(MF->getNumBlockIDs());
// Initialize the MBBOutRegsInfos
MBBOutRegsInfos.resize(MF->getNumBlockIDs());
LoopTraversal Traversal;
TraversedMBBOrder = Traversal.traverse(*MF);
}
void ReachingDefAnalysis::traverse() {
// Traverse the basic blocks.
for (LoopTraversal::TraversedMBBInfo TraversedMBB : TraversedMBBOrder)
processBasicBlock(TraversedMBB);
// Sorting all reaching defs found for a ceartin reg unit in a given BB.
for (MBBDefsInfo &MBBDefs : MBBReachingDefs) {
for (MBBRegUnitDefs &RegUnitDefs : MBBDefs)
llvm::sort(RegUnitDefs);
}
}
int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) const {