[llvm] 82492f2 - [NFC][Regalloc] Share the VirtRegAuxInfo object with LiveRangeEdit
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 07:55:05 PST 2021
Author: Mircea Trofin
Date: 2021-02-19T07:44:28-08:00
New Revision: 82492f24ffa74825cc7990aa7e06b6b0b8c32e81
URL: https://github.com/llvm/llvm-project/commit/82492f24ffa74825cc7990aa7e06b6b0b8c32e81
DIFF: https://github.com/llvm/llvm-project/commit/82492f24ffa74825cc7990aa7e06b6b0b8c32e81.diff
LOG: [NFC][Regalloc] Share the VirtRegAuxInfo object with LiveRangeEdit
VirtRegAuxInfo is an extensibility point, so the register allocator's
decision on which implementation to use should be communicated to the
other users - namely, LiveRangeEdit.
Differential Revision: https://reviews.llvm.org/D96898
Added:
Modified:
llvm/include/llvm/CodeGen/LiveRangeEdit.h
llvm/include/llvm/CodeGen/Spiller.h
llvm/lib/CodeGen/InlineSpiller.cpp
llvm/lib/CodeGen/LiveRangeEdit.cpp
llvm/lib/CodeGen/RegAllocBasic.cpp
llvm/lib/CodeGen/RegAllocGreedy.cpp
llvm/lib/CodeGen/RegAllocPBQP.cpp
llvm/lib/CodeGen/SplitKit.cpp
llvm/lib/CodeGen/SplitKit.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/LiveRangeEdit.h b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
index 87d48adc7f27..5b26a44b4ca0 100644
--- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -41,6 +41,7 @@ class MachineOperand;
class TargetInstrInfo;
class TargetRegisterInfo;
class VirtRegMap;
+class VirtRegAuxInfo;
class LiveRangeEdit : private MachineRegisterInfo::Delegate {
public:
@@ -248,8 +249,7 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
/// 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
index a3c57f6fef83..b2f5485eba02 100644
--- a/llvm/include/llvm/CodeGen/Spiller.h
+++ b/llvm/include/llvm/CodeGen/Spiller.h
@@ -15,6 +15,7 @@ class LiveRangeEdit;
class MachineFunction;
class MachineFunctionPass;
class VirtRegMap;
+class VirtRegAuxInfo;
/// Spiller interface.
///
@@ -34,8 +35,8 @@ class Spiller {
/// 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
index c315043b6f64..7c280233cfaf 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -191,19 +191,23 @@ class InlineSpiller : public Spiller {
// 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<LiveIntervals>()),
- LSS(pass.getAnalysis<LiveStacks>()),
- AA(&pass.getAnalysis<AAResultsWrapperPass>().getAAResults()),
- MDT(pass.getAnalysis<MachineDominatorTree>()),
- Loops(pass.getAnalysis<MachineLoopInfo>()), VRM(vrm),
- MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
- TRI(*mf.getSubtarget().getRegisterInfo()),
- MBFI(pass.getAnalysis<MachineBlockFrequencyInfo>()),
- HSpiller(pass, mf, vrm) {}
+ InlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM,
+ VirtRegAuxInfo &VRAI)
+ : MF(MF), LIS(Pass.getAnalysis<LiveIntervals>()),
+ LSS(Pass.getAnalysis<LiveStacks>()),
+ AA(&Pass.getAnalysis<AAResultsWrapperPass>().getAAResults()),
+ MDT(Pass.getAnalysis<MachineDominatorTree>()),
+ Loops(Pass.getAnalysis<MachineLoopInfo>()), VRM(VRM),
+ MRI(MF.getRegInfo()), TII(*MF.getSubtarget().getInstrInfo()),
+ TRI(*MF.getSubtarget().getRegisterInfo()),
+ MBFI(Pass.getAnalysis<MachineBlockFrequencyInfo>()),
+ HSpiller(Pass, MF, VRM), VRAI(VRAI) {}
void spill(LiveRangeEdit &) override;
void postOptimization() override;
@@ -239,10 +243,10 @@ Spiller::~Spiller() = default;
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 @@ void InlineSpiller::spill(LiveRangeEdit &edit) {
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
index 037cb5426235..c5d1734b0f1f 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -458,11 +458,8 @@ LiveRangeEdit::MRI_NoteNewVirtualRegister(Register VReg) {
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
index ae10b8ee9793..f8de3e30745e 100644
--- a/llvm/lib/CodeGen/RegAllocBasic.cpp
+++ b/llvm/lib/CodeGen/RegAllocBasic.cpp
@@ -320,7 +320,7 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
getAnalysis<MachineBlockFrequencyInfo>());
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
index 577e23211513..f77fd38010e4 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -3227,7 +3227,6 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
DomTree = &getAnalysis<MachineDominatorTree>();
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
- SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
Loops = &getAnalysis<MachineLoopInfo>();
Bundles = &getAnalysis<EdgeBundles>();
SpillPlacer = &getAnalysis<SpillPlacement>();
@@ -3239,13 +3238,14 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
RegCosts = TRI->getRegisterCosts(*MF);
VRAI = std::make_unique<VirtRegAuxInfo>(*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
index 73290f15c431..763505c04fb3 100644
--- a/llvm/lib/CodeGen/RegAllocPBQP.cpp
+++ b/llvm/lib/CodeGen/RegAllocPBQP.cpp
@@ -800,7 +800,14 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
PBQPVirtRegAuxInfo VRAI(MF, LIS, VRM, getAnalysis<MachineLoopInfo>(), MBFI);
VRAI.calculateSpillWeightsAndHints();
- std::unique_ptr<Spiller> 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<MachineLoopInfo>(),
+ MBFI);
+ std::unique_ptr<Spiller> VRegSpiller(
+ createInlineSpiller(*this, MF, VRM, DefaultVRAI));
MF.getRegInfo().freezeReservedRegs(MF);
diff --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp
index d3e75ca60015..ced8de4c25af 100644
--- a/llvm/lib/CodeGen/SplitKit.cpp
+++ b/llvm/lib/CodeGen/SplitKit.cpp
@@ -357,15 +357,15 @@ void SplitAnalysis::analyze(const LiveInterval *li) {
//===----------------------------------------------------------------------===//
/// 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 @@ void SplitEditor::finish(SmallVectorImpl<unsigned> *LRMap) {
}
// 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());
}
diff --git a/llvm/lib/CodeGen/SplitKit.h b/llvm/lib/CodeGen/SplitKit.h
index 0963576742d6..035baa025cad 100644
--- a/llvm/lib/CodeGen/SplitKit.h
+++ b/llvm/lib/CodeGen/SplitKit.h
@@ -44,6 +44,7 @@ class MachineRegisterInfo;
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 @@ class LLVM_LIBRARY_VISIBILITY SplitEditor {
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 @@ class LLVM_LIBRARY_VISIBILITY SplitEditor {
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);
More information about the llvm-commits
mailing list