1 //===---------- SplitKit.cpp - Toolkit for splitting live ranges ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the SplitAnalysis class as well as mutator functions for
11 // live range splitting.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "regalloc"
17 #include "LiveRangeEdit.h"
18 #include "VirtRegMap.h"
19 #include "llvm/CodeGen/CalcSpillWeights.h"
20 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
21 #include "llvm/CodeGen/MachineDominators.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineLoopInfo.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/Support/CommandLine.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/raw_ostream.h"
28 #include "llvm/Target/TargetInstrInfo.h"
29 #include "llvm/Target/TargetMachine.h"
34 AllowSplit("spiller-splits-edges",
35 cl::desc("Allow critical edge splitting during spilling"));
37 //===----------------------------------------------------------------------===//
39 //===----------------------------------------------------------------------===//
41 SplitAnalysis::SplitAnalysis(const MachineFunction &mf,
42 const LiveIntervals &lis,
43 const MachineLoopInfo &mli)
47 tii_(*mf.getTarget().getInstrInfo()),
50 void SplitAnalysis::clear() {
58 bool SplitAnalysis::canAnalyzeBranch(const MachineBasicBlock *MBB) {
59 MachineBasicBlock *T, *F;
60 SmallVector<MachineOperand, 4> Cond;
61 return !tii_.AnalyzeBranch(const_cast<MachineBasicBlock&>(*MBB), T, F, Cond);
64 /// analyzeUses - Count instructions, basic blocks, and loops using curli.
65 void SplitAnalysis::analyzeUses() {
66 const MachineRegisterInfo &MRI = mf_.getRegInfo();
67 for (MachineRegisterInfo::reg_iterator I = MRI.reg_begin(curli_->reg);
68 MachineInstr *MI = I.skipInstruction();) {
69 if (MI->isDebugValue() || !usingInstrs_.insert(MI))
71 UseSlots.push_back(lis_.getInstructionIndex(MI).getDefIndex());
72 MachineBasicBlock *MBB = MI->getParent();
73 if (usingBlocks_[MBB]++)
75 for (MachineLoop *Loop = loops_.getLoopFor(MBB); Loop;
76 Loop = Loop->getParentLoop())
79 array_pod_sort(UseSlots.begin(), UseSlots.end());
80 DEBUG(dbgs() << " counted "
81 << usingInstrs_.size() << " instrs, "
82 << usingBlocks_.size() << " blocks, "
83 << usingLoops_.size() << " loops.\n");
86 void SplitAnalysis::print(const BlockPtrSet &B, raw_ostream &OS) const {
87 for (BlockPtrSet::const_iterator I = B.begin(), E = B.end(); I != E; ++I) {
88 unsigned count = usingBlocks_.lookup(*I);
89 OS << " BB#" << (*I)->getNumber();
91 OS << '(' << count << ')';
95 // Get three sets of basic blocks surrounding a loop: Blocks inside the loop,
96 // predecessor blocks, and exit blocks.
97 void SplitAnalysis::getLoopBlocks(const MachineLoop *Loop, LoopBlocks &Blocks) {
100 // Blocks in the loop.
101 Blocks.Loop.insert(Loop->block_begin(), Loop->block_end());
103 // Predecessor blocks.
104 const MachineBasicBlock *Header = Loop->getHeader();
105 for (MachineBasicBlock::const_pred_iterator I = Header->pred_begin(),
106 E = Header->pred_end(); I != E; ++I)
107 if (!Blocks.Loop.count(*I))
108 Blocks.Preds.insert(*I);
111 for (MachineLoop::block_iterator I = Loop->block_begin(),
112 E = Loop->block_end(); I != E; ++I) {
113 const MachineBasicBlock *MBB = *I;
114 for (MachineBasicBlock::const_succ_iterator SI = MBB->succ_begin(),
115 SE = MBB->succ_end(); SI != SE; ++SI)
116 if (!Blocks.Loop.count(*SI))
117 Blocks.Exits.insert(*SI);
121 void SplitAnalysis::print(const LoopBlocks &B, raw_ostream &OS) const {
130 /// analyzeLoopPeripheralUse - Return an enum describing how curli_ is used in
131 /// and around the Loop.
132 SplitAnalysis::LoopPeripheralUse SplitAnalysis::
133 analyzeLoopPeripheralUse(const SplitAnalysis::LoopBlocks &Blocks) {
134 LoopPeripheralUse use = ContainedInLoop;
135 for (BlockCountMap::iterator I = usingBlocks_.begin(), E = usingBlocks_.end();
137 const MachineBasicBlock *MBB = I->first;
138 // Is this a peripheral block?
139 if (use < MultiPeripheral &&
140 (Blocks.Preds.count(MBB) || Blocks.Exits.count(MBB))) {
141 if (I->second > 1) use = MultiPeripheral;
142 else use = SinglePeripheral;
145 // Is it a loop block?
146 if (Blocks.Loop.count(MBB))
148 // It must be an unrelated block.
149 DEBUG(dbgs() << ", outside: BB#" << MBB->getNumber());
155 /// getCriticalExits - It may be necessary to partially break critical edges
156 /// leaving the loop if an exit block has predecessors from outside the loop
158 void SplitAnalysis::getCriticalExits(const SplitAnalysis::LoopBlocks &Blocks,
159 BlockPtrSet &CriticalExits) {
160 CriticalExits.clear();
162 // A critical exit block has curli live-in, and has a predecessor that is not
163 // in the loop nor a loop predecessor. For such an exit block, the edges
164 // carrying the new variable must be moved to a new pre-exit block.
165 for (BlockPtrSet::iterator I = Blocks.Exits.begin(), E = Blocks.Exits.end();
167 const MachineBasicBlock *Exit = *I;
168 // A single-predecessor exit block is definitely not a critical edge.
169 if (Exit->pred_size() == 1)
171 // This exit may not have curli live in at all. No need to split.
172 if (!lis_.isLiveInToMBB(*curli_, Exit))
174 // Does this exit block have a predecessor that is not a loop block or loop
176 for (MachineBasicBlock::const_pred_iterator PI = Exit->pred_begin(),
177 PE = Exit->pred_end(); PI != PE; ++PI) {
178 const MachineBasicBlock *Pred = *PI;
179 if (Blocks.Loop.count(Pred) || Blocks.Preds.count(Pred))
181 // This is a critical exit block, and we need to split the exit edge.
182 CriticalExits.insert(Exit);
188 void SplitAnalysis::getCriticalPreds(const SplitAnalysis::LoopBlocks &Blocks,
189 BlockPtrSet &CriticalPreds) {
190 CriticalPreds.clear();
192 // A critical predecessor block has curli live-out, and has a successor that
193 // has curli live-in and is not in the loop nor a loop exit block. For such a
194 // predecessor block, we must carry the value in both the 'inside' and
195 // 'outside' registers.
196 for (BlockPtrSet::iterator I = Blocks.Preds.begin(), E = Blocks.Preds.end();
198 const MachineBasicBlock *Pred = *I;
199 // Definitely not a critical edge.
200 if (Pred->succ_size() == 1)
202 // This block may not have curli live out at all if there is a PHI.
203 if (!lis_.isLiveOutOfMBB(*curli_, Pred))
205 // Does this block have a successor outside the loop?
206 for (MachineBasicBlock::const_pred_iterator SI = Pred->succ_begin(),
207 SE = Pred->succ_end(); SI != SE; ++SI) {
208 const MachineBasicBlock *Succ = *SI;
209 if (Blocks.Loop.count(Succ) || Blocks.Exits.count(Succ))
211 if (!lis_.isLiveInToMBB(*curli_, Succ))
213 // This is a critical predecessor block.
214 CriticalPreds.insert(Pred);
220 /// canSplitCriticalExits - Return true if it is possible to insert new exit
221 /// blocks before the blocks in CriticalExits.
223 SplitAnalysis::canSplitCriticalExits(const SplitAnalysis::LoopBlocks &Blocks,
224 BlockPtrSet &CriticalExits) {
225 // If we don't allow critical edge splitting, require no critical exits.
227 return CriticalExits.empty();
229 for (BlockPtrSet::iterator I = CriticalExits.begin(), E = CriticalExits.end();
231 const MachineBasicBlock *Succ = *I;
232 // We want to insert a new pre-exit MBB before Succ, and change all the
233 // in-loop blocks to branch to the pre-exit instead of Succ.
234 // Check that all the in-loop predecessors can be changed.
235 for (MachineBasicBlock::const_pred_iterator PI = Succ->pred_begin(),
236 PE = Succ->pred_end(); PI != PE; ++PI) {
237 const MachineBasicBlock *Pred = *PI;
238 // The external predecessors won't be altered.
239 if (!Blocks.Loop.count(Pred) && !Blocks.Preds.count(Pred))
241 if (!canAnalyzeBranch(Pred))
245 // If Succ's layout predecessor falls through, that too must be analyzable.
246 // We need to insert the pre-exit block in the gap.
247 MachineFunction::const_iterator MFI = Succ;
248 if (MFI == mf_.begin())
250 if (!canAnalyzeBranch(--MFI))
253 // No problems found.
257 void SplitAnalysis::analyze(const LiveInterval *li) {
263 void SplitAnalysis::getSplitLoops(LoopPtrSet &Loops) {
264 assert(curli_ && "Call analyze() before getSplitLoops");
265 if (usingLoops_.empty())
269 BlockPtrSet CriticalExits;
271 // We split around loops where curli is used outside the periphery.
272 for (LoopCountMap::const_iterator I = usingLoops_.begin(),
273 E = usingLoops_.end(); I != E; ++I) {
274 const MachineLoop *Loop = I->first;
275 getLoopBlocks(Loop, Blocks);
276 DEBUG({ dbgs() << " "; print(Blocks, dbgs()); });
278 switch(analyzeLoopPeripheralUse(Blocks)) {
281 case MultiPeripheral:
282 // FIXME: We could split a live range with multiple uses in a peripheral
283 // block and still make progress. However, it is possible that splitting
284 // another live range will insert copies into a peripheral block, and
285 // there is a small chance we can enter an infinite loop, inserting copies
287 // For safety, stick to splitting live ranges with uses outside the
289 DEBUG(dbgs() << ": multiple peripheral uses");
291 case ContainedInLoop:
292 DEBUG(dbgs() << ": fully contained\n");
294 case SinglePeripheral:
295 DEBUG(dbgs() << ": single peripheral use\n");
298 // Will it be possible to split around this loop?
299 getCriticalExits(Blocks, CriticalExits);
300 DEBUG(dbgs() << ": " << CriticalExits.size() << " critical exits\n");
301 if (!canSplitCriticalExits(Blocks, CriticalExits))
303 // This is a possible split.
307 DEBUG(dbgs() << " getSplitLoops found " << Loops.size()
308 << " candidate loops.\n");
311 const MachineLoop *SplitAnalysis::getBestSplitLoop() {
313 getSplitLoops(Loops);
317 // Pick the earliest loop.
318 // FIXME: Are there other heuristics to consider?
319 const MachineLoop *Best = 0;
321 for (LoopPtrSet::const_iterator I = Loops.begin(), E = Loops.end(); I != E;
323 SlotIndex Idx = lis_.getMBBStartIdx((*I)->getHeader());
324 if (!Best || Idx < BestIdx)
325 Best = *I, BestIdx = Idx;
327 DEBUG(dbgs() << " getBestSplitLoop found " << *Best);
331 /// isBypassLoop - Return true if curli is live through Loop and has no uses
332 /// inside the loop. Bypass loops are candidates for splitting because it can
333 /// prevent interference inside the loop.
334 bool SplitAnalysis::isBypassLoop(const MachineLoop *Loop) {
335 // If curli is live into the loop header and there are no uses in the loop, it
336 // must be live in the entire loop and live on at least one exiting edge.
337 return !usingLoops_.count(Loop) &&
338 lis_.isLiveInToMBB(*curli_, Loop->getHeader());
341 /// getBypassLoops - Get all the maximal bypass loops. These are the bypass
342 /// loops whose parent is not a bypass loop.
343 void SplitAnalysis::getBypassLoops(LoopPtrSet &BypassLoops) {
344 SmallVector<MachineLoop*, 8> Todo(loops_.begin(), loops_.end());
345 while (!Todo.empty()) {
346 MachineLoop *Loop = Todo.pop_back_val();
347 if (!usingLoops_.count(Loop)) {
348 // This is either a bypass loop or completely irrelevant.
349 if (lis_.isLiveInToMBB(*curli_, Loop->getHeader()))
350 BypassLoops.insert(Loop);
351 // Either way, skip the child loops.
355 // The child loops may be bypass loops.
356 Todo.append(Loop->begin(), Loop->end());
361 //===----------------------------------------------------------------------===//
363 //===----------------------------------------------------------------------===//
365 // Work around the fact that the std::pair constructors are broken for pointer
366 // pairs in some implementations. makeVV(x, 0) works.
367 static inline std::pair<const VNInfo*, VNInfo*>
368 makeVV(const VNInfo *a, VNInfo *b) {
369 return std::make_pair(a, b);
372 void LiveIntervalMap::reset(LiveInterval *li) {
375 liveOutCache_.clear();
378 bool LiveIntervalMap::isComplexMapped(const VNInfo *ParentVNI) const {
379 ValueMap::const_iterator i = valueMap_.find(ParentVNI);
380 return i != valueMap_.end() && i->second == 0;
383 // defValue - Introduce a li_ def for ParentVNI that could be later than
385 VNInfo *LiveIntervalMap::defValue(const VNInfo *ParentVNI, SlotIndex Idx) {
386 assert(li_ && "call reset first");
387 assert(ParentVNI && "Mapping NULL value");
388 assert(Idx.isValid() && "Invalid SlotIndex");
389 assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI");
391 // Create a new value.
392 VNInfo *VNI = li_->getNextValue(Idx, 0, lis_.getVNInfoAllocator());
394 // Preserve the PHIDef bit.
395 if (ParentVNI->isPHIDef() && Idx == ParentVNI->def)
396 VNI->setIsPHIDef(true);
398 // Use insert for lookup, so we can add missing values with a second lookup.
399 std::pair<ValueMap::iterator,bool> InsP =
400 valueMap_.insert(makeVV(ParentVNI, Idx == ParentVNI->def ? VNI : 0));
402 // This is now a complex def. Mark with a NULL in valueMap.
404 InsP.first->second = 0;
410 // mapValue - Find the mapped value for ParentVNI at Idx.
411 // Potentially create phi-def values.
412 VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx,
414 assert(li_ && "call reset first");
415 assert(ParentVNI && "Mapping NULL value");
416 assert(Idx.isValid() && "Invalid SlotIndex");
417 assert(parentli_.getVNInfoAt(Idx) == ParentVNI && "Bad ParentVNI");
419 // Use insert for lookup, so we can add missing values with a second lookup.
420 std::pair<ValueMap::iterator,bool> InsP =
421 valueMap_.insert(makeVV(ParentVNI, 0));
423 // This was an unknown value. Create a simple mapping.
425 if (simple) *simple = true;
426 return InsP.first->second = li_->createValueCopy(ParentVNI,
427 lis_.getVNInfoAllocator());
430 // This was a simple mapped value.
431 if (InsP.first->second) {
432 if (simple) *simple = true;
433 return InsP.first->second;
436 // This is a complex mapped value. There may be multiple defs, and we may need
437 // to create phi-defs.
438 if (simple) *simple = false;
439 MachineBasicBlock *IdxMBB = lis_.getMBBFromIndex(Idx);
440 assert(IdxMBB && "No MBB at Idx");
442 // Is there a def in the same MBB we can extend?
443 if (VNInfo *VNI = extendTo(IdxMBB, Idx))
446 // Now for the fun part. We know that ParentVNI potentially has multiple defs,
447 // and we may need to create even more phi-defs to preserve VNInfo SSA form.
448 // Perform a search for all predecessor blocks where we know the dominating
449 // VNInfo. Insert phi-def VNInfos along the path back to IdxMBB.
450 DEBUG(dbgs() << "\n Reaching defs for BB#" << IdxMBB->getNumber()
451 << " at " << Idx << " in " << *li_ << '\n');
454 // Blocks where li_ should be live-in.
455 SmallVector<MachineDomTreeNode*, 16> LiveIn;
456 LiveIn.push_back(mdt_[IdxMBB]);
458 // Using liveOutCache_ as a visited set, perform a BFS for all reaching defs.
459 for (unsigned i = 0; i != LiveIn.size(); ++i) {
460 MachineBasicBlock *MBB = LiveIn[i]->getBlock();
461 for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
462 PE = MBB->pred_end(); PI != PE; ++PI) {
463 MachineBasicBlock *Pred = *PI;
464 // Is this a known live-out block?
465 std::pair<LiveOutMap::iterator,bool> LOIP =
466 liveOutCache_.insert(std::make_pair(Pred, LiveOutPair()));
467 // Yes, we have been here before.
469 DEBUG(if (VNInfo *VNI = LOIP.first->second.first)
470 dbgs() << " known valno #" << VNI->id
471 << " at BB#" << Pred->getNumber() << '\n');
475 // Does Pred provide a live-out value?
476 SlotIndex Last = lis_.getMBBEndIdx(Pred).getPrevSlot();
477 if (VNInfo *VNI = extendTo(Pred, Last)) {
478 MachineBasicBlock *DefMBB = lis_.getMBBFromIndex(VNI->def);
479 DEBUG(dbgs() << " found valno #" << VNI->id
480 << " from BB#" << DefMBB->getNumber()
481 << " at BB#" << Pred->getNumber() << '\n');
482 LiveOutPair &LOP = LOIP.first->second;
484 LOP.second = mdt_[DefMBB];
487 // No, we need a live-in value for Pred as well
489 LiveIn.push_back(mdt_[Pred]);
493 // We may need to add phi-def values to preserve the SSA form.
494 // This is essentially the same iterative algorithm that SSAUpdater uses,
495 // except we already have a dominator tree, so we don't have to recompute it.
500 DEBUG(dbgs() << " Iterating over " << LiveIn.size() << " blocks.\n");
501 // Propagate live-out values down the dominator tree, inserting phi-defs when
502 // necessary. Since LiveIn was created by a BFS, going backwards makes it more
503 // likely for us to visit immediate dominators before their children.
504 for (unsigned i = LiveIn.size(); i; --i) {
505 MachineDomTreeNode *Node = LiveIn[i-1];
506 MachineBasicBlock *MBB = Node->getBlock();
507 MachineDomTreeNode *IDom = Node->getIDom();
508 LiveOutPair IDomValue;
509 // We need a live-in value to a block with no immediate dominator?
510 // This is probably an unreachable block that has survived somehow.
511 bool needPHI = !IDom;
513 // Get the IDom live-out value.
515 LiveOutMap::iterator I = liveOutCache_.find(IDom->getBlock());
516 if (I != liveOutCache_.end())
517 IDomValue = I->second;
519 // If IDom is outside our set of live-out blocks, there must be new
520 // defs, and we need a phi-def here.
524 // IDom dominates all of our predecessors, but it may not be the immediate
525 // dominator. Check if any of them have live-out values that are properly
526 // dominated by IDom. If so, we need a phi-def here.
528 for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
529 PE = MBB->pred_end(); PI != PE; ++PI) {
530 LiveOutPair Value = liveOutCache_[*PI];
531 if (!Value.first || Value.first == IDomValue.first)
533 // This predecessor is carrying something other than IDomValue.
534 // It could be because IDomValue hasn't propagated yet, or it could be
535 // because MBB is in the dominance frontier of that value.
536 if (mdt_.dominates(IDom, Value.second)) {
543 // Create a phi-def if required.
546 SlotIndex Start = lis_.getMBBStartIdx(MBB);
547 VNInfo *VNI = li_->getNextValue(Start, 0, lis_.getVNInfoAllocator());
548 VNI->setIsPHIDef(true);
549 DEBUG(dbgs() << " - BB#" << MBB->getNumber()
550 << " phi-def #" << VNI->id << " at " << Start << '\n');
551 // We no longer need li_ to be live-in.
552 LiveIn.erase(LiveIn.begin()+(i-1));
553 // Blocks in LiveIn are either IdxMBB, or have a value live-through.
556 // Check if we need to update live-out info.
557 LiveOutMap::iterator I = liveOutCache_.find(MBB);
558 if (I == liveOutCache_.end() || I->second.second == Node) {
559 // We already have a live-out defined in MBB, so this must be IdxMBB.
560 assert(MBB == IdxMBB && "Adding phi-def to known live-out");
561 li_->addRange(LiveRange(Start, Idx.getNextSlot(), VNI));
563 // This phi-def is also live-out, so color the whole block.
564 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
565 I->second = LiveOutPair(VNI, Node);
567 } else if (IDomValue.first) {
568 // No phi-def here. Remember incoming value for IdxMBB.
570 IdxVNI = IDomValue.first;
571 // Propagate IDomValue if needed:
572 // MBB is live-out and doesn't define its own value.
573 LiveOutMap::iterator I = liveOutCache_.find(MBB);
574 if (I != liveOutCache_.end() && I->second.second != Node &&
575 I->second.first != IDomValue.first) {
577 I->second = IDomValue;
578 DEBUG(dbgs() << " - BB#" << MBB->getNumber()
579 << " idom valno #" << IDomValue.first->id
580 << " from BB#" << IDom->getBlock()->getNumber() << '\n');
584 DEBUG(dbgs() << " - made " << Changes << " changes.\n");
587 assert(IdxVNI && "Didn't find value for Idx");
591 // Check the liveOutCache_ invariants.
592 for (LiveOutMap::iterator I = liveOutCache_.begin(), E = liveOutCache_.end();
594 assert(I->first && "Null MBB entry in cache");
595 assert(I->second.first && "Null VNInfo in cache");
596 assert(I->second.second && "Null DomTreeNode in cache");
597 if (I->second.second->getBlock() == I->first)
599 for (MachineBasicBlock::pred_iterator PI = I->first->pred_begin(),
600 PE = I->first->pred_end(); PI != PE; ++PI)
601 assert(liveOutCache_.lookup(*PI) == I->second && "Bad invariant");
605 // Since we went through the trouble of a full BFS visiting all reaching defs,
606 // the values in LiveIn are now accurate. No more phi-defs are needed
607 // for these blocks, so we can color the live ranges.
608 // This makes the next mapValue call much faster.
609 for (unsigned i = 0, e = LiveIn.size(); i != e; ++i) {
610 MachineBasicBlock *MBB = LiveIn[i]->getBlock();
611 SlotIndex Start = lis_.getMBBStartIdx(MBB);
613 li_->addRange(LiveRange(Start, Idx.getNextSlot(), IdxVNI));
616 // Anything in LiveIn other than IdxMBB is live-through.
617 VNInfo *VNI = liveOutCache_.lookup(MBB).first;
618 assert(VNI && "Missing block value");
619 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
626 void LiveIntervalMap::dumpCache() {
627 for (LiveOutMap::iterator I = liveOutCache_.begin(), E = liveOutCache_.end();
629 assert(I->first && "Null MBB entry in cache");
630 assert(I->second.first && "Null VNInfo in cache");
631 assert(I->second.second && "Null DomTreeNode in cache");
632 dbgs() << " cache: BB#" << I->first->getNumber()
633 << " has valno #" << I->second.first->id << " from BB#"
634 << I->second.second->getBlock()->getNumber() << ", preds";
635 for (MachineBasicBlock::pred_iterator PI = I->first->pred_begin(),
636 PE = I->first->pred_end(); PI != PE; ++PI)
637 dbgs() << " BB#" << (*PI)->getNumber();
640 dbgs() << " cache: " << liveOutCache_.size() << " entries.\n";
644 // extendTo - Find the last li_ value defined in MBB at or before Idx. The
645 // parentli_ is assumed to be live at Idx. Extend the live range to Idx.
646 // Return the found VNInfo, or NULL.
647 VNInfo *LiveIntervalMap::extendTo(const MachineBasicBlock *MBB, SlotIndex Idx) {
648 assert(li_ && "call reset first");
649 LiveInterval::iterator I = std::upper_bound(li_->begin(), li_->end(), Idx);
650 if (I == li_->begin())
653 if (I->end <= lis_.getMBBStartIdx(MBB))
656 I->end = Idx.getNextSlot();
660 // addSimpleRange - Add a simple range from parentli_ to li_.
661 // ParentVNI must be live in the [Start;End) interval.
662 void LiveIntervalMap::addSimpleRange(SlotIndex Start, SlotIndex End,
663 const VNInfo *ParentVNI) {
664 assert(li_ && "call reset first");
666 VNInfo *VNI = mapValue(ParentVNI, Start, &simple);
667 // A simple mapping is easy.
669 li_->addRange(LiveRange(Start, End, VNI));
673 // ParentVNI is a complex value. We must map per MBB.
674 MachineFunction::iterator MBB = lis_.getMBBFromIndex(Start);
675 MachineFunction::iterator MBBE = lis_.getMBBFromIndex(End.getPrevSlot());
678 li_->addRange(LiveRange(Start, End, VNI));
683 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB), VNI));
685 // Run sequence of full blocks.
686 for (++MBB; MBB != MBBE; ++MBB) {
687 Start = lis_.getMBBStartIdx(MBB);
688 li_->addRange(LiveRange(Start, lis_.getMBBEndIdx(MBB),
689 mapValue(ParentVNI, Start)));
693 Start = lis_.getMBBStartIdx(MBB);
695 li_->addRange(LiveRange(Start, End, mapValue(ParentVNI, Start)));
698 /// addRange - Add live ranges to li_ where [Start;End) intersects parentli_.
699 /// All needed values whose def is not inside [Start;End) must be defined
700 /// beforehand so mapValue will work.
701 void LiveIntervalMap::addRange(SlotIndex Start, SlotIndex End) {
702 assert(li_ && "call reset first");
703 LiveInterval::const_iterator B = parentli_.begin(), E = parentli_.end();
704 LiveInterval::const_iterator I = std::lower_bound(B, E, Start);
706 // Check if --I begins before Start and overlaps.
710 addSimpleRange(Start, std::min(End, I->end), I->valno);
714 // The remaining ranges begin after Start.
715 for (;I != E && I->start < End; ++I)
716 addSimpleRange(I->start, std::min(End, I->end), I->valno);
720 //===----------------------------------------------------------------------===//
722 //===----------------------------------------------------------------------===//
724 /// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
725 SplitEditor::SplitEditor(SplitAnalysis &sa,
728 MachineDominatorTree &mdt,
730 : sa_(sa), lis_(lis), vrm_(vrm),
731 mri_(vrm.getMachineFunction().getRegInfo()),
732 tii_(*vrm.getMachineFunction().getTarget().getInstrInfo()),
733 tri_(*vrm.getMachineFunction().getTarget().getRegisterInfo()),
735 dupli_(lis_, mdt, edit.getParent()),
736 openli_(lis_, mdt, edit.getParent())
738 // We don't need an AliasAnalysis since we will only be performing
739 // cheap-as-a-copy remats anyway.
740 edit_.anyRematerializable(lis_, tii_, 0);
743 bool SplitEditor::intervalsLiveAt(SlotIndex Idx) const {
744 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E; ++I)
745 if (*I != dupli_.getLI() && (*I)->liveAt(Idx))
750 VNInfo *SplitEditor::defFromParent(LiveIntervalMap &Reg,
753 MachineBasicBlock &MBB,
754 MachineBasicBlock::iterator I) {
756 MachineInstr *CopyMI = 0;
759 // Attempt cheap-as-a-copy rematerialization.
760 LiveRangeEdit::Remat RM(ParentVNI);
761 if (edit_.canRematerializeAt(RM, UseIdx, true, lis_)) {
762 Def = edit_.rematerializeAt(MBB, I, Reg.getLI()->reg, RM,
765 // Can't remat, just insert a copy from parent.
766 CopyMI = BuildMI(MBB, I, DebugLoc(), tii_.get(TargetOpcode::COPY),
767 Reg.getLI()->reg).addReg(edit_.getReg());
768 Def = lis_.InsertMachineInstrInMaps(CopyMI).getDefIndex();
771 // Define the value in Reg.
772 VNI = Reg.defValue(ParentVNI, Def);
773 VNI->setCopy(CopyMI);
775 // Add minimal liveness for the new value.
778 Reg.getLI()->addRange(LiveRange(Def, UseIdx.getNextSlot(), VNI));
782 /// Create a new virtual register and live interval.
783 void SplitEditor::openIntv() {
784 assert(!openli_.getLI() && "Previous LI not closed before openIntv");
786 dupli_.reset(&edit_.create(mri_, lis_, vrm_));
788 openli_.reset(&edit_.create(mri_, lis_, vrm_));
791 /// enterIntvBefore - Enter openli before the instruction at Idx. If curli is
792 /// not live before Idx, a COPY is not inserted.
793 void SplitEditor::enterIntvBefore(SlotIndex Idx) {
794 assert(openli_.getLI() && "openIntv not called before enterIntvBefore");
795 Idx = Idx.getUseIndex();
796 DEBUG(dbgs() << " enterIntvBefore " << Idx);
797 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(Idx);
799 DEBUG(dbgs() << ": not live\n");
802 DEBUG(dbgs() << ": valno " << ParentVNI->id);
803 truncatedValues.insert(ParentVNI);
804 MachineInstr *MI = lis_.getInstructionFromIndex(Idx);
805 assert(MI && "enterIntvBefore called with invalid index");
807 defFromParent(openli_, ParentVNI, Idx, *MI->getParent(), MI);
809 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
812 /// enterIntvAtEnd - Enter openli at the end of MBB.
813 void SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
814 assert(openli_.getLI() && "openIntv not called before enterIntvAtEnd");
815 SlotIndex End = lis_.getMBBEndIdx(&MBB).getPrevSlot();
816 DEBUG(dbgs() << " enterIntvAtEnd BB#" << MBB.getNumber() << ", " << End);
817 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(End);
819 DEBUG(dbgs() << ": not live\n");
822 DEBUG(dbgs() << ": valno " << ParentVNI->id);
823 truncatedValues.insert(ParentVNI);
824 defFromParent(openli_, ParentVNI, End, MBB, MBB.getFirstTerminator());
825 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
828 /// useIntv - indicate that all instructions in MBB should use openli.
829 void SplitEditor::useIntv(const MachineBasicBlock &MBB) {
830 useIntv(lis_.getMBBStartIdx(&MBB), lis_.getMBBEndIdx(&MBB));
833 void SplitEditor::useIntv(SlotIndex Start, SlotIndex End) {
834 assert(openli_.getLI() && "openIntv not called before useIntv");
835 openli_.addRange(Start, End);
836 DEBUG(dbgs() << " use [" << Start << ';' << End << "): "
837 << *openli_.getLI() << '\n');
840 /// leaveIntvAfter - Leave openli after the instruction at Idx.
841 void SplitEditor::leaveIntvAfter(SlotIndex Idx) {
842 assert(openli_.getLI() && "openIntv not called before leaveIntvAfter");
843 DEBUG(dbgs() << " leaveIntvAfter " << Idx);
845 // The interval must be live beyond the instruction at Idx.
846 Idx = Idx.getBoundaryIndex();
847 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(Idx);
849 DEBUG(dbgs() << ": not live\n");
852 DEBUG(dbgs() << ": valno " << ParentVNI->id);
854 MachineBasicBlock::iterator MII = lis_.getInstructionFromIndex(Idx);
855 VNInfo *VNI = defFromParent(dupli_, ParentVNI, Idx,
856 *MII->getParent(), llvm::next(MII));
858 // Make sure that openli is properly extended from Idx to the new copy.
859 // FIXME: This shouldn't be necessary for remats.
860 openli_.addSimpleRange(Idx, VNI->def, ParentVNI);
862 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
865 /// leaveIntvAtTop - Leave the interval at the top of MBB.
866 /// Currently, only one value can leave the interval.
867 void SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
868 assert(openli_.getLI() && "openIntv not called before leaveIntvAtTop");
869 SlotIndex Start = lis_.getMBBStartIdx(&MBB);
870 DEBUG(dbgs() << " leaveIntvAtTop BB#" << MBB.getNumber() << ", " << Start);
872 VNInfo *ParentVNI = edit_.getParent().getVNInfoAt(Start);
874 DEBUG(dbgs() << ": not live\n");
878 VNInfo *VNI = defFromParent(dupli_, ParentVNI, Start, MBB,
879 MBB.SkipPHIsAndLabels(MBB.begin()));
881 // Finally we must make sure that openli is properly extended from Start to
883 openli_.addSimpleRange(Start, VNI->def, ParentVNI);
884 DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
887 /// closeIntv - Indicate that we are done editing the currently open
888 /// LiveInterval, and ranges can be trimmed.
889 void SplitEditor::closeIntv() {
890 assert(openli_.getLI() && "openIntv not called before closeIntv");
891 DEBUG(dbgs() << " closeIntv " << *openli_.getLI() << '\n');
895 /// rewrite - Rewrite all uses of reg to use the new registers.
896 void SplitEditor::rewrite(unsigned reg) {
897 for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin(reg),
898 RE = mri_.reg_end(); RI != RE;) {
899 MachineOperand &MO = RI.getOperand();
900 unsigned OpNum = RI.getOperandNo();
901 MachineInstr *MI = MO.getParent();
903 if (MI->isDebugValue()) {
904 DEBUG(dbgs() << "Zapping " << *MI);
905 // FIXME: We can do much better with debug values.
909 SlotIndex Idx = lis_.getInstructionIndex(MI);
910 Idx = MO.isUse() ? Idx.getUseIndex() : Idx.getDefIndex();
911 LiveInterval *LI = 0;
912 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E;
914 LiveInterval *testli = *I;
915 if (testli->liveAt(Idx)) {
920 DEBUG(dbgs() << " rewr BB#" << MI->getParent()->getNumber() << '\t'<< Idx);
921 assert(LI && "No register was live at use");
923 if (MO.isUse() && !MI->isRegTiedToDefOperand(OpNum))
924 MO.setIsKill(LI->killedAt(Idx.getDefIndex()));
925 DEBUG(dbgs() << '\t' << *MI);
930 SplitEditor::addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
931 // Build vector of iterator pairs from the intervals.
932 typedef std::pair<LiveInterval::const_iterator,
933 LiveInterval::const_iterator> IIPair;
934 SmallVector<IIPair, 8> Iters;
935 for (LiveRangeEdit::iterator LI = edit_.begin(), LE = edit_.end(); LI != LE;
937 if (*LI == dupli_.getLI())
939 LiveInterval::const_iterator I = (*LI)->find(Start);
940 LiveInterval::const_iterator E = (*LI)->end();
942 Iters.push_back(std::make_pair(I, E));
945 SlotIndex sidx = Start;
946 // Break [Start;End) into segments that don't overlap any intervals.
948 SlotIndex next = sidx, eidx = End;
949 // Find overlapping intervals.
950 for (unsigned i = 0; i != Iters.size() && sidx < eidx; ++i) {
951 LiveInterval::const_iterator I = Iters[i].first;
952 // Interval I is overlapping [sidx;eidx). Trim sidx.
953 if (I->start <= sidx) {
955 // Move to the next run, remove iters when all are consumed.
956 I = ++Iters[i].first;
957 if (I == Iters[i].second) {
958 Iters.erase(Iters.begin() + i);
963 // Trim eidx too if needed.
964 if (I->start >= eidx)
969 // Now, [sidx;eidx) doesn't overlap anything in intervals_.
971 dupli_.addSimpleRange(sidx, eidx, VNI);
972 // If the interval end was truncated, we can try again from next.
979 void SplitEditor::computeRemainder() {
980 // First we need to fill in the live ranges in dupli.
981 // If values were redefined, we need a full recoloring with SSA update.
982 // If values were truncated, we only need to truncate the ranges.
983 // If values were partially rematted, we should shrink to uses.
984 // If values were fully rematted, they should be omitted.
985 // FIXME: If a single value is redefined, just move the def and truncate.
986 LiveInterval &parent = edit_.getParent();
988 DEBUG(dbgs() << "computeRemainder from " << parent << '\n');
990 // Values that are fully contained in the split intervals.
991 SmallPtrSet<const VNInfo*, 8> deadValues;
992 // Map all curli values that should have live defs in dupli.
993 for (LiveInterval::const_vni_iterator I = parent.vni_begin(),
994 E = parent.vni_end(); I != E; ++I) {
995 const VNInfo *VNI = *I;
996 // Don't transfer unused values to the new intervals.
999 // Original def is contained in the split intervals.
1000 if (intervalsLiveAt(VNI->def)) {
1001 // Did this value escape?
1002 if (dupli_.isMapped(VNI))
1003 truncatedValues.insert(VNI);
1005 deadValues.insert(VNI);
1008 // Add minimal live range at the definition.
1009 VNInfo *DVNI = dupli_.defValue(VNI, VNI->def);
1010 dupli_.getLI()->addRange(LiveRange(VNI->def, VNI->def.getNextSlot(), DVNI));
1013 // Add all ranges to dupli.
1014 for (LiveInterval::const_iterator I = parent.begin(), E = parent.end();
1016 const LiveRange &LR = *I;
1017 if (truncatedValues.count(LR.valno)) {
1018 // recolor after removing intervals_.
1019 addTruncSimpleRange(LR.start, LR.end, LR.valno);
1020 } else if (!deadValues.count(LR.valno)) {
1021 // recolor without truncation.
1022 dupli_.addSimpleRange(LR.start, LR.end, LR.valno);
1026 // Extend dupli_ to be live out of any critical loop predecessors.
1027 // This means we have multiple registers live out of those blocks.
1028 // The alternative would be to split the critical edges.
1029 if (criticalPreds_.empty())
1031 for (SplitAnalysis::BlockPtrSet::iterator I = criticalPreds_.begin(),
1032 E = criticalPreds_.end(); I != E; ++I)
1033 dupli_.extendTo(*I, lis_.getMBBEndIdx(*I).getPrevSlot());
1034 criticalPreds_.clear();
1037 void SplitEditor::finish() {
1038 assert(!openli_.getLI() && "Previous LI not closed before rewrite");
1039 assert(dupli_.getLI() && "No dupli for rewrite. Noop spilt?");
1041 // Complete dupli liveness.
1044 // Get rid of unused values and set phi-kill flags.
1045 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E; ++I)
1046 (*I)->RenumberValues(lis_);
1048 // Rewrite instructions.
1049 rewrite(edit_.getReg());
1051 // Now check if any registers were separated into multiple components.
1052 ConnectedVNInfoEqClasses ConEQ(lis_);
1053 for (unsigned i = 0, e = edit_.size(); i != e; ++i) {
1054 // Don't use iterators, they are invalidated by create() below.
1055 LiveInterval *li = edit_.get(i);
1056 unsigned NumComp = ConEQ.Classify(li);
1059 DEBUG(dbgs() << " " << NumComp << " components: " << *li << '\n');
1060 SmallVector<LiveInterval*, 8> dups;
1062 for (unsigned i = 1; i != NumComp; ++i)
1063 dups.push_back(&edit_.create(mri_, lis_, vrm_));
1064 ConEQ.Distribute(&dups[0]);
1065 // Rewrite uses to the new regs.
1069 // Calculate spill weight and allocation hints for new intervals.
1070 VirtRegAuxInfo vrai(vrm_.getMachineFunction(), lis_, sa_.loops_);
1071 for (LiveRangeEdit::iterator I = edit_.begin(), E = edit_.end(); I != E; ++I){
1072 LiveInterval &li = **I;
1073 vrai.CalculateRegClass(li.reg);
1074 vrai.CalculateWeightAndHint(li);
1075 DEBUG(dbgs() << " new interval " << mri_.getRegClass(li.reg)->getName()
1076 << ":" << li << '\n');
1081 //===----------------------------------------------------------------------===//
1083 //===----------------------------------------------------------------------===//
1085 void SplitEditor::splitAroundLoop(const MachineLoop *Loop) {
1086 SplitAnalysis::LoopBlocks Blocks;
1087 sa_.getLoopBlocks(Loop, Blocks);
1090 dbgs() << " splitAround"; sa_.print(Blocks, dbgs()); dbgs() << '\n';
1093 // Break critical edges as needed.
1094 SplitAnalysis::BlockPtrSet CriticalExits;
1095 sa_.getCriticalExits(Blocks, CriticalExits);
1096 assert(CriticalExits.empty() && "Cannot break critical exits yet");
1098 // Get critical predecessors so computeRemainder can deal with them.
1099 sa_.getCriticalPreds(Blocks, criticalPreds_);
1101 // Create new live interval for the loop.
1104 // Insert copies in the predecessors if live-in to the header.
1105 if (lis_.isLiveInToMBB(edit_.getParent(), Loop->getHeader())) {
1106 for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Preds.begin(),
1107 E = Blocks.Preds.end(); I != E; ++I) {
1108 MachineBasicBlock &MBB = const_cast<MachineBasicBlock&>(**I);
1109 enterIntvAtEnd(MBB);
1113 // Switch all loop blocks.
1114 for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Loop.begin(),
1115 E = Blocks.Loop.end(); I != E; ++I)
1118 // Insert back copies in the exit blocks.
1119 for (SplitAnalysis::BlockPtrSet::iterator I = Blocks.Exits.begin(),
1120 E = Blocks.Exits.end(); I != E; ++I) {
1121 MachineBasicBlock &MBB = const_cast<MachineBasicBlock&>(**I);
1122 leaveIntvAtTop(MBB);
1131 //===----------------------------------------------------------------------===//
1132 // Single Block Splitting
1133 //===----------------------------------------------------------------------===//
1135 /// getMultiUseBlocks - if curli has more than one use in a basic block, it
1136 /// may be an advantage to split curli for the duration of the block.
1137 bool SplitAnalysis::getMultiUseBlocks(BlockPtrSet &Blocks) {
1138 // If curli is local to one block, there is no point to splitting it.
1139 if (usingBlocks_.size() <= 1)
1141 // Add blocks with multiple uses.
1142 for (BlockCountMap::iterator I = usingBlocks_.begin(), E = usingBlocks_.end();
1144 switch (I->second) {
1149 // When there are only two uses and curli is both live in and live out,
1150 // we don't really win anything by isolating the block since we would be
1151 // inserting two copies.
1152 // The remaing register would still have two uses in the block. (Unless it
1153 // separates into disconnected components).
1154 if (lis_.isLiveInToMBB(*curli_, I->first) &&
1155 lis_.isLiveOutOfMBB(*curli_, I->first))
1159 Blocks.insert(I->first);
1161 return !Blocks.empty();
1164 /// splitSingleBlocks - Split curli into a separate live interval inside each
1165 /// basic block in Blocks.
1166 void SplitEditor::splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks) {
1167 DEBUG(dbgs() << " splitSingleBlocks for " << Blocks.size() << " blocks.\n");
1168 // Determine the first and last instruction using curli in each block.
1169 typedef std::pair<SlotIndex,SlotIndex> IndexPair;
1170 typedef DenseMap<const MachineBasicBlock*,IndexPair> IndexPairMap;
1171 IndexPairMap MBBRange;
1172 for (SplitAnalysis::InstrPtrSet::const_iterator I = sa_.usingInstrs_.begin(),
1173 E = sa_.usingInstrs_.end(); I != E; ++I) {
1174 const MachineBasicBlock *MBB = (*I)->getParent();
1175 if (!Blocks.count(MBB))
1177 SlotIndex Idx = lis_.getInstructionIndex(*I);
1178 DEBUG(dbgs() << " BB#" << MBB->getNumber() << '\t' << Idx << '\t' << **I);
1179 IndexPair &IP = MBBRange[MBB];
1180 if (!IP.first.isValid() || Idx < IP.first)
1182 if (!IP.second.isValid() || Idx > IP.second)
1186 // Create a new interval for each block.
1187 for (SplitAnalysis::BlockPtrSet::const_iterator I = Blocks.begin(),
1188 E = Blocks.end(); I != E; ++I) {
1189 IndexPair &IP = MBBRange[*I];
1190 DEBUG(dbgs() << " splitting for BB#" << (*I)->getNumber() << ": ["
1191 << IP.first << ';' << IP.second << ")\n");
1192 assert(IP.first.isValid() && IP.second.isValid());
1195 enterIntvBefore(IP.first);
1196 useIntv(IP.first.getBaseIndex(), IP.second.getBoundaryIndex());
1197 leaveIntvAfter(IP.second);
1204 //===----------------------------------------------------------------------===//
1205 // Sub Block Splitting
1206 //===----------------------------------------------------------------------===//
1208 /// getBlockForInsideSplit - If curli is contained inside a single basic block,
1209 /// and it wou pay to subdivide the interval inside that block, return it.
1210 /// Otherwise return NULL. The returned block can be passed to
1211 /// SplitEditor::splitInsideBlock.
1212 const MachineBasicBlock *SplitAnalysis::getBlockForInsideSplit() {
1213 // The interval must be exclusive to one block.
1214 if (usingBlocks_.size() != 1)
1216 // Don't to this for less than 4 instructions. We want to be sure that
1217 // splitting actually reduces the instruction count per interval.
1218 if (usingInstrs_.size() < 4)
1220 return usingBlocks_.begin()->first;
1223 /// splitInsideBlock - Split curli into multiple intervals inside MBB.
1224 void SplitEditor::splitInsideBlock(const MachineBasicBlock *MBB) {
1225 SmallVector<SlotIndex, 32> Uses;
1226 Uses.reserve(sa_.usingInstrs_.size());
1227 for (SplitAnalysis::InstrPtrSet::const_iterator I = sa_.usingInstrs_.begin(),
1228 E = sa_.usingInstrs_.end(); I != E; ++I)
1229 if ((*I)->getParent() == MBB)
1230 Uses.push_back(lis_.getInstructionIndex(*I));
1231 DEBUG(dbgs() << " splitInsideBlock BB#" << MBB->getNumber() << " for "
1232 << Uses.size() << " instructions.\n");
1233 assert(Uses.size() >= 3 && "Need at least 3 instructions");
1234 array_pod_sort(Uses.begin(), Uses.end());
1236 // Simple algorithm: Find the largest gap between uses as determined by slot
1237 // indices. Create new intervals for instructions before the gap and after the
1239 unsigned bestPos = 0;
1241 DEBUG(dbgs() << " dist (" << Uses[0]);
1242 for (unsigned i = 1, e = Uses.size(); i != e; ++i) {
1243 int g = Uses[i-1].distance(Uses[i]);
1244 DEBUG(dbgs() << ") -" << g << "- (" << Uses[i]);
1246 bestPos = i, bestGap = g;
1248 DEBUG(dbgs() << "), best: -" << bestGap << "-\n");
1250 // bestPos points to the first use after the best gap.
1251 assert(bestPos > 0 && "Invalid gap");
1253 // FIXME: Don't create intervals for low densities.
1255 // First interval before the gap. Don't create single-instr intervals.
1258 enterIntvBefore(Uses.front());
1259 useIntv(Uses.front().getBaseIndex(), Uses[bestPos-1].getBoundaryIndex());
1260 leaveIntvAfter(Uses[bestPos-1]);
1264 // Second interval after the gap.
1265 if (bestPos < Uses.size()-1) {
1267 enterIntvBefore(Uses[bestPos]);
1268 useIntv(Uses[bestPos].getBaseIndex(), Uses.back().getBoundaryIndex());
1269 leaveIntvAfter(Uses.back());