diff --git a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h index c889f3c6d4ae..0b4b0007e946 100644 --- a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h +++ b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h @@ -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; diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp index 03122ae75670..c14fa8c43b38 100644 --- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp +++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp @@ -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 {