Skip to content

Commit 2bb2f8a

Browse files
authored
[CodeGen] Remove experimental deferred spilling from GreedyRegAlloc (#137850)
This experimental option was introduced in 2015 via commit 1192294, and the target hook was added in 2020 via commit 99e865b. There does not appear to have ever been a use of this target hook in tree. This code is complicating one of the most complicated and hard to understand parts of our code base, and was an experiment introduced nearly 10 years ago. Let's get rid of it. Note that the idea described in the original patch is not neccessarily a bad one, and we might return to it someday.
1 parent 2876dbc commit 2bb2f8a

File tree

3 files changed

+15
-62
lines changed

3 files changed

+15
-62
lines changed

llvm/include/llvm/CodeGen/RegAllocEvictionAdvisor.h

-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ enum LiveRangeStage {
6666
/// Live range will be spilled. No more splitting will be attempted.
6767
RS_Spill,
6868

69-
/// Live range is in memory. Because of other evictions, it might get moved
70-
/// in a register in the end.
71-
RS_Memory,
72-
7369
/// There is nothing more we can do to this live range. Abort compilation
7470
/// if it can't be assigned.
7571
RS_Done

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

-15
Original file line numberDiff line numberDiff line change
@@ -1192,21 +1192,6 @@ class TargetRegisterInfo : public MCRegisterInfo {
11921192
return true;
11931193
}
11941194

1195-
/// Deferred spilling delays the spill insertion of a virtual register
1196-
/// after every other allocation. By deferring the spilling, it is
1197-
/// sometimes possible to eliminate that spilling altogether because
1198-
/// something else could have been eliminated, thus leaving some space
1199-
/// for the virtual register.
1200-
/// However, this comes with a compile time impact because it adds one
1201-
/// more stage to the greedy register allocator.
1202-
/// This method is used to decide whether \p VirtReg should use the deferred
1203-
/// spilling stage instead of being spilled right away.
1204-
virtual bool
1205-
shouldUseDeferredSpillingForVirtReg(const MachineFunction &MF,
1206-
const LiveInterval &VirtReg) const {
1207-
return false;
1208-
}
1209-
12101195
/// When prioritizing live ranges in register allocation, if this hook returns
12111196
/// true then the AllocationPriority of the register class will be treated as
12121197
/// more important than whether the range is local to a basic block or global.

llvm/lib/CodeGen/RegAllocGreedy.cpp

+15-43
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ static cl::opt<bool> ExhaustiveSearch(
107107
"and interference cutoffs of last chance recoloring"),
108108
cl::Hidden);
109109

110-
static cl::opt<bool> EnableDeferredSpilling(
111-
"enable-deferred-spilling", cl::Hidden,
112-
cl::desc("Instead of spilling a variable right away, defer the actual "
113-
"code insertion to the end of the allocation. That way the "
114-
"allocator might still find a suitable coloring for this "
115-
"variable because of other evicted variables."),
116-
cl::init(false));
117-
118110
// FIXME: Find a good default for this flag and remove the flag.
119111
static cl::opt<unsigned>
120112
CSRFirstTimeCost("regalloc-csr-first-time-cost",
@@ -328,7 +320,6 @@ const char *const RAGreedy::StageName[] = {
328320
"RS_Split",
329321
"RS_Split2",
330322
"RS_Spill",
331-
"RS_Memory",
332323
"RS_Done"
333324
};
334325
#endif
@@ -456,13 +447,6 @@ unsigned DefaultPriorityAdvisor::getPriority(const LiveInterval &LI) const {
456447
// Unsplit ranges that couldn't be allocated immediately are deferred until
457448
// everything else has been allocated.
458449
Prio = Size;
459-
} else if (Stage == RS_Memory) {
460-
// Memory operand should be considered last.
461-
// Change the priority such that Memory operand are assigned in
462-
// the reverse order that they came in.
463-
// TODO: Make this a member variable and probably do something about hints.
464-
static unsigned MemOp = 0;
465-
Prio = MemOp++;
466450
} else {
467451
// Giant live ranges fall back to the global assignment heuristic, which
468452
// prevents excessive spilling in pathological cases.
@@ -2650,34 +2634,22 @@ MCRegister RAGreedy::selectOrSplitImpl(const LiveInterval &VirtReg,
26502634
}
26512635

26522636
// Finally spill VirtReg itself.
2653-
if ((EnableDeferredSpilling ||
2654-
TRI->shouldUseDeferredSpillingForVirtReg(*MF, VirtReg)) &&
2655-
ExtraInfo->getStage(VirtReg) < RS_Memory) {
2656-
// TODO: This is experimental and in particular, we do not model
2657-
// the live range splitting done by spilling correctly.
2658-
// We would need a deep integration with the spiller to do the
2659-
// right thing here. Anyway, that is still good for early testing.
2660-
ExtraInfo->setStage(VirtReg, RS_Memory);
2661-
LLVM_DEBUG(dbgs() << "Do as if this register is in memory\n");
2662-
NewVRegs.push_back(VirtReg.reg());
2663-
} else {
2664-
NamedRegionTimer T("spill", "Spiller", TimerGroupName,
2665-
TimerGroupDescription, TimePassesIsEnabled);
2666-
LiveRangeEdit LRE(&VirtReg, NewVRegs, *MF, *LIS, VRM, this, &DeadRemats);
2667-
spiller().spill(LRE, &Order);
2668-
ExtraInfo->setStage(NewVRegs.begin(), NewVRegs.end(), RS_Done);
2669-
2670-
// Tell LiveDebugVariables about the new ranges. Ranges not being covered by
2671-
// the new regs are kept in LDV (still mapping to the old register), until
2672-
// we rewrite spilled locations in LDV at a later stage.
2673-
for (Register r : spiller().getSpilledRegs())
2674-
DebugVars->splitRegister(r, LRE.regs(), *LIS);
2675-
for (Register r : spiller().getReplacedRegs())
2676-
DebugVars->splitRegister(r, LRE.regs(), *LIS);
2637+
NamedRegionTimer T("spill", "Spiller", TimerGroupName,
2638+
TimerGroupDescription, TimePassesIsEnabled);
2639+
LiveRangeEdit LRE(&VirtReg, NewVRegs, *MF, *LIS, VRM, this, &DeadRemats);
2640+
spiller().spill(LRE, &Order);
2641+
ExtraInfo->setStage(NewVRegs.begin(), NewVRegs.end(), RS_Done);
2642+
2643+
// Tell LiveDebugVariables about the new ranges. Ranges not being covered by
2644+
// the new regs are kept in LDV (still mapping to the old register), until
2645+
// we rewrite spilled locations in LDV at a later stage.
2646+
for (Register r : spiller().getSpilledRegs())
2647+
DebugVars->splitRegister(r, LRE.regs(), *LIS);
2648+
for (Register r : spiller().getReplacedRegs())
2649+
DebugVars->splitRegister(r, LRE.regs(), *LIS);
26772650

2678-
if (VerifyEnabled)
2679-
MF->verify(LIS, Indexes, "After spilling", &errs());
2680-
}
2651+
if (VerifyEnabled)
2652+
MF->verify(LIS, Indexes, "After spilling", &errs());
26812653

26822654
// The live virtual register requesting allocation was spilled, so tell
26832655
// the caller not to allocate anything during this round.

0 commit comments

Comments
 (0)