aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMircea Trofin <mtrofin@google.com>2020-10-09 13:35:56 -0700
committerMircea Trofin <mtrofin@google.com>2020-10-09 13:42:23 -0700
commitc11c20fb0036bc8f69b2028422f050ee66acbb64 (patch)
tree68b43d73ab5d752d4455870d304a5fc700cd5c93 /llvm/lib/CodeGen/CalcSpillWeights.cpp
parent[Hexagon] Remove ISD node VSPLATW, use VSPLAT instead (diff)
downloadllvm-project-c11c20fb0036bc8f69b2028422f050ee66acbb64.tar.gz
llvm-project-c11c20fb0036bc8f69b2028422f050ee66acbb64.tar.bz2
llvm-project-c11c20fb0036bc8f69b2028422f050ee66acbb64.zip
[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).
Diffstat (limited to 'llvm/lib/CodeGen/CalcSpillWeights.cpp')
-rw-r--r--llvm/lib/CodeGen/CalcSpillWeights.cpp42
1 files changed, 19 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp
index b096593ac620..03490643339f 100644
--- a/llvm/lib/CodeGen/CalcSpillWeights.cpp
+++ b/llvm/lib/CodeGen/CalcSpillWeights.cpp
@@ -150,10 +150,10 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
MachineLoop *Loop = nullptr;
bool IsExiting = false;
float TotalWeight = 0;
- unsigned NumInstr = 0; // Number of instructions using li
+ unsigned NumInstr = 0; // Number of instructions using LI
SmallPtrSet<MachineInstr *, 8> Visited;
- std::pair<unsigned, unsigned> TargetHint = MRI.getRegAllocationHint(LI.reg());
+ std::pair<Register, Register> TargetHint = MRI.getRegAllocationHint(LI.reg());
if (LI.isSpillable() && VRM) {
Register Reg = LI.reg();
@@ -192,22 +192,21 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
// CopyHint is a sortable hint derived from a COPY instruction.
struct CopyHint {
- unsigned Reg;
- float Weight;
- bool IsPhys;
- CopyHint(unsigned R, float W, bool P) :
- Reg(R), Weight(W), IsPhys(P) {}
- bool operator<(const CopyHint &rhs) const {
+ const Register Reg;
+ const float Weight;
+ CopyHint(Register R, float W) : Reg(R), Weight(W) {}
+ bool operator<(const CopyHint &Rhs) const {
// Always prefer any physreg hint.
- if (IsPhys != rhs.IsPhys)
- return (IsPhys && !rhs.IsPhys);
- if (Weight != rhs.Weight)
- return (Weight > rhs.Weight);
- return Reg < rhs.Reg; // Tie-breaker.
+ if (Reg.isPhysical() != Rhs.Reg.isPhysical())
+ return Reg.isPhysical();
+ if (Weight != Rhs.Weight)
+ return (Weight > Rhs.Weight);
+ return Reg.id() < Rhs.Reg.id(); // Tie-breaker.
}
};
- std::set<CopyHint> CopyHints;
+ std::set<CopyHint> CopyHints;
+ DenseMap<unsigned, float> Hint;
for (MachineRegisterInfo::reg_instr_nodbg_iterator
I = MRI.reg_instr_nodbg_begin(LI.reg()),
E = MRI.reg_instr_nodbg_end();
@@ -250,28 +249,25 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
// Get allocation hints from copies.
if (!MI->isCopy())
continue;
- Register hint = copyHint(MI, LI.reg(), TRI, MRI);
- if (!hint)
+ Register HintReg = copyHint(MI, LI.reg(), TRI, MRI);
+ if (!HintReg)
continue;
// Force hweight onto the stack so that x86 doesn't add hidden precision,
// making the comparison incorrectly pass (i.e., 1 > 1 == true??).
//
// FIXME: we probably shouldn't use floats at all.
- volatile float HWeight = Hint[hint] += Weight;
- if (Register::isVirtualRegister(hint) || MRI.isAllocatable(hint))
- CopyHints.insert(
- CopyHint(hint, HWeight, Register::isPhysicalRegister(hint)));
+ volatile float HWeight = Hint[HintReg] += Weight;
+ if (HintReg.isVirtual() || MRI.isAllocatable(HintReg))
+ CopyHints.insert(CopyHint(HintReg, HWeight));
}
- Hint.clear();
-
// Pass all the sorted copy hints to mri.
if (ShouldUpdateLI && CopyHints.size()) {
// Remove a generic hint if previously added by target.
if (TargetHint.first == 0 && TargetHint.second)
MRI.clearSimpleHint(LI.reg());
- std::set<unsigned> HintedRegs;
+ std::set<Register> HintedRegs;
for (auto &Hint : CopyHints) {
if (!HintedRegs.insert(Hint.Reg).second ||
(TargetHint.first != 0 && Hint.Reg == TargetHint.second))