blob: 798f71465d34aad175577918e0c5cc2ea8b459a3 [file] [log] [blame]
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +00001//===---------- 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
15#define DEBUG_TYPE "splitter"
16#include "SplitKit.h"
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +000017#include "LiveRangeEdit.h"
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000018#include "VirtRegMap.h"
Jakob Stoklund Olesen08e93b12010-08-10 17:07:22 +000019#include "llvm/CodeGen/CalcSpillWeights.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000020#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000021#include "llvm/CodeGen/MachineInstrBuilder.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000022#include "llvm/CodeGen/MachineLoopInfo.h"
23#include "llvm/CodeGen/MachineRegisterInfo.h"
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000024#include "llvm/Support/CommandLine.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000025#include "llvm/Support/Debug.h"
26#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000027#include "llvm/Target/TargetInstrInfo.h"
28#include "llvm/Target/TargetMachine.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000029
30using namespace llvm;
31
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000032static cl::opt<bool>
33AllowSplit("spiller-splits-edges",
34 cl::desc("Allow critical edge splitting during spilling"));
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000035
36//===----------------------------------------------------------------------===//
37// Split Analysis
38//===----------------------------------------------------------------------===//
39
Jakob Stoklund Olesenf2c6e362010-07-20 23:50:15 +000040SplitAnalysis::SplitAnalysis(const MachineFunction &mf,
41 const LiveIntervals &lis,
42 const MachineLoopInfo &mli)
43 : mf_(mf),
44 lis_(lis),
45 loops_(mli),
46 tii_(*mf.getTarget().getInstrInfo()),
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000047 curli_(0) {}
48
49void SplitAnalysis::clear() {
50 usingInstrs_.clear();
51 usingBlocks_.clear();
52 usingLoops_.clear();
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000053 curli_ = 0;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000054}
55
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000056bool SplitAnalysis::canAnalyzeBranch(const MachineBasicBlock *MBB) {
57 MachineBasicBlock *T, *F;
58 SmallVector<MachineOperand, 4> Cond;
59 return !tii_.AnalyzeBranch(const_cast<MachineBasicBlock&>(*MBB), T, F, Cond);
60}
61
Jakob Stoklund Olesenabff2802010-07-20 16:12:37 +000062/// analyzeUses - Count instructions, basic blocks, and loops using curli.
63void SplitAnalysis::analyzeUses() {
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000064 const MachineRegisterInfo &MRI = mf_.getRegInfo();
65 for (MachineRegisterInfo::reg_iterator I = MRI.reg_begin(curli_->reg);
66 MachineInstr *MI = I.skipInstruction();) {
67 if (MI->isDebugValue() || !usingInstrs_.insert(MI))
68 continue;
69 MachineBasicBlock *MBB = MI->getParent();
70 if (usingBlocks_[MBB]++)
71 continue;
Jakob Stoklund Olesen9b90d7e2010-10-05 23:10:12 +000072 for (MachineLoop *Loop = loops_.getLoopFor(MBB); Loop;
73 Loop = Loop->getParentLoop())
Jakob Stoklund Olesen2dee7a52010-08-12 23:02:55 +000074 usingLoops_[Loop]++;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000075 }
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +000076 DEBUG(dbgs() << " counted "
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000077 << usingInstrs_.size() << " instrs, "
78 << usingBlocks_.size() << " blocks, "
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +000079 << usingLoops_.size() << " loops.\n");
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000080}
81
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +000082void SplitAnalysis::print(const BlockPtrSet &B, raw_ostream &OS) const {
83 for (BlockPtrSet::const_iterator I = B.begin(), E = B.end(); I != E; ++I) {
84 unsigned count = usingBlocks_.lookup(*I);
85 OS << " BB#" << (*I)->getNumber();
86 if (count)
87 OS << '(' << count << ')';
88 }
89}
90
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000091// Get three sets of basic blocks surrounding a loop: Blocks inside the loop,
92// predecessor blocks, and exit blocks.
93void SplitAnalysis::getLoopBlocks(const MachineLoop *Loop, LoopBlocks &Blocks) {
94 Blocks.clear();
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000095
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000096 // Blocks in the loop.
97 Blocks.Loop.insert(Loop->block_begin(), Loop->block_end());
98
99 // Predecessor blocks.
100 const MachineBasicBlock *Header = Loop->getHeader();
101 for (MachineBasicBlock::const_pred_iterator I = Header->pred_begin(),
102 E = Header->pred_end(); I != E; ++I)
103 if (!Blocks.Loop.count(*I))
104 Blocks.Preds.insert(*I);
105
106 // Exit blocks.
107 for (MachineLoop::block_iterator I = Loop->block_begin(),
108 E = Loop->block_end(); I != E; ++I) {
109 const MachineBasicBlock *MBB = *I;
110 for (MachineBasicBlock::const_succ_iterator SI = MBB->succ_begin(),
111 SE = MBB->succ_end(); SI != SE; ++SI)
112 if (!Blocks.Loop.count(*SI))
113 Blocks.Exits.insert(*SI);
114 }
115}
116
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000117void SplitAnalysis::print(const LoopBlocks &B, raw_ostream &OS) const {
118 OS << "Loop:";
119 print(B.Loop, OS);
120 OS << ", preds:";
121 print(B.Preds, OS);
122 OS << ", exits:";
123 print(B.Exits, OS);
124}
125
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000126/// analyzeLoopPeripheralUse - Return an enum describing how curli_ is used in
127/// and around the Loop.
128SplitAnalysis::LoopPeripheralUse SplitAnalysis::
129analyzeLoopPeripheralUse(const SplitAnalysis::LoopBlocks &Blocks) {
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000130 LoopPeripheralUse use = ContainedInLoop;
131 for (BlockCountMap::iterator I = usingBlocks_.begin(), E = usingBlocks_.end();
132 I != E; ++I) {
133 const MachineBasicBlock *MBB = I->first;
134 // Is this a peripheral block?
135 if (use < MultiPeripheral &&
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000136 (Blocks.Preds.count(MBB) || Blocks.Exits.count(MBB))) {
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000137 if (I->second > 1) use = MultiPeripheral;
138 else use = SinglePeripheral;
139 continue;
140 }
141 // Is it a loop block?
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000142 if (Blocks.Loop.count(MBB))
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000143 continue;
144 // It must be an unrelated block.
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000145 DEBUG(dbgs() << ", outside: BB#" << MBB->getNumber());
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000146 return OutsideLoop;
147 }
148 return use;
149}
150
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000151/// getCriticalExits - It may be necessary to partially break critical edges
Jakob Stoklund Olesen2c1442e2010-10-22 20:28:23 +0000152/// leaving the loop if an exit block has predecessors from outside the loop
153/// periphery.
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000154void SplitAnalysis::getCriticalExits(const SplitAnalysis::LoopBlocks &Blocks,
155 BlockPtrSet &CriticalExits) {
156 CriticalExits.clear();
157
Jakob Stoklund Olesen2c1442e2010-10-22 20:28:23 +0000158 // A critical exit block has curli line-in, and has a predecessor that is not
159 // in the loop nor a loop predecessor. For such an exit block, the edges
160 // carrying the new variable must be moved to a new pre-exit block.
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000161 for (BlockPtrSet::iterator I = Blocks.Exits.begin(), E = Blocks.Exits.end();
162 I != E; ++I) {
Jakob Stoklund Olesen2c1442e2010-10-22 20:28:23 +0000163 const MachineBasicBlock *Exit = *I;
164 // A single-predecessor exit block is definitely not a critical edge.
165 if (Exit->pred_size() == 1)
166 continue;
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000167 // This exit may not have curli live in at all. No need to split.
Jakob Stoklund Olesen2c1442e2010-10-22 20:28:23 +0000168 if (!lis_.isLiveInToMBB(*curli_, Exit))
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000169 continue;
Jakob Stoklund Olesen2c1442e2010-10-22 20:28:23 +0000170 // Does this exit block have a predecessor that is not a loop block or loop
171 // predecessor?
172 for (MachineBasicBlock::const_pred_iterator PI = Exit->pred_begin(),
173 PE = Exit->pred_end(); PI != PE; ++PI) {
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000174 const MachineBasicBlock *Pred = *PI;
175 if (Blocks.Loop.count(Pred) || Blocks.Preds.count(Pred))
176 continue;
177 // This is a critical exit block, and we need to split the exit edge.
Jakob Stoklund Olesen2c1442e2010-10-22 20:28:23 +0000178 CriticalExits.insert(Exit);
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000179 break;
180 }
181 }
182}
183
184/// canSplitCriticalExits - Return true if it is possible to insert new exit
185/// blocks before the blocks in CriticalExits.
186bool
187SplitAnalysis::canSplitCriticalExits(const SplitAnalysis::LoopBlocks &Blocks,
188 BlockPtrSet &CriticalExits) {
189 // If we don't allow critical edge splitting, require no critical exits.
190 if (!AllowSplit)
191 return CriticalExits.empty();
192
193 for (BlockPtrSet::iterator I = CriticalExits.begin(), E = CriticalExits.end();
194 I != E; ++I) {
195 const MachineBasicBlock *Succ = *I;
196 // We want to insert a new pre-exit MBB before Succ, and change all the
197 // in-loop blocks to branch to the pre-exit instead of Succ.
198 // Check that all the in-loop predecessors can be changed.
199 for (MachineBasicBlock::const_pred_iterator PI = Succ->pred_begin(),
200 PE = Succ->pred_end(); PI != PE; ++PI) {
201 const MachineBasicBlock *Pred = *PI;
202 // The external predecessors won't be altered.
203 if (!Blocks.Loop.count(Pred) && !Blocks.Preds.count(Pred))
204 continue;
205 if (!canAnalyzeBranch(Pred))
206 return false;
207 }
208
209 // If Succ's layout predecessor falls through, that too must be analyzable.
210 // We need to insert the pre-exit block in the gap.
211 MachineFunction::const_iterator MFI = Succ;
212 if (MFI == mf_.begin())
213 continue;
214 if (!canAnalyzeBranch(--MFI))
215 return false;
216 }
217 // No problems found.
218 return true;
219}
220
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000221void SplitAnalysis::analyze(const LiveInterval *li) {
222 clear();
223 curli_ = li;
Jakob Stoklund Olesenabff2802010-07-20 16:12:37 +0000224 analyzeUses();
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000225}
226
227const MachineLoop *SplitAnalysis::getBestSplitLoop() {
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000228 assert(curli_ && "Call analyze() before getBestSplitLoop");
229 if (usingLoops_.empty())
230 return 0;
231
Jakob Stoklund Olesenab00e9f2010-10-14 18:26:45 +0000232 LoopPtrSet Loops;
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000233 LoopBlocks Blocks;
234 BlockPtrSet CriticalExits;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000235
Jakob Stoklund Olesenab00e9f2010-10-14 18:26:45 +0000236 // We split around loops where curli is used outside the periphery.
Jakob Stoklund Olesen2dee7a52010-08-12 23:02:55 +0000237 for (LoopCountMap::const_iterator I = usingLoops_.begin(),
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000238 E = usingLoops_.end(); I != E; ++I) {
Jakob Stoklund Olesen2dee7a52010-08-12 23:02:55 +0000239 const MachineLoop *Loop = I->first;
240 getLoopBlocks(Loop, Blocks);
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000241 DEBUG({ dbgs() << " "; print(Blocks, dbgs()); });
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000242
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000243 switch(analyzeLoopPeripheralUse(Blocks)) {
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000244 case OutsideLoop:
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000245 break;
246 case MultiPeripheral:
Jakob Stoklund Olesenab00e9f2010-10-14 18:26:45 +0000247 // FIXME: We could split a live range with multiple uses in a peripheral
248 // block and still make progress. However, it is possible that splitting
249 // another live range will insert copies into a peripheral block, and
250 // there is a small chance we can enter an infinity loop, inserting copies
251 // forever.
252 // For safety, stick to splitting live ranges with uses outside the
253 // periphery.
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000254 DEBUG(dbgs() << ": multiple peripheral uses\n");
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000255 break;
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000256 case ContainedInLoop:
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000257 DEBUG(dbgs() << ": fully contained\n");
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000258 continue;
259 case SinglePeripheral:
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000260 DEBUG(dbgs() << ": single peripheral use\n");
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000261 continue;
262 }
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000263 // Will it be possible to split around this loop?
264 getCriticalExits(Blocks, CriticalExits);
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000265 DEBUG(dbgs() << ": " << CriticalExits.size() << " critical exits\n");
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000266 if (!canSplitCriticalExits(Blocks, CriticalExits))
267 continue;
268 // This is a possible split.
Jakob Stoklund Olesenab00e9f2010-10-14 18:26:45 +0000269 Loops.insert(Loop);
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000270 }
271
Jakob Stoklund Olesenab00e9f2010-10-14 18:26:45 +0000272 DEBUG(dbgs() << " getBestSplitLoop found " << Loops.size()
273 << " candidate loops.\n");
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000274
275 if (Loops.empty())
276 return 0;
277
278 // Pick the earliest loop.
279 // FIXME: Are there other heuristics to consider?
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000280 const MachineLoop *Best = 0;
281 SlotIndex BestIdx;
282 for (LoopPtrSet::const_iterator I = Loops.begin(), E = Loops.end(); I != E;
283 ++I) {
284 SlotIndex Idx = lis_.getMBBStartIdx((*I)->getHeader());
285 if (!Best || Idx < BestIdx)
286 Best = *I, BestIdx = Idx;
287 }
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +0000288 DEBUG(dbgs() << " getBestSplitLoop found " << *Best);
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000289 return Best;
290}
291
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000292//===----------------------------------------------------------------------===//
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000293// LiveIntervalMap
294//===----------------------------------------------------------------------===//
295
Jakob Stoklund Olesenb3e96812010-09-13 21:29:45 +0000296// Work around the fact that the std::pair constructors are broken for pointer
297// pairs in some implementations. makeVV(x, 0) works.
298static inline std::pair<const VNInfo*, VNInfo*>
299makeVV(const VNInfo *a, VNInfo *b) {
300 return std::make_pair(a, b);
301}
302
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000303void LiveIntervalMap::reset(LiveInterval *li) {
304 li_ = li;
305 valueMap_.clear();
306}
307
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000308bool LiveIntervalMap::isComplexMapped(const VNInfo *ParentVNI) const {
309 ValueMap::const_iterator i = valueMap_.find(ParentVNI);
310 return i != valueMap_.end() && i->second == 0;
311}
312
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000313// defValue - Introduce a li_ def for ParentVNI that could be later than
314// ParentVNI->def.
315VNInfo *LiveIntervalMap::defValue(const VNInfo *ParentVNI, SlotIndex Idx) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000316 assert(li_ && "call reset first");
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000317 assert(ParentVNI && "Mapping NULL value");
318 assert(Idx.isValid() && "Invalid SlotIndex");
319 assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI");
320
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000321 // Create a new value.
Lang Hames6e2968c2010-09-25 12:04:16 +0000322 VNInfo *VNI = li_->getNextValue(Idx, 0, lis_.getVNInfoAllocator());
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000323
324 // Use insert for lookup, so we can add missing values with a second lookup.
325 std::pair<ValueMap::iterator,bool> InsP =
326 valueMap_.insert(makeVV(ParentVNI, Idx == ParentVNI->def ? VNI : 0));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000327
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000328 // This is now a complex def. Mark with a NULL in valueMap.
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000329 if (!InsP.second)
330 InsP.first->second = 0;
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000331
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000332 return VNI;
333}
334
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000335
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000336// mapValue - Find the mapped value for ParentVNI at Idx.
337// Potentially create phi-def values.
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000338VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx,
339 bool *simple) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000340 assert(li_ && "call reset first");
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000341 assert(ParentVNI && "Mapping NULL value");
342 assert(Idx.isValid() && "Invalid SlotIndex");
343 assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI");
344
345 // Use insert for lookup, so we can add missing values with a second lookup.
346 std::pair<ValueMap::iterator,bool> InsP =
Jakob Stoklund Olesenb3e96812010-09-13 21:29:45 +0000347 valueMap_.insert(makeVV(ParentVNI, 0));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000348
349 // This was an unknown value. Create a simple mapping.
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000350 if (InsP.second) {
351 if (simple) *simple = true;
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000352 return InsP.first->second = li_->createValueCopy(ParentVNI,
353 lis_.getVNInfoAllocator());
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000354 }
355
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000356 // This was a simple mapped value.
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000357 if (InsP.first->second) {
358 if (simple) *simple = true;
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000359 return InsP.first->second;
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000360 }
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000361
362 // This is a complex mapped value. There may be multiple defs, and we may need
363 // to create phi-defs.
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000364 if (simple) *simple = false;
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000365 MachineBasicBlock *IdxMBB = lis_.getMBBFromIndex(Idx);
366 assert(IdxMBB && "No MBB at Idx");
367
368 // Is there a def in the same MBB we can extend?
369 if (VNInfo *VNI = extendTo(IdxMBB, Idx))
370 return VNI;
371
372 // Now for the fun part. We know that ParentVNI potentially has multiple defs,
373 // and we may need to create even more phi-defs to preserve VNInfo SSA form.
374 // Perform a depth-first search for predecessor blocks where we know the
375 // dominating VNInfo. Insert phi-def VNInfos along the path back to IdxMBB.
376
377 // Track MBBs where we have created or learned the dominating value.
378 // This may change during the DFS as we create new phi-defs.
379 typedef DenseMap<MachineBasicBlock*, VNInfo*> MBBValueMap;
380 MBBValueMap DomValue;
Jakob Stoklund Olesen984a7fc2010-10-05 20:36:28 +0000381 typedef SplitAnalysis::BlockPtrSet BlockPtrSet;
382 BlockPtrSet Visited;
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000383
Jakob Stoklund Olesen984a7fc2010-10-05 20:36:28 +0000384 // Iterate over IdxMBB predecessors in a depth-first order.
385 // Skip begin() since that is always IdxMBB.
386 for (idf_ext_iterator<MachineBasicBlock*, BlockPtrSet>
387 IDFI = llvm::next(idf_ext_begin(IdxMBB, Visited)),
388 IDFE = idf_ext_end(IdxMBB, Visited); IDFI != IDFE;) {
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000389 MachineBasicBlock *MBB = *IDFI;
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000390 SlotIndex End = lis_.getMBBEndIdx(MBB).getPrevSlot();
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000391
392 // We are operating on the restricted CFG where ParentVNI is live.
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000393 if (parentli_.getVNInfoAt(End) != ParentVNI) {
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000394 IDFI.skipChildren();
395 continue;
396 }
397
398 // Do we have a dominating value in this block?
399 VNInfo *VNI = extendTo(MBB, End);
400 if (!VNI) {
401 ++IDFI;
402 continue;
403 }
404
Jakob Stoklund Olesen984a7fc2010-10-05 20:36:28 +0000405 // Yes, VNI dominates MBB. Make sure we visit MBB again from other paths.
406 Visited.erase(MBB);
407
408 // Track the path back to IdxMBB, creating phi-defs
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000409 // as needed along the way.
410 for (unsigned PI = IDFI.getPathLength()-1; PI != 0; --PI) {
Jakob Stoklund Olesenff3ae862010-08-18 20:29:53 +0000411 // Start from MBB's immediate successor. End at IdxMBB.
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000412 MachineBasicBlock *Succ = IDFI.getPath(PI-1);
413 std::pair<MBBValueMap::iterator, bool> InsP =
414 DomValue.insert(MBBValueMap::value_type(Succ, VNI));
Jakob Stoklund Olesenff3ae862010-08-18 20:29:53 +0000415
416 // This is the first time we backtrack to Succ.
417 if (InsP.second)
418 continue;
419
420 // We reached Succ again with the same VNI. Nothing is going to change.
421 VNInfo *OVNI = InsP.first->second;
422 if (OVNI == VNI)
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000423 break;
Jakob Stoklund Olesenff3ae862010-08-18 20:29:53 +0000424
425 // Succ already has a phi-def. No need to continue.
426 SlotIndex Start = lis_.getMBBStartIdx(Succ);
427 if (OVNI->def == Start)
428 break;
429
430 // We have a collision between the old and new VNI at Succ. That means
431 // neither dominates and we need a new phi-def.
Lang Hames6e2968c2010-09-25 12:04:16 +0000432 VNI = li_->getNextValue(Start, 0, lis_.getVNInfoAllocator());
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000433 VNI->setIsPHIDef(true);
434 InsP.first->second = VNI;
Jakob Stoklund Olesenff3ae862010-08-18 20:29:53 +0000435
436 // Replace OVNI with VNI in the remaining path.
437 for (; PI > 1 ; --PI) {
438 MBBValueMap::iterator I = DomValue.find(IDFI.getPath(PI-2));
439 if (I == DomValue.end() || I->second != OVNI)
440 break;
441 I->second = VNI;
442 }
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000443 }
444
445 // No need to search the children, we found a dominating value.
Jakob Stoklund Olesencf16bea2010-08-18 20:06:05 +0000446 IDFI.skipChildren();
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000447 }
448
449 // The search should at least find a dominating value for IdxMBB.
450 assert(!DomValue.empty() && "Couldn't find a reaching definition");
451
452 // Since we went through the trouble of a full DFS visiting all reaching defs,
453 // the values in DomValue are now accurate. No more phi-defs are needed for
454 // these blocks, so we can color the live ranges.
455 // This makes the next mapValue call much faster.
456 VNInfo *IdxVNI = 0;
457 for (MBBValueMap::iterator I = DomValue.begin(), E = DomValue.end(); I != E;
458 ++I) {
459 MachineBasicBlock *MBB = I->first;
460 VNInfo *VNI = I->second;
461 SlotIndex Start = lis_.getMBBStartIdx(MBB);
462 if (MBB == IdxMBB) {
463 // Don't add full liveness to IdxMBB, stop at Idx.
464 if (Start != Idx)
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000465 li_->addRange(LiveRange(Start, Idx.getNextSlot(), VNI));
Jakob Stoklund Olesenff3ae862010-08-18 20:29:53 +0000466 // The caller had better add some liveness to IdxVNI, or it leaks.
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000467 IdxVNI = VNI;
468 } else
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000469 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000470 }
471
472 assert(IdxVNI && "Didn't find value for Idx");
473 return IdxVNI;
474}
475
476// extendTo - Find the last li_ value defined in MBB at or before Idx. The
477// parentli_ is assumed to be live at Idx. Extend the live range to Idx.
478// Return the found VNInfo, or NULL.
479VNInfo *LiveIntervalMap::extendTo(MachineBasicBlock *MBB, SlotIndex Idx) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000480 assert(li_ && "call reset first");
481 LiveInterval::iterator I = std::upper_bound(li_->begin(), li_->end(), Idx);
482 if (I == li_->begin())
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000483 return 0;
484 --I;
Jakob Stoklund Olesenfc60d772010-10-05 20:36:25 +0000485 if (I->end <= lis_.getMBBStartIdx(MBB))
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000486 return 0;
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000487 if (I->end <= Idx)
488 I->end = Idx.getNextSlot();
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000489 return I->valno;
490}
491
492// addSimpleRange - Add a simple range from parentli_ to li_.
493// ParentVNI must be live in the [Start;End) interval.
494void LiveIntervalMap::addSimpleRange(SlotIndex Start, SlotIndex End,
495 const VNInfo *ParentVNI) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000496 assert(li_ && "call reset first");
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000497 bool simple;
498 VNInfo *VNI = mapValue(ParentVNI, Start, &simple);
499 // A simple mapping is easy.
500 if (simple) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000501 li_->addRange(LiveRange(Start, End, VNI));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000502 return;
503 }
504
505 // ParentVNI is a complex value. We must map per MBB.
506 MachineFunction::iterator MBB = lis_.getMBBFromIndex(Start);
Jakob Stoklund Olesendbc36092010-10-05 22:19:29 +0000507 MachineFunction::iterator MBBE = lis_.getMBBFromIndex(End.getPrevSlot());
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000508
509 if (MBB == MBBE) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000510 li_->addRange(LiveRange(Start, End, VNI));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000511 return;
512 }
513
514 // First block.
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000515 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000516
517 // Run sequence of full blocks.
518 for (++MBB; MBB != MBBE; ++MBB) {
519 Start = lis_.getMBBStartIdx(MBB);
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000520 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB),
521 mapValue(ParentVNI, Start)));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000522 }
523
524 // Final block.
525 Start = lis_.getMBBStartIdx(MBB);
526 if (Start != End)
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000527 li_->addRange(LiveRange(Start, End, mapValue(ParentVNI, Start)));
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000528}
529
530/// addRange - Add live ranges to li_ where [Start;End) intersects parentli_.
531/// All needed values whose def is not inside [Start;End) must be defined
532/// beforehand so mapValue will work.
533void LiveIntervalMap::addRange(SlotIndex Start, SlotIndex End) {
Jakob Stoklund Olesen9ca2aeb2010-09-13 23:29:09 +0000534 assert(li_ && "call reset first");
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000535 LiveInterval::const_iterator B = parentli_.begin(), E = parentli_.end();
536 LiveInterval::const_iterator I = std::lower_bound(B, E, Start);
537
538 // Check if --I begins before Start and overlaps.
539 if (I != B) {
540 --I;
541 if (I->end > Start)
542 addSimpleRange(Start, std::min(End, I->end), I->valno);
543 ++I;
544 }
545
546 // The remaining ranges begin after Start.
547 for (;I != E && I->start < End; ++I)
548 addSimpleRange(I->start, std::min(End, I->end), I->valno);
549}
550
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000551VNInfo *LiveIntervalMap::defByCopyFrom(unsigned Reg,
552 const VNInfo *ParentVNI,
553 MachineBasicBlock &MBB,
554 MachineBasicBlock::iterator I) {
555 const TargetInstrDesc &TID = MBB.getParent()->getTarget().getInstrInfo()->
556 get(TargetOpcode::COPY);
557 MachineInstr *MI = BuildMI(MBB, I, DebugLoc(), TID, li_->reg).addReg(Reg);
558 SlotIndex DefIdx = lis_.InsertMachineInstrInMaps(MI).getDefIndex();
559 VNInfo *VNI = defValue(ParentVNI, DefIdx);
560 VNI->setCopy(MI);
561 li_->addRange(LiveRange(DefIdx, DefIdx.getNextSlot(), VNI));
562 return VNI;
563}
564
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000565//===----------------------------------------------------------------------===//
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000566// Split Editor
567//===----------------------------------------------------------------------===//
568
569/// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000570SplitEditor::SplitEditor(SplitAnalysis &sa, LiveIntervals &lis, VirtRegMap &vrm,
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000571 LiveRangeEdit &edit)
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000572 : sa_(sa), lis_(lis), vrm_(vrm),
573 mri_(vrm.getMachineFunction().getRegInfo()),
574 tii_(*vrm.getMachineFunction().getTarget().getInstrInfo()),
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000575 edit_(edit),
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000576 dupli_(lis_, edit.getParent()),
577 openli_(lis_, edit.getParent())
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000578{
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000579}
580
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000581bool SplitEditor::intervalsLiveAt(SlotIndex Idx) const {
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000582 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E; ++I)
583 if (*I != dupli_.getLI() && (*I)->liveAt(Idx))
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000584 return true;
585 return false;
586}
587
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000588/// Create a new virtual register and live interval.
589void SplitEditor::openIntv() {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000590 assert(!openli_.getLI() && "Previous LI not closed before openIntv");
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000591
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000592 if (!dupli_.getLI())
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000593 dupli_.reset(&edit_.create(mri_, lis_, vrm_));
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000594
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000595 openli_.reset(&edit_.create(mri_, lis_, vrm_));
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000596}
597
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000598/// enterIntvBefore - Enter openli before the instruction at Idx. If curli is
599/// not live before Idx, a COPY is not inserted.
600void SplitEditor::enterIntvBefore(SlotIndex Idx) {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000601 assert(openli_.getLI() && "openIntv not called before enterIntvBefore");
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000602 DEBUG(dbgs() << " enterIntvBefore " << Idx);
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000603 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(Idx.getUseIndex());
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000604 if (!ParentVNI) {
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000605 DEBUG(dbgs() << ": not live\n");
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000606 return;
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000607 }
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000608 DEBUG(dbgs() << ": valno " << ParentVNI->id);
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000609 truncatedValues.insert(ParentVNI);
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000610 MachineInstr *MI = lis_.getInstructionFromIndex(Idx);
611 assert(MI && "enterIntvBefore called with invalid index");
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000612 VNInfo *VNI = openli_.defByCopyFrom(edit_.getReg(), ParentVNI,
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000613 *MI->getParent(), MI);
614 openli_.getLI()->addRange(LiveRange(VNI->def, Idx.getDefIndex(), VNI));
615 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000616}
617
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000618/// enterIntvAtEnd - Enter openli at the end of MBB.
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000619void SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000620 assert(openli_.getLI() && "openIntv not called before enterIntvAtEnd");
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000621 SlotIndex End = lis_.getMBBEndIdx(&MBB);
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000622 DEBUG(dbgs() << " enterIntvAtEnd BB#" << MBB.getNumber() << ", " << End);
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000623 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(End.getPrevSlot());
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000624 if (!ParentVNI) {
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000625 DEBUG(dbgs() << ": not live\n");
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000626 return;
627 }
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000628 DEBUG(dbgs() << ": valno " << ParentVNI->id);
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000629 truncatedValues.insert(ParentVNI);
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000630 VNInfo *VNI = openli_.defByCopyFrom(edit_.getReg(), ParentVNI,
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000631 MBB, MBB.getFirstTerminator());
632 // Make sure openli is live out of MBB.
633 openli_.getLI()->addRange(LiveRange(VNI->def, End, VNI));
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000634 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000635}
636
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000637/// useIntv - indicate that all instructions in MBB should use openli.
638void SplitEditor::useIntv(const MachineBasicBlock &MBB) {
639 useIntv(lis_.getMBBStartIdx(&MBB), lis_.getMBBEndIdx(&MBB));
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000640}
641
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000642void SplitEditor::useIntv(SlotIndex Start, SlotIndex End) {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000643 assert(openli_.getLI() && "openIntv not called before useIntv");
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000644 openli_.addRange(Start, End);
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000645 DEBUG(dbgs() << " use [" << Start << ';' << End << "): "
646 << *openli_.getLI() << '\n');
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000647}
648
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000649/// leaveIntvAfter - Leave openli after the instruction at Idx.
650void SplitEditor::leaveIntvAfter(SlotIndex Idx) {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000651 assert(openli_.getLI() && "openIntv not called before leaveIntvAfter");
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000652 DEBUG(dbgs() << " leaveIntvAfter " << Idx);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000653
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000654 // The interval must be live beyond the instruction at Idx.
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000655 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(Idx.getBoundaryIndex());
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000656 if (!ParentVNI) {
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000657 DEBUG(dbgs() << ": not live\n");
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000658 return;
659 }
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000660 DEBUG(dbgs() << ": valno " << ParentVNI->id);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000661
Jakob Stoklund Olesenfc60d772010-10-05 20:36:25 +0000662 MachineBasicBlock::iterator MII = lis_.getInstructionFromIndex(Idx);
663 MachineBasicBlock *MBB = MII->getParent();
664 VNInfo *VNI = dupli_.defByCopyFrom(openli_.getLI()->reg, ParentVNI, *MBB,
665 llvm::next(MII));
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000666
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000667 // Finally we must make sure that openli is properly extended from Idx to the
668 // new copy.
Jakob Stoklund Olesenfc60d772010-10-05 20:36:25 +0000669 openli_.addSimpleRange(Idx.getBoundaryIndex(), VNI->def, ParentVNI);
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000670 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000671}
672
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000673/// leaveIntvAtTop - Leave the interval at the top of MBB.
674/// Currently, only one value can leave the interval.
675void SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000676 assert(openli_.getLI() && "openIntv not called before leaveIntvAtTop");
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000677 SlotIndex Start = lis_.getMBBStartIdx(&MBB);
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000678 DEBUG(dbgs() << " leaveIntvAtTop BB#" << MBB.getNumber() << ", " << Start);
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000679
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000680 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(Start);
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000681 if (!ParentVNI) {
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000682 DEBUG(dbgs() << ": not live\n");
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000683 return;
684 }
685
Jakob Stoklund Olesen5eb308b2010-08-06 22:17:33 +0000686 // We are going to insert a back copy, so we must have a dupli_.
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000687 VNInfo *VNI = dupli_.defByCopyFrom(openli_.getLI()->reg, ParentVNI,
688 MBB, MBB.begin());
Jakob Stoklund Olesen5eb308b2010-08-06 22:17:33 +0000689
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000690 // Finally we must make sure that openli is properly extended from Start to
691 // the new copy.
Jakob Stoklund Olesenfc60d772010-10-05 20:36:25 +0000692 openli_.addSimpleRange(Start, VNI->def, ParentVNI);
Jakob Stoklund Olesen9b24afe2010-10-07 17:56:35 +0000693 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000694}
695
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000696/// closeIntv - Indicate that we are done editing the currently open
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000697/// LiveInterval, and ranges can be trimmed.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000698void SplitEditor::closeIntv() {
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000699 assert(openli_.getLI() && "openIntv not called before closeIntv");
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000700
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +0000701 DEBUG(dbgs() << " closeIntv cleaning up\n");
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000702 DEBUG(dbgs() << " open " << *openli_.getLI() << '\n');
Jakob Stoklund Olesendd9f3fd2010-09-13 23:29:11 +0000703 openli_.reset(0);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000704}
705
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000706/// rewrite - Rewrite all uses of reg to use the new registers.
707void SplitEditor::rewrite(unsigned reg) {
708 for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin(reg),
709 RE = mri_.reg_end(); RI != RE;) {
710 MachineOperand &MO = RI.getOperand();
711 MachineInstr *MI = MO.getParent();
712 ++RI;
713 if (MI->isDebugValue()) {
714 DEBUG(dbgs() << "Zapping " << *MI);
715 // FIXME: We can do much better with debug values.
716 MO.setReg(0);
717 continue;
718 }
719 SlotIndex Idx = lis_.getInstructionIndex(MI);
720 Idx = MO.isUse() ? Idx.getUseIndex() : Idx.getDefIndex();
721 LiveInterval *LI = 0;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000722 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E;
723 ++I) {
724 LiveInterval *testli = *I;
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000725 if (testli->liveAt(Idx)) {
726 LI = testli;
727 break;
728 }
729 }
Jakob Stoklund Olesen9d999772010-10-21 18:47:08 +0000730 DEBUG(dbgs() << " rewr BB#" << MI->getParent()->getNumber() << '\t'<< Idx);
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000731 assert(LI && "No register was live at use");
732 MO.setReg(LI->reg);
Jakob Stoklund Olesen9d999772010-10-21 18:47:08 +0000733 DEBUG(dbgs() << '\t' << *MI);
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000734 }
735}
736
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000737void
738SplitEditor::addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000739 // Build vector of iterator pairs from the intervals.
740 typedef std::pair<LiveInterval::const_iterator,
741 LiveInterval::const_iterator> IIPair;
742 SmallVector<IIPair, 8> Iters;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000743 for (LiveRangeEdit::iterator LI = edit_.begin(), LE = edit_.end(); LI != LE;
744 ++LI) {
Jakob Stoklund Olesen9d999772010-10-21 18:47:08 +0000745 if (*LI == dupli_.getLI())
746 continue;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000747 LiveInterval::const_iterator I = (*LI)->find(Start);
748 LiveInterval::const_iterator E = (*LI)->end();
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000749 if (I != E)
750 Iters.push_back(std::make_pair(I, E));
751 }
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000752
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000753 SlotIndex sidx = Start;
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000754 // Break [Start;End) into segments that don't overlap any intervals.
755 for (;;) {
756 SlotIndex next = sidx, eidx = End;
757 // Find overlapping intervals.
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000758 for (unsigned i = 0; i != Iters.size() && sidx < eidx; ++i) {
759 LiveInterval::const_iterator I = Iters[i].first;
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000760 // Interval I is overlapping [sidx;eidx). Trim sidx.
761 if (I->start <= sidx) {
762 sidx = I->end;
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000763 // Move to the next run, remove iters when all are consumed.
764 I = ++Iters[i].first;
765 if (I == Iters[i].second) {
766 Iters.erase(Iters.begin() + i);
767 --i;
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000768 continue;
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000769 }
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000770 }
771 // Trim eidx too if needed.
772 if (I->start >= eidx)
773 continue;
774 eidx = I->start;
Jakob Stoklund Olesen4b3041c2010-10-07 17:56:39 +0000775 next = I->end;
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000776 }
777 // Now, [sidx;eidx) doesn't overlap anything in intervals_.
778 if (sidx < eidx)
779 dupli_.addSimpleRange(sidx, eidx, VNI);
780 // If the interval end was truncated, we can try again from next.
781 if (next <= sidx)
782 break;
783 sidx = next;
784 }
785}
786
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000787void SplitEditor::computeRemainder() {
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000788 // First we need to fill in the live ranges in dupli.
789 // If values were redefined, we need a full recoloring with SSA update.
790 // If values were truncated, we only need to truncate the ranges.
791 // If values were partially rematted, we should shrink to uses.
792 // If values were fully rematted, they should be omitted.
793 // FIXME: If a single value is redefined, just move the def and truncate.
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000794 LiveInterval &parent = edit_.getParent();
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000795
796 // Values that are fully contained in the split intervals.
797 SmallPtrSet<const VNInfo*, 8> deadValues;
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000798 // Map all curli values that should have live defs in dupli.
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000799 for (LiveInterval::const_vni_iterator I = parent.vni_begin(),
800 E = parent.vni_end(); I != E; ++I) {
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000801 const VNInfo *VNI = *I;
802 // Original def is contained in the split intervals.
803 if (intervalsLiveAt(VNI->def)) {
804 // Did this value escape?
805 if (dupli_.isMapped(VNI))
806 truncatedValues.insert(VNI);
807 else
808 deadValues.insert(VNI);
809 continue;
810 }
811 // Add minimal live range at the definition.
812 VNInfo *DVNI = dupli_.defValue(VNI, VNI->def);
813 dupli_.getLI()->addRange(LiveRange(VNI->def, VNI->def.getNextSlot(), DVNI));
814 }
815
816 // Add all ranges to dupli.
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000817 for (LiveInterval::const_iterator I = parent.begin(), E = parent.end();
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000818 I != E; ++I) {
819 const LiveRange &LR = *I;
820 if (truncatedValues.count(LR.valno)) {
821 // recolor after removing intervals_.
822 addTruncSimpleRange(LR.start, LR.end, LR.valno);
823 } else if (!deadValues.count(LR.valno)) {
824 // recolor without truncation.
825 dupli_.addSimpleRange(LR.start, LR.end, LR.valno);
826 }
827 }
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000828}
829
830void SplitEditor::finish() {
831 assert(!openli_.getLI() && "Previous LI not closed before rewrite");
832 assert(dupli_.getLI() && "No dupli for rewrite. Noop spilt?");
833
834 // Complete dupli liveness.
835 computeRemainder();
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000836
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000837 // Get rid of unused values and set phi-kill flags.
838 dupli_.getLI()->RenumberValues(lis_);
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000839
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000840 // Now check if dupli was separated into multiple connected components.
841 ConnectedVNInfoEqClasses ConEQ(lis_);
842 if (unsigned NumComp = ConEQ.Classify(dupli_.getLI())) {
843 DEBUG(dbgs() << " Remainder has " << NumComp << " connected components: "
844 << *dupli_.getLI() << '\n');
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000845 // Did the remainder break up? Create intervals for all the components.
846 if (NumComp > 1) {
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000847 SmallVector<LiveInterval*, 8> dups;
848 dups.push_back(dupli_.getLI());
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000849 for (unsigned i = 1; i != NumComp; ++i)
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000850 dups.push_back(&edit_.create(mri_, lis_, vrm_));
851 ConEQ.Distribute(&dups[0]);
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000852 // Rewrite uses to the new regs.
853 rewrite(dupli_.getLI()->reg);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000854 }
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000855 }
856
857 // Rewrite instructions.
Jakob Stoklund Olesen9d5d48b2010-10-15 00:34:01 +0000858 rewrite(edit_.getReg());
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000859
Jakob Stoklund Olesen08e93b12010-08-10 17:07:22 +0000860 // Calculate spill weight and allocation hints for new intervals.
861 VirtRegAuxInfo vrai(vrm_.getMachineFunction(), lis_, sa_.loops_);
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000862 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E; ++I){
863 LiveInterval &li = **I;
Jakob Stoklund Olesen9db3ea42010-08-10 18:37:40 +0000864 vrai.CalculateRegClass(li.reg);
Jakob Stoklund Olesen08e93b12010-08-10 17:07:22 +0000865 vrai.CalculateWeightAndHint(li);
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +0000866 DEBUG(dbgs() << " new interval " << mri_.getRegClass(li.reg)->getName()
867 << ":" << li << '\n');
Jakob Stoklund Olesen08e93b12010-08-10 17:07:22 +0000868 }
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000869}
870
871
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000872//===----------------------------------------------------------------------===//
873// Loop Splitting
874//===----------------------------------------------------------------------===//
875
Jakob Stoklund Olesen57d0f2d2010-10-05 22:19:33 +0000876void SplitEditor::splitAroundLoop(const MachineLoop *Loop) {
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000877 SplitAnalysis::LoopBlocks Blocks;
878 sa_.getLoopBlocks(Loop, Blocks);
879
Jakob Stoklund Olesen452a9fd2010-10-07 18:47:07 +0000880 DEBUG({
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +0000881 dbgs() << " splitAround"; sa_.print(Blocks, dbgs()); dbgs() << '\n';
Jakob Stoklund Olesen452a9fd2010-10-07 18:47:07 +0000882 });
883
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000884 // Break critical edges as needed.
885 SplitAnalysis::BlockPtrSet CriticalExits;
886 sa_.getCriticalExits(Blocks, CriticalExits);
887 assert(CriticalExits.empty() && "Cannot break critical exits yet");
888
889 // Create new live interval for the loop.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000890 openIntv();
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000891
892 // Insert copies in the predecessors.
893 for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Preds.begin(),
894 E = Blocks.Preds.end(); I != E; ++I) {
895 MachineBasicBlock &MBB = const_cast<MachineBasicBlock&>(**I);
Jakob Stoklund Olesenf6a129a2010-09-16 00:01:36 +0000896 enterIntvAtEnd(MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000897 }
898
899 // Switch all loop blocks.
900 for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Loop.begin(),
901 E = Blocks.Loop.end(); I != E; ++I)
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000902 useIntv(**I);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000903
904 // Insert back copies in the exit blocks.
905 for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Exits.begin(),
906 E = Blocks.Exits.end(); I != E; ++I) {
907 MachineBasicBlock &MBB = const_cast<MachineBasicBlock&>(**I);
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000908 leaveIntvAtTop(MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000909 }
910
911 // Done.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000912 closeIntv();
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000913 finish();
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000914}
915
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000916
917//===----------------------------------------------------------------------===//
918// Single Block Splitting
919//===----------------------------------------------------------------------===//
920
Jakob Stoklund Olesen2bfb3242010-10-22 22:48:56 +0000921/// getMultiUseBlocks - if curli has more than one use in a basic block, it
922/// may be an advantage to split curli for the duration of the block.
923bool SplitAnalysis::getMultiUseBlocks(BlockPtrSet &Blocks) {
924 // If curli is local to one block, there is no point to splitting it.
925 if (usingBlocks_.size() <= 1)
926 return false;
927 // Add blocks with multiple uses.
928 for (BlockCountMap::iterator I = usingBlocks_.begin(), E = usingBlocks_.end();
929 I != E; ++I)
930 switch (I->second) {
931 case 0:
932 case 1:
933 continue;
934 case 2: {
935 // When there are only two uses and curli is both live in and live out,
936 // we don't really win anything by isolating the block since we would be
937 // inserting two copies.
938 // The remaing register would still have two uses in the block. (Unless it
939 // separates into disconnected components).
940 if (lis_.isLiveInToMBB(*curli_, I->first) &&
941 lis_.isLiveOutOfMBB(*curli_, I->first))
942 continue;
943 } // Fall through.
944 default:
945 Blocks.insert(I->first);
946 }
947 return !Blocks.empty();
948}
949
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000950/// splitSingleBlocks - Split curli into a separate live interval inside each
Jakob Stoklund Olesen57d0f2d2010-10-05 22:19:33 +0000951/// basic block in Blocks.
952void SplitEditor::splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks) {
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +0000953 DEBUG(dbgs() << " splitSingleBlocks for " << Blocks.size() << " blocks.\n");
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000954 // Determine the first and last instruction using curli in each block.
955 typedef std::pair<SlotIndex,SlotIndex> IndexPair;
956 typedef DenseMap<const MachineBasicBlock*,IndexPair> IndexPairMap;
957 IndexPairMap MBBRange;
958 for (SplitAnalysis::InstrPtrSet::const_iterator I = sa_.usingInstrs_.begin(),
959 E = sa_.usingInstrs_.end(); I != E; ++I) {
960 const MachineBasicBlock *MBB = (*I)->getParent();
961 if (!Blocks.count(MBB))
962 continue;
963 SlotIndex Idx = lis_.getInstructionIndex(*I);
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +0000964 DEBUG(dbgs() << " BB#" << MBB->getNumber() << '\t' << Idx << '\t' << **I);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000965 IndexPair &IP = MBBRange[MBB];
966 if (!IP.first.isValid() || Idx < IP.first)
967 IP.first = Idx;
968 if (!IP.second.isValid() || Idx > IP.second)
969 IP.second = Idx;
970 }
971
972 // Create a new interval for each block.
973 for (SplitAnalysis::BlockPtrSet::const_iterator I = Blocks.begin(),
974 E = Blocks.end(); I != E; ++I) {
975 IndexPair &IP = MBBRange[*I];
Jakob Stoklund Olesene1f543f2010-08-12 18:50:55 +0000976 DEBUG(dbgs() << " splitting for BB#" << (*I)->getNumber() << ": ["
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000977 << IP.first << ';' << IP.second << ")\n");
978 assert(IP.first.isValid() && IP.second.isValid());
979
980 openIntv();
981 enterIntvBefore(IP.first);
982 useIntv(IP.first.getBaseIndex(), IP.second.getBoundaryIndex());
983 leaveIntvAfter(IP.second);
984 closeIntv();
985 }
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000986 finish();
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000987}
988
Jakob Stoklund Olesenfc412d82010-08-13 21:18:48 +0000989
990//===----------------------------------------------------------------------===//
991// Sub Block Splitting
992//===----------------------------------------------------------------------===//
993
994/// getBlockForInsideSplit - If curli is contained inside a single basic block,
995/// and it wou pay to subdivide the interval inside that block, return it.
996/// Otherwise return NULL. The returned block can be passed to
997/// SplitEditor::splitInsideBlock.
998const MachineBasicBlock *SplitAnalysis::getBlockForInsideSplit() {
999 // The interval must be exclusive to one block.
1000 if (usingBlocks_.size() != 1)
1001 return 0;
1002 // Don't to this for less than 4 instructions. We want to be sure that
1003 // splitting actually reduces the instruction count per interval.
1004 if (usingInstrs_.size() < 4)
1005 return 0;
1006 return usingBlocks_.begin()->first;
1007}
1008
Jakob Stoklund Olesen57d0f2d2010-10-05 22:19:33 +00001009/// splitInsideBlock - Split curli into multiple intervals inside MBB.
1010void SplitEditor::splitInsideBlock(const MachineBasicBlock *MBB) {
Jakob Stoklund Olesenfc412d82010-08-13 21:18:48 +00001011 SmallVector<SlotIndex, 32> Uses;
1012 Uses.reserve(sa_.usingInstrs_.size());
1013 for (SplitAnalysis::InstrPtrSet::const_iterator I = sa_.usingInstrs_.begin(),
1014 E = sa_.usingInstrs_.end(); I != E; ++I)
1015 if ((*I)->getParent() == MBB)
1016 Uses.push_back(lis_.getInstructionIndex(*I));
1017 DEBUG(dbgs() << " splitInsideBlock BB#" << MBB->getNumber() << " for "
1018 << Uses.size() << " instructions.\n");
1019 assert(Uses.size() >= 3 && "Need at least 3 instructions");
1020 array_pod_sort(Uses.begin(), Uses.end());
1021
1022 // Simple algorithm: Find the largest gap between uses as determined by slot
1023 // indices. Create new intervals for instructions before the gap and after the
1024 // gap.
1025 unsigned bestPos = 0;
1026 int bestGap = 0;
1027 DEBUG(dbgs() << " dist (" << Uses[0]);
1028 for (unsigned i = 1, e = Uses.size(); i != e; ++i) {
1029 int g = Uses[i-1].distance(Uses[i]);
1030 DEBUG(dbgs() << ") -" << g << "- (" << Uses[i]);
1031 if (g > bestGap)
1032 bestPos = i, bestGap = g;
1033 }
1034 DEBUG(dbgs() << "), best: -" << bestGap << "-\n");
1035
1036 // bestPos points to the first use after the best gap.
1037 assert(bestPos > 0 && "Invalid gap");
1038
1039 // FIXME: Don't create intervals for low densities.
1040
1041 // First interval before the gap. Don't create single-instr intervals.
1042 if (bestPos > 1) {
1043 openIntv();
1044 enterIntvBefore(Uses.front());
1045 useIntv(Uses.front().getBaseIndex(), Uses[bestPos-1].getBoundaryIndex());
1046 leaveIntvAfter(Uses[bestPos-1]);
1047 closeIntv();
1048 }
1049
1050 // Second interval after the gap.
1051 if (bestPos < Uses.size()-1) {
1052 openIntv();
1053 enterIntvBefore(Uses[bestPos]);
1054 useIntv(Uses[bestPos].getBaseIndex(), Uses.back().getBoundaryIndex());
1055 leaveIntvAfter(Uses.back());
1056 closeIntv();
1057 }
1058
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +00001059 finish();
Jakob Stoklund Olesenfc412d82010-08-13 21:18:48 +00001060}