Skip to content

Commit 4e9dfcb

Browse files
author
git apple-llvm automerger
committed
Merge commit '819044ad2d6a' from llvm.org/master into apple/main
2 parents 2648b3e + 819044a commit 4e9dfcb

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

llvm/lib/CodeGen/AllocationOrder.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/ADT/STLExtras.h"
2121
#include "llvm/ADT/SmallVector.h"
22-
#include "llvm/MC/MCRegister.h"
22+
#include "llvm/CodeGen/Register.h"
2323

2424
namespace llvm {
2525

@@ -110,8 +110,13 @@ class LLVM_LIBRARY_VISIBILITY AllocationOrder {
110110
/// Get the allocation order without reordered hints.
111111
ArrayRef<MCPhysReg> getOrder() const { return Order; }
112112

113-
/// Return true if PhysReg is a preferred register.
114-
bool isHint(unsigned PhysReg) const { return is_contained(Hints, PhysReg); }
113+
/// Return true if Reg is a preferred physical register.
114+
bool isHint(Register Reg) const {
115+
assert(!Reg.isPhysical() ||
116+
Reg.id() <
117+
static_cast<uint32_t>(std::numeric_limits<MCPhysReg>::max()));
118+
return Reg.isPhysical() && is_contained(Hints, Reg.id());
119+
}
115120
};
116121

117122
} // end namespace llvm

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class RAGreedy : public MachineFunctionPass,
147147
// Convenient shortcuts.
148148
using PQueue = std::priority_queue<std::pair<unsigned, unsigned>>;
149149
using SmallLISet = SmallPtrSet<LiveInterval *, 4>;
150-
using SmallVirtRegSet = SmallSet<unsigned, 16>;
150+
using SmallVirtRegSet = SmallSet<Register, 16>;
151151

152152
// context
153153
MachineFunction *MF;
@@ -260,7 +260,7 @@ class RAGreedy : public MachineFunctionPass,
260260
void setStage(Iterator Begin, Iterator End, LiveRangeStage NewStage) {
261261
ExtraRegInfo.resize(MRI->getNumVirtRegs());
262262
for (;Begin != End; ++Begin) {
263-
unsigned Reg = *Begin;
263+
Register Reg = *Begin;
264264
if (ExtraRegInfo[Reg].Stage == RS_New)
265265
ExtraRegInfo[Reg].Stage = NewStage;
266266
}
@@ -291,8 +291,8 @@ class RAGreedy : public MachineFunctionPass,
291291

292292
public:
293293
using EvictorInfo =
294-
std::pair<unsigned /* evictor */, unsigned /* physreg */>;
295-
using EvicteeInfo = llvm::DenseMap<unsigned /* evictee */, EvictorInfo>;
294+
std::pair<Register /* evictor */, MCRegister /* physreg */>;
295+
using EvicteeInfo = llvm::DenseMap<Register /* evictee */, EvictorInfo>;
296296

297297
private:
298298
/// Each Vreg that has been evicted in the last stage of selectOrSplit will
@@ -308,14 +308,14 @@ class RAGreedy : public MachineFunctionPass,
308308
/// longer relevant.
309309
/// \param Evictee The evictee Vreg for whom we want to clear collected
310310
/// eviction info.
311-
void clearEvicteeInfo(unsigned Evictee) { Evictees.erase(Evictee); }
311+
void clearEvicteeInfo(Register Evictee) { Evictees.erase(Evictee); }
312312

313313
/// Track new eviction.
314314
/// The Evictor vreg has evicted the Evictee vreg from Physreg.
315315
/// \param PhysReg The physical register Evictee was evicted from.
316316
/// \param Evictor The evictor Vreg that evicted Evictee.
317317
/// \param Evictee The evictee Vreg.
318-
void addEviction(unsigned PhysReg, unsigned Evictor, unsigned Evictee) {
318+
void addEviction(MCRegister PhysReg, Register Evictor, Register Evictee) {
319319
Evictees[Evictee].first = Evictor;
320320
Evictees[Evictee].second = PhysReg;
321321
}
@@ -324,7 +324,7 @@ class RAGreedy : public MachineFunctionPass,
324324
/// \param Evictee The evictee vreg.
325325
/// \return The Evictor vreg which evicted Evictee vreg from PhysReg. 0 if
326326
/// nobody has evicted Evictee from PhysReg.
327-
EvictorInfo getEvictor(unsigned Evictee) {
327+
EvictorInfo getEvictor(Register Evictee) {
328328
if (Evictees.count(Evictee)) {
329329
return Evictees[Evictee];
330330
}
@@ -349,7 +349,7 @@ class RAGreedy : public MachineFunctionPass,
349349
/// Global live range splitting candidate info.
350350
struct GlobalSplitCandidate {
351351
// Register intended for assignment, or 0.
352-
unsigned PhysReg;
352+
MCRegister PhysReg;
353353

354354
// SplitKit interval index for this candidate.
355355
unsigned IntvIdx;
@@ -446,7 +446,7 @@ class RAGreedy : public MachineFunctionPass,
446446
bool addSplitConstraints(InterferenceCache::Cursor, BlockFrequency&);
447447
bool addThroughConstraints(InterferenceCache::Cursor, ArrayRef<unsigned>);
448448
bool growRegion(GlobalSplitCandidate &Cand);
449-
bool splitCanCauseEvictionChain(unsigned Evictee, GlobalSplitCandidate &Cand,
449+
bool splitCanCauseEvictionChain(Register Evictee, GlobalSplitCandidate &Cand,
450450
unsigned BBNumber,
451451
const AllocationOrder &Order);
452452
bool splitCanCauseLocalSpill(unsigned VirtRegToSplit,
@@ -457,20 +457,20 @@ class RAGreedy : public MachineFunctionPass,
457457
bool *CanCauseEvictionChain);
458458
bool calcCompactRegion(GlobalSplitCandidate&);
459459
void splitAroundRegion(LiveRangeEdit&, ArrayRef<unsigned>);
460-
void calcGapWeights(unsigned, SmallVectorImpl<float>&);
460+
void calcGapWeights(MCRegister, SmallVectorImpl<float> &);
461461
Register canReassign(LiveInterval &VirtReg, Register PrevReg);
462462
bool shouldEvict(LiveInterval &A, bool, LiveInterval &B, bool);
463463
bool canEvictInterference(LiveInterval &, MCRegister, bool, EvictionCost &,
464464
const SmallVirtRegSet &);
465-
bool canEvictInterferenceInRange(LiveInterval &VirtReg, Register oPhysReg,
465+
bool canEvictInterferenceInRange(LiveInterval &VirtReg, MCRegister PhysReg,
466466
SlotIndex Start, SlotIndex End,
467467
EvictionCost &MaxCost);
468468
unsigned getCheapestEvicteeWeight(const AllocationOrder &Order,
469469
LiveInterval &VirtReg, SlotIndex Start,
470470
SlotIndex End, float *BestEvictWeight);
471-
void evictInterference(LiveInterval&, Register,
472-
SmallVectorImpl<Register>&);
473-
bool mayRecolorAllInterferences(unsigned PhysReg, LiveInterval &VirtReg,
471+
void evictInterference(LiveInterval &, MCRegister,
472+
SmallVectorImpl<Register> &);
473+
bool mayRecolorAllInterferences(MCRegister PhysReg, LiveInterval &VirtReg,
474474
SmallLISet &RecoloringCandidates,
475475
const SmallVirtRegSet &FixedRegisters);
476476

@@ -480,8 +480,8 @@ class RAGreedy : public MachineFunctionPass,
480480
unsigned tryEvict(LiveInterval&, AllocationOrder&,
481481
SmallVectorImpl<Register>&, unsigned,
482482
const SmallVirtRegSet&);
483-
unsigned tryRegionSplit(LiveInterval&, AllocationOrder&,
484-
SmallVectorImpl<Register>&);
483+
MCRegister tryRegionSplit(LiveInterval &, AllocationOrder &,
484+
SmallVectorImpl<Register> &);
485485
/// Calculate cost of region splitting.
486486
unsigned calculateRegionSplitCost(LiveInterval &VirtReg,
487487
AllocationOrder &Order,
@@ -530,7 +530,7 @@ class RAGreedy : public MachineFunctionPass,
530530
};
531531
using HintsInfo = SmallVector<HintInfo, 4>;
532532

533-
BlockFrequency getBrokenHintFreq(const HintsInfo &, unsigned);
533+
BlockFrequency getBrokenHintFreq(const HintsInfo &, MCRegister);
534534
void collectHintInfo(unsigned, HintsInfo &);
535535

536536
bool isUnusedCalleeSavedReg(MCRegister PhysReg) const;
@@ -777,12 +777,14 @@ Register RAGreedy::tryAssign(LiveInterval &VirtReg,
777777
// preferred register.
778778
if (Register Hint = MRI->getSimpleHint(VirtReg.reg()))
779779
if (Order.isHint(Hint)) {
780-
LLVM_DEBUG(dbgs() << "missed hint " << printReg(Hint, TRI) << '\n');
780+
MCRegister PhysHint = Hint.asMCReg();
781+
LLVM_DEBUG(dbgs() << "missed hint " << printReg(PhysHint, TRI) << '\n');
781782
EvictionCost MaxCost;
782783
MaxCost.setBrokenHints(1);
783-
if (canEvictInterference(VirtReg, Hint, true, MaxCost, FixedRegisters)) {
784-
evictInterference(VirtReg, Hint, NewVRegs);
785-
return Hint;
784+
if (canEvictInterference(VirtReg, PhysHint, true, MaxCost,
785+
FixedRegisters)) {
786+
evictInterference(VirtReg, PhysHint, NewVRegs);
787+
return PhysHint;
786788
}
787789
// Record the missed hint, we may be able to recover
788790
// at the end if the surrounding allocation changed.
@@ -969,7 +971,7 @@ bool RAGreedy::canEvictInterference(LiveInterval &VirtReg, MCRegister PhysReg,
969971
/// when returning true.
970972
/// \return True when interference can be evicted cheaper than MaxCost.
971973
bool RAGreedy::canEvictInterferenceInRange(LiveInterval &VirtReg,
972-
Register PhysReg, SlotIndex Start,
974+
MCRegister PhysReg, SlotIndex Start,
973975
SlotIndex End,
974976
EvictionCost &MaxCost) {
975977
EvictionCost Cost;
@@ -1045,7 +1047,7 @@ unsigned RAGreedy::getCheapestEvicteeWeight(const AllocationOrder &Order,
10451047
/// evictInterference - Evict any interferring registers that prevent VirtReg
10461048
/// from being assigned to Physreg. This assumes that canEvictInterference
10471049
/// returned true.
1048-
void RAGreedy::evictInterference(LiveInterval &VirtReg, Register PhysReg,
1050+
void RAGreedy::evictInterference(LiveInterval &VirtReg, MCRegister PhysReg,
10491051
SmallVectorImpl<Register> &NewVRegs) {
10501052
// Make sure that VirtReg has a cascade number, and assign that cascade
10511053
// number to every evicted register. These live ranges than then only be
@@ -1113,7 +1115,7 @@ unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
11131115
// Keep track of the cheapest interference seen so far.
11141116
EvictionCost BestCost;
11151117
BestCost.setMax();
1116-
unsigned BestPhys = 0;
1118+
MCRegister BestPhys;
11171119
unsigned OrderLimit = Order.getOrder().size();
11181120

11191121
// When we are just looking for a reduced cost per use, don't break any
@@ -1478,13 +1480,13 @@ BlockFrequency RAGreedy::calcSpillCost() {
14781480
/// artifact of Evictee.
14791481
/// \return True if splitting Evictee may cause a bad eviction chain, false
14801482
/// otherwise.
1481-
bool RAGreedy::splitCanCauseEvictionChain(unsigned Evictee,
1483+
bool RAGreedy::splitCanCauseEvictionChain(Register Evictee,
14821484
GlobalSplitCandidate &Cand,
14831485
unsigned BBNumber,
14841486
const AllocationOrder &Order) {
14851487
EvictionTrack::EvictorInfo VregEvictorInfo = LastEvicted.getEvictor(Evictee);
14861488
unsigned Evictor = VregEvictorInfo.first;
1487-
unsigned PhysReg = VregEvictorInfo.second;
1489+
MCRegister PhysReg = VregEvictorInfo.second;
14881490

14891491
// No actual evictor.
14901492
if (!Evictor || !PhysReg)
@@ -1581,7 +1583,7 @@ BlockFrequency RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand,
15811583
bool *CanCauseEvictionChain) {
15821584
BlockFrequency GlobalCost = 0;
15831585
const BitVector &LiveBundles = Cand.LiveBundles;
1584-
unsigned VirtRegToSplit = SA->getParent().reg();
1586+
Register VirtRegToSplit = SA->getParent().reg();
15851587
ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
15861588
for (unsigned I = 0; I != UseBlocks.size(); ++I) {
15871589
const SplitAnalysis::BlockInfo &BI = UseBlocks[I];
@@ -1808,10 +1810,11 @@ void RAGreedy::splitAroundRegion(LiveRangeEdit &LREdit,
18081810
MF->verify(this, "After splitting live range around region");
18091811
}
18101812

1811-
unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
1812-
SmallVectorImpl<Register> &NewVRegs) {
1813+
MCRegister RAGreedy::tryRegionSplit(LiveInterval &VirtReg,
1814+
AllocationOrder &Order,
1815+
SmallVectorImpl<Register> &NewVRegs) {
18131816
if (!TRI->shouldRegionSplitForVirtReg(*MF, VirtReg))
1814-
return 0;
1817+
return MCRegister::NoRegister;
18151818
unsigned NumCands = 0;
18161819
BlockFrequency SpillCost = calcSpillCost();
18171820
BlockFrequency BestCost;
@@ -1841,12 +1844,12 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
18411844
// current max frequency.
18421845
if (HasCompact && (BestCost > SpillCost) && (BestCand != NoCand) &&
18431846
CanCauseEvictionChain) {
1844-
return 0;
1847+
return MCRegister::NoRegister;
18451848
}
18461849

18471850
// No solutions found, fall back to single block splitting.
18481851
if (!HasCompact && BestCand == NoCand)
1849-
return 0;
1852+
return MCRegister::NoRegister;
18501853

18511854
return doRegionSplit(VirtReg, BestCand, HasCompact, NewVRegs);
18521855
}
@@ -2129,7 +2132,7 @@ RAGreedy::tryInstructionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
21292132
///
21302133
/// GapWeight[I] represents the gap between UseSlots[I] and UseSlots[I + 1].
21312134
///
2132-
void RAGreedy::calcGapWeights(unsigned PhysReg,
2135+
void RAGreedy::calcGapWeights(MCRegister PhysReg,
21332136
SmallVectorImpl<float> &GapWeight) {
21342137
assert(SA->getUseBlocks().size() == 1 && "Not a local interval");
21352138
const SplitAnalysis::BlockInfo &BI = SA->getUseBlocks().front();
@@ -2476,7 +2479,7 @@ unsigned RAGreedy::trySplit(LiveInterval &VirtReg, AllocationOrder &Order,
24762479
// ranges already made dubious progress with region splitting, so they go
24772480
// straight to single block splitting.
24782481
if (getStage(VirtReg) < RS_Split2) {
2479-
unsigned PhysReg = tryRegionSplit(VirtReg, Order, NewVRegs);
2482+
MCRegister PhysReg = tryRegionSplit(VirtReg, Order, NewVRegs);
24802483
if (PhysReg || !NewVRegs.empty())
24812484
return PhysReg;
24822485
}
@@ -2506,10 +2509,9 @@ static bool hasTiedDef(MachineRegisterInfo *MRI, unsigned reg) {
25062509
/// for \p VirtReg.
25072510
/// \p FixedRegisters contains all the virtual registers that cannot be
25082511
/// recolored.
2509-
bool
2510-
RAGreedy::mayRecolorAllInterferences(unsigned PhysReg, LiveInterval &VirtReg,
2511-
SmallLISet &RecoloringCandidates,
2512-
const SmallVirtRegSet &FixedRegisters) {
2512+
bool RAGreedy::mayRecolorAllInterferences(
2513+
MCRegister PhysReg, LiveInterval &VirtReg, SmallLISet &RecoloringCandidates,
2514+
const SmallVirtRegSet &FixedRegisters) {
25132515
const TargetRegisterClass *CurRC = MRI->getRegClass(VirtReg.reg());
25142516

25152517
for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) {
@@ -2878,7 +2880,7 @@ void RAGreedy::collectHintInfo(unsigned Reg, HintsInfo &Out) {
28782880
/// \p PhysReg was used.
28792881
/// \return The cost of \p List for \p PhysReg.
28802882
BlockFrequency RAGreedy::getBrokenHintFreq(const HintsInfo &List,
2881-
unsigned PhysReg) {
2883+
MCRegister PhysReg) {
28822884
BlockFrequency Cost = 0;
28832885
for (const HintInfo &Info : List) {
28842886
if (Info.PhysReg != PhysReg)
@@ -2924,7 +2926,7 @@ void RAGreedy::tryHintRecoloring(LiveInterval &VirtReg) {
29242926
// Get the live interval mapped with this virtual register to be able
29252927
// to check for the interference with the new color.
29262928
LiveInterval &LI = LIS->getInterval(Reg);
2927-
Register CurrPhys = VRM->getPhys(Reg);
2929+
MCRegister CurrPhys = VRM->getPhys(Reg);
29282930
// Check that the new color matches the register class constraints and
29292931
// that it is free for this live range.
29302932
if (CurrPhys != PhysReg && (!MRI->getRegClass(Reg)->contains(PhysReg) ||

0 commit comments

Comments
 (0)