Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 1 | //===- CalcSpillWeights.cpp -----------------------------------------------===// |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/CalcSpillWeights.h" |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/SmallPtrSet.h" |
| 12 | #include "llvm/CodeGen/LiveInterval.h" |
Matthias Braun | fa621d2 | 2017-12-13 02:51:04 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/LiveIntervals.h" |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunction.h" |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineInstr.h" |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineLoopInfo.h" |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineOperand.h" |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
David Blaikie | 4831923 | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/TargetInstrInfo.h" |
David Blaikie | e3a9b4c | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 21 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/VirtRegMap.h" |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 25 | #include <cassert> |
| 26 | #include <tuple> |
| 27 | |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
Chandler Carruth | 8677f2f | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 30 | #define DEBUG_TYPE "calcspillweights" |
| 31 | |
Arnaud A. de Grandmaison | 095f994 | 2013-11-11 19:04:45 +0000 | [diff] [blame] | 32 | void llvm::calculateSpillWeightsAndHints(LiveIntervals &LIS, |
Arnaud A. de Grandmaison | a77da05 | 2013-11-10 17:46:31 +0000 | [diff] [blame] | 33 | MachineFunction &MF, |
Robert Lougher | 0d87d63 | 2015-08-10 11:59:44 +0000 | [diff] [blame] | 34 | VirtRegMap *VRM, |
Arnaud A. de Grandmaison | a77da05 | 2013-11-10 17:46:31 +0000 | [diff] [blame] | 35 | const MachineLoopInfo &MLI, |
Arnaud A. de Grandmaison | d736763 | 2013-11-11 19:56:14 +0000 | [diff] [blame] | 36 | const MachineBlockFrequencyInfo &MBFI, |
| 37 | VirtRegAuxInfo::NormalizingFn norm) { |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 38 | LLVM_DEBUG(dbgs() << "********** Compute Spill Weights **********\n" |
| 39 | << "********** Function: " << MF.getName() << '\n'); |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 40 | |
Jakob Stoklund Olesen | d67582e | 2012-06-20 21:25:05 +0000 | [diff] [blame] | 41 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
Robert Lougher | 0d87d63 | 2015-08-10 11:59:44 +0000 | [diff] [blame] | 42 | VirtRegAuxInfo VRAI(MF, LIS, VRM, MLI, MBFI, norm); |
Jakob Stoklund Olesen | d67582e | 2012-06-20 21:25:05 +0000 | [diff] [blame] | 43 | for (unsigned i = 0, e = MRI.getNumVirtRegs(); i != e; ++i) { |
| 44 | unsigned Reg = TargetRegisterInfo::index2VirtReg(i); |
| 45 | if (MRI.reg_nodbg_empty(Reg)) |
| 46 | continue; |
Arnaud A. de Grandmaison | 095f994 | 2013-11-11 19:04:45 +0000 | [diff] [blame] | 47 | VRAI.calculateSpillWeightAndHint(LIS.getInterval(Reg)); |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 48 | } |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 51 | // Return the preferred allocation register for reg, given a COPY instruction. |
| 52 | static unsigned copyHint(const MachineInstr *mi, unsigned reg, |
| 53 | const TargetRegisterInfo &tri, |
| 54 | const MachineRegisterInfo &mri) { |
| 55 | unsigned sub, hreg, hsub; |
| 56 | if (mi->getOperand(0).getReg() == reg) { |
| 57 | sub = mi->getOperand(0).getSubReg(); |
| 58 | hreg = mi->getOperand(1).getReg(); |
| 59 | hsub = mi->getOperand(1).getSubReg(); |
| 60 | } else { |
| 61 | sub = mi->getOperand(1).getSubReg(); |
| 62 | hreg = mi->getOperand(0).getReg(); |
| 63 | hsub = mi->getOperand(0).getSubReg(); |
| 64 | } |
| 65 | |
| 66 | if (!hreg) |
| 67 | return 0; |
| 68 | |
| 69 | if (TargetRegisterInfo::isVirtualRegister(hreg)) |
| 70 | return sub == hsub ? hreg : 0; |
| 71 | |
| 72 | const TargetRegisterClass *rc = mri.getRegClass(reg); |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 73 | unsigned CopiedPReg = (hsub ? tri.getSubReg(hreg, hsub) : hreg); |
| 74 | if (rc->contains(CopiedPReg)) |
| 75 | return CopiedPReg; |
| 76 | |
| 77 | // Check if reg:sub matches so that a super register could be hinted. |
| 78 | if (sub) |
| 79 | return tri.getMatchingSuperReg(CopiedPReg, sub, rc); |
| 80 | |
| 81 | return 0; |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 82 | } |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 83 | |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 84 | // Check if all values in LI are rematerializable |
| 85 | static bool isRematerializable(const LiveInterval &LI, |
| 86 | const LiveIntervals &LIS, |
Robert Lougher | 0d87d63 | 2015-08-10 11:59:44 +0000 | [diff] [blame] | 87 | VirtRegMap *VRM, |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 88 | const TargetInstrInfo &TII) { |
Robert Lougher | 0d87d63 | 2015-08-10 11:59:44 +0000 | [diff] [blame] | 89 | unsigned Reg = LI.reg; |
| 90 | unsigned Original = VRM ? VRM->getOriginal(Reg) : 0; |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 91 | for (LiveInterval::const_vni_iterator I = LI.vni_begin(), E = LI.vni_end(); |
| 92 | I != E; ++I) { |
| 93 | const VNInfo *VNI = *I; |
| 94 | if (VNI->isUnused()) |
| 95 | continue; |
| 96 | if (VNI->isPHIDef()) |
| 97 | return false; |
| 98 | |
| 99 | MachineInstr *MI = LIS.getInstructionFromIndex(VNI->def); |
| 100 | assert(MI && "Dead valno in interval"); |
| 101 | |
Robert Lougher | 0d87d63 | 2015-08-10 11:59:44 +0000 | [diff] [blame] | 102 | // Trace copies introduced by live range splitting. The inline |
| 103 | // spiller can rematerialize through these copies, so the spill |
| 104 | // weight must reflect this. |
| 105 | if (VRM) { |
| 106 | while (MI->isFullCopy()) { |
| 107 | // The copy destination must match the interval register. |
| 108 | if (MI->getOperand(0).getReg() != Reg) |
| 109 | return false; |
| 110 | |
| 111 | // Get the source register. |
| 112 | Reg = MI->getOperand(1).getReg(); |
| 113 | |
| 114 | // If the original (pre-splitting) registers match this |
| 115 | // copy came from a split. |
| 116 | if (!TargetRegisterInfo::isVirtualRegister(Reg) || |
| 117 | VRM->getOriginal(Reg) != Original) |
| 118 | return false; |
| 119 | |
| 120 | // Follow the copy live-in value. |
| 121 | const LiveInterval &SrcLI = LIS.getInterval(Reg); |
| 122 | LiveQueryResult SrcQ = SrcLI.Query(VNI->def); |
| 123 | VNI = SrcQ.valueIn(); |
| 124 | assert(VNI && "Copy from non-existing value"); |
| 125 | if (VNI->isPHIDef()) |
| 126 | return false; |
| 127 | MI = LIS.getInstructionFromIndex(VNI->def); |
| 128 | assert(MI && "Dead valno in interval"); |
| 129 | } |
| 130 | } |
| 131 | |
Duncan P. N. Exon Smith | 567409d | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 132 | if (!TII.isTriviallyReMaterializable(*MI, LIS.getAliasAnalysis())) |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 133 | return false; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 138 | void VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &li) { |
| 139 | float weight = weightCalcHelper(li); |
| 140 | // Check if unspillable. |
| 141 | if (weight < 0) |
| 142 | return; |
| 143 | li.weight = weight; |
| 144 | } |
| 145 | |
| 146 | float VirtRegAuxInfo::futureWeight(LiveInterval &li, SlotIndex start, |
| 147 | SlotIndex end) { |
| 148 | return weightCalcHelper(li, &start, &end); |
| 149 | } |
| 150 | |
| 151 | float VirtRegAuxInfo::weightCalcHelper(LiveInterval &li, SlotIndex *start, |
| 152 | SlotIndex *end) { |
Jakob Stoklund Olesen | 1394e6d | 2011-04-26 18:52:36 +0000 | [diff] [blame] | 153 | MachineRegisterInfo &mri = MF.getRegInfo(); |
Eric Christopher | 6035518 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 154 | const TargetRegisterInfo &tri = *MF.getSubtarget().getRegisterInfo(); |
Craig Topper | 4ba8443 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 155 | MachineBasicBlock *mbb = nullptr; |
| 156 | MachineLoop *loop = nullptr; |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 157 | bool isExiting = false; |
| 158 | float totalWeight = 0; |
Arnaud A. de Grandmaison | 8025a39 | 2014-11-04 20:51:24 +0000 | [diff] [blame] | 159 | unsigned numInstr = 0; // Number of instructions using li |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 160 | SmallPtrSet<MachineInstr*, 8> visited; |
| 161 | |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 162 | std::pair<unsigned, unsigned> TargetHint = mri.getRegAllocationHint(li.reg); |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 163 | |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 164 | // Don't recompute spill weight for an unspillable register. |
| 165 | bool Spillable = li.isSpillable(); |
| 166 | |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 167 | bool localSplitArtifact = start && end; |
| 168 | |
| 169 | // Do not update future local split artifacts. |
| 170 | bool updateLI = !localSplitArtifact; |
| 171 | |
| 172 | if (localSplitArtifact) { |
| 173 | MachineBasicBlock *localMBB = LIS.getMBBFromIndex(*end); |
| 174 | assert(localMBB == LIS.getMBBFromIndex(*start) && |
| 175 | "start and end are expected to be in the same basic block"); |
| 176 | |
| 177 | // Local split artifact will have 2 additional copy instructions and they |
| 178 | // will be in the same BB. |
| 179 | // localLI = COPY other |
| 180 | // ... |
| 181 | // other = COPY localLI |
| 182 | totalWeight += LiveIntervals::getSpillWeight(true, false, &MBFI, localMBB); |
| 183 | totalWeight += LiveIntervals::getSpillWeight(false, true, &MBFI, localMBB); |
| 184 | |
| 185 | numInstr += 2; |
| 186 | } |
| 187 | |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 188 | // CopyHint is a sortable hint derived from a COPY instruction. |
| 189 | struct CopyHint { |
| 190 | unsigned Reg; |
| 191 | float Weight; |
| 192 | bool IsPhys; |
Jonas Paulsson | af9a1a1 | 2018-10-05 14:23:11 +0000 | [diff] [blame] | 193 | CopyHint(unsigned R, float W, bool P) : |
| 194 | Reg(R), Weight(W), IsPhys(P) {} |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 195 | bool operator<(const CopyHint &rhs) const { |
| 196 | // Always prefer any physreg hint. |
| 197 | if (IsPhys != rhs.IsPhys) |
| 198 | return (IsPhys && !rhs.IsPhys); |
| 199 | if (Weight != rhs.Weight) |
| 200 | return (Weight > rhs.Weight); |
Jonas Paulsson | af9a1a1 | 2018-10-05 14:23:11 +0000 | [diff] [blame] | 201 | return Reg < rhs.Reg; // Tie-breaker. |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 202 | } |
| 203 | }; |
| 204 | std::set<CopyHint> CopyHints; |
| 205 | |
Owen Anderson | 76604af | 2014-03-13 06:02:25 +0000 | [diff] [blame] | 206 | for (MachineRegisterInfo::reg_instr_iterator |
| 207 | I = mri.reg_instr_begin(li.reg), E = mri.reg_instr_end(); |
| 208 | I != E; ) { |
| 209 | MachineInstr *mi = &*(I++); |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 210 | |
| 211 | // For local split artifacts, we are interested only in instructions between |
| 212 | // the expected start and end of the range. |
| 213 | SlotIndex si = LIS.getInstructionIndex(*mi); |
| 214 | if (localSplitArtifact && ((si < *start) || (si > *end))) |
| 215 | continue; |
| 216 | |
Arnaud A. de Grandmaison | 8025a39 | 2014-11-04 20:51:24 +0000 | [diff] [blame] | 217 | numInstr++; |
Shiva Chen | 24abe71 | 2018-05-09 02:42:00 +0000 | [diff] [blame] | 218 | if (mi->isIdentityCopy() || mi->isImplicitDef() || mi->isDebugInstr()) |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 219 | continue; |
David Blaikie | 5401ba7 | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 220 | if (!visited.insert(mi).second) |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 221 | continue; |
| 222 | |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 223 | float weight = 1.0f; |
| 224 | if (Spillable) { |
| 225 | // Get loop info for mi. |
| 226 | if (mi->getParent() != mbb) { |
| 227 | mbb = mi->getParent(); |
Jakob Stoklund Olesen | 1394e6d | 2011-04-26 18:52:36 +0000 | [diff] [blame] | 228 | loop = Loops.getLoopFor(mbb); |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 229 | isExiting = loop ? loop->isLoopExiting(mbb) : false; |
| 230 | } |
| 231 | |
| 232 | // Calculate instr weight. |
| 233 | bool reads, writes; |
Benjamin Kramer | a4f0aad | 2014-03-02 13:30:33 +0000 | [diff] [blame] | 234 | std::tie(reads, writes) = mi->readsWritesVirtualRegister(li.reg); |
Duncan P. N. Exon Smith | 5144d35 | 2016-02-27 20:14:29 +0000 | [diff] [blame] | 235 | weight = LiveIntervals::getSpillWeight(writes, reads, &MBFI, *mi); |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 236 | |
| 237 | // Give extra weight to what looks like a loop induction variable update. |
Jakob Stoklund Olesen | 1394e6d | 2011-04-26 18:52:36 +0000 | [diff] [blame] | 238 | if (writes && isExiting && LIS.isLiveOutOfMBB(li, mbb)) |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 239 | weight *= 3; |
| 240 | |
| 241 | totalWeight += weight; |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 244 | // Get allocation hints from copies. |
Jonas Paulsson | af9a1a1 | 2018-10-05 14:23:11 +0000 | [diff] [blame] | 245 | if (!mi->isCopy()) |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 246 | continue; |
| 247 | unsigned hint = copyHint(mi, li.reg, tri, mri); |
| 248 | if (!hint) |
| 249 | continue; |
Duncan P. N. Exon Smith | d5ebbc5 | 2014-04-21 17:57:01 +0000 | [diff] [blame] | 250 | // Force hweight onto the stack so that x86 doesn't add hidden precision, |
| 251 | // making the comparison incorrectly pass (i.e., 1 > 1 == true??). |
| 252 | // |
| 253 | // FIXME: we probably shouldn't use floats at all. |
| 254 | volatile float hweight = Hint[hint] += weight; |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 255 | if (TargetRegisterInfo::isVirtualRegister(hint) || mri.isAllocatable(hint)) |
Jonas Paulsson | af9a1a1 | 2018-10-05 14:23:11 +0000 | [diff] [blame] | 256 | CopyHints.insert(CopyHint(hint, hweight, tri.isPhysicalRegister(hint))); |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Jakob Stoklund Olesen | 1394e6d | 2011-04-26 18:52:36 +0000 | [diff] [blame] | 259 | Hint.clear(); |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 260 | |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 261 | // Pass all the sorted copy hints to mri. |
| 262 | if (updateLI && CopyHints.size()) { |
| 263 | // Remove a generic hint if previously added by target. |
| 264 | if (TargetHint.first == 0 && TargetHint.second) |
| 265 | mri.clearSimpleHint(li.reg); |
| 266 | |
Jonas Paulsson | abaa9ca | 2018-10-03 12:51:19 +0000 | [diff] [blame] | 267 | std::set<unsigned> HintedRegs; |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 268 | for (auto &Hint : CopyHints) { |
Jonas Paulsson | abaa9ca | 2018-10-03 12:51:19 +0000 | [diff] [blame] | 269 | if (!HintedRegs.insert(Hint.Reg).second || |
| 270 | (TargetHint.first != 0 && Hint.Reg == TargetHint.second)) |
| 271 | // Don't add the same reg twice or the target-type hint again. |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 272 | continue; |
| 273 | mri.addRegAllocationHint(li.reg, Hint.Reg); |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 274 | } |
Jonas Paulsson | 48d461f | 2017-12-05 10:52:24 +0000 | [diff] [blame] | 275 | |
| 276 | // Weakly boost the spill weight of hinted registers. |
| 277 | totalWeight *= 1.01F; |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 280 | // If the live interval was already unspillable, leave it that way. |
| 281 | if (!Spillable) |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 282 | return -1.0; |
Jakob Stoklund Olesen | 6094bd8 | 2011-03-29 21:20:19 +0000 | [diff] [blame] | 283 | |
Andrew Kaylor | fb2b3b0 | 2016-02-08 22:52:51 +0000 | [diff] [blame] | 284 | // Mark li as unspillable if all live ranges are tiny and the interval |
| 285 | // is not live at any reg mask. If the interval is live at a reg mask |
| 286 | // spilling may be required. |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 287 | if (updateLI && li.isZeroLength(LIS.getSlotIndexes()) && |
Andrew Kaylor | fb2b3b0 | 2016-02-08 22:52:51 +0000 | [diff] [blame] | 288 | !li.isLiveAtIndexes(LIS.getRegMaskSlots())) { |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 289 | li.markNotSpillable(); |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 290 | return -1.0; |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | // If all of the definitions of the interval are re-materializable, |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 294 | // it is a preferred candidate for spilling. |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 295 | // FIXME: this gets much more complicated once we support non-trivial |
| 296 | // re-materialization. |
Robert Lougher | 0d87d63 | 2015-08-10 11:59:44 +0000 | [diff] [blame] | 297 | if (isRematerializable(li, LIS, VRM, *MF.getSubtarget().getInstrInfo())) |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 298 | totalWeight *= 0.5F; |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 299 | |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 300 | if (localSplitArtifact) |
| 301 | return normalize(totalWeight, start->distance(*end), numInstr); |
| 302 | return normalize(totalWeight, li.getSize(), numInstr); |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 303 | } |