Skip to content

Commit 82492f2

Browse files
committed
[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
1 parent 3c297a2 commit 82492f2

File tree

9 files changed

+52
-41
lines changed

9 files changed

+52
-41
lines changed

llvm/include/llvm/CodeGen/LiveRangeEdit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MachineOperand;
4141
class TargetInstrInfo;
4242
class TargetRegisterInfo;
4343
class VirtRegMap;
44+
class VirtRegAuxInfo;
4445

4546
class LiveRangeEdit : private MachineRegisterInfo::Delegate {
4647
public:
@@ -248,8 +249,7 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
248249

249250
/// calculateRegClassAndHint - Recompute register class and hint for each new
250251
/// register.
251-
void calculateRegClassAndHint(MachineFunction &, const MachineLoopInfo &,
252-
const MachineBlockFrequencyInfo &);
252+
void calculateRegClassAndHint(MachineFunction &, VirtRegAuxInfo &);
253253
};
254254

255255
} // end namespace llvm

llvm/include/llvm/CodeGen/Spiller.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class LiveRangeEdit;
1515
class MachineFunction;
1616
class MachineFunctionPass;
1717
class VirtRegMap;
18+
class VirtRegAuxInfo;
1819

1920
/// Spiller interface.
2021
///
@@ -34,8 +35,8 @@ class Spiller {
3435

3536
/// Create and return a spiller that will insert spill code directly instead
3637
/// of deferring though VirtRegMap.
37-
Spiller *createInlineSpiller(MachineFunctionPass &pass, MachineFunction &mf,
38-
VirtRegMap &vrm);
38+
Spiller *createInlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF,
39+
VirtRegMap &VRM, VirtRegAuxInfo &VRAI);
3940

4041
} // end namespace llvm
4142

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,23 @@ class InlineSpiller : public Spiller {
191191
// Object records spills information and does the hoisting.
192192
HoistSpillHelper HSpiller;
193193

194+
// Live range weight calculator.
195+
VirtRegAuxInfo &VRAI;
196+
194197
~InlineSpiller() override = default;
195198

196199
public:
197-
InlineSpiller(MachineFunctionPass &pass, MachineFunction &mf, VirtRegMap &vrm)
198-
: MF(mf), LIS(pass.getAnalysis<LiveIntervals>()),
199-
LSS(pass.getAnalysis<LiveStacks>()),
200-
AA(&pass.getAnalysis<AAResultsWrapperPass>().getAAResults()),
201-
MDT(pass.getAnalysis<MachineDominatorTree>()),
202-
Loops(pass.getAnalysis<MachineLoopInfo>()), VRM(vrm),
203-
MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
204-
TRI(*mf.getSubtarget().getRegisterInfo()),
205-
MBFI(pass.getAnalysis<MachineBlockFrequencyInfo>()),
206-
HSpiller(pass, mf, vrm) {}
200+
InlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM,
201+
VirtRegAuxInfo &VRAI)
202+
: MF(MF), LIS(Pass.getAnalysis<LiveIntervals>()),
203+
LSS(Pass.getAnalysis<LiveStacks>()),
204+
AA(&Pass.getAnalysis<AAResultsWrapperPass>().getAAResults()),
205+
MDT(Pass.getAnalysis<MachineDominatorTree>()),
206+
Loops(Pass.getAnalysis<MachineLoopInfo>()), VRM(VRM),
207+
MRI(MF.getRegInfo()), TII(*MF.getSubtarget().getInstrInfo()),
208+
TRI(*MF.getSubtarget().getRegisterInfo()),
209+
MBFI(Pass.getAnalysis<MachineBlockFrequencyInfo>()),
210+
HSpiller(Pass, MF, VRM), VRAI(VRAI) {}
207211

208212
void spill(LiveRangeEdit &) override;
209213
void postOptimization() override;
@@ -239,10 +243,10 @@ Spiller::~Spiller() = default;
239243

240244
void Spiller::anchor() {}
241245

242-
Spiller *llvm::createInlineSpiller(MachineFunctionPass &pass,
243-
MachineFunction &mf,
244-
VirtRegMap &vrm) {
245-
return new InlineSpiller(pass, mf, vrm);
246+
Spiller *llvm::createInlineSpiller(MachineFunctionPass &Pass,
247+
MachineFunction &MF, VirtRegMap &VRM,
248+
VirtRegAuxInfo &VRAI) {
249+
return new InlineSpiller(Pass, MF, VRM, VRAI);
246250
}
247251

248252
//===----------------------------------------------------------------------===//
@@ -1200,7 +1204,7 @@ void InlineSpiller::spill(LiveRangeEdit &edit) {
12001204
if (!RegsToSpill.empty())
12011205
spillAll();
12021206

1203-
Edit->calculateRegClassAndHint(MF, Loops, MBFI);
1207+
Edit->calculateRegClassAndHint(MF, VRAI);
12041208
}
12051209

12061210
/// Optimizations after all the reg selections and spills are done.

llvm/lib/CodeGen/LiveRangeEdit.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,8 @@ LiveRangeEdit::MRI_NoteNewVirtualRegister(Register VReg) {
458458
NewRegs.push_back(VReg);
459459
}
460460

461-
void
462-
LiveRangeEdit::calculateRegClassAndHint(MachineFunction &MF,
463-
const MachineLoopInfo &Loops,
464-
const MachineBlockFrequencyInfo &MBFI) {
465-
VirtRegAuxInfo VRAI(MF, LIS, *VRM, Loops, MBFI);
461+
void LiveRangeEdit::calculateRegClassAndHint(MachineFunction &MF,
462+
VirtRegAuxInfo &VRAI) {
466463
for (unsigned I = 0, Size = size(); I < Size; ++I) {
467464
LiveInterval &LI = LIS.getInterval(get(I));
468465
if (MRI.recomputeRegClass(LI.reg()))

llvm/lib/CodeGen/RegAllocBasic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
320320
getAnalysis<MachineBlockFrequencyInfo>());
321321
VRAI.calculateSpillWeightsAndHints();
322322

323-
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
323+
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, VRAI));
324324

325325
allocatePhysRegs();
326326
postOptimization();

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,6 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
32273227
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
32283228
DomTree = &getAnalysis<MachineDominatorTree>();
32293229
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
3230-
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
32313230
Loops = &getAnalysis<MachineLoopInfo>();
32323231
Bundles = &getAnalysis<EdgeBundles>();
32333232
SpillPlacer = &getAnalysis<SpillPlacement>();
@@ -3239,13 +3238,14 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
32393238
RegCosts = TRI->getRegisterCosts(*MF);
32403239

32413240
VRAI = std::make_unique<VirtRegAuxInfo>(*MF, *LIS, *VRM, *Loops, *MBFI);
3241+
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, *VRAI));
32423242

32433243
VRAI->calculateSpillWeightsAndHints();
32443244

32453245
LLVM_DEBUG(LIS->dump());
32463246

32473247
SA.reset(new SplitAnalysis(*VRM, *LIS, *Loops));
3248-
SE.reset(new SplitEditor(*SA, *AA, *LIS, *VRM, *DomTree, *MBFI));
3248+
SE.reset(new SplitEditor(*SA, *AA, *LIS, *VRM, *DomTree, *MBFI, *VRAI));
32493249
ExtraRegInfo.clear();
32503250
ExtraRegInfo.resize(MRI->getNumVirtRegs());
32513251
NextCascade = 1;

llvm/lib/CodeGen/RegAllocPBQP.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,14 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
800800
PBQPVirtRegAuxInfo VRAI(MF, LIS, VRM, getAnalysis<MachineLoopInfo>(), MBFI);
801801
VRAI.calculateSpillWeightsAndHints();
802802

803-
std::unique_ptr<Spiller> VRegSpiller(createInlineSpiller(*this, MF, VRM));
803+
// FIXME: we create DefaultVRAI here to match existing behavior pre-passing
804+
// the VRAI through the spiller to the live range editor. However, it probably
805+
// makes more sense to pass the PBQP VRAI. The existing behavior had
806+
// LiveRangeEdit make its own VirtRegAuxInfo object.
807+
VirtRegAuxInfo DefaultVRAI(MF, LIS, VRM, getAnalysis<MachineLoopInfo>(),
808+
MBFI);
809+
std::unique_ptr<Spiller> VRegSpiller(
810+
createInlineSpiller(*this, MF, VRM, DefaultVRAI));
804811

805812
MF.getRegInfo().freezeReservedRegs(MF);
806813

llvm/lib/CodeGen/SplitKit.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,15 @@ void SplitAnalysis::analyze(const LiveInterval *li) {
357357
//===----------------------------------------------------------------------===//
358358

359359
/// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
360-
SplitEditor::SplitEditor(SplitAnalysis &sa, AliasAnalysis &aa,
361-
LiveIntervals &lis, VirtRegMap &vrm,
362-
MachineDominatorTree &mdt,
363-
MachineBlockFrequencyInfo &mbfi)
364-
: SA(sa), AA(aa), LIS(lis), VRM(vrm),
365-
MRI(vrm.getMachineFunction().getRegInfo()), MDT(mdt),
366-
TII(*vrm.getMachineFunction().getSubtarget().getInstrInfo()),
367-
TRI(*vrm.getMachineFunction().getSubtarget().getRegisterInfo()),
368-
MBFI(mbfi), RegAssign(Allocator) {}
360+
SplitEditor::SplitEditor(SplitAnalysis &SA, AliasAnalysis &AA,
361+
LiveIntervals &LIS, VirtRegMap &VRM,
362+
MachineDominatorTree &MDT,
363+
MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo &VRAI)
364+
: SA(SA), AA(AA), LIS(LIS), VRM(VRM),
365+
MRI(VRM.getMachineFunction().getRegInfo()), MDT(MDT),
366+
TII(*VRM.getMachineFunction().getSubtarget().getInstrInfo()),
367+
TRI(*VRM.getMachineFunction().getSubtarget().getRegisterInfo()),
368+
MBFI(MBFI), VRAI(VRAI), RegAssign(Allocator) {}
369369

370370
void SplitEditor::reset(LiveRangeEdit &LRE, ComplementSpillMode SM) {
371371
Edit = &LRE;
@@ -1502,7 +1502,7 @@ void SplitEditor::finish(SmallVectorImpl<unsigned> *LRMap) {
15021502
}
15031503

15041504
// Calculate spill weight and allocation hints for new intervals.
1505-
Edit->calculateRegClassAndHint(VRM.getMachineFunction(), SA.Loops, MBFI);
1505+
Edit->calculateRegClassAndHint(VRM.getMachineFunction(), VRAI);
15061506

15071507
assert(!LRMap || LRMap->size() == Edit->size());
15081508
}

llvm/lib/CodeGen/SplitKit.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class MachineRegisterInfo;
4444
class TargetInstrInfo;
4545
class TargetRegisterInfo;
4646
class VirtRegMap;
47+
class VirtRegAuxInfo;
4748

4849
/// Determines the latest safe point in a block in which we can insert a split,
4950
/// spill or other instruction related with CurLI.
@@ -272,6 +273,7 @@ class LLVM_LIBRARY_VISIBILITY SplitEditor {
272273
const TargetInstrInfo &TII;
273274
const TargetRegisterInfo &TRI;
274275
const MachineBlockFrequencyInfo &MBFI;
276+
VirtRegAuxInfo &VRAI;
275277

276278
public:
277279
/// ComplementSpillMode - Select how the complement live range should be
@@ -457,9 +459,9 @@ class LLVM_LIBRARY_VISIBILITY SplitEditor {
457459
public:
458460
/// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
459461
/// Newly created intervals will be appended to newIntervals.
460-
SplitEditor(SplitAnalysis &sa, AAResults &aa, LiveIntervals &lis,
461-
VirtRegMap &vrm, MachineDominatorTree &mdt,
462-
MachineBlockFrequencyInfo &mbfi);
462+
SplitEditor(SplitAnalysis &SA, AAResults &AA, LiveIntervals &LIS,
463+
VirtRegMap &VRM, MachineDominatorTree &MDT,
464+
MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo &VRAI);
463465

464466
/// reset - Prepare for a new split.
465467
void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition);

0 commit comments

Comments
 (0)