29 #define DEBUG_TYPE "calcspillweights" 37 LLVM_DEBUG(
dbgs() <<
"********** Compute Spill Weights **********\n" 38 <<
"********** Function: " << MF.
getName() <<
'\n');
42 for (
unsigned i = 0,
e = MRI.getNumVirtRegs(); i !=
e; ++i) {
44 if (MRI.reg_nodbg_empty(Reg))
70 return sub == hsub ? hreg :
Register();
90 unsigned Original = VRM ? VRM->
getOriginal(Reg) : 0;
100 assert(MI &&
"Dead valno in interval");
124 assert(VNI &&
"Copy from non-existing value");
128 assert(MI &&
"Dead valno in interval");
157 bool isExiting =
false;
158 float totalWeight = 0;
159 unsigned numInstr = 0;
167 bool localSplitArtifact = start &&
end;
170 bool updateLI = !localSplitArtifact;
172 if (localSplitArtifact) {
175 "start and end are expected to be in the same basic block");
193 CopyHint(
unsigned R,
float W,
bool P) :
194 Reg(R), Weight(W), IsPhys(P) {}
195 bool operator<(
const CopyHint &rhs)
const {
197 if (IsPhys != rhs.IsPhys)
198 return (IsPhys && !rhs.IsPhys);
199 if (Weight != rhs.Weight)
200 return (Weight > rhs.Weight);
201 return Reg < rhs.Reg;
204 std::set<CopyHint> CopyHints;
213 SlotIndex si = LIS.getInstructionIndex(*mi);
214 if (localSplitArtifact && ((si < *start) || (si > *end)))
220 if (!visited.
insert(mi).second)
228 loop =
Loops.getLoopFor(mbb);
238 if (writes && isExiting && LIS.isLiveOutOfMBB(li, mbb))
241 totalWeight += weight;
254 volatile float hweight = Hint[hint] += weight;
263 if (updateLI && CopyHints.size()) {
265 if (TargetHint.first == 0 && TargetHint.second)
268 std::set<unsigned> HintedRegs;
269 for (
auto &Hint : CopyHints) {
270 if (!HintedRegs.insert(Hint.Reg).second ||
271 (TargetHint.first != 0 && Hint.Reg == TargetHint.second))
278 totalWeight *= 1.01F;
288 if (updateLI && li.
isZeroLength(LIS.getSlotIndexes()) &&
301 if (localSplitArtifact)
302 return normalize(totalWeight, start->
distance(*end), numInstr);
303 return normalize(totalWeight, li.
getSize(), numInstr);
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
const_iterator end(StringRef path)
Get end iterator over path.
Calculate auxiliary information for a virtual register such as its spill weight and allocation hint...
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
SlotIndex def
The index of the defining instruction.
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &MI)
Calculate the spill weight to assign to a single instruction.
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
This class represents lattice values for constants.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LiveInterval - This class represents the liveness of a register, or stack slot.
unsigned getSubReg() const
bool isLiveAtIndexes(ArrayRef< SlotIndex > Slots) const
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
VNInfo - Value Number Information.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
bool isUnused() const
Returns true if this value is unused.
const HexagonInstrInfo * TII
std::pair< bool, bool > readsWritesVirtualRegister(Register Reg, SmallVectorImpl< unsigned > *Ops=nullptr) const
Return a pair of bools (reads, writes) indicating if this instruction reads or writes Reg...
Result of a LiveRange query.
static reg_instr_iterator reg_instr_end()
defusechain_iterator - This class provides iterator support for machine operands in the function that...
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
static bool isRematerializable(const LiveInterval &LI, const LiveIntervals &LIS, VirtRegMap *VRM, const TargetInstrInfo &TII)
bool isIdentityCopy() const
Return true is the instruction is an identity copy.
Register getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
AliasAnalysis * getAliasAnalysis() const
bool isZeroLength(SlotIndexes *Indexes) const
Returns true if the live range is zero length, i.e.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
float futureWeight(LiveInterval &li, SlotIndex start, SlotIndex end)
Compute future expected spill weight of a split artifact of li that will span between start and end s...
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned const MachineRegisterInfo * MRI
VNInfoList::const_iterator const_vni_iterator
bool isLoopExiting(const BlockT *BB) const
True if terminator in the block can branch to another block that is outside of the current loop...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static Register copyHint(const MachineInstr *mi, unsigned reg, const TargetRegisterInfo &tri, const MachineRegisterInfo &mri)
LiveInterval & getInterval(Register Reg)
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
bool isImplicitDef() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isDebugInstr() const
float weightCalcHelper(LiveInterval &li, SlotIndex *start=nullptr, SlotIndex *end=nullptr)
Helper function for weight calculations.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF, VirtRegMap *VRM, const MachineLoopInfo &MLI, const MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo::NormalizingFn norm=normalizeSpillWeight)
Compute spill weights and allocation hints for all virtual register live intervals.
std::pair< unsigned, unsigned > getRegAllocationHint(Register VReg) const
getRegAllocationHint - Return the register allocation hint for the specified virtual register...
void calculateSpillWeightAndHint(LiveInterval &li)
(re)compute li's spill weight and allocation hint.
Promote Memory to Register
void clearSimpleHint(unsigned VReg)
void markNotSpillable()
markNotSpillable - Mark interval as not spillable
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getSize() const
getSize - Returns the sum of sizes of all the LiveRange's.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx, const TargetRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg...
int distance(SlotIndex other) const
Return the distance from this index to the given one.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
void addRegAllocationHint(unsigned VReg, unsigned PrefReg)
addRegAllocationHint - Add a register allocation hint to the hints vector for VReg.
bool isSpillable() const
isSpillable - Can this interval be spilled?
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
static uint64_t sub(uint64_t LeftOp, uint64_t RightOp)
bool isTriviallyReMaterializable(const MachineInstr &MI, AAResults *AA=nullptr) const
Return true if the instruction is trivially rematerializable, meaning it has no side effects and requ...
float(*)(float, unsigned, unsigned) NormalizingFn
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
SlotIndex - An opaque wrapper around machine indexes.
unsigned getOriginal(unsigned VirtReg) const
getOriginal - Return the original virtual register that VirtReg descends from through splitting...
reg_instr_iterator reg_instr_begin(unsigned RegNo) const
Wrapper class representing virtual and physical registers.