Skip to content

Commit 294eca3

Browse files
committed
[regalloc] Remove -consider-local-interval-cost
Discussed extensively on D98232. The functionality introduced in D35816 never worked correctly. In D98232, it was fixed, but, as it was introducing a large compile-time regression, and the value of the original patch was called into doubt, we disabled it by default everywhere. A year later, it appears that caused no grief, so it seems safe to remove the disabled code. This should be accompanied by re-opening bug 26810. Differential Revision: https://reviews.llvm.org/D121128
1 parent b6a7600 commit 294eca3

File tree

9 files changed

+49
-611
lines changed

9 files changed

+49
-611
lines changed

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
272272
/// a finer grain to tune the register allocator.
273273
virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const;
274274

275-
/// True if the subtarget should consider the cost of local intervals
276-
/// created by a split candidate when choosing the best split candidate. This
277-
/// heuristic may be compile time intensive.
278-
virtual bool enableAdvancedRASplitCost() const;
279-
280275
/// Enable use of alias analysis during code generation (during MI
281276
/// scheduling, DAGCombine, etc.).
282277
virtual bool useAA() const;

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 6 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ CSRFirstTimeCost("regalloc-csr-first-time-cost",
124124
cl::desc("Cost for first time use of callee-saved register."),
125125
cl::init(0), cl::Hidden);
126126

127-
static cl::opt<bool> ConsiderLocalIntervalCost(
128-
"consider-local-interval-cost", cl::Hidden,
129-
cl::desc("Consider the cost of local intervals created by a split "
130-
"candidate when choosing the best split candidate."),
131-
cl::init(false));
132-
133127
static cl::opt<long> GrowRegionComplexityBudget(
134128
"grow-region-complexity-budget",
135129
cl::desc("growRegion() does not scale with the number of BB edges, so "
@@ -996,44 +990,12 @@ bool RAGreedy::splitCanCauseEvictionChain(Register Evictee,
996990
return true;
997991
}
998992

999-
/// Check if splitting VirtRegToSplit will create a local split interval
1000-
/// in basic block number BBNumber that may cause a spill.
1001-
///
1002-
/// \param VirtRegToSplit The register considered to be split.
1003-
/// \param Cand The split candidate that determines the physical
1004-
/// register we are splitting for and the interferences.
1005-
/// \param BBNumber The number of a BB for which the region split process
1006-
/// will create a local split interval.
1007-
/// \param Order The physical registers that may get evicted by a
1008-
/// split artifact of VirtRegToSplit.
1009-
/// \return True if splitting VirtRegToSplit may cause a spill, false
1010-
/// otherwise.
1011-
bool RAGreedy::splitCanCauseLocalSpill(unsigned VirtRegToSplit,
1012-
GlobalSplitCandidate &Cand,
1013-
unsigned BBNumber,
1014-
const AllocationOrder &Order) {
1015-
Cand.Intf.moveToBlock(BBNumber);
1016-
1017-
// Check if the local interval will find a non interfereing assignment.
1018-
for (auto PhysReg : Order.getOrder()) {
1019-
if (!Matrix->checkInterference(Cand.Intf.first().getPrevIndex(),
1020-
Cand.Intf.last(), PhysReg))
1021-
return false;
1022-
}
1023-
1024-
// The local interval is not able to find non interferencing assignment
1025-
// and not able to evict a less worthy interval, therfore, it can cause a
1026-
// spill.
1027-
return true;
1028-
}
1029-
1030993
/// calcGlobalSplitCost - Return the global split cost of following the split
1031994
/// pattern in LiveBundles. This cost should be added to the local cost of the
1032995
/// interference pattern in SplitConstraints.
1033996
///
1034997
BlockFrequency RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand,
1035-
const AllocationOrder &Order,
1036-
bool *CanCauseEvictionChain) {
998+
const AllocationOrder &Order) {
1037999
BlockFrequency GlobalCost = 0;
10381000
const BitVector &LiveBundles = Cand.LiveBundles;
10391001
Register VirtRegToSplit = SA->getParent().reg();
@@ -1046,29 +1008,6 @@ BlockFrequency RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand,
10461008
unsigned Ins = 0;
10471009

10481010
Cand.Intf.moveToBlock(BC.Number);
1049-
// Check wheather a local interval is going to be created during the region
1050-
// split. Calculate adavanced spilt cost (cost of local intervals) if option
1051-
// is enabled.
1052-
if (EnableAdvancedRASplitCost && Cand.Intf.hasInterference() && BI.LiveIn &&
1053-
BI.LiveOut && RegIn && RegOut) {
1054-
1055-
if (CanCauseEvictionChain &&
1056-
splitCanCauseEvictionChain(VirtRegToSplit, Cand, BC.Number, Order)) {
1057-
// This interference causes our eviction from this assignment, we might
1058-
// evict somebody else and eventually someone will spill, add that cost.
1059-
// See splitCanCauseEvictionChain for detailed description of scenarios.
1060-
GlobalCost += SpillPlacer->getBlockFrequency(BC.Number);
1061-
GlobalCost += SpillPlacer->getBlockFrequency(BC.Number);
1062-
1063-
*CanCauseEvictionChain = true;
1064-
1065-
} else if (splitCanCauseLocalSpill(VirtRegToSplit, Cand, BC.Number,
1066-
Order)) {
1067-
// This interference causes local interval to spill, add that cost.
1068-
GlobalCost += SpillPlacer->getBlockFrequency(BC.Number);
1069-
GlobalCost += SpillPlacer->getBlockFrequency(BC.Number);
1070-
}
1071-
}
10721011

10731012
if (BI.LiveIn)
10741013
Ins += RegIn != (BC.Entry == SpillPlacement::PrefReg);
@@ -1089,20 +1028,6 @@ BlockFrequency RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand,
10891028
if (Cand.Intf.hasInterference()) {
10901029
GlobalCost += SpillPlacer->getBlockFrequency(Number);
10911030
GlobalCost += SpillPlacer->getBlockFrequency(Number);
1092-
1093-
// Check wheather a local interval is going to be created during the
1094-
// region split.
1095-
if (EnableAdvancedRASplitCost && CanCauseEvictionChain &&
1096-
splitCanCauseEvictionChain(VirtRegToSplit, Cand, Number, Order)) {
1097-
// This interference cause our eviction from this assignment, we might
1098-
// evict somebody else, add that cost.
1099-
// See splitCanCauseEvictionChain for detailed description of
1100-
// scenarios.
1101-
GlobalCost += SpillPlacer->getBlockFrequency(Number);
1102-
GlobalCost += SpillPlacer->getBlockFrequency(Number);
1103-
1104-
*CanCauseEvictionChain = true;
1105-
}
11061031
}
11071032
continue;
11081033
}
@@ -1285,19 +1210,8 @@ MCRegister RAGreedy::tryRegionSplit(const LiveInterval &VirtReg,
12851210
MBFI->printBlockFreq(dbgs(), BestCost) << '\n');
12861211
}
12871212

1288-
bool CanCauseEvictionChain = false;
1289-
unsigned BestCand =
1290-
calculateRegionSplitCost(VirtReg, Order, BestCost, NumCands,
1291-
false /*IgnoreCSR*/, &CanCauseEvictionChain);
1292-
1293-
// Split candidates with compact regions can cause a bad eviction sequence.
1294-
// See splitCanCauseEvictionChain for detailed description of scenarios.
1295-
// To avoid it, we need to comapre the cost with the spill cost and not the
1296-
// current max frequency.
1297-
if (HasCompact && (BestCost > SpillCost) && (BestCand != NoCand) &&
1298-
CanCauseEvictionChain) {
1299-
return MCRegister::NoRegister;
1300-
}
1213+
unsigned BestCand = calculateRegionSplitCost(VirtReg, Order, BestCost,
1214+
NumCands, false /*IgnoreCSR*/);
13011215

13021216
// No solutions found, fall back to single block splitting.
13031217
if (!HasCompact && BestCand == NoCand)
@@ -1309,8 +1223,8 @@ MCRegister RAGreedy::tryRegionSplit(const LiveInterval &VirtReg,
13091223
unsigned RAGreedy::calculateRegionSplitCost(const LiveInterval &VirtReg,
13101224
AllocationOrder &Order,
13111225
BlockFrequency &BestCost,
1312-
unsigned &NumCands, bool IgnoreCSR,
1313-
bool *CanCauseEvictionChain) {
1226+
unsigned &NumCands,
1227+
bool IgnoreCSR) {
13141228
unsigned BestCand = NoCand;
13151229
for (MCPhysReg PhysReg : Order) {
13161230
assert(PhysReg);
@@ -1373,8 +1287,7 @@ unsigned RAGreedy::calculateRegionSplitCost(const LiveInterval &VirtReg,
13731287
continue;
13741288
}
13751289

1376-
bool HasEvictionChain = false;
1377-
Cost += calcGlobalSplitCost(Cand, Order, &HasEvictionChain);
1290+
Cost += calcGlobalSplitCost(Cand, Order);
13781291
LLVM_DEBUG({
13791292
dbgs() << ", total = ";
13801293
MBFI->printBlockFreq(dbgs(), Cost) << " with bundles";
@@ -1385,24 +1298,10 @@ unsigned RAGreedy::calculateRegionSplitCost(const LiveInterval &VirtReg,
13851298
if (Cost < BestCost) {
13861299
BestCand = NumCands;
13871300
BestCost = Cost;
1388-
// See splitCanCauseEvictionChain for detailed description of bad
1389-
// eviction chain scenarios.
1390-
if (CanCauseEvictionChain)
1391-
*CanCauseEvictionChain = HasEvictionChain;
13921301
}
13931302
++NumCands;
13941303
}
13951304

1396-
if (CanCauseEvictionChain && BestCand != NoCand) {
1397-
// See splitCanCauseEvictionChain for detailed description of bad
1398-
// eviction chain scenarios.
1399-
LLVM_DEBUG(dbgs() << "Best split candidate of vreg "
1400-
<< printReg(VirtReg.reg(), TRI) << " may ");
1401-
if (!(*CanCauseEvictionChain))
1402-
LLVM_DEBUG(dbgs() << "not ");
1403-
LLVM_DEBUG(dbgs() << "cause bad eviction chain\n");
1404-
}
1405-
14061305
return BestCand;
14071306
}
14081307

@@ -2738,11 +2637,6 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27382637
TII = MF->getSubtarget().getInstrInfo();
27392638
RCI.runOnMachineFunction(mf);
27402639

2741-
EnableAdvancedRASplitCost =
2742-
ConsiderLocalIntervalCost.getNumOccurrences()
2743-
? ConsiderLocalIntervalCost
2744-
: MF->getSubtarget().enableAdvancedRASplitCost();
2745-
27462640
if (VerifyEnabled)
27472641
MF->verify(this, "Before greedy register allocator");
27482642

llvm/lib/CodeGen/RegAllocGreedy.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,6 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
320320
/// Callee-save register cost, calculated once per machine function.
321321
BlockFrequency CSRCost;
322322

323-
/// Enable or not the consideration of the cost of local intervals created
324-
/// by a split candidate when choosing the best split candidate.
325-
bool EnableAdvancedRASplitCost;
326-
327323
/// Set of broken hints that may be reconciled later because of eviction.
328324
SmallSetVector<const LiveInterval *, 8> SetOfBrokenHints;
329325

@@ -380,12 +376,8 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
380376
bool splitCanCauseEvictionChain(Register Evictee, GlobalSplitCandidate &Cand,
381377
unsigned BBNumber,
382378
const AllocationOrder &Order);
383-
bool splitCanCauseLocalSpill(unsigned VirtRegToSplit,
384-
GlobalSplitCandidate &Cand, unsigned BBNumber,
385-
const AllocationOrder &Order);
386379
BlockFrequency calcGlobalSplitCost(GlobalSplitCandidate &,
387-
const AllocationOrder &Order,
388-
bool *CanCauseEvictionChain);
380+
const AllocationOrder &Order);
389381
bool calcCompactRegion(GlobalSplitCandidate &);
390382
void splitAroundRegion(LiveRangeEdit &, ArrayRef<unsigned>);
391383
void calcGapWeights(MCRegister, SmallVectorImpl<float> &);
@@ -414,8 +406,7 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
414406
unsigned calculateRegionSplitCost(const LiveInterval &VirtReg,
415407
AllocationOrder &Order,
416408
BlockFrequency &BestCost,
417-
unsigned &NumCands, bool IgnoreCSR,
418-
bool *CanCauseEvictionChain = nullptr);
409+
unsigned &NumCands, bool IgnoreCSR);
419410
/// Perform region splitting.
420411
unsigned doRegionSplit(const LiveInterval &VirtReg, unsigned BestCand,
421412
bool HasCompact, SmallVectorImpl<Register> &NewVRegs);

llvm/lib/CodeGen/TargetSubtargetInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ bool TargetSubtargetInfo::enableRALocalReassignment(
4545
return true;
4646
}
4747

48-
bool TargetSubtargetInfo::enableAdvancedRASplitCost() const {
49-
return false;
50-
}
51-
5248
bool TargetSubtargetInfo::enablePostRAScheduler() const {
5349
return getSchedModel().PostRAScheduler;
5450
}

llvm/lib/Target/AArch64/AArch64Subtarget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,6 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo {
623623

624624
bool enableEarlyIfConversion() const override;
625625

626-
bool enableAdvancedRASplitCost() const override { return false; }
627-
628626
std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const override;
629627

630628
bool isCallingConvWin64(CallingConv::ID CC) const {

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,6 @@ class X86Subtarget final : public X86GenSubtargetInfo {
995995
AntiDepBreakMode getAntiDepBreakMode() const override {
996996
return TargetSubtargetInfo::ANTIDEP_CRITICAL;
997997
}
998-
999-
bool enableAdvancedRASplitCost() const override { return false; }
1000998
};
1001999

10021000
} // end namespace llvm

0 commit comments

Comments
 (0)