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