Index: llvm/include/llvm/CodeGen/LiveIntervals.h =================================================================== --- llvm/include/llvm/CodeGen/LiveIntervals.h +++ llvm/include/llvm/CodeGen/LiveIntervals.h @@ -93,12 +93,27 @@ /// interference. SmallVector RegUnitRanges; + public: static char ID; LiveIntervals(); + LiveIntervals(MachineFunction &MF, SlotIndexes *Indexes, + MachineDominatorTree *DT); ~LiveIntervals() override; + void init(MachineFunction &MF, SlotIndexes *Indexes, + MachineDominatorTree *DT); + + + MachineDominatorTree *getDomTree() { + return DomTree; + } + + const MachineDominatorTree *getDomTree() const { + return DomTree; + } + /// Calculate the spill weight to assign to a single instruction. static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, Index: llvm/include/llvm/CodeGen/SlotIndexes.h =================================================================== --- llvm/include/llvm/CodeGen/SlotIndexes.h +++ llvm/include/llvm/CodeGen/SlotIndexes.h @@ -357,6 +357,7 @@ void getAnalysisUsage(AnalysisUsage &au) const override; void releaseMemory() override; + void calculate(MachineFunction &fn); bool runOnMachineFunction(MachineFunction &fn) override; /// Dump the indexes. Index: llvm/lib/CodeGen/LiveIntervals.cpp =================================================================== --- llvm/lib/CodeGen/LiveIntervals.cpp +++ llvm/lib/CodeGen/LiveIntervals.cpp @@ -117,13 +117,14 @@ VNInfoAllocator.Reset(); } -bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { - MF = &fn; +void LiveIntervals::init(MachineFunction &MF_, SlotIndexes *Indexes_, + MachineDominatorTree *DT_) { + MF = &MF_; + Indexes = Indexes_; + DomTree = DT_; MRI = &MF->getRegInfo(); TRI = MF->getSubtarget().getRegisterInfo(); TII = MF->getSubtarget().getInstrInfo(); - Indexes = &getAnalysis(); - DomTree = &getAnalysis(); if (!LICalc) LICalc = new LiveIntervalCalc(); @@ -141,6 +142,10 @@ for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i) getRegUnit(i); } +} + +bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { + init(fn, &getAnalysis(), &getAnalysis()); LLVM_DEBUG(dump()); return false; } Index: llvm/lib/CodeGen/SlotIndexes.cpp =================================================================== --- llvm/lib/CodeGen/SlotIndexes.cpp +++ llvm/lib/CodeGen/SlotIndexes.cpp @@ -47,8 +47,7 @@ ileAllocator.Reset(); } -bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) { - +void SlotIndexes::calculate(MachineFunction &fn) { // Compute numbering as follows: // Grab an iterator to the start of the index list. // Iterate over all MBBs, and within each MBB all MIs, keeping the MI @@ -105,7 +104,10 @@ // Sort the Idx2MBBMap llvm::sort(idx2MBBMap, less_first()); +} +bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) { + calculate(fn); LLVM_DEBUG(mf->print(dbgs(), this)); // And we're done!