Skip to content

Commit c11c20f

Browse files
committed
[NFC][Regalloc] VirtRegAuxInfo::Hint does not need to be a field
It is only used in weightCalcHelper, and cleared upon its finishing its job there. The patch further cleans up style guide discrepancies, and simplifies CopyHint by removing duplicate 'IsPhys' information (it's what the Reg field would report).
1 parent 6fd994b commit c11c20f

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

llvm/include/llvm/CodeGen/CalcSpillWeights.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class VirtRegMap;
4949
VirtRegMap *const VRM;
5050
const MachineLoopInfo &Loops;
5151
const MachineBlockFrequencyInfo &MBFI;
52-
DenseMap<unsigned, float> Hint;
5352

5453
public:
5554
VirtRegAuxInfo(MachineFunction &MF, LiveIntervals &LIS, VirtRegMap *VRM,

llvm/lib/CodeGen/CalcSpillWeights.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
150150
MachineLoop *Loop = nullptr;
151151
bool IsExiting = false;
152152
float TotalWeight = 0;
153-
unsigned NumInstr = 0; // Number of instructions using li
153+
unsigned NumInstr = 0; // Number of instructions using LI
154154
SmallPtrSet<MachineInstr *, 8> Visited;
155155

156-
std::pair<unsigned, unsigned> TargetHint = MRI.getRegAllocationHint(LI.reg());
156+
std::pair<Register, Register> TargetHint = MRI.getRegAllocationHint(LI.reg());
157157

158158
if (LI.isSpillable() && VRM) {
159159
Register Reg = LI.reg();
@@ -192,22 +192,21 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
192192

193193
// CopyHint is a sortable hint derived from a COPY instruction.
194194
struct CopyHint {
195-
unsigned Reg;
196-
float Weight;
197-
bool IsPhys;
198-
CopyHint(unsigned R, float W, bool P) :
199-
Reg(R), Weight(W), IsPhys(P) {}
200-
bool operator<(const CopyHint &rhs) const {
195+
const Register Reg;
196+
const float Weight;
197+
CopyHint(Register R, float W) : Reg(R), Weight(W) {}
198+
bool operator<(const CopyHint &Rhs) const {
201199
// Always prefer any physreg hint.
202-
if (IsPhys != rhs.IsPhys)
203-
return (IsPhys && !rhs.IsPhys);
204-
if (Weight != rhs.Weight)
205-
return (Weight > rhs.Weight);
206-
return Reg < rhs.Reg; // Tie-breaker.
200+
if (Reg.isPhysical() != Rhs.Reg.isPhysical())
201+
return Reg.isPhysical();
202+
if (Weight != Rhs.Weight)
203+
return (Weight > Rhs.Weight);
204+
return Reg.id() < Rhs.Reg.id(); // Tie-breaker.
207205
}
208206
};
209-
std::set<CopyHint> CopyHints;
210207

208+
std::set<CopyHint> CopyHints;
209+
DenseMap<unsigned, float> Hint;
211210
for (MachineRegisterInfo::reg_instr_nodbg_iterator
212211
I = MRI.reg_instr_nodbg_begin(LI.reg()),
213212
E = MRI.reg_instr_nodbg_end();
@@ -250,28 +249,25 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
250249
// Get allocation hints from copies.
251250
if (!MI->isCopy())
252251
continue;
253-
Register hint = copyHint(MI, LI.reg(), TRI, MRI);
254-
if (!hint)
252+
Register HintReg = copyHint(MI, LI.reg(), TRI, MRI);
253+
if (!HintReg)
255254
continue;
256255
// Force hweight onto the stack so that x86 doesn't add hidden precision,
257256
// making the comparison incorrectly pass (i.e., 1 > 1 == true??).
258257
//
259258
// FIXME: we probably shouldn't use floats at all.
260-
volatile float HWeight = Hint[hint] += Weight;
261-
if (Register::isVirtualRegister(hint) || MRI.isAllocatable(hint))
262-
CopyHints.insert(
263-
CopyHint(hint, HWeight, Register::isPhysicalRegister(hint)));
259+
volatile float HWeight = Hint[HintReg] += Weight;
260+
if (HintReg.isVirtual() || MRI.isAllocatable(HintReg))
261+
CopyHints.insert(CopyHint(HintReg, HWeight));
264262
}
265263

266-
Hint.clear();
267-
268264
// Pass all the sorted copy hints to mri.
269265
if (ShouldUpdateLI && CopyHints.size()) {
270266
// Remove a generic hint if previously added by target.
271267
if (TargetHint.first == 0 && TargetHint.second)
272268
MRI.clearSimpleHint(LI.reg());
273269

274-
std::set<unsigned> HintedRegs;
270+
std::set<Register> HintedRegs;
275271
for (auto &Hint : CopyHints) {
276272
if (!HintedRegs.insert(Hint.Reg).second ||
277273
(TargetHint.first != 0 && Hint.Reg == TargetHint.second))

0 commit comments

Comments
 (0)