Skip to content

Commit d13349b

Browse files
committed
Spiller: Deatach legacy pass and supply analyses instead
1 parent 2054a81 commit d13349b

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

llvm/include/llvm/CodeGen/Spiller.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class MachineFunction;
1919
class MachineFunctionPass;
2020
class VirtRegMap;
2121
class VirtRegAuxInfo;
22+
class LiveIntervals;
23+
class LiveStacks;
24+
class MachineDominatorTree;
25+
class MachineBlockFrequencyInfo;
2226

2327
/// Spiller interface.
2428
///
@@ -41,12 +45,20 @@ class Spiller {
4145
virtual ArrayRef<Register> getReplacedRegs() = 0;
4246

4347
virtual void postOptimization() {}
48+
49+
struct RequiredAnalyses {
50+
LiveIntervals &LIS;
51+
LiveStacks &LSS;
52+
MachineDominatorTree &MDT;
53+
const MachineBlockFrequencyInfo &MBFI;
54+
};
4455
};
4556

4657
/// Create and return a spiller that will insert spill code directly instead
4758
/// of deferring though VirtRegMap.
48-
Spiller *createInlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF,
49-
VirtRegMap &VRM, VirtRegAuxInfo &VRAI);
59+
Spiller *createInlineSpiller(const Spiller::RequiredAnalyses &Analyses,
60+
MachineFunction &MF, VirtRegMap &VRM,
61+
VirtRegAuxInfo &VRAI);
5062

5163
} // end namespace llvm
5264

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ RestrictStatepointRemat("restrict-statepoint-remat",
7575
cl::desc("Restrict remat for statepoint operands"));
7676

7777
namespace {
78-
7978
class HoistSpillHelper : private LiveRangeEdit::Delegate {
8079
MachineFunction &MF;
8180
LiveIntervals &LIS;
@@ -128,15 +127,11 @@ class HoistSpillHelper : private LiveRangeEdit::Delegate {
128127
DenseMap<MachineBasicBlock *, unsigned> &SpillsToIns);
129128

130129
public:
131-
HoistSpillHelper(MachineFunctionPass &pass, MachineFunction &mf,
132-
VirtRegMap &vrm)
133-
: MF(mf), LIS(pass.getAnalysis<LiveIntervalsWrapperPass>().getLIS()),
134-
LSS(pass.getAnalysis<LiveStacksWrapperLegacy>().getLS()),
135-
MDT(pass.getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree()),
130+
HoistSpillHelper(const Spiller::RequiredAnalyses &Analyses,
131+
MachineFunction &mf, VirtRegMap &vrm)
132+
: MF(mf), LIS(Analyses.LIS), LSS(Analyses.LSS), MDT(Analyses.MDT),
136133
VRM(vrm), MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
137-
TRI(*mf.getSubtarget().getRegisterInfo()),
138-
MBFI(
139-
pass.getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI()),
134+
TRI(*mf.getSubtarget().getRegisterInfo()), MBFI(Analyses.MBFI),
140135
IPA(LIS, mf.getNumBlockIDs()) {}
141136

142137
void addToMergeableSpills(MachineInstr &Spill, int StackSlot,
@@ -190,16 +185,12 @@ class InlineSpiller : public Spiller {
190185
~InlineSpiller() override = default;
191186

192187
public:
193-
InlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM,
194-
VirtRegAuxInfo &VRAI)
195-
: MF(MF), LIS(Pass.getAnalysis<LiveIntervalsWrapperPass>().getLIS()),
196-
LSS(Pass.getAnalysis<LiveStacksWrapperLegacy>().getLS()),
197-
MDT(Pass.getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree()),
188+
InlineSpiller(const Spiller::RequiredAnalyses &Analyses, MachineFunction &MF,
189+
VirtRegMap &VRM, VirtRegAuxInfo &VRAI)
190+
: MF(MF), LIS(Analyses.LIS), LSS(Analyses.LSS), MDT(Analyses.MDT),
198191
VRM(VRM), MRI(MF.getRegInfo()), TII(*MF.getSubtarget().getInstrInfo()),
199-
TRI(*MF.getSubtarget().getRegisterInfo()),
200-
MBFI(
201-
Pass.getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI()),
202-
HSpiller(Pass, MF, VRM), VRAI(VRAI) {}
192+
TRI(*MF.getSubtarget().getRegisterInfo()), MBFI(Analyses.MBFI),
193+
HSpiller(Analyses, MF, VRM), VRAI(VRAI) {}
203194

204195
void spill(LiveRangeEdit &) override;
205196
ArrayRef<Register> getSpilledRegs() override { return RegsToSpill; }
@@ -237,10 +228,11 @@ Spiller::~Spiller() = default;
237228

238229
void Spiller::anchor() {}
239230

240-
Spiller *llvm::createInlineSpiller(MachineFunctionPass &Pass,
241-
MachineFunction &MF, VirtRegMap &VRM,
242-
VirtRegAuxInfo &VRAI) {
243-
return new InlineSpiller(Pass, MF, VRM, VRAI);
231+
Spiller *
232+
llvm::createInlineSpiller(const InlineSpiller::RequiredAnalyses &Analyses,
233+
MachineFunction &MF, VirtRegMap &VRM,
234+
VirtRegAuxInfo &VRAI) {
235+
return new InlineSpiller(Analyses, MF, VRM, VRAI);
244236
}
245237

246238
//===----------------------------------------------------------------------===//

llvm/lib/CodeGen/RegAllocBasic.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/CodeGen/LiveRegMatrix.h"
2323
#include "llvm/CodeGen/LiveStacks.h"
2424
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
25+
#include "llvm/CodeGen/MachineDominators.h"
2526
#include "llvm/CodeGen/MachineFunctionPass.h"
2627
#include "llvm/CodeGen/MachineLoopInfo.h"
2728
#include "llvm/CodeGen/Passes.h"
@@ -187,6 +188,7 @@ void RABasic::getAnalysisUsage(AnalysisUsage &AU) const {
187188
AU.addRequired<ProfileSummaryInfoWrapperPass>();
188189
AU.addRequired<MachineBlockFrequencyInfoWrapperPass>();
189190
AU.addPreserved<MachineBlockFrequencyInfoWrapperPass>();
191+
AU.addRequired<MachineDominatorTreeWrapperPass>();
190192
AU.addRequiredID(MachineDominatorsID);
191193
AU.addPreservedID(MachineDominatorsID);
192194
AU.addRequired<MachineLoopInfoWrapperPass>();
@@ -310,16 +312,20 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
310312
<< "********** Function: " << mf.getName() << '\n');
311313

312314
MF = &mf;
315+
auto &MBFI = getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
316+
auto &LiveStks = getAnalysis<LiveStacksWrapperLegacy>().getLS();
317+
auto &MDT = getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
318+
313319
RegAllocBase::init(getAnalysis<VirtRegMapWrapperLegacy>().getVRM(),
314320
getAnalysis<LiveIntervalsWrapperPass>().getLIS(),
315321
getAnalysis<LiveRegMatrixWrapperLegacy>().getLRM());
316-
VirtRegAuxInfo VRAI(
317-
*MF, *LIS, *VRM, getAnalysis<MachineLoopInfoWrapperPass>().getLI(),
318-
getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI(),
319-
&getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI());
322+
VirtRegAuxInfo VRAI(*MF, *LIS, *VRM,
323+
getAnalysis<MachineLoopInfoWrapperPass>().getLI(), MBFI,
324+
&getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI());
320325
VRAI.calculateSpillWeightsAndHints();
321326

322-
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, VRAI));
327+
SpillerInstance.reset(
328+
createInlineSpiller({*LIS, LiveStks, MDT, MBFI}, *MF, *VRM, VRAI));
323329

324330
allocatePhysRegs();
325331
postOptimization();

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27332733
Bundles = &getAnalysis<EdgeBundlesWrapperLegacy>().getEdgeBundles();
27342734
SpillPlacer = &getAnalysis<SpillPlacementWrapperLegacy>().getResult();
27352735
DebugVars = &getAnalysis<LiveDebugVariablesWrapperLegacy>().getLDV();
2736+
auto &LSS = getAnalysis<LiveStacksWrapperLegacy>().getLS();
27362737

27372738
initializeCSRCost();
27382739

@@ -2754,7 +2755,8 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27542755
->getAdvisor(*MF, *this);
27552756

27562757
VRAI = std::make_unique<VirtRegAuxInfo>(*MF, *LIS, *VRM, *Loops, *MBFI);
2757-
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, *VRAI));
2758+
SpillerInstance.reset(
2759+
createInlineSpiller({*LIS, LSS, *DomTree, *MBFI}, *MF, *VRM, *VRAI));
27582760

27592761
VRAI->calculateSpillWeightsAndHints();
27602762

llvm/lib/CodeGen/RegAllocPBQP.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,9 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
794794
MachineBlockFrequencyInfo &MBFI =
795795
getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
796796

797+
auto &LiveStks = getAnalysis<LiveStacksWrapperLegacy>().getLS();
798+
auto &MDT = getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
799+
797800
VirtRegMap &VRM = getAnalysis<VirtRegMapWrapperLegacy>().getVRM();
798801

799802
PBQPVirtRegAuxInfo VRAI(
@@ -807,7 +810,7 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
807810
VirtRegAuxInfo DefaultVRAI(
808811
MF, LIS, VRM, getAnalysis<MachineLoopInfoWrapperPass>().getLI(), MBFI);
809812
std::unique_ptr<Spiller> VRegSpiller(
810-
createInlineSpiller(*this, MF, VRM, DefaultVRAI));
813+
createInlineSpiller({LIS, LiveStks, MDT, MBFI}, MF, VRM, DefaultVRAI));
811814

812815
MF.getRegInfo().freezeReservedRegs();
813816

0 commit comments

Comments
 (0)