diff --git a/llvm/include/llvm/CodeGen/LiveRangeEdit.h b/llvm/include/llvm/CodeGen/LiveRangeEdit.h --- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h +++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h @@ -41,6 +41,7 @@ class TargetInstrInfo; class TargetRegisterInfo; class VirtRegMap; +class VirtRegAuxInfo; class LiveRangeEdit : private MachineRegisterInfo::Delegate { public: @@ -248,8 +249,7 @@ /// calculateRegClassAndHint - Recompute register class and hint for each new /// register. - void calculateRegClassAndHint(MachineFunction &, const MachineLoopInfo &, - const MachineBlockFrequencyInfo &); + void calculateRegClassAndHint(MachineFunction &, VirtRegAuxInfo &); }; } // end namespace llvm diff --git a/llvm/include/llvm/CodeGen/Spiller.h b/llvm/include/llvm/CodeGen/Spiller.h --- a/llvm/include/llvm/CodeGen/Spiller.h +++ b/llvm/include/llvm/CodeGen/Spiller.h @@ -15,6 +15,7 @@ class MachineFunction; class MachineFunctionPass; class VirtRegMap; +class VirtRegAuxInfo; /// Spiller interface. /// @@ -34,8 +35,8 @@ /// Create and return a spiller that will insert spill code directly instead /// of deferring though VirtRegMap. -Spiller *createInlineSpiller(MachineFunctionPass &pass, MachineFunction &mf, - VirtRegMap &vrm); +Spiller *createInlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, + VirtRegMap &VRM, VirtRegAuxInfo &VRAI); } // end namespace llvm diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp --- a/llvm/lib/CodeGen/InlineSpiller.cpp +++ b/llvm/lib/CodeGen/InlineSpiller.cpp @@ -191,19 +191,23 @@ // Object records spills information and does the hoisting. HoistSpillHelper HSpiller; + // Live range weight calculator. + VirtRegAuxInfo &VRAI; + ~InlineSpiller() override = default; public: - InlineSpiller(MachineFunctionPass &pass, MachineFunction &mf, VirtRegMap &vrm) - : MF(mf), LIS(pass.getAnalysis()), - LSS(pass.getAnalysis()), - AA(&pass.getAnalysis().getAAResults()), - MDT(pass.getAnalysis()), - Loops(pass.getAnalysis()), VRM(vrm), - MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()), - TRI(*mf.getSubtarget().getRegisterInfo()), - MBFI(pass.getAnalysis()), - HSpiller(pass, mf, vrm) {} + InlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM, + VirtRegAuxInfo &VRAI) + : MF(MF), LIS(Pass.getAnalysis()), + LSS(Pass.getAnalysis()), + AA(&Pass.getAnalysis().getAAResults()), + MDT(Pass.getAnalysis()), + Loops(Pass.getAnalysis()), VRM(VRM), + MRI(MF.getRegInfo()), TII(*MF.getSubtarget().getInstrInfo()), + TRI(*MF.getSubtarget().getRegisterInfo()), + MBFI(Pass.getAnalysis()), + HSpiller(Pass, MF, VRM), VRAI(VRAI) {} void spill(LiveRangeEdit &) override; void postOptimization() override; @@ -239,10 +243,10 @@ void Spiller::anchor() {} -Spiller *llvm::createInlineSpiller(MachineFunctionPass &pass, - MachineFunction &mf, - VirtRegMap &vrm) { - return new InlineSpiller(pass, mf, vrm); +Spiller *llvm::createInlineSpiller(MachineFunctionPass &Pass, + MachineFunction &MF, VirtRegMap &VRM, + VirtRegAuxInfo &VRAI) { + return new InlineSpiller(Pass, MF, VRM, VRAI); } //===----------------------------------------------------------------------===// @@ -1200,7 +1204,7 @@ if (!RegsToSpill.empty()) spillAll(); - Edit->calculateRegClassAndHint(MF, Loops, MBFI); + Edit->calculateRegClassAndHint(MF, VRAI); } /// Optimizations after all the reg selections and spills are done. diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp --- a/llvm/lib/CodeGen/LiveRangeEdit.cpp +++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp @@ -458,11 +458,8 @@ NewRegs.push_back(VReg); } -void -LiveRangeEdit::calculateRegClassAndHint(MachineFunction &MF, - const MachineLoopInfo &Loops, - const MachineBlockFrequencyInfo &MBFI) { - VirtRegAuxInfo VRAI(MF, LIS, *VRM, Loops, MBFI); +void LiveRangeEdit::calculateRegClassAndHint(MachineFunction &MF, + VirtRegAuxInfo &VRAI) { for (unsigned I = 0, Size = size(); I < Size; ++I) { LiveInterval &LI = LIS.getInterval(get(I)); if (MRI.recomputeRegClass(LI.reg())) diff --git a/llvm/lib/CodeGen/RegAllocBasic.cpp b/llvm/lib/CodeGen/RegAllocBasic.cpp --- a/llvm/lib/CodeGen/RegAllocBasic.cpp +++ b/llvm/lib/CodeGen/RegAllocBasic.cpp @@ -320,7 +320,7 @@ getAnalysis()); VRAI.calculateSpillWeightsAndHints(); - SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM)); + SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, VRAI)); allocatePhysRegs(); postOptimization(); diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -3227,7 +3227,6 @@ MBFI = &getAnalysis(); DomTree = &getAnalysis(); ORE = &getAnalysis().getORE(); - SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM)); Loops = &getAnalysis(); Bundles = &getAnalysis(); SpillPlacer = &getAnalysis(); @@ -3239,13 +3238,14 @@ RegCosts = TRI->getRegisterCosts(*MF); VRAI = std::make_unique(*MF, *LIS, *VRM, *Loops, *MBFI); + SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, *VRAI)); VRAI->calculateSpillWeightsAndHints(); LLVM_DEBUG(LIS->dump()); SA.reset(new SplitAnalysis(*VRM, *LIS, *Loops)); - SE.reset(new SplitEditor(*SA, *AA, *LIS, *VRM, *DomTree, *MBFI)); + SE.reset(new SplitEditor(*SA, *AA, *LIS, *VRM, *DomTree, *MBFI, *VRAI)); ExtraRegInfo.clear(); ExtraRegInfo.resize(MRI->getNumVirtRegs()); NextCascade = 1; diff --git a/llvm/lib/CodeGen/RegAllocPBQP.cpp b/llvm/lib/CodeGen/RegAllocPBQP.cpp --- a/llvm/lib/CodeGen/RegAllocPBQP.cpp +++ b/llvm/lib/CodeGen/RegAllocPBQP.cpp @@ -800,7 +800,14 @@ PBQPVirtRegAuxInfo VRAI(MF, LIS, VRM, getAnalysis(), MBFI); VRAI.calculateSpillWeightsAndHints(); - std::unique_ptr VRegSpiller(createInlineSpiller(*this, MF, VRM)); + // FIXME: we create DefaultVRAI here to match existing behavior pre-passing + // the VRAI through the spiller to the live range editor. However, it probably + // makes more sense to pass the PBQP VRAI. The existing behavior had + // LiveRangeEdit make its own VirtRegAuxInfo object. + VirtRegAuxInfo DefaultVRAI(MF, LIS, VRM, getAnalysis(), + MBFI); + std::unique_ptr VRegSpiller( + createInlineSpiller(*this, MF, VRM, DefaultVRAI)); MF.getRegInfo().freezeReservedRegs(MF); diff --git a/llvm/lib/CodeGen/SplitKit.h b/llvm/lib/CodeGen/SplitKit.h --- a/llvm/lib/CodeGen/SplitKit.h +++ b/llvm/lib/CodeGen/SplitKit.h @@ -44,6 +44,7 @@ class TargetInstrInfo; class TargetRegisterInfo; class VirtRegMap; +class VirtRegAuxInfo; /// Determines the latest safe point in a block in which we can insert a split, /// spill or other instruction related with CurLI. @@ -272,6 +273,7 @@ const TargetInstrInfo &TII; const TargetRegisterInfo &TRI; const MachineBlockFrequencyInfo &MBFI; + VirtRegAuxInfo &VRAI; public: /// ComplementSpillMode - Select how the complement live range should be @@ -457,9 +459,9 @@ public: /// Create a new SplitEditor for editing the LiveInterval analyzed by SA. /// Newly created intervals will be appended to newIntervals. - SplitEditor(SplitAnalysis &sa, AAResults &aa, LiveIntervals &lis, - VirtRegMap &vrm, MachineDominatorTree &mdt, - MachineBlockFrequencyInfo &mbfi); + SplitEditor(SplitAnalysis &SA, AAResults &AA, LiveIntervals &LIS, + VirtRegMap &VRM, MachineDominatorTree &MDT, + MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo &VRAI); /// reset - Prepare for a new split. void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition); diff --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp --- a/llvm/lib/CodeGen/SplitKit.cpp +++ b/llvm/lib/CodeGen/SplitKit.cpp @@ -357,15 +357,15 @@ //===----------------------------------------------------------------------===// /// Create a new SplitEditor for editing the LiveInterval analyzed by SA. -SplitEditor::SplitEditor(SplitAnalysis &sa, AliasAnalysis &aa, - LiveIntervals &lis, VirtRegMap &vrm, - MachineDominatorTree &mdt, - MachineBlockFrequencyInfo &mbfi) - : SA(sa), AA(aa), LIS(lis), VRM(vrm), - MRI(vrm.getMachineFunction().getRegInfo()), MDT(mdt), - TII(*vrm.getMachineFunction().getSubtarget().getInstrInfo()), - TRI(*vrm.getMachineFunction().getSubtarget().getRegisterInfo()), - MBFI(mbfi), RegAssign(Allocator) {} +SplitEditor::SplitEditor(SplitAnalysis &SA, AliasAnalysis &AA, + LiveIntervals &LIS, VirtRegMap &VRM, + MachineDominatorTree &MDT, + MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo &VRAI) + : SA(SA), AA(AA), LIS(LIS), VRM(VRM), + MRI(VRM.getMachineFunction().getRegInfo()), MDT(MDT), + TII(*VRM.getMachineFunction().getSubtarget().getInstrInfo()), + TRI(*VRM.getMachineFunction().getSubtarget().getRegisterInfo()), + MBFI(MBFI), VRAI(VRAI), RegAssign(Allocator) {} void SplitEditor::reset(LiveRangeEdit &LRE, ComplementSpillMode SM) { Edit = &LRE; @@ -1502,7 +1502,7 @@ } // Calculate spill weight and allocation hints for new intervals. - Edit->calculateRegClassAndHint(VRM.getMachineFunction(), SA.Loops, MBFI); + Edit->calculateRegClassAndHint(VRM.getMachineFunction(), VRAI); assert(!LRMap || LRMap->size() == Edit->size()); }