Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 1 | //===---------- SplitKit.cpp - Toolkit for splitting live ranges ----------===// |
| 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 | // |
| 10 | // This file contains the SplitAnalysis class as well as mutator functions for |
| 11 | // live range splitting. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Jakob Stoklund Olesen | 376dcbd | 2010-11-03 20:39:23 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "regalloc" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 16 | #include "SplitKit.h" |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 17 | #include "LiveRangeEdit.h" |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 18 | #include "VirtRegMap.h" |
Jakob Stoklund Olesen | 08e93b1 | 2010-08-10 17:07:22 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/CalcSpillWeights.h" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Jakob Stoklund Olesen | d68f458 | 2010-10-28 20:34:50 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineDominators.h" |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CommandLine.h" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Debug.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetInstrInfo.h" |
| 28 | #include "llvm/Target/TargetMachine.h" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace llvm; |
| 31 | |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 32 | static cl::opt<bool> |
| 33 | AllowSplit("spiller-splits-edges", |
| 34 | cl::desc("Allow critical edge splitting during spilling")); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 35 | |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | // Split Analysis |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
Jakob Stoklund Olesen | 1b847de | 2011-02-19 00:53:42 +0000 | [diff] [blame] | 40 | SplitAnalysis::SplitAnalysis(const VirtRegMap &vrm, |
Jakob Stoklund Olesen | f2c6e36 | 2010-07-20 23:50:15 +0000 | [diff] [blame] | 41 | const LiveIntervals &lis, |
| 42 | const MachineLoopInfo &mli) |
Jakob Stoklund Olesen | 1b847de | 2011-02-19 00:53:42 +0000 | [diff] [blame] | 43 | : MF(vrm.getMachineFunction()), |
| 44 | VRM(vrm), |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 45 | LIS(lis), |
| 46 | Loops(mli), |
Jakob Stoklund Olesen | 1b847de | 2011-02-19 00:53:42 +0000 | [diff] [blame] | 47 | TII(*MF.getTarget().getInstrInfo()), |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 48 | CurLI(0) {} |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 49 | |
| 50 | void SplitAnalysis::clear() { |
Jakob Stoklund Olesen | b5fa933 | 2011-01-18 21:13:27 +0000 | [diff] [blame] | 51 | UseSlots.clear(); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 52 | UsingInstrs.clear(); |
| 53 | UsingBlocks.clear(); |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 54 | LiveBlocks.clear(); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 55 | CurLI = 0; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 58 | bool SplitAnalysis::canAnalyzeBranch(const MachineBasicBlock *MBB) { |
| 59 | MachineBasicBlock *T, *F; |
| 60 | SmallVector<MachineOperand, 4> Cond; |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 61 | return !TII.AnalyzeBranch(const_cast<MachineBasicBlock&>(*MBB), T, F, Cond); |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 64 | /// analyzeUses - Count instructions, basic blocks, and loops using CurLI. |
Jakob Stoklund Olesen | abff280 | 2010-07-20 16:12:37 +0000 | [diff] [blame] | 65 | void SplitAnalysis::analyzeUses() { |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 66 | const MachineRegisterInfo &MRI = MF.getRegInfo(); |
Jakob Stoklund Olesen | a372d16 | 2011-02-09 21:52:09 +0000 | [diff] [blame] | 67 | for (MachineRegisterInfo::reg_iterator I = MRI.reg_begin(CurLI->reg), |
| 68 | E = MRI.reg_end(); I != E; ++I) { |
| 69 | MachineOperand &MO = I.getOperand(); |
| 70 | if (MO.isUse() && MO.isUndef()) |
| 71 | continue; |
| 72 | MachineInstr *MI = MO.getParent(); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 73 | if (MI->isDebugValue() || !UsingInstrs.insert(MI)) |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 74 | continue; |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 75 | UseSlots.push_back(LIS.getInstructionIndex(MI).getDefIndex()); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 76 | MachineBasicBlock *MBB = MI->getParent(); |
Jakob Stoklund Olesen | 4f5c9d2 | 2011-02-09 23:56:18 +0000 | [diff] [blame] | 77 | UsingBlocks[MBB]++; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 78 | } |
Jakob Stoklund Olesen | b5fa933 | 2011-01-18 21:13:27 +0000 | [diff] [blame] | 79 | array_pod_sort(UseSlots.begin(), UseSlots.end()); |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 80 | calcLiveBlockInfo(); |
Jakob Stoklund Olesen | e1f543f | 2010-08-12 18:50:55 +0000 | [diff] [blame] | 81 | DEBUG(dbgs() << " counted " |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 82 | << UsingInstrs.size() << " instrs, " |
Jakob Stoklund Olesen | 4f5c9d2 | 2011-02-09 23:56:18 +0000 | [diff] [blame] | 83 | << UsingBlocks.size() << " blocks.\n"); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 86 | /// calcLiveBlockInfo - Fill the LiveBlocks array with information about blocks |
| 87 | /// where CurLI is live. |
| 88 | void SplitAnalysis::calcLiveBlockInfo() { |
| 89 | if (CurLI->empty()) |
| 90 | return; |
| 91 | |
| 92 | LiveInterval::const_iterator LVI = CurLI->begin(); |
| 93 | LiveInterval::const_iterator LVE = CurLI->end(); |
| 94 | |
| 95 | SmallVectorImpl<SlotIndex>::const_iterator UseI, UseE; |
| 96 | UseI = UseSlots.begin(); |
| 97 | UseE = UseSlots.end(); |
| 98 | |
| 99 | // Loop over basic blocks where CurLI is live. |
| 100 | MachineFunction::iterator MFI = LIS.getMBBFromIndex(LVI->start); |
| 101 | for (;;) { |
| 102 | BlockInfo BI; |
| 103 | BI.MBB = MFI; |
| 104 | SlotIndex Start, Stop; |
| 105 | tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB); |
| 106 | |
| 107 | // The last split point is the latest possible insertion point that dominates |
| 108 | // all successor blocks. If interference reaches LastSplitPoint, it is not |
| 109 | // possible to insert a split or reload that makes CurLI live in the |
| 110 | // outgoing bundle. |
| 111 | MachineBasicBlock::iterator LSP = LIS.getLastSplitPoint(*CurLI, BI.MBB); |
| 112 | if (LSP == BI.MBB->end()) |
| 113 | BI.LastSplitPoint = Stop; |
| 114 | else |
| 115 | BI.LastSplitPoint = LIS.getInstructionIndex(LSP); |
| 116 | |
| 117 | // LVI is the first live segment overlapping MBB. |
| 118 | BI.LiveIn = LVI->start <= Start; |
| 119 | if (!BI.LiveIn) |
| 120 | BI.Def = LVI->start; |
| 121 | |
| 122 | // Find the first and last uses in the block. |
| 123 | BI.Uses = hasUses(MFI); |
| 124 | if (BI.Uses && UseI != UseE) { |
| 125 | BI.FirstUse = *UseI; |
| 126 | assert(BI.FirstUse >= Start); |
| 127 | do ++UseI; |
| 128 | while (UseI != UseE && *UseI < Stop); |
| 129 | BI.LastUse = UseI[-1]; |
| 130 | assert(BI.LastUse < Stop); |
| 131 | } |
| 132 | |
| 133 | // Look for gaps in the live range. |
| 134 | bool hasGap = false; |
| 135 | BI.LiveOut = true; |
| 136 | while (LVI->end < Stop) { |
| 137 | SlotIndex LastStop = LVI->end; |
| 138 | if (++LVI == LVE || LVI->start >= Stop) { |
| 139 | BI.Kill = LastStop; |
| 140 | BI.LiveOut = false; |
| 141 | break; |
| 142 | } |
| 143 | if (LastStop < LVI->start) { |
| 144 | hasGap = true; |
| 145 | BI.Kill = LastStop; |
| 146 | BI.Def = LVI->start; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Don't set LiveThrough when the block has a gap. |
| 151 | BI.LiveThrough = !hasGap && BI.LiveIn && BI.LiveOut; |
| 152 | LiveBlocks.push_back(BI); |
| 153 | |
| 154 | // LVI is now at LVE or LVI->end >= Stop. |
| 155 | if (LVI == LVE) |
| 156 | break; |
| 157 | |
| 158 | // Live segment ends exactly at Stop. Move to the next segment. |
| 159 | if (LVI->end == Stop && ++LVI == LVE) |
| 160 | break; |
| 161 | |
| 162 | // Pick the next basic block. |
| 163 | if (LVI->start < Stop) |
| 164 | ++MFI; |
| 165 | else |
| 166 | MFI = LIS.getMBBFromIndex(LVI->start); |
| 167 | } |
| 168 | } |
| 169 | |
Jakob Stoklund Olesen | 06c0f25 | 2011-02-21 23:09:46 +0000 | [diff] [blame] | 170 | bool SplitAnalysis::isOriginalEndpoint(SlotIndex Idx) const { |
| 171 | unsigned OrigReg = VRM.getOriginal(CurLI->reg); |
| 172 | const LiveInterval &Orig = LIS.getInterval(OrigReg); |
| 173 | assert(!Orig.empty() && "Splitting empty interval?"); |
| 174 | LiveInterval::const_iterator I = Orig.find(Idx); |
| 175 | |
| 176 | // Range containing Idx should begin at Idx. |
| 177 | if (I != Orig.end() && I->start <= Idx) |
| 178 | return I->start == Idx; |
| 179 | |
| 180 | // Range does not contain Idx, previous must end at Idx. |
| 181 | return I != Orig.begin() && (--I)->end == Idx; |
| 182 | } |
| 183 | |
Jakob Stoklund Olesen | 532de3d | 2010-10-22 20:28:21 +0000 | [diff] [blame] | 184 | void SplitAnalysis::print(const BlockPtrSet &B, raw_ostream &OS) const { |
| 185 | for (BlockPtrSet::const_iterator I = B.begin(), E = B.end(); I != E; ++I) { |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 186 | unsigned count = UsingBlocks.lookup(*I); |
Jakob Stoklund Olesen | 532de3d | 2010-10-22 20:28:21 +0000 | [diff] [blame] | 187 | OS << " BB#" << (*I)->getNumber(); |
| 188 | if (count) |
| 189 | OS << '(' << count << ')'; |
| 190 | } |
| 191 | } |
| 192 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 193 | void SplitAnalysis::analyze(const LiveInterval *li) { |
| 194 | clear(); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 195 | CurLI = li; |
Jakob Stoklund Olesen | abff280 | 2010-07-20 16:12:37 +0000 | [diff] [blame] | 196 | analyzeUses(); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Jakob Stoklund Olesen | 697483a | 2010-12-15 17:49:52 +0000 | [diff] [blame] | 199 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 200 | //===----------------------------------------------------------------------===// |
| 201 | // Split Editor |
| 202 | //===----------------------------------------------------------------------===// |
| 203 | |
| 204 | /// Create a new SplitEditor for editing the LiveInterval analyzed by SA. |
Jakob Stoklund Olesen | d68f458 | 2010-10-28 20:34:50 +0000 | [diff] [blame] | 205 | SplitEditor::SplitEditor(SplitAnalysis &sa, |
| 206 | LiveIntervals &lis, |
| 207 | VirtRegMap &vrm, |
| 208 | MachineDominatorTree &mdt, |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 209 | LiveRangeEdit &edit) |
Jakob Stoklund Olesen | 0eeca44 | 2011-02-19 00:42:33 +0000 | [diff] [blame] | 210 | : SA(sa), LIS(lis), VRM(vrm), |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 211 | MRI(vrm.getMachineFunction().getRegInfo()), |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 212 | MDT(mdt), |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 213 | TII(*vrm.getMachineFunction().getTarget().getInstrInfo()), |
| 214 | TRI(*vrm.getMachineFunction().getTarget().getRegisterInfo()), |
| 215 | Edit(edit), |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 216 | OpenIdx(0), |
| 217 | RegAssign(Allocator) |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 218 | { |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 219 | // We don't need an AliasAnalysis since we will only be performing |
| 220 | // cheap-as-a-copy remats anyway. |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 221 | Edit.anyRematerializable(LIS, TII, 0); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 224 | void SplitEditor::dump() const { |
| 225 | if (RegAssign.empty()) { |
| 226 | dbgs() << " empty\n"; |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | for (RegAssignMap::const_iterator I = RegAssign.begin(); I.valid(); ++I) |
| 231 | dbgs() << " [" << I.start() << ';' << I.stop() << "):" << I.value(); |
| 232 | dbgs() << '\n'; |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 235 | VNInfo *SplitEditor::defValue(unsigned RegIdx, |
| 236 | const VNInfo *ParentVNI, |
| 237 | SlotIndex Idx) { |
| 238 | assert(ParentVNI && "Mapping NULL value"); |
| 239 | assert(Idx.isValid() && "Invalid SlotIndex"); |
| 240 | assert(Edit.getParent().getVNInfoAt(Idx) == ParentVNI && "Bad Parent VNI"); |
| 241 | LiveInterval *LI = Edit.get(RegIdx); |
| 242 | |
| 243 | // Create a new value. |
| 244 | VNInfo *VNI = LI->getNextValue(Idx, 0, LIS.getVNInfoAllocator()); |
| 245 | |
| 246 | // Preserve the PHIDef bit. |
| 247 | if (ParentVNI->isPHIDef() && Idx == ParentVNI->def) |
| 248 | VNI->setIsPHIDef(true); |
| 249 | |
| 250 | // Use insert for lookup, so we can add missing values with a second lookup. |
| 251 | std::pair<ValueMap::iterator, bool> InsP = |
| 252 | Values.insert(std::make_pair(std::make_pair(RegIdx, ParentVNI->id), VNI)); |
| 253 | |
| 254 | // This was the first time (RegIdx, ParentVNI) was mapped. |
| 255 | // Keep it as a simple def without any liveness. |
| 256 | if (InsP.second) |
| 257 | return VNI; |
| 258 | |
| 259 | // If the previous value was a simple mapping, add liveness for it now. |
| 260 | if (VNInfo *OldVNI = InsP.first->second) { |
| 261 | SlotIndex Def = OldVNI->def; |
| 262 | LI->addRange(LiveRange(Def, Def.getNextSlot(), OldVNI)); |
| 263 | // No longer a simple mapping. |
| 264 | InsP.first->second = 0; |
| 265 | } |
| 266 | |
| 267 | // This is a complex mapping, add liveness for VNI |
| 268 | SlotIndex Def = VNI->def; |
| 269 | LI->addRange(LiveRange(Def, Def.getNextSlot(), VNI)); |
| 270 | |
| 271 | return VNI; |
| 272 | } |
| 273 | |
| 274 | void SplitEditor::markComplexMapped(unsigned RegIdx, const VNInfo *ParentVNI) { |
| 275 | assert(ParentVNI && "Mapping NULL value"); |
| 276 | VNInfo *&VNI = Values[std::make_pair(RegIdx, ParentVNI->id)]; |
| 277 | |
| 278 | // ParentVNI was either unmapped or already complex mapped. Either way. |
| 279 | if (!VNI) |
| 280 | return; |
| 281 | |
| 282 | // This was previously a single mapping. Make sure the old def is represented |
| 283 | // by a trivial live range. |
| 284 | SlotIndex Def = VNI->def; |
| 285 | Edit.get(RegIdx)->addRange(LiveRange(Def, Def.getNextSlot(), VNI)); |
| 286 | VNI = 0; |
| 287 | } |
| 288 | |
Jakob Stoklund Olesen | 1c38ba6 | 2011-03-02 01:59:34 +0000 | [diff] [blame] | 289 | // extendRange - Extend the live range to reach Idx. |
| 290 | // Potentially create phi-def values. |
| 291 | void SplitEditor::extendRange(unsigned RegIdx, SlotIndex Idx) { |
| 292 | assert(Idx.isValid() && "Invalid SlotIndex"); |
| 293 | MachineBasicBlock *IdxMBB = LIS.getMBBFromIndex(Idx); |
| 294 | assert(IdxMBB && "No MBB at Idx"); |
| 295 | LiveInterval *LI = Edit.get(RegIdx); |
| 296 | |
| 297 | // Is there a def in the same MBB we can extend? |
| 298 | if (LI->extendInBlock(LIS.getMBBStartIdx(IdxMBB), Idx)) |
| 299 | return; |
| 300 | |
| 301 | // Now for the fun part. We know that ParentVNI potentially has multiple defs, |
| 302 | // and we may need to create even more phi-defs to preserve VNInfo SSA form. |
| 303 | // Perform a search for all predecessor blocks where we know the dominating |
| 304 | // VNInfo. Insert phi-def VNInfos along the path back to IdxMBB. |
| 305 | DEBUG(dbgs() << "\n Reaching defs for BB#" << IdxMBB->getNumber() |
| 306 | << " at " << Idx << " in " << *LI << '\n'); |
| 307 | |
| 308 | // Blocks where LI should be live-in. |
| 309 | SmallVector<MachineDomTreeNode*, 16> LiveIn; |
| 310 | LiveIn.push_back(MDT[IdxMBB]); |
| 311 | |
| 312 | // Using LiveOutCache as a visited set, perform a BFS for all reaching defs. |
| 313 | for (unsigned i = 0; i != LiveIn.size(); ++i) { |
| 314 | MachineBasicBlock *MBB = LiveIn[i]->getBlock(); |
| 315 | for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(), |
| 316 | PE = MBB->pred_end(); PI != PE; ++PI) { |
| 317 | MachineBasicBlock *Pred = *PI; |
| 318 | // Is this a known live-out block? |
| 319 | std::pair<LiveOutMap::iterator,bool> LOIP = |
| 320 | LiveOutCache.insert(std::make_pair(Pred, LiveOutPair())); |
| 321 | // Yes, we have been here before. |
| 322 | if (!LOIP.second) |
| 323 | continue; |
| 324 | |
| 325 | // Does Pred provide a live-out value? |
| 326 | SlotIndex Start, Last; |
| 327 | tie(Start, Last) = LIS.getSlotIndexes()->getMBBRange(Pred); |
| 328 | Last = Last.getPrevSlot(); |
| 329 | if (VNInfo *VNI = LI->extendInBlock(Start, Last)) { |
| 330 | MachineBasicBlock *DefMBB = LIS.getMBBFromIndex(VNI->def); |
| 331 | LiveOutPair &LOP = LOIP.first->second; |
| 332 | LOP.first = VNI; |
| 333 | LOP.second = MDT[DefMBB]; |
| 334 | continue; |
| 335 | } |
| 336 | // No, we need a live-in value for Pred as well |
| 337 | if (Pred != IdxMBB) |
| 338 | LiveIn.push_back(MDT[Pred]); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // We may need to add phi-def values to preserve the SSA form. |
| 343 | VNInfo *IdxVNI = updateSSA(RegIdx, LiveIn, Idx, IdxMBB); |
| 344 | |
| 345 | #ifndef NDEBUG |
| 346 | // Check the LiveOutCache invariants. |
| 347 | for (LiveOutMap::iterator I = LiveOutCache.begin(), E = LiveOutCache.end(); |
| 348 | I != E; ++I) { |
| 349 | assert(I->first && "Null MBB entry in cache"); |
| 350 | assert(I->second.first && "Null VNInfo in cache"); |
| 351 | assert(I->second.second && "Null DomTreeNode in cache"); |
| 352 | if (I->second.second->getBlock() == I->first) |
| 353 | continue; |
| 354 | for (MachineBasicBlock::pred_iterator PI = I->first->pred_begin(), |
| 355 | PE = I->first->pred_end(); PI != PE; ++PI) |
| 356 | assert(LiveOutCache.lookup(*PI) == I->second && "Bad invariant"); |
| 357 | } |
| 358 | #endif |
| 359 | |
| 360 | // Since we went through the trouble of a full BFS visiting all reaching defs, |
| 361 | // the values in LiveIn are now accurate. No more phi-defs are needed |
| 362 | // for these blocks, so we can color the live ranges. |
| 363 | for (unsigned i = 0, e = LiveIn.size(); i != e; ++i) { |
| 364 | MachineBasicBlock *MBB = LiveIn[i]->getBlock(); |
| 365 | SlotIndex Start = LIS.getMBBStartIdx(MBB); |
| 366 | VNInfo *VNI = LiveOutCache.lookup(MBB).first; |
| 367 | |
| 368 | // Anything in LiveIn other than IdxMBB is live-through. |
| 369 | // In IdxMBB, we should stop at Idx unless the same value is live-out. |
| 370 | if (MBB == IdxMBB && IdxVNI != VNI) |
| 371 | LI->addRange(LiveRange(Start, Idx.getNextSlot(), IdxVNI)); |
| 372 | else |
| 373 | LI->addRange(LiveRange(Start, LIS.getMBBEndIdx(MBB), VNI)); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | VNInfo *SplitEditor::updateSSA(unsigned RegIdx, |
| 378 | SmallVectorImpl<MachineDomTreeNode*> &LiveIn, |
| 379 | SlotIndex Idx, |
| 380 | const MachineBasicBlock *IdxMBB) { |
| 381 | // This is essentially the same iterative algorithm that SSAUpdater uses, |
| 382 | // except we already have a dominator tree, so we don't have to recompute it. |
| 383 | LiveInterval *LI = Edit.get(RegIdx); |
| 384 | VNInfo *IdxVNI = 0; |
| 385 | unsigned Changes; |
| 386 | do { |
| 387 | Changes = 0; |
| 388 | DEBUG(dbgs() << " Iterating over " << LiveIn.size() << " blocks.\n"); |
| 389 | // Propagate live-out values down the dominator tree, inserting phi-defs |
| 390 | // when necessary. Since LiveIn was created by a BFS, going backwards makes |
| 391 | // it more likely for us to visit immediate dominators before their |
| 392 | // children. |
| 393 | for (unsigned i = LiveIn.size(); i; --i) { |
| 394 | MachineDomTreeNode *Node = LiveIn[i-1]; |
| 395 | MachineBasicBlock *MBB = Node->getBlock(); |
| 396 | MachineDomTreeNode *IDom = Node->getIDom(); |
| 397 | LiveOutPair IDomValue; |
| 398 | // We need a live-in value to a block with no immediate dominator? |
| 399 | // This is probably an unreachable block that has survived somehow. |
| 400 | bool needPHI = !IDom; |
| 401 | |
| 402 | // Get the IDom live-out value. |
| 403 | if (!needPHI) { |
| 404 | LiveOutMap::iterator I = LiveOutCache.find(IDom->getBlock()); |
| 405 | if (I != LiveOutCache.end()) |
| 406 | IDomValue = I->second; |
| 407 | else |
| 408 | // If IDom is outside our set of live-out blocks, there must be new |
| 409 | // defs, and we need a phi-def here. |
| 410 | needPHI = true; |
| 411 | } |
| 412 | |
| 413 | // IDom dominates all of our predecessors, but it may not be the immediate |
| 414 | // dominator. Check if any of them have live-out values that are properly |
| 415 | // dominated by IDom. If so, we need a phi-def here. |
| 416 | if (!needPHI) { |
| 417 | for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(), |
| 418 | PE = MBB->pred_end(); PI != PE; ++PI) { |
| 419 | LiveOutPair Value = LiveOutCache[*PI]; |
| 420 | if (!Value.first || Value.first == IDomValue.first) |
| 421 | continue; |
| 422 | // This predecessor is carrying something other than IDomValue. |
| 423 | // It could be because IDomValue hasn't propagated yet, or it could be |
| 424 | // because MBB is in the dominance frontier of that value. |
| 425 | if (MDT.dominates(IDom, Value.second)) { |
| 426 | needPHI = true; |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | // Create a phi-def if required. |
| 433 | if (needPHI) { |
| 434 | ++Changes; |
| 435 | SlotIndex Start = LIS.getMBBStartIdx(MBB); |
| 436 | VNInfo *VNI = LI->getNextValue(Start, 0, LIS.getVNInfoAllocator()); |
| 437 | VNI->setIsPHIDef(true); |
| 438 | DEBUG(dbgs() << " - BB#" << MBB->getNumber() |
| 439 | << " phi-def #" << VNI->id << " at " << Start << '\n'); |
| 440 | // We no longer need LI to be live-in. |
| 441 | LiveIn.erase(LiveIn.begin()+(i-1)); |
| 442 | // Blocks in LiveIn are either IdxMBB, or have a value live-through. |
| 443 | if (MBB == IdxMBB) |
| 444 | IdxVNI = VNI; |
| 445 | // Check if we need to update live-out info. |
| 446 | LiveOutMap::iterator I = LiveOutCache.find(MBB); |
| 447 | if (I == LiveOutCache.end() || I->second.second == Node) { |
| 448 | // We already have a live-out defined in MBB, so this must be IdxMBB. |
| 449 | assert(MBB == IdxMBB && "Adding phi-def to known live-out"); |
| 450 | LI->addRange(LiveRange(Start, Idx.getNextSlot(), VNI)); |
| 451 | } else { |
| 452 | // This phi-def is also live-out, so color the whole block. |
| 453 | LI->addRange(LiveRange(Start, LIS.getMBBEndIdx(MBB), VNI)); |
| 454 | I->second = LiveOutPair(VNI, Node); |
| 455 | } |
| 456 | } else if (IDomValue.first) { |
| 457 | // No phi-def here. Remember incoming value for IdxMBB. |
| 458 | if (MBB == IdxMBB) |
| 459 | IdxVNI = IDomValue.first; |
| 460 | // Propagate IDomValue if needed: |
| 461 | // MBB is live-out and doesn't define its own value. |
| 462 | LiveOutMap::iterator I = LiveOutCache.find(MBB); |
| 463 | if (I != LiveOutCache.end() && I->second.second != Node && |
| 464 | I->second.first != IDomValue.first) { |
| 465 | ++Changes; |
| 466 | I->second = IDomValue; |
| 467 | DEBUG(dbgs() << " - BB#" << MBB->getNumber() |
| 468 | << " idom valno #" << IDomValue.first->id |
| 469 | << " from BB#" << IDom->getBlock()->getNumber() << '\n'); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | DEBUG(dbgs() << " - made " << Changes << " changes.\n"); |
| 474 | } while (Changes); |
| 475 | |
| 476 | assert(IdxVNI && "Didn't find value for Idx"); |
| 477 | return IdxVNI; |
| 478 | } |
| 479 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 480 | VNInfo *SplitEditor::defFromParent(unsigned RegIdx, |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 481 | VNInfo *ParentVNI, |
| 482 | SlotIndex UseIdx, |
| 483 | MachineBasicBlock &MBB, |
| 484 | MachineBasicBlock::iterator I) { |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 485 | MachineInstr *CopyMI = 0; |
| 486 | SlotIndex Def; |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 487 | LiveInterval *LI = Edit.get(RegIdx); |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 488 | |
| 489 | // Attempt cheap-as-a-copy rematerialization. |
| 490 | LiveRangeEdit::Remat RM(ParentVNI); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 491 | if (Edit.canRematerializeAt(RM, UseIdx, true, LIS)) { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 492 | Def = Edit.rematerializeAt(MBB, I, LI->reg, RM, LIS, TII, TRI); |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 493 | } else { |
| 494 | // Can't remat, just insert a copy from parent. |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 495 | CopyMI = BuildMI(MBB, I, DebugLoc(), TII.get(TargetOpcode::COPY), LI->reg) |
| 496 | .addReg(Edit.getReg()); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 497 | Def = LIS.InsertMachineInstrInMaps(CopyMI).getDefIndex(); |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 500 | // Temporarily mark all values as complex mapped. |
| 501 | markComplexMapped(RegIdx, ParentVNI); |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 502 | |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 503 | // Define the value in Reg. |
| 504 | VNInfo *VNI = defValue(RegIdx, ParentVNI, Def); |
| 505 | VNI->setCopy(CopyMI); |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 506 | return VNI; |
| 507 | } |
| 508 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 509 | /// Create a new virtual register and live interval. |
| 510 | void SplitEditor::openIntv() { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 511 | assert(!OpenIdx && "Previous LI not closed before openIntv"); |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 512 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 513 | // Create the complement as index 0. |
Jakob Stoklund Olesen | 1c38ba6 | 2011-03-02 01:59:34 +0000 | [diff] [blame] | 514 | if (Edit.empty()) |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 515 | Edit.create(MRI, LIS, VRM); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 516 | |
| 517 | // Create the open interval. |
| 518 | OpenIdx = Edit.size(); |
| 519 | Edit.create(MRI, LIS, VRM); |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 522 | SlotIndex SplitEditor::enterIntvBefore(SlotIndex Idx) { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 523 | assert(OpenIdx && "openIntv not called before enterIntvBefore"); |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 524 | DEBUG(dbgs() << " enterIntvBefore " << Idx); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 525 | Idx = Idx.getBaseIndex(); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 526 | VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx); |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 527 | if (!ParentVNI) { |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 528 | DEBUG(dbgs() << ": not live\n"); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 529 | return Idx; |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 530 | } |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 531 | DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n'); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 532 | MachineInstr *MI = LIS.getInstructionFromIndex(Idx); |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 533 | assert(MI && "enterIntvBefore called with invalid index"); |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 534 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 535 | VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI); |
| 536 | return VNI->def; |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 539 | SlotIndex SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 540 | assert(OpenIdx && "openIntv not called before enterIntvAtEnd"); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 541 | SlotIndex End = LIS.getMBBEndIdx(&MBB); |
| 542 | SlotIndex Last = End.getPrevSlot(); |
| 543 | DEBUG(dbgs() << " enterIntvAtEnd BB#" << MBB.getNumber() << ", " << Last); |
| 544 | VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Last); |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 545 | if (!ParentVNI) { |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 546 | DEBUG(dbgs() << ": not live\n"); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 547 | return End; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 548 | } |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 549 | DEBUG(dbgs() << ": valno " << ParentVNI->id); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 550 | VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB, |
Jakob Stoklund Olesen | cb64047 | 2011-02-04 19:33:11 +0000 | [diff] [blame] | 551 | LIS.getLastSplitPoint(Edit.getParent(), &MBB)); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 552 | RegAssign.insert(VNI->def, End, OpenIdx); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 553 | DEBUG(dump()); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 554 | return VNI->def; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 557 | /// useIntv - indicate that all instructions in MBB should use OpenLI. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 558 | void SplitEditor::useIntv(const MachineBasicBlock &MBB) { |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 559 | useIntv(LIS.getMBBStartIdx(&MBB), LIS.getMBBEndIdx(&MBB)); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 562 | void SplitEditor::useIntv(SlotIndex Start, SlotIndex End) { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 563 | assert(OpenIdx && "openIntv not called before useIntv"); |
| 564 | DEBUG(dbgs() << " useIntv [" << Start << ';' << End << "):"); |
| 565 | RegAssign.insert(Start, End, OpenIdx); |
| 566 | DEBUG(dump()); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 569 | SlotIndex SplitEditor::leaveIntvAfter(SlotIndex Idx) { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 570 | assert(OpenIdx && "openIntv not called before leaveIntvAfter"); |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 571 | DEBUG(dbgs() << " leaveIntvAfter " << Idx); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 572 | |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 573 | // The interval must be live beyond the instruction at Idx. |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 574 | Idx = Idx.getBoundaryIndex(); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 575 | VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx); |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 576 | if (!ParentVNI) { |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 577 | DEBUG(dbgs() << ": not live\n"); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 578 | return Idx.getNextSlot(); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 579 | } |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 580 | DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n'); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 581 | |
Jakob Stoklund Olesen | 01cb34b | 2011-02-08 18:50:18 +0000 | [diff] [blame] | 582 | MachineInstr *MI = LIS.getInstructionFromIndex(Idx); |
| 583 | assert(MI && "No instruction at index"); |
| 584 | VNInfo *VNI = defFromParent(0, ParentVNI, Idx, *MI->getParent(), |
| 585 | llvm::next(MachineBasicBlock::iterator(MI))); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 586 | return VNI->def; |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 589 | SlotIndex SplitEditor::leaveIntvBefore(SlotIndex Idx) { |
| 590 | assert(OpenIdx && "openIntv not called before leaveIntvBefore"); |
| 591 | DEBUG(dbgs() << " leaveIntvBefore " << Idx); |
| 592 | |
| 593 | // The interval must be live into the instruction at Idx. |
| 594 | Idx = Idx.getBoundaryIndex(); |
| 595 | VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx); |
| 596 | if (!ParentVNI) { |
| 597 | DEBUG(dbgs() << ": not live\n"); |
| 598 | return Idx.getNextSlot(); |
| 599 | } |
| 600 | DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n'); |
| 601 | |
| 602 | MachineInstr *MI = LIS.getInstructionFromIndex(Idx); |
| 603 | assert(MI && "No instruction at index"); |
| 604 | VNInfo *VNI = defFromParent(0, ParentVNI, Idx, *MI->getParent(), MI); |
| 605 | return VNI->def; |
| 606 | } |
| 607 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 608 | SlotIndex SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 609 | assert(OpenIdx && "openIntv not called before leaveIntvAtTop"); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 610 | SlotIndex Start = LIS.getMBBStartIdx(&MBB); |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 611 | DEBUG(dbgs() << " leaveIntvAtTop BB#" << MBB.getNumber() << ", " << Start); |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 612 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 613 | VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Start); |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 614 | if (!ParentVNI) { |
Jakob Stoklund Olesen | 9b24afe | 2010-10-07 17:56:35 +0000 | [diff] [blame] | 615 | DEBUG(dbgs() << ": not live\n"); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 616 | return Start; |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 619 | VNInfo *VNI = defFromParent(0, ParentVNI, Start, MBB, |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 620 | MBB.SkipPHIsAndLabels(MBB.begin())); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 621 | RegAssign.insert(Start, VNI->def, OpenIdx); |
| 622 | DEBUG(dump()); |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 623 | return VNI->def; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Jakob Stoklund Olesen | 5c716bd | 2011-02-08 18:50:21 +0000 | [diff] [blame] | 626 | void SplitEditor::overlapIntv(SlotIndex Start, SlotIndex End) { |
| 627 | assert(OpenIdx && "openIntv not called before overlapIntv"); |
| 628 | assert(Edit.getParent().getVNInfoAt(Start) == |
| 629 | Edit.getParent().getVNInfoAt(End.getPrevSlot()) && |
| 630 | "Parent changes value in extended range"); |
| 631 | assert(Edit.get(0)->getVNInfoAt(Start) && "Start must come from leaveIntv*"); |
| 632 | assert(LIS.getMBBFromIndex(Start) == LIS.getMBBFromIndex(End) && |
| 633 | "Range cannot span basic blocks"); |
| 634 | |
Jakob Stoklund Olesen | d3fdaeb | 2011-03-02 00:49:28 +0000 | [diff] [blame] | 635 | // Treat this as useIntv() for now. |
| 636 | // The complement interval will be extended as needed by extendRange(). |
Jakob Stoklund Olesen | 5c716bd | 2011-02-08 18:50:21 +0000 | [diff] [blame] | 637 | DEBUG(dbgs() << " overlapIntv [" << Start << ';' << End << "):"); |
| 638 | RegAssign.insert(Start, End, OpenIdx); |
| 639 | DEBUG(dump()); |
| 640 | } |
| 641 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 642 | /// closeIntv - Indicate that we are done editing the currently open |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 643 | /// LiveInterval, and ranges can be trimmed. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 644 | void SplitEditor::closeIntv() { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 645 | assert(OpenIdx && "openIntv not called before closeIntv"); |
| 646 | OpenIdx = 0; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Jakob Stoklund Olesen | e2dc0c9 | 2011-03-02 23:05:16 +0000 | [diff] [blame^] | 649 | void SplitEditor::extendPHIKillRanges() { |
| 650 | // Extend live ranges to be live-out for successor PHI values. |
| 651 | for (LiveInterval::const_vni_iterator I = Edit.getParent().vni_begin(), |
| 652 | E = Edit.getParent().vni_end(); I != E; ++I) { |
| 653 | const VNInfo *PHIVNI = *I; |
| 654 | if (PHIVNI->isUnused() || !PHIVNI->isPHIDef()) |
| 655 | continue; |
| 656 | unsigned RegIdx = RegAssign.lookup(PHIVNI->def); |
| 657 | MachineBasicBlock *MBB = LIS.getMBBFromIndex(PHIVNI->def); |
| 658 | for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(), |
| 659 | PE = MBB->pred_end(); PI != PE; ++PI) { |
| 660 | SlotIndex End = LIS.getMBBEndIdx(*PI).getPrevSlot(); |
| 661 | // The predecessor may not have a live-out value. That is OK, like an |
| 662 | // undef PHI operand. |
| 663 | if (Edit.getParent().liveAt(End)) { |
| 664 | assert(RegAssign.lookup(End) == RegIdx && |
| 665 | "Different register assignment in phi predecessor"); |
| 666 | extendRange(RegIdx, End); |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 672 | /// rewriteAssigned - Rewrite all uses of Edit.getReg(). |
| 673 | void SplitEditor::rewriteAssigned() { |
| 674 | for (MachineRegisterInfo::reg_iterator RI = MRI.reg_begin(Edit.getReg()), |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 675 | RE = MRI.reg_end(); RI != RE;) { |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 676 | MachineOperand &MO = RI.getOperand(); |
| 677 | MachineInstr *MI = MO.getParent(); |
| 678 | ++RI; |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 679 | // LiveDebugVariables should have handled all DBG_VALUE instructions. |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 680 | if (MI->isDebugValue()) { |
| 681 | DEBUG(dbgs() << "Zapping " << *MI); |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 682 | MO.setReg(0); |
| 683 | continue; |
| 684 | } |
Jakob Stoklund Olesen | a372d16 | 2011-02-09 21:52:09 +0000 | [diff] [blame] | 685 | |
| 686 | // <undef> operands don't really read the register, so just assign them to |
| 687 | // the complement. |
| 688 | if (MO.isUse() && MO.isUndef()) { |
| 689 | MO.setReg(Edit.get(0)->reg); |
| 690 | continue; |
| 691 | } |
| 692 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 693 | SlotIndex Idx = LIS.getInstructionIndex(MI); |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 694 | Idx = MO.isUse() ? Idx.getUseIndex() : Idx.getDefIndex(); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 695 | |
| 696 | // Rewrite to the mapped register at Idx. |
| 697 | unsigned RegIdx = RegAssign.lookup(Idx); |
| 698 | MO.setReg(Edit.get(RegIdx)->reg); |
| 699 | DEBUG(dbgs() << " rewr BB#" << MI->getParent()->getNumber() << '\t' |
| 700 | << Idx << ':' << RegIdx << '\t' << *MI); |
| 701 | |
| 702 | // Extend liveness to Idx. |
Jakob Stoklund Olesen | 1c38ba6 | 2011-03-02 01:59:34 +0000 | [diff] [blame] | 703 | extendRange(RegIdx, Idx); |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 707 | /// rewriteSplit - Rewrite uses of Intvs[0] according to the ConEQ mapping. |
| 708 | void SplitEditor::rewriteComponents(const SmallVectorImpl<LiveInterval*> &Intvs, |
| 709 | const ConnectedVNInfoEqClasses &ConEq) { |
| 710 | for (MachineRegisterInfo::reg_iterator RI = MRI.reg_begin(Intvs[0]->reg), |
| 711 | RE = MRI.reg_end(); RI != RE;) { |
| 712 | MachineOperand &MO = RI.getOperand(); |
| 713 | MachineInstr *MI = MO.getParent(); |
| 714 | ++RI; |
| 715 | if (MO.isUse() && MO.isUndef()) |
Jakob Stoklund Olesen | 9d99977 | 2010-10-21 18:47:08 +0000 | [diff] [blame] | 716 | continue; |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 717 | // DBG_VALUE instructions should have been eliminated earlier. |
| 718 | SlotIndex Idx = LIS.getInstructionIndex(MI); |
| 719 | Idx = MO.isUse() ? Idx.getUseIndex() : Idx.getDefIndex(); |
| 720 | DEBUG(dbgs() << " rewr BB#" << MI->getParent()->getNumber() << '\t' |
| 721 | << Idx << ':'); |
| 722 | const VNInfo *VNI = Intvs[0]->getVNInfoAt(Idx); |
| 723 | assert(VNI && "Interval not live at use."); |
| 724 | MO.setReg(Intvs[ConEq.getEqClass(VNI)]->reg); |
| 725 | DEBUG(dbgs() << VNI->id << '\t' << *MI); |
Eric Christopher | 463a297 | 2011-02-03 05:40:54 +0000 | [diff] [blame] | 726 | } |
Eric Christopher | 463a297 | 2011-02-03 05:40:54 +0000 | [diff] [blame] | 727 | } |
Jakob Stoklund Olesen | 2cd2111 | 2011-02-03 00:54:23 +0000 | [diff] [blame] | 728 | |
Eric Christopher | 463a297 | 2011-02-03 05:40:54 +0000 | [diff] [blame] | 729 | void SplitEditor::finish() { |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 730 | assert(OpenIdx == 0 && "Previous LI not closed before rewrite"); |
Eric Christopher | 463a297 | 2011-02-03 05:40:54 +0000 | [diff] [blame] | 731 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 732 | // At this point, the live intervals in Edit contain VNInfos corresponding to |
| 733 | // the inserted copies. |
| 734 | |
| 735 | // Add the original defs from the parent interval. |
| 736 | for (LiveInterval::const_vni_iterator I = Edit.getParent().vni_begin(), |
| 737 | E = Edit.getParent().vni_end(); I != E; ++I) { |
| 738 | const VNInfo *ParentVNI = *I; |
Jakob Stoklund Olesen | 9ecd1e7 | 2011-02-04 00:59:23 +0000 | [diff] [blame] | 739 | if (ParentVNI->isUnused()) |
| 740 | continue; |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 741 | unsigned RegIdx = RegAssign.lookup(ParentVNI->def); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 742 | // Mark all values as complex to force liveness computation. |
| 743 | // This should really only be necessary for remat victims, but we are lazy. |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 744 | markComplexMapped(RegIdx, ParentVNI); |
| 745 | defValue(RegIdx, ParentVNI, ParentVNI->def); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | #ifndef NDEBUG |
| 749 | // Every new interval must have a def by now, otherwise the split is bogus. |
| 750 | for (LiveRangeEdit::iterator I = Edit.begin(), E = Edit.end(); I != E; ++I) |
| 751 | assert((*I)->hasAtLeastOneValue() && "Split interval has no value"); |
| 752 | #endif |
| 753 | |
| 754 | // FIXME: Don't recompute the liveness of all values, infer it from the |
| 755 | // overlaps between the parent live interval and RegAssign. |
Jakob Stoklund Olesen | d3fdaeb | 2011-03-02 00:49:28 +0000 | [diff] [blame] | 756 | // The extendRange algorithm is only necessary when: |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 757 | // - The parent value maps to multiple defs, and new phis are needed, or |
| 758 | // - The value has been rematerialized before some uses, and we want to |
| 759 | // minimize the live range so it only reaches the remaining uses. |
| 760 | // All other values have simple liveness that can be computed from RegAssign |
| 761 | // and the parent live interval. |
| 762 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 763 | // Rewrite instructions. |
Jakob Stoklund Olesen | e2dc0c9 | 2011-03-02 23:05:16 +0000 | [diff] [blame^] | 764 | extendPHIKillRanges(); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 765 | rewriteAssigned(); |
| 766 | |
| 767 | // FIXME: Delete defs that were rematted everywhere. |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 768 | |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 769 | // Get rid of unused values and set phi-kill flags. |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 770 | for (LiveRangeEdit::iterator I = Edit.begin(), E = Edit.end(); I != E; ++I) |
| 771 | (*I)->RenumberValues(LIS); |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 772 | |
Jakob Stoklund Olesen | 3a0e071 | 2010-10-26 22:36:09 +0000 | [diff] [blame] | 773 | // Now check if any registers were separated into multiple components. |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 774 | ConnectedVNInfoEqClasses ConEQ(LIS); |
| 775 | for (unsigned i = 0, e = Edit.size(); i != e; ++i) { |
Jakob Stoklund Olesen | 3a0e071 | 2010-10-26 22:36:09 +0000 | [diff] [blame] | 776 | // Don't use iterators, they are invalidated by create() below. |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 777 | LiveInterval *li = Edit.get(i); |
Jakob Stoklund Olesen | 3a0e071 | 2010-10-26 22:36:09 +0000 | [diff] [blame] | 778 | unsigned NumComp = ConEQ.Classify(li); |
| 779 | if (NumComp <= 1) |
| 780 | continue; |
| 781 | DEBUG(dbgs() << " " << NumComp << " components: " << *li << '\n'); |
| 782 | SmallVector<LiveInterval*, 8> dups; |
| 783 | dups.push_back(li); |
| 784 | for (unsigned i = 1; i != NumComp; ++i) |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 785 | dups.push_back(&Edit.create(MRI, LIS, VRM)); |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 786 | rewriteComponents(dups, ConEQ); |
Jakob Stoklund Olesen | 3a0e071 | 2010-10-26 22:36:09 +0000 | [diff] [blame] | 787 | ConEQ.Distribute(&dups[0]); |
Jakob Stoklund Olesen | 3a0e071 | 2010-10-26 22:36:09 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Jakob Stoklund Olesen | 08e93b1 | 2010-08-10 17:07:22 +0000 | [diff] [blame] | 790 | // Calculate spill weight and allocation hints for new intervals. |
Jakob Stoklund Olesen | 0eeca44 | 2011-02-19 00:42:33 +0000 | [diff] [blame] | 791 | VirtRegAuxInfo vrai(VRM.getMachineFunction(), LIS, SA.Loops); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 792 | for (LiveRangeEdit::iterator I = Edit.begin(), E = Edit.end(); I != E; ++I){ |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 793 | LiveInterval &li = **I; |
Jakob Stoklund Olesen | 9db3ea4 | 2010-08-10 18:37:40 +0000 | [diff] [blame] | 794 | vrai.CalculateRegClass(li.reg); |
Jakob Stoklund Olesen | 08e93b1 | 2010-08-10 17:07:22 +0000 | [diff] [blame] | 795 | vrai.CalculateWeightAndHint(li); |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 796 | DEBUG(dbgs() << " new interval " << MRI.getRegClass(li.reg)->getName() |
Jakob Stoklund Olesen | e1f543f | 2010-08-12 18:50:55 +0000 | [diff] [blame] | 797 | << ":" << li << '\n'); |
Jakob Stoklund Olesen | 08e93b1 | 2010-08-10 17:07:22 +0000 | [diff] [blame] | 798 | } |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 802 | //===----------------------------------------------------------------------===// |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 803 | // Single Block Splitting |
| 804 | //===----------------------------------------------------------------------===// |
| 805 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 806 | /// getMultiUseBlocks - if CurLI has more than one use in a basic block, it |
| 807 | /// may be an advantage to split CurLI for the duration of the block. |
Jakob Stoklund Olesen | 2bfb324 | 2010-10-22 22:48:56 +0000 | [diff] [blame] | 808 | bool SplitAnalysis::getMultiUseBlocks(BlockPtrSet &Blocks) { |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 809 | // If CurLI is local to one block, there is no point to splitting it. |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 810 | if (LiveBlocks.size() <= 1) |
Jakob Stoklund Olesen | 2bfb324 | 2010-10-22 22:48:56 +0000 | [diff] [blame] | 811 | return false; |
| 812 | // Add blocks with multiple uses. |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 813 | for (unsigned i = 0, e = LiveBlocks.size(); i != e; ++i) { |
| 814 | const BlockInfo &BI = LiveBlocks[i]; |
| 815 | if (!BI.Uses) |
Jakob Stoklund Olesen | 2bfb324 | 2010-10-22 22:48:56 +0000 | [diff] [blame] | 816 | continue; |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 817 | unsigned Instrs = UsingBlocks.lookup(BI.MBB); |
| 818 | if (Instrs <= 1) |
| 819 | continue; |
| 820 | if (Instrs == 2 && BI.LiveIn && BI.LiveOut && !BI.LiveThrough) |
| 821 | continue; |
| 822 | Blocks.insert(BI.MBB); |
| 823 | } |
Jakob Stoklund Olesen | 2bfb324 | 2010-10-22 22:48:56 +0000 | [diff] [blame] | 824 | return !Blocks.empty(); |
| 825 | } |
| 826 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 827 | /// splitSingleBlocks - Split CurLI into a separate live interval inside each |
Jakob Stoklund Olesen | 57d0f2d | 2010-10-05 22:19:33 +0000 | [diff] [blame] | 828 | /// basic block in Blocks. |
| 829 | void SplitEditor::splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks) { |
Jakob Stoklund Olesen | e1f543f | 2010-08-12 18:50:55 +0000 | [diff] [blame] | 830 | DEBUG(dbgs() << " splitSingleBlocks for " << Blocks.size() << " blocks.\n"); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 831 | |
Jakob Stoklund Olesen | 0eeca44 | 2011-02-19 00:42:33 +0000 | [diff] [blame] | 832 | for (unsigned i = 0, e = SA.LiveBlocks.size(); i != e; ++i) { |
| 833 | const SplitAnalysis::BlockInfo &BI = SA.LiveBlocks[i]; |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 834 | if (!BI.Uses || !Blocks.count(BI.MBB)) |
| 835 | continue; |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 836 | |
| 837 | openIntv(); |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 838 | SlotIndex SegStart = enterIntvBefore(BI.FirstUse); |
Jakob Stoklund Olesen | c70f687 | 2011-02-23 18:26:31 +0000 | [diff] [blame] | 839 | if (!BI.LiveOut || BI.LastUse < BI.LastSplitPoint) { |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 840 | useIntv(SegStart, leaveIntvAfter(BI.LastUse)); |
| 841 | } else { |
Jakob Stoklund Olesen | c70f687 | 2011-02-23 18:26:31 +0000 | [diff] [blame] | 842 | // The last use is after the last valid split point. |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 843 | SlotIndex SegStop = leaveIntvBefore(BI.LastSplitPoint); |
| 844 | useIntv(SegStart, SegStop); |
| 845 | overlapIntv(SegStop, BI.LastUse); |
| 846 | } |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 847 | closeIntv(); |
| 848 | } |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 849 | finish(); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 850 | } |