1 //===-- RegAllocGreedy.cpp - greedy register allocator --------------------===//
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 defines the RAGreedy function pass for register allocation in
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "regalloc"
16 #include "AllocationOrder.h"
17 #include "LiveIntervalUnion.h"
18 #include "LiveRangeEdit.h"
19 #include "RegAllocBase.h"
21 #include "SpillPlacement.h"
23 #include "VirtRegMap.h"
24 #include "llvm/ADT/Statistic.h"
25 #include "llvm/Analysis/AliasAnalysis.h"
26 #include "llvm/Function.h"
27 #include "llvm/PassAnalysisSupport.h"
28 #include "llvm/CodeGen/CalcSpillWeights.h"
29 #include "llvm/CodeGen/EdgeBundles.h"
30 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
31 #include "llvm/CodeGen/LiveStackAnalysis.h"
32 #include "llvm/CodeGen/MachineDominators.h"
33 #include "llvm/CodeGen/MachineFunctionPass.h"
34 #include "llvm/CodeGen/MachineLoopInfo.h"
35 #include "llvm/CodeGen/MachineLoopRanges.h"
36 #include "llvm/CodeGen/MachineRegisterInfo.h"
37 #include "llvm/CodeGen/Passes.h"
38 #include "llvm/CodeGen/RegAllocRegistry.h"
39 #include "llvm/CodeGen/RegisterCoalescer.h"
40 #include "llvm/Target/TargetOptions.h"
41 #include "llvm/Support/Debug.h"
42 #include "llvm/Support/ErrorHandling.h"
43 #include "llvm/Support/raw_ostream.h"
44 #include "llvm/Support/Timer.h"
50 STATISTIC(NumGlobalSplits, "Number of split global live ranges");
51 STATISTIC(NumLocalSplits, "Number of split local live ranges");
52 STATISTIC(NumReassigned, "Number of interferences reassigned");
53 STATISTIC(NumEvicted, "Number of interferences evicted");
55 static RegisterRegAlloc greedyRegAlloc("greedy", "greedy register allocator",
56 createGreedyRegisterAllocator);
59 class RAGreedy : public MachineFunctionPass,
61 private LiveRangeEdit::Delegate {
65 BitVector ReservedRegs;
70 MachineDominatorTree *DomTree;
71 MachineLoopInfo *Loops;
72 MachineLoopRanges *LoopRanges;
74 SpillPlacement *SpillPlacer;
77 std::auto_ptr<Spiller> SpillerInstance;
78 std::priority_queue<std::pair<unsigned, unsigned> > Queue;
80 // Live ranges pass through a number of stages as we try to allocate them.
81 // Some of the stages may also create new live ranges:
83 // - Region splitting.
84 // - Per-block splitting.
88 // Ranges produced by one of the stages skip the previous stages when they are
89 // dequeued. This improves performance because we can skip interference checks
90 // that are unlikely to give any results. It also guarantees that the live
91 // range splitting algorithm terminates, something that is otherwise hard to
94 RS_Original, ///< Never seen before, never split.
95 RS_Second, ///< Second time in the queue.
96 RS_Region, ///< Produced by region splitting.
97 RS_Block, ///< Produced by per-block splitting.
98 RS_Local, ///< Produced by local splitting.
99 RS_Spill ///< Produced by spilling.
102 IndexedMap<unsigned char, VirtReg2IndexFunctor> LRStage;
104 LiveRangeStage getStage(const LiveInterval &VirtReg) const {
105 return LiveRangeStage(LRStage[VirtReg.reg]);
108 template<typename Iterator>
109 void setStage(Iterator Begin, Iterator End, LiveRangeStage NewStage) {
110 LRStage.resize(MRI->getNumVirtRegs());
111 for (;Begin != End; ++Begin)
112 LRStage[(*Begin)->reg] = NewStage;
116 std::auto_ptr<SplitAnalysis> SA;
117 std::auto_ptr<SplitEditor> SE;
119 /// All basic blocks where the current register is live.
120 SmallVector<SpillPlacement::BlockConstraint, 8> SplitConstraints;
122 typedef std::pair<SlotIndex, SlotIndex> IndexPair;
124 /// Global live range splitting candidate info.
125 struct GlobalSplitCandidate {
127 SmallVector<IndexPair, 8> Interference;
128 BitVector LiveBundles;
131 /// Candidate info for for each PhysReg in AllocationOrder.
132 /// This vector never shrinks, but grows to the size of the largest register
134 SmallVector<GlobalSplitCandidate, 32> GlobalCand;
136 /// For every instruction in SA->UseSlots, store the previous non-copy
138 SmallVector<SlotIndex, 8> PrevSlot;
143 /// Return the pass name.
144 virtual const char* getPassName() const {
145 return "Greedy Register Allocator";
148 /// RAGreedy analysis usage.
149 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
150 virtual void releaseMemory();
151 virtual Spiller &spiller() { return *SpillerInstance; }
152 virtual void enqueue(LiveInterval *LI);
153 virtual LiveInterval *dequeue();
154 virtual unsigned selectOrSplit(LiveInterval&,
155 SmallVectorImpl<LiveInterval*>&);
157 /// Perform register allocation.
158 virtual bool runOnMachineFunction(MachineFunction &mf);
163 void LRE_WillEraseInstruction(MachineInstr*);
164 bool LRE_CanEraseVirtReg(unsigned);
165 void LRE_WillShrinkVirtReg(unsigned);
167 bool checkUncachedInterference(LiveInterval&, unsigned);
168 LiveInterval *getSingleInterference(LiveInterval&, unsigned);
169 bool reassignVReg(LiveInterval &InterferingVReg, unsigned OldPhysReg);
171 void mapGlobalInterference(unsigned, SmallVectorImpl<IndexPair>&);
172 float calcSplitConstraints(const SmallVectorImpl<IndexPair>&);
174 float calcGlobalSplitCost(const BitVector&);
175 void splitAroundRegion(LiveInterval&, unsigned, const BitVector&,
176 SmallVectorImpl<LiveInterval*>&);
177 void calcGapWeights(unsigned, SmallVectorImpl<float>&);
178 SlotIndex getPrevMappedIndex(const MachineInstr*);
179 void calcPrevSlots();
180 unsigned nextSplitPoint(unsigned);
181 bool canEvictInterference(LiveInterval&, unsigned, float&);
183 unsigned tryReassign(LiveInterval&, AllocationOrder&,
184 SmallVectorImpl<LiveInterval*>&);
185 unsigned tryEvict(LiveInterval&, AllocationOrder&,
186 SmallVectorImpl<LiveInterval*>&);
187 unsigned tryRegionSplit(LiveInterval&, AllocationOrder&,
188 SmallVectorImpl<LiveInterval*>&);
189 unsigned tryLocalSplit(LiveInterval&, AllocationOrder&,
190 SmallVectorImpl<LiveInterval*>&);
191 unsigned trySplit(LiveInterval&, AllocationOrder&,
192 SmallVectorImpl<LiveInterval*>&);
194 } // end anonymous namespace
196 char RAGreedy::ID = 0;
198 FunctionPass* llvm::createGreedyRegisterAllocator() {
199 return new RAGreedy();
202 RAGreedy::RAGreedy(): MachineFunctionPass(ID), LRStage(RS_Original) {
203 initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
204 initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
205 initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
206 initializeStrongPHIEliminationPass(*PassRegistry::getPassRegistry());
207 initializeRegisterCoalescerAnalysisGroup(*PassRegistry::getPassRegistry());
208 initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
209 initializeLiveStacksPass(*PassRegistry::getPassRegistry());
210 initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry());
211 initializeMachineLoopInfoPass(*PassRegistry::getPassRegistry());
212 initializeMachineLoopRangesPass(*PassRegistry::getPassRegistry());
213 initializeVirtRegMapPass(*PassRegistry::getPassRegistry());
214 initializeEdgeBundlesPass(*PassRegistry::getPassRegistry());
215 initializeSpillPlacementPass(*PassRegistry::getPassRegistry());
218 void RAGreedy::getAnalysisUsage(AnalysisUsage &AU) const {
219 AU.setPreservesCFG();
220 AU.addRequired<AliasAnalysis>();
221 AU.addPreserved<AliasAnalysis>();
222 AU.addRequired<LiveIntervals>();
223 AU.addRequired<SlotIndexes>();
224 AU.addPreserved<SlotIndexes>();
226 AU.addRequiredID(StrongPHIEliminationID);
227 AU.addRequiredTransitive<RegisterCoalescer>();
228 AU.addRequired<CalculateSpillWeights>();
229 AU.addRequired<LiveStacks>();
230 AU.addPreserved<LiveStacks>();
231 AU.addRequired<MachineDominatorTree>();
232 AU.addPreserved<MachineDominatorTree>();
233 AU.addRequired<MachineLoopInfo>();
234 AU.addPreserved<MachineLoopInfo>();
235 AU.addRequired<MachineLoopRanges>();
236 AU.addPreserved<MachineLoopRanges>();
237 AU.addRequired<VirtRegMap>();
238 AU.addPreserved<VirtRegMap>();
239 AU.addRequired<EdgeBundles>();
240 AU.addRequired<SpillPlacement>();
241 MachineFunctionPass::getAnalysisUsage(AU);
245 //===----------------------------------------------------------------------===//
246 // LiveRangeEdit delegate methods
247 //===----------------------------------------------------------------------===//
249 void RAGreedy::LRE_WillEraseInstruction(MachineInstr *MI) {
250 // LRE itself will remove from SlotIndexes and parent basic block.
251 VRM->RemoveMachineInstrFromMaps(MI);
254 bool RAGreedy::LRE_CanEraseVirtReg(unsigned VirtReg) {
255 if (unsigned PhysReg = VRM->getPhys(VirtReg)) {
256 unassign(LIS->getInterval(VirtReg), PhysReg);
259 // Unassigned virtreg is probably in the priority queue.
260 // RegAllocBase will erase it after dequeueing.
264 void RAGreedy::LRE_WillShrinkVirtReg(unsigned VirtReg) {
265 unsigned PhysReg = VRM->getPhys(VirtReg);
269 // Register is assigned, put it back on the queue for reassignment.
270 LiveInterval &LI = LIS->getInterval(VirtReg);
271 unassign(LI, PhysReg);
275 void RAGreedy::releaseMemory() {
276 SpillerInstance.reset(0);
278 RegAllocBase::releaseMemory();
281 void RAGreedy::enqueue(LiveInterval *LI) {
282 // Prioritize live ranges by size, assigning larger ranges first.
283 // The queue holds (size, reg) pairs.
284 const unsigned Size = LI->getSize();
285 const unsigned Reg = LI->reg;
286 assert(TargetRegisterInfo::isVirtualRegister(Reg) &&
287 "Can only enqueue virtual registers");
291 if (LRStage[Reg] == RS_Original)
292 // 1st generation ranges are handled first, long -> short.
293 Prio = (1u << 31) + Size;
295 // Repeat offenders are handled second, short -> long
296 Prio = (1u << 30) - Size;
298 // Boost ranges that have a physical register hint.
299 const unsigned Hint = VRM->getRegAllocPref(Reg);
300 if (TargetRegisterInfo::isPhysicalRegister(Hint))
303 Queue.push(std::make_pair(Prio, Reg));
306 LiveInterval *RAGreedy::dequeue() {
309 LiveInterval *LI = &LIS->getInterval(Queue.top().second);
314 //===----------------------------------------------------------------------===//
315 // Register Reassignment
316 //===----------------------------------------------------------------------===//
318 // Check interference without using the cache.
319 bool RAGreedy::checkUncachedInterference(LiveInterval &VirtReg,
321 for (const unsigned *AliasI = TRI->getOverlaps(PhysReg); *AliasI; ++AliasI) {
322 LiveIntervalUnion::Query subQ(&VirtReg, &PhysReg2LiveUnion[*AliasI]);
323 if (subQ.checkInterference())
329 /// getSingleInterference - Return the single interfering virtual register
330 /// assigned to PhysReg. Return 0 if more than one virtual register is
332 LiveInterval *RAGreedy::getSingleInterference(LiveInterval &VirtReg,
334 // Check physreg and aliases.
335 LiveInterval *Interference = 0;
336 for (const unsigned *AliasI = TRI->getOverlaps(PhysReg); *AliasI; ++AliasI) {
337 LiveIntervalUnion::Query &Q = query(VirtReg, *AliasI);
338 if (Q.checkInterference()) {
341 if (Q.collectInterferingVRegs(2) > 1)
343 Interference = Q.interferingVRegs().front();
349 // Attempt to reassign this virtual register to a different physical register.
351 // FIXME: we are not yet caching these "second-level" interferences discovered
352 // in the sub-queries. These interferences can change with each call to
353 // selectOrSplit. However, we could implement a "may-interfere" cache that
354 // could be conservatively dirtied when we reassign or split.
356 // FIXME: This may result in a lot of alias queries. We could summarize alias
357 // live intervals in their parent register's live union, but it's messy.
358 bool RAGreedy::reassignVReg(LiveInterval &InterferingVReg,
359 unsigned WantedPhysReg) {
360 assert(TargetRegisterInfo::isVirtualRegister(InterferingVReg.reg) &&
361 "Can only reassign virtual registers");
362 assert(TRI->regsOverlap(WantedPhysReg, VRM->getPhys(InterferingVReg.reg)) &&
363 "inconsistent phys reg assigment");
365 AllocationOrder Order(InterferingVReg.reg, *VRM, ReservedRegs);
366 while (unsigned PhysReg = Order.next()) {
367 // Don't reassign to a WantedPhysReg alias.
368 if (TRI->regsOverlap(PhysReg, WantedPhysReg))
371 if (checkUncachedInterference(InterferingVReg, PhysReg))
374 // Reassign the interfering virtual reg to this physical reg.
375 unsigned OldAssign = VRM->getPhys(InterferingVReg.reg);
376 DEBUG(dbgs() << "reassigning: " << InterferingVReg << " from " <<
377 TRI->getName(OldAssign) << " to " << TRI->getName(PhysReg) << '\n');
378 unassign(InterferingVReg, OldAssign);
379 assign(InterferingVReg, PhysReg);
386 /// tryReassign - Try to reassign a single interference to a different physreg.
387 /// @param VirtReg Currently unassigned virtual register.
388 /// @param Order Physregs to try.
389 /// @return Physreg to assign VirtReg, or 0.
390 unsigned RAGreedy::tryReassign(LiveInterval &VirtReg, AllocationOrder &Order,
391 SmallVectorImpl<LiveInterval*> &NewVRegs){
392 NamedRegionTimer T("Reassign", TimerGroupName, TimePassesIsEnabled);
395 while (unsigned PhysReg = Order.next()) {
396 LiveInterval *InterferingVReg = getSingleInterference(VirtReg, PhysReg);
397 if (!InterferingVReg)
399 if (TargetRegisterInfo::isPhysicalRegister(InterferingVReg->reg))
401 if (reassignVReg(*InterferingVReg, PhysReg))
408 //===----------------------------------------------------------------------===//
409 // Interference eviction
410 //===----------------------------------------------------------------------===//
412 /// canEvict - Return true if all interferences between VirtReg and PhysReg can
413 /// be evicted. Set maxWeight to the maximal spill weight of an interference.
414 bool RAGreedy::canEvictInterference(LiveInterval &VirtReg, unsigned PhysReg,
417 for (const unsigned *AliasI = TRI->getOverlaps(PhysReg); *AliasI; ++AliasI) {
418 LiveIntervalUnion::Query &Q = query(VirtReg, *AliasI);
419 // If there is 10 or more interferences, chances are one is smaller.
420 if (Q.collectInterferingVRegs(10) >= 10)
423 // Check if any interfering live range is heavier than VirtReg.
424 for (unsigned i = 0, e = Q.interferingVRegs().size(); i != e; ++i) {
425 LiveInterval *Intf = Q.interferingVRegs()[i];
426 if (TargetRegisterInfo::isPhysicalRegister(Intf->reg))
428 if (Intf->weight >= VirtReg.weight)
430 Weight = std::max(Weight, Intf->weight);
437 /// tryEvict - Try to evict all interferences for a physreg.
438 /// @param VirtReg Currently unassigned virtual register.
439 /// @param Order Physregs to try.
440 /// @return Physreg to assign VirtReg, or 0.
441 unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
442 AllocationOrder &Order,
443 SmallVectorImpl<LiveInterval*> &NewVRegs){
444 NamedRegionTimer T("Evict", TimerGroupName, TimePassesIsEnabled);
446 // Keep track of the lightest single interference seen so far.
447 float BestWeight = 0;
448 unsigned BestPhys = 0;
451 while (unsigned PhysReg = Order.next()) {
453 if (!canEvictInterference(VirtReg, PhysReg, Weight))
456 // This is an eviction candidate.
457 DEBUG(dbgs() << "max " << PrintReg(PhysReg, TRI) << " interference = "
459 if (BestPhys && Weight >= BestWeight)
465 // Stop if the hint can be used.
466 if (Order.isHint(PhysReg))
473 DEBUG(dbgs() << "evicting " << PrintReg(BestPhys, TRI) << " interference\n");
474 for (const unsigned *AliasI = TRI->getOverlaps(BestPhys); *AliasI; ++AliasI) {
475 LiveIntervalUnion::Query &Q = query(VirtReg, *AliasI);
476 assert(Q.seenAllInterferences() && "Didn't check all interfererences.");
477 for (unsigned i = 0, e = Q.interferingVRegs().size(); i != e; ++i) {
478 LiveInterval *Intf = Q.interferingVRegs()[i];
479 unassign(*Intf, VRM->getPhys(Intf->reg));
481 NewVRegs.push_back(Intf);
488 //===----------------------------------------------------------------------===//
490 //===----------------------------------------------------------------------===//
492 /// mapGlobalInterference - Compute a map of the interference from PhysReg and
493 /// its aliases in each block in SA->LiveBlocks.
494 /// If LiveBlocks[i] is live-in, Ranges[i].first is the first interference.
495 /// If LiveBlocks[i] is live-out, Ranges[i].second is the last interference.
496 void RAGreedy::mapGlobalInterference(unsigned PhysReg,
497 SmallVectorImpl<IndexPair> &Ranges) {
498 Ranges.assign(SA->LiveBlocks.size(), IndexPair());
499 LiveInterval &VirtReg = const_cast<LiveInterval&>(SA->getParent());
500 for (const unsigned *AI = TRI->getOverlaps(PhysReg); *AI; ++AI) {
501 if (!query(VirtReg, *AI).checkInterference())
503 LiveIntervalUnion::SegmentIter IntI =
504 PhysReg2LiveUnion[*AI].find(VirtReg.beginIndex());
507 for (unsigned i = 0, e = SA->LiveBlocks.size(); i != e; ++i) {
508 const SplitAnalysis::BlockInfo &BI = SA->LiveBlocks[i];
509 IndexPair &IP = Ranges[i];
511 // Skip interference-free blocks.
512 if (IntI.start() >= BI.Stop)
515 // First interference in block.
517 IntI.advanceTo(BI.Start);
520 if (IntI.start() >= BI.Stop)
522 if (!IP.first.isValid() || IntI.start() < IP.first)
523 IP.first = IntI.start();
526 // Last interference in block.
528 IntI.advanceTo(BI.Stop);
529 if (!IntI.valid() || IntI.start() >= BI.Stop)
531 if (IntI.stop() <= BI.Start)
533 if (!IP.second.isValid() || IntI.stop() > IP.second)
534 IP.second = IntI.stop();
540 /// calcSplitConstraints - Fill out the SplitConstraints vector based on the
541 /// interference pattern in Intf. Return the static cost of this split,
542 /// assuming that all preferences in SplitConstraints are met.
543 float RAGreedy::calcSplitConstraints(const SmallVectorImpl<IndexPair> &Intf) {
544 // Reset interference dependent info.
545 SplitConstraints.resize(SA->LiveBlocks.size());
546 float StaticCost = 0;
547 for (unsigned i = 0, e = SA->LiveBlocks.size(); i != e; ++i) {
548 SplitAnalysis::BlockInfo &BI = SA->LiveBlocks[i];
549 SpillPlacement::BlockConstraint &BC = SplitConstraints[i];
550 IndexPair IP = Intf[i];
552 BC.Number = BI.MBB->getNumber();
553 BC.Entry = (BI.Uses && BI.LiveIn) ?
554 SpillPlacement::PrefReg : SpillPlacement::DontCare;
555 BC.Exit = (BI.Uses && BI.LiveOut) ?
556 SpillPlacement::PrefReg : SpillPlacement::DontCare;
558 // Number of spill code instructions to insert.
561 // Interference for the live-in value.
562 if (IP.first.isValid()) {
563 if (IP.first <= BI.Start)
564 BC.Entry = SpillPlacement::MustSpill, Ins += BI.Uses;
566 BC.Entry = SpillPlacement::PrefSpill;
567 else if (IP.first < BI.FirstUse)
568 BC.Entry = SpillPlacement::PrefSpill, ++Ins;
569 else if (IP.first < (BI.LiveThrough ? BI.LastUse : BI.Kill))
573 // Interference for the live-out value.
574 if (IP.second.isValid()) {
575 if (IP.second >= BI.LastSplitPoint)
576 BC.Exit = SpillPlacement::MustSpill, Ins += BI.Uses;
578 BC.Exit = SpillPlacement::PrefSpill;
579 else if (IP.second > BI.LastUse)
580 BC.Exit = SpillPlacement::PrefSpill, ++Ins;
581 else if (IP.second > (BI.LiveThrough ? BI.FirstUse : BI.Def))
585 // Accumulate the total frequency of inserted spill code.
587 StaticCost += Ins * SpillPlacer->getBlockFrequency(BC.Number);
593 /// calcGlobalSplitCost - Return the global split cost of following the split
594 /// pattern in LiveBundles. This cost should be added to the local cost of the
595 /// interference pattern in SplitConstraints.
597 float RAGreedy::calcGlobalSplitCost(const BitVector &LiveBundles) {
598 float GlobalCost = 0;
599 for (unsigned i = 0, e = SA->LiveBlocks.size(); i != e; ++i) {
600 SplitAnalysis::BlockInfo &BI = SA->LiveBlocks[i];
601 SpillPlacement::BlockConstraint &BC = SplitConstraints[i];
602 bool RegIn = LiveBundles[Bundles->getBundle(BC.Number, 0)];
603 bool RegOut = LiveBundles[Bundles->getBundle(BC.Number, 1)];
607 Ins += RegIn != RegOut;
610 Ins += RegIn != (BC.Entry == SpillPlacement::PrefReg);
612 Ins += RegOut != (BC.Exit == SpillPlacement::PrefReg);
615 GlobalCost += Ins * SpillPlacer->getBlockFrequency(BC.Number);
620 /// splitAroundRegion - Split VirtReg around the region determined by
621 /// LiveBundles. Make an effort to avoid interference from PhysReg.
623 /// The 'register' interval is going to contain as many uses as possible while
624 /// avoiding interference. The 'stack' interval is the complement constructed by
625 /// SplitEditor. It will contain the rest.
627 void RAGreedy::splitAroundRegion(LiveInterval &VirtReg, unsigned PhysReg,
628 const BitVector &LiveBundles,
629 SmallVectorImpl<LiveInterval*> &NewVRegs) {
631 dbgs() << "Splitting around region for " << PrintReg(PhysReg, TRI)
633 for (int i = LiveBundles.find_first(); i>=0; i = LiveBundles.find_next(i))
634 dbgs() << " EB#" << i;
638 // First compute interference ranges in the live blocks.
639 SmallVector<IndexPair, 8> InterferenceRanges;
640 mapGlobalInterference(PhysReg, InterferenceRanges);
642 LiveRangeEdit LREdit(VirtReg, NewVRegs, this);
645 // Create the main cross-block interval.
648 // First add all defs that are live out of a block.
649 for (unsigned i = 0, e = SA->LiveBlocks.size(); i != e; ++i) {
650 SplitAnalysis::BlockInfo &BI = SA->LiveBlocks[i];
651 bool RegIn = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 0)];
652 bool RegOut = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 1)];
654 // Should the register be live out?
655 if (!BI.LiveOut || !RegOut)
658 IndexPair &IP = InterferenceRanges[i];
659 DEBUG(dbgs() << "BB#" << BI.MBB->getNumber() << " -> EB#"
660 << Bundles->getBundle(BI.MBB->getNumber(), 1)
661 << " [" << BI.Start << ';' << BI.LastSplitPoint << '-'
662 << BI.Stop << ") intf [" << IP.first << ';' << IP.second
665 // The interference interval should either be invalid or overlap MBB.
666 assert((!IP.first.isValid() || IP.first < BI.Stop) && "Bad interference");
667 assert((!IP.second.isValid() || IP.second > BI.Start)
668 && "Bad interference");
670 // Check interference leaving the block.
671 if (!IP.second.isValid()) {
672 // Block is interference-free.
673 DEBUG(dbgs() << ", no interference");
675 assert(BI.LiveThrough && "No uses, but not live through block?");
676 // Block is live-through without interference.
677 DEBUG(dbgs() << ", no uses"
678 << (RegIn ? ", live-through.\n" : ", stack in.\n"));
680 SE->enterIntvAtEnd(*BI.MBB);
683 if (!BI.LiveThrough) {
684 DEBUG(dbgs() << ", not live-through.\n");
685 SE->useIntv(SE->enterIntvBefore(BI.Def), BI.Stop);
689 // Block is live-through, but entry bundle is on the stack.
690 // Reload just before the first use.
691 DEBUG(dbgs() << ", not live-in, enter before first use.\n");
692 SE->useIntv(SE->enterIntvBefore(BI.FirstUse), BI.Stop);
695 DEBUG(dbgs() << ", live-through.\n");
699 // Block has interference.
700 DEBUG(dbgs() << ", interference to " << IP.second);
702 if (!BI.LiveThrough && IP.second <= BI.Def) {
703 // The interference doesn't reach the outgoing segment.
704 DEBUG(dbgs() << " doesn't affect def from " << BI.Def << '\n');
705 SE->useIntv(BI.Def, BI.Stop);
711 // No uses in block, avoid interference by reloading as late as possible.
712 DEBUG(dbgs() << ", no uses.\n");
713 SlotIndex SegStart = SE->enterIntvAtEnd(*BI.MBB);
714 assert(SegStart >= IP.second && "Couldn't avoid interference");
718 if (IP.second.getBoundaryIndex() < BI.LastUse) {
719 // There are interference-free uses at the end of the block.
720 // Find the first use that can get the live-out register.
721 SmallVectorImpl<SlotIndex>::const_iterator UI =
722 std::lower_bound(SA->UseSlots.begin(), SA->UseSlots.end(),
723 IP.second.getBoundaryIndex());
724 assert(UI != SA->UseSlots.end() && "Couldn't find last use");
726 assert(Use <= BI.LastUse && "Couldn't find last use");
727 // Only attempt a split befroe the last split point.
728 if (Use.getBaseIndex() <= BI.LastSplitPoint) {
729 DEBUG(dbgs() << ", free use at " << Use << ".\n");
730 SlotIndex SegStart = SE->enterIntvBefore(Use);
731 assert(SegStart >= IP.second && "Couldn't avoid interference");
732 assert(SegStart < BI.LastSplitPoint && "Impossible split point");
733 SE->useIntv(SegStart, BI.Stop);
738 // Interference is after the last use.
739 DEBUG(dbgs() << " after last use.\n");
740 SlotIndex SegStart = SE->enterIntvAtEnd(*BI.MBB);
741 assert(SegStart >= IP.second && "Couldn't avoid interference");
744 // Now all defs leading to live bundles are handled, do everything else.
745 for (unsigned i = 0, e = SA->LiveBlocks.size(); i != e; ++i) {
746 SplitAnalysis::BlockInfo &BI = SA->LiveBlocks[i];
747 bool RegIn = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 0)];
748 bool RegOut = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 1)];
750 // Is the register live-in?
751 if (!BI.LiveIn || !RegIn)
754 // We have an incoming register. Check for interference.
755 IndexPair &IP = InterferenceRanges[i];
757 DEBUG(dbgs() << "EB#" << Bundles->getBundle(BI.MBB->getNumber(), 0)
758 << " -> BB#" << BI.MBB->getNumber() << " [" << BI.Start << ';'
759 << BI.LastSplitPoint << '-' << BI.Stop << ')');
761 // Check interference entering the block.
762 if (!IP.first.isValid()) {
763 // Block is interference-free.
764 DEBUG(dbgs() << ", no interference");
766 assert(BI.LiveThrough && "No uses, but not live through block?");
767 // Block is live-through without interference.
769 DEBUG(dbgs() << ", no uses, live-through.\n");
770 SE->useIntv(BI.Start, BI.Stop);
772 DEBUG(dbgs() << ", no uses, stack-out.\n");
773 SE->leaveIntvAtTop(*BI.MBB);
777 if (!BI.LiveThrough) {
778 DEBUG(dbgs() << ", killed in block.\n");
779 SE->useIntv(BI.Start, SE->leaveIntvAfter(BI.Kill));
783 // Block is live-through, but exit bundle is on the stack.
784 // Spill immediately after the last use.
785 if (BI.LastUse < BI.LastSplitPoint) {
786 DEBUG(dbgs() << ", uses, stack-out.\n");
787 SE->useIntv(BI.Start, SE->leaveIntvAfter(BI.LastUse));
790 // The last use is after the last split point, it is probably an
792 DEBUG(dbgs() << ", uses at " << BI.LastUse << " after split point "
793 << BI.LastSplitPoint << ", stack-out.\n");
794 SlotIndex SegEnd = SE->leaveIntvBefore(BI.LastSplitPoint);
795 SE->useIntv(BI.Start, SegEnd);
796 // Run a double interval from the split to the last use.
797 // This makes it possible to spill the complement without affecting the
799 SE->overlapIntv(SegEnd, BI.LastUse);
802 // Register is live-through.
803 DEBUG(dbgs() << ", uses, live-through.\n");
804 SE->useIntv(BI.Start, BI.Stop);
808 // Block has interference.
809 DEBUG(dbgs() << ", interference from " << IP.first);
811 if (!BI.LiveThrough && IP.first >= BI.Kill) {
812 // The interference doesn't reach the outgoing segment.
813 DEBUG(dbgs() << " doesn't affect kill at " << BI.Kill << '\n');
814 SE->useIntv(BI.Start, BI.Kill);
819 // No uses in block, avoid interference by spilling as soon as possible.
820 DEBUG(dbgs() << ", no uses.\n");
821 SlotIndex SegEnd = SE->leaveIntvAtTop(*BI.MBB);
822 assert(SegEnd <= IP.first && "Couldn't avoid interference");
825 if (IP.first.getBaseIndex() > BI.FirstUse) {
826 // There are interference-free uses at the beginning of the block.
827 // Find the last use that can get the register.
828 SmallVectorImpl<SlotIndex>::const_iterator UI =
829 std::lower_bound(SA->UseSlots.begin(), SA->UseSlots.end(),
830 IP.first.getBaseIndex());
831 assert(UI != SA->UseSlots.begin() && "Couldn't find first use");
832 SlotIndex Use = (--UI)->getBoundaryIndex();
833 DEBUG(dbgs() << ", free use at " << *UI << ".\n");
834 SlotIndex SegEnd = SE->leaveIntvAfter(Use);
835 assert(SegEnd <= IP.first && "Couldn't avoid interference");
836 SE->useIntv(BI.Start, SegEnd);
840 // Interference is before the first use.
841 DEBUG(dbgs() << " before first use.\n");
842 SlotIndex SegEnd = SE->leaveIntvAtTop(*BI.MBB);
843 assert(SegEnd <= IP.first && "Couldn't avoid interference");
848 // FIXME: Should we be more aggressive about splitting the stack region into
849 // per-block segments? The current approach allows the stack region to
850 // separate into connected components. Some components may be allocatable.
855 MF->verify(this, "After splitting live range around region");
858 // Make sure that at least one of the new intervals can allocate to PhysReg.
859 // That was the whole point of splitting the live range.
861 for (LiveRangeEdit::iterator I = LREdit.begin(), E = LREdit.end(); I != E;
863 if (!checkUncachedInterference(**I, PhysReg)) {
867 assert(found && "No allocatable intervals after pointless splitting");
872 unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
873 SmallVectorImpl<LiveInterval*> &NewVRegs) {
874 BitVector LiveBundles, BestBundles;
876 unsigned BestReg = 0;
879 for (unsigned Cand = 0; unsigned PhysReg = Order.next(); ++Cand) {
880 if (GlobalCand.size() <= Cand)
881 GlobalCand.resize(Cand+1);
882 GlobalCand[Cand].PhysReg = PhysReg;
884 mapGlobalInterference(PhysReg, GlobalCand[Cand].Interference);
885 float Cost = calcSplitConstraints(GlobalCand[Cand].Interference);
886 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tstatic = " << Cost);
887 if (BestReg && Cost >= BestCost) {
888 DEBUG(dbgs() << " higher.\n");
892 SpillPlacer->placeSpills(SplitConstraints, LiveBundles);
893 // No live bundles, defer to splitSingleBlocks().
894 if (!LiveBundles.any()) {
895 DEBUG(dbgs() << " no bundles.\n");
899 Cost += calcGlobalSplitCost(LiveBundles);
901 dbgs() << ", total = " << Cost << " with bundles";
902 for (int i = LiveBundles.find_first(); i>=0; i = LiveBundles.find_next(i))
903 dbgs() << " EB#" << i;
906 if (!BestReg || Cost < BestCost) {
908 BestCost = 0.98f * Cost; // Prevent rounding effects.
909 BestBundles.swap(LiveBundles);
916 splitAroundRegion(VirtReg, BestReg, BestBundles, NewVRegs);
917 setStage(NewVRegs.begin(), NewVRegs.end(), RS_Region);
922 //===----------------------------------------------------------------------===//
924 //===----------------------------------------------------------------------===//
927 /// calcGapWeights - Compute the maximum spill weight that needs to be evicted
928 /// in order to use PhysReg between two entries in SA->UseSlots.
930 /// GapWeight[i] represents the gap between UseSlots[i] and UseSlots[i+1].
932 void RAGreedy::calcGapWeights(unsigned PhysReg,
933 SmallVectorImpl<float> &GapWeight) {
934 assert(SA->LiveBlocks.size() == 1 && "Not a local interval");
935 const SplitAnalysis::BlockInfo &BI = SA->LiveBlocks.front();
936 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
937 const unsigned NumGaps = Uses.size()-1;
939 // Start and end points for the interference check.
940 SlotIndex StartIdx = BI.LiveIn ? BI.FirstUse.getBaseIndex() : BI.FirstUse;
941 SlotIndex StopIdx = BI.LiveOut ? BI.LastUse.getBoundaryIndex() : BI.LastUse;
943 GapWeight.assign(NumGaps, 0.0f);
945 // Add interference from each overlapping register.
946 for (const unsigned *AI = TRI->getOverlaps(PhysReg); *AI; ++AI) {
947 if (!query(const_cast<LiveInterval&>(SA->getParent()), *AI)
948 .checkInterference())
951 // We know that VirtReg is a continuous interval from FirstUse to LastUse,
952 // so we don't need InterferenceQuery.
954 // Interference that overlaps an instruction is counted in both gaps
955 // surrounding the instruction. The exception is interference before
956 // StartIdx and after StopIdx.
958 LiveIntervalUnion::SegmentIter IntI = PhysReg2LiveUnion[*AI].find(StartIdx);
959 for (unsigned Gap = 0; IntI.valid() && IntI.start() < StopIdx; ++IntI) {
960 // Skip the gaps before IntI.
961 while (Uses[Gap+1].getBoundaryIndex() < IntI.start())
962 if (++Gap == NumGaps)
967 // Update the gaps covered by IntI.
968 const float weight = IntI.value()->weight;
969 for (; Gap != NumGaps; ++Gap) {
970 GapWeight[Gap] = std::max(GapWeight[Gap], weight);
971 if (Uses[Gap+1].getBaseIndex() >= IntI.stop())
980 /// getPrevMappedIndex - Return the slot index of the last non-copy instruction
981 /// before MI that has a slot index. If MI is the first mapped instruction in
982 /// its block, return the block start index instead.
984 SlotIndex RAGreedy::getPrevMappedIndex(const MachineInstr *MI) {
985 assert(MI && "Missing MachineInstr");
986 const MachineBasicBlock *MBB = MI->getParent();
987 MachineBasicBlock::const_iterator B = MBB->begin(), I = MI;
989 if (!(--I)->isDebugValue() && !I->isCopy())
990 return Indexes->getInstructionIndex(I);
991 return Indexes->getMBBStartIdx(MBB);
994 /// calcPrevSlots - Fill in the PrevSlot array with the index of the previous
995 /// real non-copy instruction for each instruction in SA->UseSlots.
997 void RAGreedy::calcPrevSlots() {
998 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
1000 PrevSlot.reserve(Uses.size());
1001 for (unsigned i = 0, e = Uses.size(); i != e; ++i) {
1002 const MachineInstr *MI = Indexes->getInstructionFromIndex(Uses[i]);
1003 PrevSlot.push_back(getPrevMappedIndex(MI).getDefIndex());
1007 /// nextSplitPoint - Find the next index into SA->UseSlots > i such that it may
1008 /// be beneficial to split before UseSlots[i].
1010 /// 0 is always a valid split point
1011 unsigned RAGreedy::nextSplitPoint(unsigned i) {
1012 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
1013 const unsigned Size = Uses.size();
1014 assert(i != Size && "No split points after the end");
1015 // Allow split before i when Uses[i] is not adjacent to the previous use.
1016 while (++i != Size && PrevSlot[i].getBaseIndex() <= Uses[i-1].getBaseIndex())
1021 /// tryLocalSplit - Try to split VirtReg into smaller intervals inside its only
1024 unsigned RAGreedy::tryLocalSplit(LiveInterval &VirtReg, AllocationOrder &Order,
1025 SmallVectorImpl<LiveInterval*> &NewVRegs) {
1026 assert(SA->LiveBlocks.size() == 1 && "Not a local interval");
1027 const SplitAnalysis::BlockInfo &BI = SA->LiveBlocks.front();
1029 // Note that it is possible to have an interval that is live-in or live-out
1030 // while only covering a single block - A phi-def can use undef values from
1031 // predecessors, and the block could be a single-block loop.
1032 // We don't bother doing anything clever about such a case, we simply assume
1033 // that the interval is continuous from FirstUse to LastUse. We should make
1034 // sure that we don't do anything illegal to such an interval, though.
1036 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
1037 if (Uses.size() <= 2)
1039 const unsigned NumGaps = Uses.size()-1;
1042 dbgs() << "tryLocalSplit: ";
1043 for (unsigned i = 0, e = Uses.size(); i != e; ++i)
1044 dbgs() << ' ' << SA->UseSlots[i];
1048 // For every use, find the previous mapped non-copy instruction.
1049 // We use this to detect valid split points, and to estimate new interval
1053 unsigned BestBefore = NumGaps;
1054 unsigned BestAfter = 0;
1057 const float blockFreq = SpillPlacer->getBlockFrequency(BI.MBB->getNumber());
1058 SmallVector<float, 8> GapWeight;
1061 while (unsigned PhysReg = Order.next()) {
1062 // Keep track of the largest spill weight that would need to be evicted in
1063 // order to make use of PhysReg between UseSlots[i] and UseSlots[i+1].
1064 calcGapWeights(PhysReg, GapWeight);
1066 // Try to find the best sequence of gaps to close.
1067 // The new spill weight must be larger than any gap interference.
1069 // We will split before Uses[SplitBefore] and after Uses[SplitAfter].
1070 unsigned SplitBefore = 0, SplitAfter = nextSplitPoint(1) - 1;
1072 // MaxGap should always be max(GapWeight[SplitBefore..SplitAfter-1]).
1073 // It is the spill weight that needs to be evicted.
1074 float MaxGap = GapWeight[0];
1075 for (unsigned i = 1; i != SplitAfter; ++i)
1076 MaxGap = std::max(MaxGap, GapWeight[i]);
1079 // Live before/after split?
1080 const bool LiveBefore = SplitBefore != 0 || BI.LiveIn;
1081 const bool LiveAfter = SplitAfter != NumGaps || BI.LiveOut;
1083 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << ' '
1084 << Uses[SplitBefore] << '-' << Uses[SplitAfter]
1085 << " i=" << MaxGap);
1087 // Stop before the interval gets so big we wouldn't be making progress.
1088 if (!LiveBefore && !LiveAfter) {
1089 DEBUG(dbgs() << " all\n");
1092 // Should the interval be extended or shrunk?
1094 if (MaxGap < HUGE_VALF) {
1095 // Estimate the new spill weight.
1097 // Each instruction reads and writes the register, except the first
1098 // instr doesn't read when !FirstLive, and the last instr doesn't write
1101 // We will be inserting copies before and after, so the total number of
1102 // reads and writes is 2 * EstUses.
1104 const unsigned EstUses = 2*(SplitAfter - SplitBefore) +
1105 2*(LiveBefore + LiveAfter);
1107 // Try to guess the size of the new interval. This should be trivial,
1108 // but the slot index of an inserted copy can be a lot smaller than the
1109 // instruction it is inserted before if there are many dead indexes
1112 // We measure the distance from the instruction before SplitBefore to
1113 // get a conservative estimate.
1115 // The final distance can still be different if inserting copies
1116 // triggers a slot index renumbering.
1118 const float EstWeight = normalizeSpillWeight(blockFreq * EstUses,
1119 PrevSlot[SplitBefore].distance(Uses[SplitAfter]));
1120 // Would this split be possible to allocate?
1121 // Never allocate all gaps, we wouldn't be making progress.
1122 float Diff = EstWeight - MaxGap;
1123 DEBUG(dbgs() << " w=" << EstWeight << " d=" << Diff);
1126 if (Diff > BestDiff) {
1127 DEBUG(dbgs() << " (best)");
1129 BestBefore = SplitBefore;
1130 BestAfter = SplitAfter;
1137 SplitBefore = nextSplitPoint(SplitBefore);
1138 if (SplitBefore < SplitAfter) {
1139 DEBUG(dbgs() << " shrink\n");
1140 // Recompute the max when necessary.
1141 if (GapWeight[SplitBefore - 1] >= MaxGap) {
1142 MaxGap = GapWeight[SplitBefore];
1143 for (unsigned i = SplitBefore + 1; i != SplitAfter; ++i)
1144 MaxGap = std::max(MaxGap, GapWeight[i]);
1151 // Try to extend the interval.
1152 if (SplitAfter >= NumGaps) {
1153 DEBUG(dbgs() << " end\n");
1157 DEBUG(dbgs() << " extend\n");
1158 for (unsigned e = nextSplitPoint(SplitAfter + 1) - 1;
1159 SplitAfter != e; ++SplitAfter)
1160 MaxGap = std::max(MaxGap, GapWeight[SplitAfter]);
1165 // Didn't find any candidates?
1166 if (BestBefore == NumGaps)
1169 DEBUG(dbgs() << "Best local split range: " << Uses[BestBefore]
1170 << '-' << Uses[BestAfter] << ", " << BestDiff
1171 << ", " << (BestAfter - BestBefore + 1) << " instrs\n");
1173 LiveRangeEdit LREdit(VirtReg, NewVRegs, this);
1177 SlotIndex SegStart = SE->enterIntvBefore(Uses[BestBefore]);
1178 SlotIndex SegStop = SE->leaveIntvAfter(Uses[BestAfter]);
1179 SE->useIntv(SegStart, SegStop);
1182 setStage(NewVRegs.begin(), NewVRegs.end(), RS_Local);
1188 //===----------------------------------------------------------------------===//
1189 // Live Range Splitting
1190 //===----------------------------------------------------------------------===//
1192 /// trySplit - Try to split VirtReg or one of its interferences, making it
1194 /// @return Physreg when VirtReg may be assigned and/or new NewVRegs.
1195 unsigned RAGreedy::trySplit(LiveInterval &VirtReg, AllocationOrder &Order,
1196 SmallVectorImpl<LiveInterval*>&NewVRegs) {
1197 // Local intervals are handled separately.
1198 if (LIS->intervalIsInOneMBB(VirtReg)) {
1199 NamedRegionTimer T("Local Splitting", TimerGroupName, TimePassesIsEnabled);
1200 SA->analyze(&VirtReg);
1201 return tryLocalSplit(VirtReg, Order, NewVRegs);
1204 NamedRegionTimer T("Global Splitting", TimerGroupName, TimePassesIsEnabled);
1206 // Don't iterate global splitting.
1207 // Move straight to spilling if this range was produced by a global split.
1208 LiveRangeStage Stage = getStage(VirtReg);
1209 if (Stage >= RS_Block)
1212 SA->analyze(&VirtReg);
1214 // First try to split around a region spanning multiple blocks.
1215 if (Stage < RS_Region) {
1216 unsigned PhysReg = tryRegionSplit(VirtReg, Order, NewVRegs);
1217 if (PhysReg || !NewVRegs.empty())
1221 // Then isolate blocks with multiple uses.
1222 if (Stage < RS_Block) {
1223 SplitAnalysis::BlockPtrSet Blocks;
1224 if (SA->getMultiUseBlocks(Blocks)) {
1225 LiveRangeEdit LREdit(VirtReg, NewVRegs, this);
1227 SE->splitSingleBlocks(Blocks);
1228 setStage(NewVRegs.begin(), NewVRegs.end(), RS_Block);
1230 MF->verify(this, "After splitting live range around basic blocks");
1234 // Don't assign any physregs.
1239 //===----------------------------------------------------------------------===//
1241 //===----------------------------------------------------------------------===//
1243 unsigned RAGreedy::selectOrSplit(LiveInterval &VirtReg,
1244 SmallVectorImpl<LiveInterval*> &NewVRegs) {
1245 LiveRangeStage Stage = getStage(VirtReg);
1246 if (Stage == RS_Original)
1247 LRStage[VirtReg.reg] = RS_Second;
1249 // First try assigning a free register.
1250 AllocationOrder Order(VirtReg.reg, *VRM, ReservedRegs);
1251 while (unsigned PhysReg = Order.next()) {
1252 if (!checkPhysRegInterference(VirtReg, PhysReg))
1256 if (unsigned PhysReg = tryReassign(VirtReg, Order, NewVRegs))
1259 if (unsigned PhysReg = tryEvict(VirtReg, Order, NewVRegs))
1262 assert(NewVRegs.empty() && "Cannot append to existing NewVRegs");
1264 // The first time we see a live range, don't try to split or spill.
1265 // Wait until the second time, when all smaller ranges have been allocated.
1266 // This gives a better picture of the interference to split around.
1267 if (Stage == RS_Original) {
1268 NewVRegs.push_back(&VirtReg);
1272 assert(Stage < RS_Spill && "Cannot allocate after spilling");
1274 // Try splitting VirtReg or interferences.
1275 unsigned PhysReg = trySplit(VirtReg, Order, NewVRegs);
1276 if (PhysReg || !NewVRegs.empty())
1279 // Finally spill VirtReg itself.
1280 NamedRegionTimer T("Spiller", TimerGroupName, TimePassesIsEnabled);
1281 LiveRangeEdit LRE(VirtReg, NewVRegs, this);
1282 spiller().spill(LRE);
1285 MF->verify(this, "After spilling");
1287 // The live virtual register requesting allocation was spilled, so tell
1288 // the caller not to allocate anything during this round.
1292 bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
1293 DEBUG(dbgs() << "********** GREEDY REGISTER ALLOCATION **********\n"
1294 << "********** Function: "
1295 << ((Value*)mf.getFunction())->getName() << '\n');
1299 MF->verify(this, "Before greedy register allocator");
1301 RegAllocBase::init(getAnalysis<VirtRegMap>(), getAnalysis<LiveIntervals>());
1302 Indexes = &getAnalysis<SlotIndexes>();
1303 DomTree = &getAnalysis<MachineDominatorTree>();
1304 ReservedRegs = TRI->getReservedRegs(*MF);
1305 SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
1306 Loops = &getAnalysis<MachineLoopInfo>();
1307 LoopRanges = &getAnalysis<MachineLoopRanges>();
1308 Bundles = &getAnalysis<EdgeBundles>();
1309 SpillPlacer = &getAnalysis<SpillPlacement>();
1311 SA.reset(new SplitAnalysis(*VRM, *LIS, *Loops));
1312 SE.reset(new SplitEditor(*SA, *LIS, *VRM, *DomTree));
1314 LRStage.resize(MRI->getNumVirtRegs());
1318 LIS->addKillFlags();
1322 NamedRegionTimer T("Rewriter", TimerGroupName, TimePassesIsEnabled);
1323 VRM->rewrite(Indexes);
1326 // The pass output is in VirtRegMap. Release all the transient data.