blob: ef391434289b21d5d156fa12ad035dc4cb71a273 [file] [log] [blame]
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001//===-- RegAllocGreedy.cpp - greedy register allocator --------------------===//
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 defines the RAGreedy function pass for register allocation in
11// optimized builds.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "regalloc"
Jakob Stoklund Olesendd479e92010-12-10 22:21:05 +000016#include "AllocationOrder.h"
Jakob Stoklund Olesen5907d862011-04-02 06:03:35 +000017#include "InterferenceCache.h"
Jakob Stoklund Olesencfafc542011-04-05 21:40:37 +000018#include "LiveDebugVariables.h"
Jakob Stoklund Olesenf428eb62010-12-17 23:16:32 +000019#include "LiveRangeEdit.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000020#include "RegAllocBase.h"
21#include "Spiller.h"
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +000022#include "SpillPlacement.h"
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +000023#include "SplitKit.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000024#include "VirtRegMap.h"
Jakob Stoklund Olesen0db841f2011-02-17 22:53:48 +000025#include "llvm/ADT/Statistic.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000026#include "llvm/Analysis/AliasAnalysis.h"
27#include "llvm/Function.h"
28#include "llvm/PassAnalysisSupport.h"
29#include "llvm/CodeGen/CalcSpillWeights.h"
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +000030#include "llvm/CodeGen/EdgeBundles.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000031#include "llvm/CodeGen/LiveIntervalAnalysis.h"
32#include "llvm/CodeGen/LiveStackAnalysis.h"
Jakob Stoklund Olesenf428eb62010-12-17 23:16:32 +000033#include "llvm/CodeGen/MachineDominators.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000034#include "llvm/CodeGen/MachineFunctionPass.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000035#include "llvm/CodeGen/MachineLoopInfo.h"
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +000036#include "llvm/CodeGen/MachineLoopRanges.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000037#include "llvm/CodeGen/MachineRegisterInfo.h"
38#include "llvm/CodeGen/Passes.h"
39#include "llvm/CodeGen/RegAllocRegistry.h"
40#include "llvm/CodeGen/RegisterCoalescer.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000041#include "llvm/Target/TargetOptions.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000042#include "llvm/Support/Debug.h"
43#include "llvm/Support/ErrorHandling.h"
44#include "llvm/Support/raw_ostream.h"
Jakob Stoklund Olesen533f58e2010-12-11 00:19:56 +000045#include "llvm/Support/Timer.h"
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000046
Jakob Stoklund Olesen98d96482011-02-22 23:01:52 +000047#include <queue>
48
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000049using namespace llvm;
50
Jakob Stoklund Olesen0db841f2011-02-17 22:53:48 +000051STATISTIC(NumGlobalSplits, "Number of split global live ranges");
52STATISTIC(NumLocalSplits, "Number of split local live ranges");
Jakob Stoklund Olesen0db841f2011-02-17 22:53:48 +000053STATISTIC(NumEvicted, "Number of interferences evicted");
54
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000055static RegisterRegAlloc greedyRegAlloc("greedy", "greedy register allocator",
56 createGreedyRegisterAllocator);
57
58namespace {
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +000059class RAGreedy : public MachineFunctionPass,
60 public RegAllocBase,
61 private LiveRangeEdit::Delegate {
62
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000063 // context
64 MachineFunction *MF;
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000065 BitVector ReservedRegs;
66
67 // analyses
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +000068 SlotIndexes *Indexes;
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000069 LiveStacks *LS;
Jakob Stoklund Olesenf428eb62010-12-17 23:16:32 +000070 MachineDominatorTree *DomTree;
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +000071 MachineLoopInfo *Loops;
72 MachineLoopRanges *LoopRanges;
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +000073 EdgeBundles *Bundles;
74 SpillPlacement *SpillPlacer;
Jakob Stoklund Olesenf428eb62010-12-17 23:16:32 +000075
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +000076 // state
77 std::auto_ptr<Spiller> SpillerInstance;
Jakob Stoklund Olesen98d96482011-02-22 23:01:52 +000078 std::priority_queue<std::pair<unsigned, unsigned> > Queue;
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +000079
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:
82 //
83 // - Region splitting.
84 // - Per-block splitting.
85 // - Local splitting.
86 // - Spilling.
87 //
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
92 // ensure.
93 enum LiveRangeStage {
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +000094 RS_New, ///< Never seen before.
95 RS_First, ///< First time in the queue.
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +000096 RS_Second, ///< Second time in the queue.
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +000097 RS_Global, ///< Produced by global splitting.
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +000098 RS_Local, ///< Produced by local splitting.
99 RS_Spill ///< Produced by spilling.
100 };
101
102 IndexedMap<unsigned char, VirtReg2IndexFunctor> LRStage;
103
104 LiveRangeStage getStage(const LiveInterval &VirtReg) const {
105 return LiveRangeStage(LRStage[VirtReg.reg]);
106 }
107
108 template<typename Iterator>
109 void setStage(Iterator Begin, Iterator End, LiveRangeStage NewStage) {
110 LRStage.resize(MRI->getNumVirtRegs());
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +0000111 for (;Begin != End; ++Begin) {
112 unsigned Reg = (*Begin)->reg;
113 if (LRStage[Reg] == RS_New)
114 LRStage[Reg] = NewStage;
115 }
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +0000116 }
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000117
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000118 // splitting state.
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +0000119 std::auto_ptr<SplitAnalysis> SA;
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000120 std::auto_ptr<SplitEditor> SE;
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000121
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000122 /// Cached per-block interference maps
123 InterferenceCache IntfCache;
124
Jakob Stoklund Olesen7b41fbe2011-04-07 17:27:46 +0000125 /// All basic blocks where the current register has uses.
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000126 SmallVector<SpillPlacement::BlockConstraint, 8> SplitConstraints;
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000127
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000128 /// Global live range splitting candidate info.
129 struct GlobalSplitCandidate {
130 unsigned PhysReg;
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000131 BitVector LiveBundles;
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000132 SmallVector<unsigned, 8> ActiveBlocks;
133
134 void reset(unsigned Reg) {
135 PhysReg = Reg;
136 LiveBundles.clear();
137 ActiveBlocks.clear();
138 }
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000139 };
140
141 /// Candidate info for for each PhysReg in AllocationOrder.
142 /// This vector never shrinks, but grows to the size of the largest register
143 /// class.
144 SmallVector<GlobalSplitCandidate, 32> GlobalCand;
145
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000146 /// For every instruction in SA->UseSlots, store the previous non-copy
147 /// instruction.
148 SmallVector<SlotIndex, 8> PrevSlot;
149
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000150public:
151 RAGreedy();
152
153 /// Return the pass name.
154 virtual const char* getPassName() const {
Jakob Stoklund Olesen533f58e2010-12-11 00:19:56 +0000155 return "Greedy Register Allocator";
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000156 }
157
158 /// RAGreedy analysis usage.
159 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000160 virtual void releaseMemory();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000161 virtual Spiller &spiller() { return *SpillerInstance; }
Jakob Stoklund Olesen98d96482011-02-22 23:01:52 +0000162 virtual void enqueue(LiveInterval *LI);
163 virtual LiveInterval *dequeue();
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000164 virtual unsigned selectOrSplit(LiveInterval&,
165 SmallVectorImpl<LiveInterval*>&);
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000166
167 /// Perform register allocation.
168 virtual bool runOnMachineFunction(MachineFunction &mf);
169
170 static char ID;
Andrew Trickb853e6c2010-12-09 18:15:21 +0000171
172private:
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +0000173 void LRE_WillEraseInstruction(MachineInstr*);
Jakob Stoklund Olesen7792e982011-03-13 01:23:11 +0000174 bool LRE_CanEraseVirtReg(unsigned);
Jakob Stoklund Olesen1d5b8452011-03-16 22:56:16 +0000175 void LRE_WillShrinkVirtReg(unsigned);
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +0000176 void LRE_DidCloneVirtReg(unsigned, unsigned);
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +0000177
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000178 bool addSplitConstraints(InterferenceCache::Cursor, float&);
179 void addThroughConstraints(InterferenceCache::Cursor, ArrayRef<unsigned>);
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000180 void growRegion(GlobalSplitCandidate &Cand, InterferenceCache::Cursor);
181 float calcGlobalSplitCost(GlobalSplitCandidate&, InterferenceCache::Cursor);
182 void splitAroundRegion(LiveInterval&, GlobalSplitCandidate&,
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000183 SmallVectorImpl<LiveInterval*>&);
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000184 void calcGapWeights(unsigned, SmallVectorImpl<float>&);
185 SlotIndex getPrevMappedIndex(const MachineInstr*);
186 void calcPrevSlots();
187 unsigned nextSplitPoint(unsigned);
Jakob Stoklund Olesend17924b2011-03-04 21:32:50 +0000188 bool canEvictInterference(LiveInterval&, unsigned, float&);
Jakob Stoklund Olesenb64d92e2010-12-14 00:37:44 +0000189
Jakob Stoklund Olesen6bfba2e2011-04-20 18:19:48 +0000190 unsigned tryAssign(LiveInterval&, AllocationOrder&,
191 SmallVectorImpl<LiveInterval*>&);
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000192 unsigned tryEvict(LiveInterval&, AllocationOrder&,
Jakob Stoklund Olesen6bfba2e2011-04-20 18:19:48 +0000193 SmallVectorImpl<LiveInterval*>&, unsigned = ~0u);
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000194 unsigned tryRegionSplit(LiveInterval&, AllocationOrder&,
195 SmallVectorImpl<LiveInterval*>&);
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000196 unsigned tryLocalSplit(LiveInterval&, AllocationOrder&,
197 SmallVectorImpl<LiveInterval*>&);
Jakob Stoklund Olesenb64d92e2010-12-14 00:37:44 +0000198 unsigned trySplit(LiveInterval&, AllocationOrder&,
199 SmallVectorImpl<LiveInterval*>&);
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000200};
201} // end anonymous namespace
202
203char RAGreedy::ID = 0;
204
205FunctionPass* llvm::createGreedyRegisterAllocator() {
206 return new RAGreedy();
207}
208
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +0000209RAGreedy::RAGreedy(): MachineFunctionPass(ID), LRStage(RS_New) {
Jakob Stoklund Olesencfafc542011-04-05 21:40:37 +0000210 initializeLiveDebugVariablesPass(*PassRegistry::getPassRegistry());
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000211 initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000212 initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
213 initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
214 initializeStrongPHIEliminationPass(*PassRegistry::getPassRegistry());
215 initializeRegisterCoalescerAnalysisGroup(*PassRegistry::getPassRegistry());
216 initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
217 initializeLiveStacksPass(*PassRegistry::getPassRegistry());
218 initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry());
219 initializeMachineLoopInfoPass(*PassRegistry::getPassRegistry());
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +0000220 initializeMachineLoopRangesPass(*PassRegistry::getPassRegistry());
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000221 initializeVirtRegMapPass(*PassRegistry::getPassRegistry());
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000222 initializeEdgeBundlesPass(*PassRegistry::getPassRegistry());
223 initializeSpillPlacementPass(*PassRegistry::getPassRegistry());
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000224}
225
226void RAGreedy::getAnalysisUsage(AnalysisUsage &AU) const {
227 AU.setPreservesCFG();
228 AU.addRequired<AliasAnalysis>();
229 AU.addPreserved<AliasAnalysis>();
230 AU.addRequired<LiveIntervals>();
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000231 AU.addRequired<SlotIndexes>();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000232 AU.addPreserved<SlotIndexes>();
Jakob Stoklund Olesencfafc542011-04-05 21:40:37 +0000233 AU.addRequired<LiveDebugVariables>();
234 AU.addPreserved<LiveDebugVariables>();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000235 if (StrongPHIElim)
236 AU.addRequiredID(StrongPHIEliminationID);
237 AU.addRequiredTransitive<RegisterCoalescer>();
238 AU.addRequired<CalculateSpillWeights>();
239 AU.addRequired<LiveStacks>();
240 AU.addPreserved<LiveStacks>();
Jakob Stoklund Olesenf428eb62010-12-17 23:16:32 +0000241 AU.addRequired<MachineDominatorTree>();
242 AU.addPreserved<MachineDominatorTree>();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000243 AU.addRequired<MachineLoopInfo>();
244 AU.addPreserved<MachineLoopInfo>();
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +0000245 AU.addRequired<MachineLoopRanges>();
246 AU.addPreserved<MachineLoopRanges>();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000247 AU.addRequired<VirtRegMap>();
248 AU.addPreserved<VirtRegMap>();
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000249 AU.addRequired<EdgeBundles>();
250 AU.addRequired<SpillPlacement>();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000251 MachineFunctionPass::getAnalysisUsage(AU);
252}
253
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +0000254
255//===----------------------------------------------------------------------===//
256// LiveRangeEdit delegate methods
257//===----------------------------------------------------------------------===//
258
259void RAGreedy::LRE_WillEraseInstruction(MachineInstr *MI) {
260 // LRE itself will remove from SlotIndexes and parent basic block.
261 VRM->RemoveMachineInstrFromMaps(MI);
262}
263
Jakob Stoklund Olesen7792e982011-03-13 01:23:11 +0000264bool RAGreedy::LRE_CanEraseVirtReg(unsigned VirtReg) {
265 if (unsigned PhysReg = VRM->getPhys(VirtReg)) {
266 unassign(LIS->getInterval(VirtReg), PhysReg);
267 return true;
268 }
269 // Unassigned virtreg is probably in the priority queue.
270 // RegAllocBase will erase it after dequeueing.
271 return false;
272}
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +0000273
Jakob Stoklund Olesen1d5b8452011-03-16 22:56:16 +0000274void RAGreedy::LRE_WillShrinkVirtReg(unsigned VirtReg) {
275 unsigned PhysReg = VRM->getPhys(VirtReg);
276 if (!PhysReg)
277 return;
278
279 // Register is assigned, put it back on the queue for reassignment.
280 LiveInterval &LI = LIS->getInterval(VirtReg);
281 unassign(LI, PhysReg);
282 enqueue(&LI);
283}
284
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +0000285void RAGreedy::LRE_DidCloneVirtReg(unsigned New, unsigned Old) {
286 // LRE may clone a virtual register because dead code elimination causes it to
287 // be split into connected components. Ensure that the new register gets the
288 // same stage as the parent.
289 LRStage.grow(New);
290 LRStage[New] = LRStage[Old];
291}
292
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000293void RAGreedy::releaseMemory() {
294 SpillerInstance.reset(0);
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +0000295 LRStage.clear();
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000296 GlobalCand.clear();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +0000297 RegAllocBase::releaseMemory();
298}
299
Jakob Stoklund Olesen98d96482011-02-22 23:01:52 +0000300void RAGreedy::enqueue(LiveInterval *LI) {
301 // Prioritize live ranges by size, assigning larger ranges first.
302 // The queue holds (size, reg) pairs.
Jakob Stoklund Olesen107d3662011-02-24 23:21:36 +0000303 const unsigned Size = LI->getSize();
304 const unsigned Reg = LI->reg;
Jakob Stoklund Olesen98d96482011-02-22 23:01:52 +0000305 assert(TargetRegisterInfo::isVirtualRegister(Reg) &&
306 "Can only enqueue virtual registers");
Jakob Stoklund Olesen107d3662011-02-24 23:21:36 +0000307 unsigned Prio;
Jakob Stoklund Olesen90c1d7d2010-12-08 22:57:16 +0000308
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +0000309 LRStage.grow(Reg);
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +0000310 if (LRStage[Reg] == RS_New)
311 LRStage[Reg] = RS_First;
312
Jakob Stoklund Oleseneb291572011-03-27 22:49:21 +0000313 if (LRStage[Reg] == RS_Second)
314 // Unsplit ranges that couldn't be allocated immediately are deferred until
315 // everything else has been allocated. Long ranges are allocated last so
316 // they are split against realistic interference.
317 Prio = (1u << 31) - Size;
318 else {
319 // Everything else is allocated in long->short order. Long ranges that don't
320 // fit should be spilled ASAP so they don't create interference.
Jakob Stoklund Olesen107d3662011-02-24 23:21:36 +0000321 Prio = (1u << 31) + Size;
Jakob Stoklund Olesend2a50732011-02-23 00:56:56 +0000322
Jakob Stoklund Oleseneb291572011-03-27 22:49:21 +0000323 // Boost ranges that have a physical register hint.
324 if (TargetRegisterInfo::isPhysicalRegister(VRM->getRegAllocPref(Reg)))
325 Prio |= (1u << 30);
326 }
Jakob Stoklund Olesen107d3662011-02-24 23:21:36 +0000327
328 Queue.push(std::make_pair(Prio, Reg));
Jakob Stoklund Olesen90c1d7d2010-12-08 22:57:16 +0000329}
330
Jakob Stoklund Olesen98d96482011-02-22 23:01:52 +0000331LiveInterval *RAGreedy::dequeue() {
332 if (Queue.empty())
333 return 0;
334 LiveInterval *LI = &LIS->getInterval(Queue.top().second);
335 Queue.pop();
336 return LI;
337}
Jakob Stoklund Olesen770d42d2010-12-22 22:01:30 +0000338
Jakob Stoklund Olesen6bfba2e2011-04-20 18:19:48 +0000339
340//===----------------------------------------------------------------------===//
341// Direct Assignment
342//===----------------------------------------------------------------------===//
343
344/// tryAssign - Try to assign VirtReg to an available register.
345unsigned RAGreedy::tryAssign(LiveInterval &VirtReg,
346 AllocationOrder &Order,
347 SmallVectorImpl<LiveInterval*> &NewVRegs) {
348 Order.rewind();
349 unsigned PhysReg;
350 while ((PhysReg = Order.next()))
351 if (!checkPhysRegInterference(VirtReg, PhysReg))
352 break;
353 if (!PhysReg || Order.isHint(PhysReg))
354 return PhysReg;
355
356 // PhysReg is available. Try to evict interference from a cheaper alternative.
357 unsigned Cost = TRI->getCostPerUse(PhysReg);
358
359 // Most registers have 0 additional cost.
360 if (!Cost)
361 return PhysReg;
362
363 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << " is available at cost " << Cost
364 << '\n');
365 unsigned CheapReg = tryEvict(VirtReg, Order, NewVRegs, Cost);
366 return CheapReg ? CheapReg : PhysReg;
367}
368
369
Jakob Stoklund Olesen770d42d2010-12-22 22:01:30 +0000370//===----------------------------------------------------------------------===//
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000371// Interference eviction
372//===----------------------------------------------------------------------===//
373
374/// canEvict - Return true if all interferences between VirtReg and PhysReg can
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000375/// be evicted.
376/// Return false if any interference is heavier than MaxWeight.
377/// On return, set MaxWeight to the maximal spill weight of an interference.
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000378bool RAGreedy::canEvictInterference(LiveInterval &VirtReg, unsigned PhysReg,
Jakob Stoklund Olesend17924b2011-03-04 21:32:50 +0000379 float &MaxWeight) {
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000380 float Weight = 0;
381 for (const unsigned *AliasI = TRI->getOverlaps(PhysReg); *AliasI; ++AliasI) {
382 LiveIntervalUnion::Query &Q = query(VirtReg, *AliasI);
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000383 // If there is 10 or more interferences, chances are one is heavier.
384 if (Q.collectInterferingVRegs(10, MaxWeight) >= 10)
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000385 return false;
386
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000387 // Check if any interfering live range is heavier than MaxWeight.
388 for (unsigned i = Q.interferingVRegs().size(); i; --i) {
389 LiveInterval *Intf = Q.interferingVRegs()[i - 1];
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000390 if (TargetRegisterInfo::isPhysicalRegister(Intf->reg))
391 return false;
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000392 if (Intf->weight >= MaxWeight)
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000393 return false;
394 Weight = std::max(Weight, Intf->weight);
Jakob Stoklund Olesen27106382011-02-09 01:14:03 +0000395 }
396 }
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000397 MaxWeight = Weight;
398 return true;
399}
Jakob Stoklund Olesen27106382011-02-09 01:14:03 +0000400
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000401/// tryEvict - Try to evict all interferences for a physreg.
402/// @param VirtReg Currently unassigned virtual register.
403/// @param Order Physregs to try.
404/// @return Physreg to assign VirtReg, or 0.
405unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
406 AllocationOrder &Order,
Jakob Stoklund Olesen6bfba2e2011-04-20 18:19:48 +0000407 SmallVectorImpl<LiveInterval*> &NewVRegs,
408 unsigned CostPerUseLimit) {
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000409 NamedRegionTimer T("Evict", TimerGroupName, TimePassesIsEnabled);
410
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000411 // Keep track of the lightest single interference seen so far.
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000412 float BestWeight = VirtReg.weight;
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000413 unsigned BestPhys = 0;
414
415 Order.rewind();
416 while (unsigned PhysReg = Order.next()) {
Jakob Stoklund Olesen6bfba2e2011-04-20 18:19:48 +0000417 if (TRI->getCostPerUse(PhysReg) >= CostPerUseLimit)
418 continue;
419 // The first use of a register in a function has cost 1.
420 if (CostPerUseLimit == 1 && !MRI->isPhysRegUsed(PhysReg))
421 continue;
422
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000423 float Weight = BestWeight;
Jakob Stoklund Olesend17924b2011-03-04 21:32:50 +0000424 if (!canEvictInterference(VirtReg, PhysReg, Weight))
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000425 continue;
426
427 // This is an eviction candidate.
Jakob Stoklund Olesen3f5bedf2011-04-11 21:47:01 +0000428 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << " interference = "
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000429 << Weight << '\n');
430 if (BestPhys && Weight >= BestWeight)
431 continue;
432
433 // Best so far.
434 BestPhys = PhysReg;
435 BestWeight = Weight;
Jakob Stoklund Olesen57f1e2c2011-02-25 01:04:22 +0000436 // Stop if the hint can be used.
437 if (Order.isHint(PhysReg))
438 break;
Jakob Stoklund Olesen27106382011-02-09 01:14:03 +0000439 }
440
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +0000441 if (!BestPhys)
442 return 0;
443
444 DEBUG(dbgs() << "evicting " << PrintReg(BestPhys, TRI) << " interference\n");
445 for (const unsigned *AliasI = TRI->getOverlaps(BestPhys); *AliasI; ++AliasI) {
446 LiveIntervalUnion::Query &Q = query(VirtReg, *AliasI);
447 assert(Q.seenAllInterferences() && "Didn't check all interfererences.");
448 for (unsigned i = 0, e = Q.interferingVRegs().size(); i != e; ++i) {
449 LiveInterval *Intf = Q.interferingVRegs()[i];
450 unassign(*Intf, VRM->getPhys(Intf->reg));
451 ++NumEvicted;
452 NewVRegs.push_back(Intf);
453 }
454 }
455 return BestPhys;
Andrew Trickb853e6c2010-12-09 18:15:21 +0000456}
457
Jakob Stoklund Olesen770d42d2010-12-22 22:01:30 +0000458
459//===----------------------------------------------------------------------===//
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000460// Region Splitting
461//===----------------------------------------------------------------------===//
462
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000463/// addSplitConstraints - Fill out the SplitConstraints vector based on the
464/// interference pattern in Physreg and its aliases. Add the constraints to
465/// SpillPlacement and return the static cost of this split in Cost, assuming
466/// that all preferences in SplitConstraints are met.
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000467/// Return false if there are no bundles with positive bias.
468bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf,
469 float &Cost) {
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000470 ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000471
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000472 // Reset interference dependent info.
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000473 SplitConstraints.resize(UseBlocks.size());
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000474 float StaticCost = 0;
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000475 for (unsigned i = 0; i != UseBlocks.size(); ++i) {
476 const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000477 SpillPlacement::BlockConstraint &BC = SplitConstraints[i];
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000478
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +0000479 BC.Number = BI.MBB->getNumber();
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000480 Intf.moveToBlock(BC.Number);
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000481 BC.Entry = BI.LiveIn ? SpillPlacement::PrefReg : SpillPlacement::DontCare;
482 BC.Exit = BI.LiveOut ? SpillPlacement::PrefReg : SpillPlacement::DontCare;
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000483
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000484 if (!Intf.hasInterference())
485 continue;
486
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000487 // Number of spill code instructions to insert.
488 unsigned Ins = 0;
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000489
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000490 // Interference for the live-in value.
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000491 if (BI.LiveIn) {
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000492 if (Intf.first() <= Indexes->getMBBStartIdx(BC.Number))
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000493 BC.Entry = SpillPlacement::MustSpill, ++Ins;
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000494 else if (Intf.first() < BI.FirstUse)
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000495 BC.Entry = SpillPlacement::PrefSpill, ++Ins;
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000496 else if (Intf.first() < (BI.LiveThrough ? BI.LastUse : BI.Kill))
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000497 ++Ins;
Jakob Stoklund Olesena50c5392011-02-08 23:02:58 +0000498 }
499
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000500 // Interference for the live-out value.
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000501 if (BI.LiveOut) {
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000502 if (Intf.last() >= SA->getLastSplitPoint(BC.Number))
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000503 BC.Exit = SpillPlacement::MustSpill, ++Ins;
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000504 else if (Intf.last() > BI.LastUse)
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000505 BC.Exit = SpillPlacement::PrefSpill, ++Ins;
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000506 else if (Intf.last() > (BI.LiveThrough ? BI.FirstUse : BI.Def))
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000507 ++Ins;
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000508 }
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000509
510 // Accumulate the total frequency of inserted spill code.
511 if (Ins)
512 StaticCost += Ins * SpillPlacer->getBlockFrequency(BC.Number);
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000513 }
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000514 Cost = StaticCost;
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000515
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000516 // Add constraints for use-blocks. Note that these are the only constraints
517 // that may add a positive bias, it is downhill from here.
518 SpillPlacer->addConstraints(SplitConstraints);
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000519 return SpillPlacer->scanActiveBundles();
520}
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000521
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000522
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000523/// addThroughConstraints - Add constraints and links to SpillPlacer from the
524/// live-through blocks in Blocks.
525void RAGreedy::addThroughConstraints(InterferenceCache::Cursor Intf,
526 ArrayRef<unsigned> Blocks) {
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000527 const unsigned GroupSize = 8;
528 SpillPlacement::BlockConstraint BCS[GroupSize];
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000529 unsigned TBS[GroupSize];
530 unsigned B = 0, T = 0;
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000531
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000532 for (unsigned i = 0; i != Blocks.size(); ++i) {
533 unsigned Number = Blocks[i];
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000534 Intf.moveToBlock(Number);
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000535
Jakob Stoklund Olesen7b41fbe2011-04-07 17:27:46 +0000536 if (!Intf.hasInterference()) {
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000537 assert(T < GroupSize && "Array overflow");
538 TBS[T] = Number;
539 if (++T == GroupSize) {
540 SpillPlacer->addLinks(ArrayRef<unsigned>(TBS, T));
541 T = 0;
542 }
Jakob Stoklund Olesen7b41fbe2011-04-07 17:27:46 +0000543 continue;
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000544 }
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000545
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000546 assert(B < GroupSize && "Array overflow");
547 BCS[B].Number = Number;
548
Jakob Stoklund Olesen7b41fbe2011-04-07 17:27:46 +0000549 // Interference for the live-in value.
550 if (Intf.first() <= Indexes->getMBBStartIdx(Number))
551 BCS[B].Entry = SpillPlacement::MustSpill;
552 else
553 BCS[B].Entry = SpillPlacement::PrefSpill;
554
555 // Interference for the live-out value.
556 if (Intf.last() >= SA->getLastSplitPoint(Number))
557 BCS[B].Exit = SpillPlacement::MustSpill;
558 else
559 BCS[B].Exit = SpillPlacement::PrefSpill;
560
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000561 if (++B == GroupSize) {
562 ArrayRef<SpillPlacement::BlockConstraint> Array(BCS, B);
563 SpillPlacer->addConstraints(Array);
564 B = 0;
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000565 }
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000566 }
567
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000568 ArrayRef<SpillPlacement::BlockConstraint> Array(BCS, B);
569 SpillPlacer->addConstraints(Array);
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000570 SpillPlacer->addLinks(ArrayRef<unsigned>(TBS, T));
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000571}
572
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000573void RAGreedy::growRegion(GlobalSplitCandidate &Cand,
574 InterferenceCache::Cursor Intf) {
575 // Keep track of through blocks that have not been added to SpillPlacer.
576 BitVector Todo = SA->getThroughBlocks();
577 SmallVectorImpl<unsigned> &ActiveBlocks = Cand.ActiveBlocks;
578 unsigned AddedTo = 0;
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000579#ifndef NDEBUG
580 unsigned Visited = 0;
581#endif
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000582
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000583 for (;;) {
584 ArrayRef<unsigned> NewBundles = SpillPlacer->getRecentPositive();
585 if (NewBundles.empty())
586 break;
587 // Find new through blocks in the periphery of PrefRegBundles.
588 for (int i = 0, e = NewBundles.size(); i != e; ++i) {
589 unsigned Bundle = NewBundles[i];
590 // Look at all blocks connected to Bundle in the full graph.
591 ArrayRef<unsigned> Blocks = Bundles->getBlocks(Bundle);
592 for (ArrayRef<unsigned>::iterator I = Blocks.begin(), E = Blocks.end();
593 I != E; ++I) {
594 unsigned Block = *I;
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000595 if (!Todo.test(Block))
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000596 continue;
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000597 Todo.reset(Block);
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000598 // This is a new through block. Add it to SpillPlacer later.
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000599 ActiveBlocks.push_back(Block);
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000600#ifndef NDEBUG
601 ++Visited;
602#endif
603 }
604 }
605 // Any new blocks to add?
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000606 if (ActiveBlocks.size() > AddedTo) {
607 ArrayRef<unsigned> Add(&ActiveBlocks[AddedTo],
608 ActiveBlocks.size() - AddedTo);
609 addThroughConstraints(Intf, Add);
610 AddedTo = ActiveBlocks.size();
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000611 }
612 // Perhaps iterating can enable more bundles?
613 SpillPlacer->iterate();
614 }
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000615 DEBUG(dbgs() << ", v=" << Visited);
616}
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000617
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000618/// calcGlobalSplitCost - Return the global split cost of following the split
619/// pattern in LiveBundles. This cost should be added to the local cost of the
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000620/// interference pattern in SplitConstraints.
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000621///
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000622float RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand,
623 InterferenceCache::Cursor Intf) {
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000624 float GlobalCost = 0;
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000625 const BitVector &LiveBundles = Cand.LiveBundles;
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000626 ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
627 for (unsigned i = 0; i != UseBlocks.size(); ++i) {
628 const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000629 SpillPlacement::BlockConstraint &BC = SplitConstraints[i];
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000630 bool RegIn = LiveBundles[Bundles->getBundle(BC.Number, 0)];
631 bool RegOut = LiveBundles[Bundles->getBundle(BC.Number, 1)];
632 unsigned Ins = 0;
633
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000634 if (BI.LiveIn)
635 Ins += RegIn != (BC.Entry == SpillPlacement::PrefReg);
636 if (BI.LiveOut)
637 Ins += RegOut != (BC.Exit == SpillPlacement::PrefReg);
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000638 if (Ins)
639 GlobalCost += Ins * SpillPlacer->getBlockFrequency(BC.Number);
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000640 }
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000641
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000642 for (unsigned i = 0, e = Cand.ActiveBlocks.size(); i != e; ++i) {
643 unsigned Number = Cand.ActiveBlocks[i];
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000644 bool RegIn = LiveBundles[Bundles->getBundle(Number, 0)];
645 bool RegOut = LiveBundles[Bundles->getBundle(Number, 1)];
Jakob Stoklund Olesen9a543522011-04-06 21:32:41 +0000646 if (!RegIn && !RegOut)
647 continue;
648 if (RegIn && RegOut) {
649 // We need double spill code if this block has interference.
650 Intf.moveToBlock(Number);
651 if (Intf.hasInterference())
652 GlobalCost += 2*SpillPlacer->getBlockFrequency(Number);
653 continue;
654 }
655 // live-in / stack-out or stack-in live-out.
656 GlobalCost += SpillPlacer->getBlockFrequency(Number);
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000657 }
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000658 return GlobalCost;
659}
660
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000661/// splitAroundRegion - Split VirtReg around the region determined by
662/// LiveBundles. Make an effort to avoid interference from PhysReg.
663///
664/// The 'register' interval is going to contain as many uses as possible while
665/// avoiding interference. The 'stack' interval is the complement constructed by
666/// SplitEditor. It will contain the rest.
667///
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000668void RAGreedy::splitAroundRegion(LiveInterval &VirtReg,
669 GlobalSplitCandidate &Cand,
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000670 SmallVectorImpl<LiveInterval*> &NewVRegs) {
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000671 const BitVector &LiveBundles = Cand.LiveBundles;
672
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000673 DEBUG({
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000674 dbgs() << "Splitting around region for " << PrintReg(Cand.PhysReg, TRI)
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000675 << " with bundles";
676 for (int i = LiveBundles.find_first(); i>=0; i = LiveBundles.find_next(i))
677 dbgs() << " EB#" << i;
678 dbgs() << ".\n";
679 });
680
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000681 InterferenceCache::Cursor Intf(IntfCache, Cand.PhysReg);
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +0000682 LiveRangeEdit LREdit(VirtReg, NewVRegs, this);
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000683 SE->reset(LREdit);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000684
685 // Create the main cross-block interval.
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +0000686 const unsigned MainIntv = SE->openIntv();
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000687
688 // First add all defs that are live out of a block.
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000689 ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
690 for (unsigned i = 0; i != UseBlocks.size(); ++i) {
691 const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000692 bool RegIn = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 0)];
693 bool RegOut = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 1)];
694
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +0000695 // Create separate intervals for isolated blocks with multiple uses.
696 if (!RegIn && !RegOut && BI.FirstUse != BI.LastUse) {
697 DEBUG(dbgs() << "BB#" << BI.MBB->getNumber() << " isolated.\n");
698 SE->splitSingleBlock(BI);
699 SE->selectIntv(MainIntv);
700 continue;
701 }
702
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000703 // Should the register be live out?
704 if (!BI.LiveOut || !RegOut)
705 continue;
706
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000707 SlotIndex Start, Stop;
708 tie(Start, Stop) = Indexes->getMBBRange(BI.MBB);
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000709 Intf.moveToBlock(BI.MBB->getNumber());
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000710 DEBUG(dbgs() << "BB#" << BI.MBB->getNumber() << " -> EB#"
Jakob Stoklund Olesen2dfbb3e2011-02-03 20:29:43 +0000711 << Bundles->getBundle(BI.MBB->getNumber(), 1)
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000712 << " [" << Start << ';'
713 << SA->getLastSplitPoint(BI.MBB->getNumber()) << '-' << Stop
714 << ") intf [" << Intf.first() << ';' << Intf.last() << ')');
Jakob Stoklund Olesen2dfbb3e2011-02-03 20:29:43 +0000715
716 // The interference interval should either be invalid or overlap MBB.
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000717 assert((!Intf.hasInterference() || Intf.first() < Stop)
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000718 && "Bad interference");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000719 assert((!Intf.hasInterference() || Intf.last() > Start)
Jakob Stoklund Olesen36d61862011-03-03 03:41:29 +0000720 && "Bad interference");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000721
722 // Check interference leaving the block.
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000723 if (!Intf.hasInterference()) {
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000724 // Block is interference-free.
725 DEBUG(dbgs() << ", no interference");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000726 if (!BI.LiveThrough) {
727 DEBUG(dbgs() << ", not live-through.\n");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000728 SE->useIntv(SE->enterIntvBefore(BI.Def), Stop);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000729 continue;
730 }
731 if (!RegIn) {
732 // Block is live-through, but entry bundle is on the stack.
733 // Reload just before the first use.
734 DEBUG(dbgs() << ", not live-in, enter before first use.\n");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000735 SE->useIntv(SE->enterIntvBefore(BI.FirstUse), Stop);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000736 continue;
737 }
738 DEBUG(dbgs() << ", live-through.\n");
739 continue;
740 }
741
742 // Block has interference.
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000743 DEBUG(dbgs() << ", interference to " << Intf.last());
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000744
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000745 if (!BI.LiveThrough && Intf.last() <= BI.Def) {
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000746 // The interference doesn't reach the outgoing segment.
747 DEBUG(dbgs() << " doesn't affect def from " << BI.Def << '\n');
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000748 SE->useIntv(BI.Def, Stop);
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000749 continue;
750 }
751
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000752 SlotIndex LastSplitPoint = SA->getLastSplitPoint(BI.MBB->getNumber());
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000753 if (Intf.last().getBoundaryIndex() < BI.LastUse) {
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000754 // There are interference-free uses at the end of the block.
755 // Find the first use that can get the live-out register.
Jakob Stoklund Olesenc0de9952011-01-20 17:45:23 +0000756 SmallVectorImpl<SlotIndex>::const_iterator UI =
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000757 std::lower_bound(SA->UseSlots.begin(), SA->UseSlots.end(),
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000758 Intf.last().getBoundaryIndex());
Jakob Stoklund Olesenc0de9952011-01-20 17:45:23 +0000759 assert(UI != SA->UseSlots.end() && "Couldn't find last use");
760 SlotIndex Use = *UI;
Jakob Stoklund Olesenc0de9952011-01-20 17:45:23 +0000761 assert(Use <= BI.LastUse && "Couldn't find last use");
Jakob Stoklund Olesen8a2bbde2011-02-08 23:26:48 +0000762 // Only attempt a split befroe the last split point.
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000763 if (Use.getBaseIndex() <= LastSplitPoint) {
Jakob Stoklund Olesen8a2bbde2011-02-08 23:26:48 +0000764 DEBUG(dbgs() << ", free use at " << Use << ".\n");
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000765 SlotIndex SegStart = SE->enterIntvBefore(Use);
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000766 assert(SegStart >= Intf.last() && "Couldn't avoid interference");
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000767 assert(SegStart < LastSplitPoint && "Impossible split point");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000768 SE->useIntv(SegStart, Stop);
Jakob Stoklund Olesen8a2bbde2011-02-08 23:26:48 +0000769 continue;
770 }
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000771 }
772
773 // Interference is after the last use.
774 DEBUG(dbgs() << " after last use.\n");
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000775 SlotIndex SegStart = SE->enterIntvAtEnd(*BI.MBB);
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000776 assert(SegStart >= Intf.last() && "Couldn't avoid interference");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000777 }
778
779 // Now all defs leading to live bundles are handled, do everything else.
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000780 for (unsigned i = 0; i != UseBlocks.size(); ++i) {
781 const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000782 bool RegIn = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 0)];
783 bool RegOut = LiveBundles[Bundles->getBundle(BI.MBB->getNumber(), 1)];
784
785 // Is the register live-in?
786 if (!BI.LiveIn || !RegIn)
787 continue;
788
789 // We have an incoming register. Check for interference.
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000790 SlotIndex Start, Stop;
791 tie(Start, Stop) = Indexes->getMBBRange(BI.MBB);
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000792 Intf.moveToBlock(BI.MBB->getNumber());
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000793 DEBUG(dbgs() << "EB#" << Bundles->getBundle(BI.MBB->getNumber(), 0)
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000794 << " -> BB#" << BI.MBB->getNumber() << " [" << Start << ';'
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000795 << SA->getLastSplitPoint(BI.MBB->getNumber()) << '-' << Stop
796 << ')');
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000797
798 // Check interference entering the block.
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000799 if (!Intf.hasInterference()) {
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000800 // Block is interference-free.
801 DEBUG(dbgs() << ", no interference");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000802 if (!BI.LiveThrough) {
803 DEBUG(dbgs() << ", killed in block.\n");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000804 SE->useIntv(Start, SE->leaveIntvAfter(BI.Kill));
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000805 continue;
806 }
807 if (!RegOut) {
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000808 SlotIndex LastSplitPoint = SA->getLastSplitPoint(BI.MBB->getNumber());
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000809 // Block is live-through, but exit bundle is on the stack.
810 // Spill immediately after the last use.
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000811 if (BI.LastUse < LastSplitPoint) {
Jakob Stoklund Olesen5c716bd2011-02-08 18:50:21 +0000812 DEBUG(dbgs() << ", uses, stack-out.\n");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000813 SE->useIntv(Start, SE->leaveIntvAfter(BI.LastUse));
Jakob Stoklund Olesen5c716bd2011-02-08 18:50:21 +0000814 continue;
815 }
816 // The last use is after the last split point, it is probably an
817 // indirect jump.
818 DEBUG(dbgs() << ", uses at " << BI.LastUse << " after split point "
Jakob Stoklund Olesen612f7802011-04-05 04:20:29 +0000819 << LastSplitPoint << ", stack-out.\n");
820 SlotIndex SegEnd = SE->leaveIntvBefore(LastSplitPoint);
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000821 SE->useIntv(Start, SegEnd);
Jakob Stoklund Olesen5c716bd2011-02-08 18:50:21 +0000822 // Run a double interval from the split to the last use.
823 // This makes it possible to spill the complement without affecting the
824 // indirect branch.
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000825 SE->overlapIntv(SegEnd, BI.LastUse);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000826 continue;
827 }
828 // Register is live-through.
829 DEBUG(dbgs() << ", uses, live-through.\n");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000830 SE->useIntv(Start, Stop);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000831 continue;
832 }
833
834 // Block has interference.
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000835 DEBUG(dbgs() << ", interference from " << Intf.first());
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000836
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000837 if (!BI.LiveThrough && Intf.first() >= BI.Kill) {
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000838 // The interference doesn't reach the outgoing segment.
839 DEBUG(dbgs() << " doesn't affect kill at " << BI.Kill << '\n');
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000840 SE->useIntv(Start, BI.Kill);
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000841 continue;
842 }
843
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000844 if (Intf.first().getBaseIndex() > BI.FirstUse) {
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000845 // There are interference-free uses at the beginning of the block.
846 // Find the last use that can get the register.
Jakob Stoklund Olesenc0de9952011-01-20 17:45:23 +0000847 SmallVectorImpl<SlotIndex>::const_iterator UI =
Jakob Stoklund Olesenfe3f99f2011-02-05 01:06:39 +0000848 std::lower_bound(SA->UseSlots.begin(), SA->UseSlots.end(),
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000849 Intf.first().getBaseIndex());
Jakob Stoklund Olesenc0de9952011-01-20 17:45:23 +0000850 assert(UI != SA->UseSlots.begin() && "Couldn't find first use");
851 SlotIndex Use = (--UI)->getBoundaryIndex();
852 DEBUG(dbgs() << ", free use at " << *UI << ".\n");
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000853 SlotIndex SegEnd = SE->leaveIntvAfter(Use);
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000854 assert(SegEnd <= Intf.first() && "Couldn't avoid interference");
Jakob Stoklund Olesen6c8afd72011-04-04 15:32:15 +0000855 SE->useIntv(Start, SegEnd);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000856 continue;
857 }
858
859 // Interference is before the first use.
860 DEBUG(dbgs() << " before first use.\n");
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000861 SlotIndex SegEnd = SE->leaveIntvAtTop(*BI.MBB);
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +0000862 assert(SegEnd <= Intf.first() && "Couldn't avoid interference");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000863 }
864
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000865 // Handle live-through blocks.
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000866 for (unsigned i = 0, e = Cand.ActiveBlocks.size(); i != e; ++i) {
867 unsigned Number = Cand.ActiveBlocks[i];
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000868 bool RegIn = LiveBundles[Bundles->getBundle(Number, 0)];
869 bool RegOut = LiveBundles[Bundles->getBundle(Number, 1)];
870 DEBUG(dbgs() << "Live through BB#" << Number << '\n');
871 if (RegIn && RegOut) {
872 Intf.moveToBlock(Number);
873 if (!Intf.hasInterference()) {
874 SE->useIntv(Indexes->getMBBStartIdx(Number),
875 Indexes->getMBBEndIdx(Number));
876 continue;
877 }
878 }
879 MachineBasicBlock *MBB = MF->getBlockNumbered(Number);
880 if (RegIn)
881 SE->leaveIntvAtTop(*MBB);
882 if (RegOut)
883 SE->enterIntvAtEnd(*MBB);
884 }
885
Jakob Stoklund Olesen0db841f2011-02-17 22:53:48 +0000886 ++NumGlobalSplits;
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000887
Jakob Stoklund Olesen59280462011-04-21 18:38:15 +0000888 SmallVector<unsigned, 8> IntvMap;
889 SE->finish(&IntvMap);
890 LRStage.resize(MRI->getNumVirtRegs());
891
892 // Sort out the new intervals created by splitting. We get four kinds:
893 // - Remainder intervals should not be split again.
894 // - Candidate intervals can be assigned to Cand.PhysReg.
895 // - Block-local splits are candidates for local splitting.
896 // - DCE leftovers should go back on the queue.
897 for (unsigned i = 0, e = LREdit.size(); i != e; ++i) {
898 unsigned Reg = LREdit.get(i)->reg;
899
900 // Ignore old intervals from DCE.
901 if (LRStage[Reg] != RS_New)
902 continue;
903
904 // Remainder interval. Don't try splitting again, spill if it doesn't
905 // allocate.
906 if (IntvMap[i] == 0) {
907 LRStage[Reg] = RS_Global;
908 continue;
909 }
910
911 // Other intervals are treated as new. This includes the main interval,
912 // local intervals created for blocks with multiple uses, and anything
913 // created by DCE.
914 }
915
Jakob Stoklund Oleseneb291572011-03-27 22:49:21 +0000916 if (VerifyEnabled)
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000917 MF->verify(this, "After splitting live range around region");
918}
919
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000920unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
921 SmallVectorImpl<LiveInterval*> &NewVRegs) {
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000922 float BestCost = 0;
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000923 const unsigned NoCand = ~0u;
924 unsigned BestCand = NoCand;
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000925
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000926 Order.rewind();
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000927 for (unsigned Cand = 0; unsigned PhysReg = Order.next(); ++Cand) {
928 if (GlobalCand.size() <= Cand)
929 GlobalCand.resize(Cand+1);
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000930 GlobalCand[Cand].reset(PhysReg);
Jakob Stoklund Olesen96dcd952011-03-05 01:10:31 +0000931
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000932 SpillPlacer->prepare(GlobalCand[Cand].LiveBundles);
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000933 float Cost;
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000934 InterferenceCache::Cursor Intf(IntfCache, PhysReg);
935 if (!addSplitConstraints(Intf, Cost)) {
936 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tno positive bundles\n");
Jakob Stoklund Olesen1b400e82011-04-06 21:32:38 +0000937 continue;
938 }
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000939 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tstatic = " << Cost);
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000940 if (BestCand != NoCand && Cost >= BestCost) {
941 DEBUG(dbgs() << " worse than "
942 << PrintReg(GlobalCand[BestCand].PhysReg, TRI) << '\n');
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000943 continue;
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000944 }
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000945 growRegion(GlobalCand[Cand], Intf);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000946
Jakob Stoklund Olesen9efa2a22011-04-06 19:13:57 +0000947 SpillPlacer->finish();
948
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000949 // No live bundles, defer to splitSingleBlocks().
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000950 if (!GlobalCand[Cand].LiveBundles.any()) {
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000951 DEBUG(dbgs() << " no bundles.\n");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000952 continue;
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000953 }
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000954
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000955 Cost += calcGlobalSplitCost(GlobalCand[Cand], Intf);
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000956 DEBUG({
957 dbgs() << ", total = " << Cost << " with bundles";
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000958 for (int i = GlobalCand[Cand].LiveBundles.find_first(); i>=0;
959 i = GlobalCand[Cand].LiveBundles.find_next(i))
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000960 dbgs() << " EB#" << i;
961 dbgs() << ".\n";
962 });
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000963 if (BestCand == NoCand || Cost < BestCost) {
964 BestCand = Cand;
Jakob Stoklund Olesen874be742011-03-05 03:28:51 +0000965 BestCost = 0.98f * Cost; // Prevent rounding effects.
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000966 }
967 }
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000968
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000969 if (BestCand == NoCand)
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000970 return 0;
971
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000972 splitAroundRegion(VirtReg, GlobalCand[BestCand], NewVRegs);
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +0000973 return 0;
974}
975
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000976
977//===----------------------------------------------------------------------===//
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000978// Local Splitting
979//===----------------------------------------------------------------------===//
980
981
982/// calcGapWeights - Compute the maximum spill weight that needs to be evicted
983/// in order to use PhysReg between two entries in SA->UseSlots.
984///
985/// GapWeight[i] represents the gap between UseSlots[i] and UseSlots[i+1].
986///
987void RAGreedy::calcGapWeights(unsigned PhysReg,
988 SmallVectorImpl<float> &GapWeight) {
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000989 assert(SA->getUseBlocks().size() == 1 && "Not a local interval");
990 const SplitAnalysis::BlockInfo &BI = SA->getUseBlocks().front();
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000991 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
992 const unsigned NumGaps = Uses.size()-1;
993
994 // Start and end points for the interference check.
995 SlotIndex StartIdx = BI.LiveIn ? BI.FirstUse.getBaseIndex() : BI.FirstUse;
996 SlotIndex StopIdx = BI.LiveOut ? BI.LastUse.getBoundaryIndex() : BI.LastUse;
997
998 GapWeight.assign(NumGaps, 0.0f);
999
1000 // Add interference from each overlapping register.
1001 for (const unsigned *AI = TRI->getOverlaps(PhysReg); *AI; ++AI) {
1002 if (!query(const_cast<LiveInterval&>(SA->getParent()), *AI)
1003 .checkInterference())
1004 continue;
1005
1006 // We know that VirtReg is a continuous interval from FirstUse to LastUse,
1007 // so we don't need InterferenceQuery.
1008 //
1009 // Interference that overlaps an instruction is counted in both gaps
1010 // surrounding the instruction. The exception is interference before
1011 // StartIdx and after StopIdx.
1012 //
1013 LiveIntervalUnion::SegmentIter IntI = PhysReg2LiveUnion[*AI].find(StartIdx);
1014 for (unsigned Gap = 0; IntI.valid() && IntI.start() < StopIdx; ++IntI) {
1015 // Skip the gaps before IntI.
1016 while (Uses[Gap+1].getBoundaryIndex() < IntI.start())
1017 if (++Gap == NumGaps)
1018 break;
1019 if (Gap == NumGaps)
1020 break;
1021
1022 // Update the gaps covered by IntI.
1023 const float weight = IntI.value()->weight;
1024 for (; Gap != NumGaps; ++Gap) {
1025 GapWeight[Gap] = std::max(GapWeight[Gap], weight);
1026 if (Uses[Gap+1].getBaseIndex() >= IntI.stop())
1027 break;
1028 }
1029 if (Gap == NumGaps)
1030 break;
1031 }
1032 }
1033}
1034
1035/// getPrevMappedIndex - Return the slot index of the last non-copy instruction
1036/// before MI that has a slot index. If MI is the first mapped instruction in
1037/// its block, return the block start index instead.
1038///
1039SlotIndex RAGreedy::getPrevMappedIndex(const MachineInstr *MI) {
1040 assert(MI && "Missing MachineInstr");
1041 const MachineBasicBlock *MBB = MI->getParent();
1042 MachineBasicBlock::const_iterator B = MBB->begin(), I = MI;
1043 while (I != B)
1044 if (!(--I)->isDebugValue() && !I->isCopy())
1045 return Indexes->getInstructionIndex(I);
1046 return Indexes->getMBBStartIdx(MBB);
1047}
1048
1049/// calcPrevSlots - Fill in the PrevSlot array with the index of the previous
1050/// real non-copy instruction for each instruction in SA->UseSlots.
1051///
1052void RAGreedy::calcPrevSlots() {
1053 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
1054 PrevSlot.clear();
1055 PrevSlot.reserve(Uses.size());
1056 for (unsigned i = 0, e = Uses.size(); i != e; ++i) {
1057 const MachineInstr *MI = Indexes->getInstructionFromIndex(Uses[i]);
1058 PrevSlot.push_back(getPrevMappedIndex(MI).getDefIndex());
1059 }
1060}
1061
1062/// nextSplitPoint - Find the next index into SA->UseSlots > i such that it may
1063/// be beneficial to split before UseSlots[i].
1064///
1065/// 0 is always a valid split point
1066unsigned RAGreedy::nextSplitPoint(unsigned i) {
1067 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
1068 const unsigned Size = Uses.size();
1069 assert(i != Size && "No split points after the end");
1070 // Allow split before i when Uses[i] is not adjacent to the previous use.
1071 while (++i != Size && PrevSlot[i].getBaseIndex() <= Uses[i-1].getBaseIndex())
1072 ;
1073 return i;
1074}
1075
1076/// tryLocalSplit - Try to split VirtReg into smaller intervals inside its only
1077/// basic block.
1078///
1079unsigned RAGreedy::tryLocalSplit(LiveInterval &VirtReg, AllocationOrder &Order,
1080 SmallVectorImpl<LiveInterval*> &NewVRegs) {
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +00001081 assert(SA->getUseBlocks().size() == 1 && "Not a local interval");
1082 const SplitAnalysis::BlockInfo &BI = SA->getUseBlocks().front();
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +00001083
1084 // Note that it is possible to have an interval that is live-in or live-out
1085 // while only covering a single block - A phi-def can use undef values from
1086 // predecessors, and the block could be a single-block loop.
1087 // We don't bother doing anything clever about such a case, we simply assume
1088 // that the interval is continuous from FirstUse to LastUse. We should make
1089 // sure that we don't do anything illegal to such an interval, though.
1090
1091 const SmallVectorImpl<SlotIndex> &Uses = SA->UseSlots;
1092 if (Uses.size() <= 2)
1093 return 0;
1094 const unsigned NumGaps = Uses.size()-1;
1095
1096 DEBUG({
1097 dbgs() << "tryLocalSplit: ";
1098 for (unsigned i = 0, e = Uses.size(); i != e; ++i)
1099 dbgs() << ' ' << SA->UseSlots[i];
1100 dbgs() << '\n';
1101 });
1102
1103 // For every use, find the previous mapped non-copy instruction.
1104 // We use this to detect valid split points, and to estimate new interval
1105 // sizes.
1106 calcPrevSlots();
1107
1108 unsigned BestBefore = NumGaps;
1109 unsigned BestAfter = 0;
1110 float BestDiff = 0;
1111
Jakob Stoklund Olesen40a42a22011-03-04 00:58:40 +00001112 const float blockFreq = SpillPlacer->getBlockFrequency(BI.MBB->getNumber());
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +00001113 SmallVector<float, 8> GapWeight;
1114
1115 Order.rewind();
1116 while (unsigned PhysReg = Order.next()) {
1117 // Keep track of the largest spill weight that would need to be evicted in
1118 // order to make use of PhysReg between UseSlots[i] and UseSlots[i+1].
1119 calcGapWeights(PhysReg, GapWeight);
1120
1121 // Try to find the best sequence of gaps to close.
1122 // The new spill weight must be larger than any gap interference.
1123
1124 // We will split before Uses[SplitBefore] and after Uses[SplitAfter].
1125 unsigned SplitBefore = 0, SplitAfter = nextSplitPoint(1) - 1;
1126
1127 // MaxGap should always be max(GapWeight[SplitBefore..SplitAfter-1]).
1128 // It is the spill weight that needs to be evicted.
1129 float MaxGap = GapWeight[0];
1130 for (unsigned i = 1; i != SplitAfter; ++i)
1131 MaxGap = std::max(MaxGap, GapWeight[i]);
1132
1133 for (;;) {
1134 // Live before/after split?
1135 const bool LiveBefore = SplitBefore != 0 || BI.LiveIn;
1136 const bool LiveAfter = SplitAfter != NumGaps || BI.LiveOut;
1137
1138 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << ' '
1139 << Uses[SplitBefore] << '-' << Uses[SplitAfter]
1140 << " i=" << MaxGap);
1141
1142 // Stop before the interval gets so big we wouldn't be making progress.
1143 if (!LiveBefore && !LiveAfter) {
1144 DEBUG(dbgs() << " all\n");
1145 break;
1146 }
1147 // Should the interval be extended or shrunk?
1148 bool Shrink = true;
1149 if (MaxGap < HUGE_VALF) {
1150 // Estimate the new spill weight.
1151 //
1152 // Each instruction reads and writes the register, except the first
1153 // instr doesn't read when !FirstLive, and the last instr doesn't write
1154 // when !LastLive.
1155 //
1156 // We will be inserting copies before and after, so the total number of
1157 // reads and writes is 2 * EstUses.
1158 //
1159 const unsigned EstUses = 2*(SplitAfter - SplitBefore) +
1160 2*(LiveBefore + LiveAfter);
1161
1162 // Try to guess the size of the new interval. This should be trivial,
1163 // but the slot index of an inserted copy can be a lot smaller than the
1164 // instruction it is inserted before if there are many dead indexes
1165 // between them.
1166 //
1167 // We measure the distance from the instruction before SplitBefore to
1168 // get a conservative estimate.
1169 //
1170 // The final distance can still be different if inserting copies
1171 // triggers a slot index renumbering.
1172 //
1173 const float EstWeight = normalizeSpillWeight(blockFreq * EstUses,
1174 PrevSlot[SplitBefore].distance(Uses[SplitAfter]));
1175 // Would this split be possible to allocate?
1176 // Never allocate all gaps, we wouldn't be making progress.
1177 float Diff = EstWeight - MaxGap;
1178 DEBUG(dbgs() << " w=" << EstWeight << " d=" << Diff);
1179 if (Diff > 0) {
1180 Shrink = false;
1181 if (Diff > BestDiff) {
1182 DEBUG(dbgs() << " (best)");
1183 BestDiff = Diff;
1184 BestBefore = SplitBefore;
1185 BestAfter = SplitAfter;
1186 }
1187 }
1188 }
1189
1190 // Try to shrink.
1191 if (Shrink) {
1192 SplitBefore = nextSplitPoint(SplitBefore);
1193 if (SplitBefore < SplitAfter) {
1194 DEBUG(dbgs() << " shrink\n");
1195 // Recompute the max when necessary.
1196 if (GapWeight[SplitBefore - 1] >= MaxGap) {
1197 MaxGap = GapWeight[SplitBefore];
1198 for (unsigned i = SplitBefore + 1; i != SplitAfter; ++i)
1199 MaxGap = std::max(MaxGap, GapWeight[i]);
1200 }
1201 continue;
1202 }
1203 MaxGap = 0;
1204 }
1205
1206 // Try to extend the interval.
1207 if (SplitAfter >= NumGaps) {
1208 DEBUG(dbgs() << " end\n");
1209 break;
1210 }
1211
1212 DEBUG(dbgs() << " extend\n");
1213 for (unsigned e = nextSplitPoint(SplitAfter + 1) - 1;
1214 SplitAfter != e; ++SplitAfter)
1215 MaxGap = std::max(MaxGap, GapWeight[SplitAfter]);
1216 continue;
1217 }
1218 }
1219
1220 // Didn't find any candidates?
1221 if (BestBefore == NumGaps)
1222 return 0;
1223
1224 DEBUG(dbgs() << "Best local split range: " << Uses[BestBefore]
1225 << '-' << Uses[BestAfter] << ", " << BestDiff
1226 << ", " << (BestAfter - BestBefore + 1) << " instrs\n");
1227
Jakob Stoklund Olesen92a55f42011-03-09 00:57:29 +00001228 LiveRangeEdit LREdit(VirtReg, NewVRegs, this);
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +00001229 SE->reset(LREdit);
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +00001230
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +00001231 SE->openIntv();
1232 SlotIndex SegStart = SE->enterIntvBefore(Uses[BestBefore]);
1233 SlotIndex SegStop = SE->leaveIntvAfter(Uses[BestAfter]);
1234 SE->useIntv(SegStart, SegStop);
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +00001235 SE->finish();
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +00001236 setStage(NewVRegs.begin(), NewVRegs.end(), RS_Local);
Jakob Stoklund Olesen0db841f2011-02-17 22:53:48 +00001237 ++NumLocalSplits;
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +00001238
1239 return 0;
1240}
1241
1242//===----------------------------------------------------------------------===//
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001243// Live Range Splitting
1244//===----------------------------------------------------------------------===//
1245
1246/// trySplit - Try to split VirtReg or one of its interferences, making it
1247/// assignable.
1248/// @return Physreg when VirtReg may be assigned and/or new NewVRegs.
1249unsigned RAGreedy::trySplit(LiveInterval &VirtReg, AllocationOrder &Order,
1250 SmallVectorImpl<LiveInterval*>&NewVRegs) {
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +00001251 // Local intervals are handled separately.
Jakob Stoklund Olesena2ebf602011-02-19 00:38:40 +00001252 if (LIS->intervalIsInOneMBB(VirtReg)) {
1253 NamedRegionTimer T("Local Splitting", TimerGroupName, TimePassesIsEnabled);
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +00001254 SA->analyze(&VirtReg);
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +00001255 return tryLocalSplit(VirtReg, Order, NewVRegs);
Jakob Stoklund Olesena2ebf602011-02-19 00:38:40 +00001256 }
1257
1258 NamedRegionTimer T("Global Splitting", TimerGroupName, TimePassesIsEnabled);
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001259
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +00001260 // Don't iterate global splitting.
1261 // Move straight to spilling if this range was produced by a global split.
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +00001262 if (getStage(VirtReg) >= RS_Global)
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +00001263 return 0;
1264
1265 SA->analyze(&VirtReg);
1266
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001267 // First try to split around a region spanning multiple blocks.
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +00001268 unsigned PhysReg = tryRegionSplit(VirtReg, Order, NewVRegs);
1269 if (PhysReg || !NewVRegs.empty())
1270 return PhysReg;
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001271
1272 // Then isolate blocks with multiple uses.
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +00001273 SplitAnalysis::BlockPtrSet Blocks;
1274 if (SA->getMultiUseBlocks(Blocks)) {
1275 LiveRangeEdit LREdit(VirtReg, NewVRegs, this);
1276 SE->reset(LREdit);
1277 SE->splitSingleBlocks(Blocks);
1278 setStage(NewVRegs.begin(), NewVRegs.end(), RS_Global);
1279 if (VerifyEnabled)
1280 MF->verify(this, "After splitting live range around basic blocks");
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001281 }
1282
1283 // Don't assign any physregs.
1284 return 0;
1285}
1286
1287
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +00001288//===----------------------------------------------------------------------===//
Jakob Stoklund Olesen770d42d2010-12-22 22:01:30 +00001289// Main Entry Point
1290//===----------------------------------------------------------------------===//
1291
1292unsigned RAGreedy::selectOrSplit(LiveInterval &VirtReg,
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001293 SmallVectorImpl<LiveInterval*> &NewVRegs) {
Jakob Stoklund Olesen770d42d2010-12-22 22:01:30 +00001294 // First try assigning a free register.
Jakob Stoklund Olesendd479e92010-12-10 22:21:05 +00001295 AllocationOrder Order(VirtReg.reg, *VRM, ReservedRegs);
Jakob Stoklund Olesen6bfba2e2011-04-20 18:19:48 +00001296 if (unsigned PhysReg = tryAssign(VirtReg, Order, NewVRegs))
1297 return PhysReg;
Andrew Trickb853e6c2010-12-09 18:15:21 +00001298
Jakob Stoklund Olesen98c81412011-02-23 00:29:52 +00001299 if (unsigned PhysReg = tryEvict(VirtReg, Order, NewVRegs))
Jakob Stoklund Olesen46c83c82010-12-14 00:37:49 +00001300 return PhysReg;
Andrew Trickb853e6c2010-12-09 18:15:21 +00001301
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001302 assert(NewVRegs.empty() && "Cannot append to existing NewVRegs");
1303
Jakob Stoklund Olesen107d3662011-02-24 23:21:36 +00001304 // The first time we see a live range, don't try to split or spill.
1305 // Wait until the second time, when all smaller ranges have been allocated.
1306 // This gives a better picture of the interference to split around.
Jakob Stoklund Oleseneb291572011-03-27 22:49:21 +00001307 LiveRangeStage Stage = getStage(VirtReg);
Jakob Stoklund Olesenf22ca3f2011-03-30 02:52:39 +00001308 if (Stage == RS_First) {
Jakob Stoklund Oleseneb291572011-03-27 22:49:21 +00001309 LRStage[VirtReg.reg] = RS_Second;
Jakob Stoklund Olesenc1655e12011-03-19 23:02:47 +00001310 DEBUG(dbgs() << "wait for second round\n");
Jakob Stoklund Olesen107d3662011-02-24 23:21:36 +00001311 NewVRegs.push_back(&VirtReg);
1312 return 0;
1313 }
1314
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +00001315 assert(Stage < RS_Spill && "Cannot allocate after spilling");
1316
Jakob Stoklund Olesen46c83c82010-12-14 00:37:49 +00001317 // Try splitting VirtReg or interferences.
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +00001318 unsigned PhysReg = trySplit(VirtReg, Order, NewVRegs);
1319 if (PhysReg || !NewVRegs.empty())
Jakob Stoklund Olesenb64d92e2010-12-14 00:37:44 +00001320 return PhysReg;
1321
Jakob Stoklund Olesen770d42d2010-12-22 22:01:30 +00001322 // Finally spill VirtReg itself.
Jakob Stoklund Olesen533f58e2010-12-11 00:19:56 +00001323 NamedRegionTimer T("Spiller", TimerGroupName, TimePassesIsEnabled);
Jakob Stoklund Olesen47dbf6c2011-03-10 01:51:42 +00001324 LiveRangeEdit LRE(VirtReg, NewVRegs, this);
1325 spiller().spill(LRE);
Jakob Stoklund Olesen6094bd82011-03-29 21:20:19 +00001326 setStage(NewVRegs.begin(), NewVRegs.end(), RS_Spill);
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001327
Jakob Stoklund Olesenc46570d2011-03-16 22:56:08 +00001328 if (VerifyEnabled)
1329 MF->verify(this, "After spilling");
1330
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001331 // The live virtual register requesting allocation was spilled, so tell
1332 // the caller not to allocate anything during this round.
1333 return 0;
1334}
1335
1336bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
1337 DEBUG(dbgs() << "********** GREEDY REGISTER ALLOCATION **********\n"
1338 << "********** Function: "
1339 << ((Value*)mf.getFunction())->getName() << '\n');
1340
1341 MF = &mf;
Jakob Stoklund Olesenaf249642010-12-17 23:16:35 +00001342 if (VerifyEnabled)
Jakob Stoklund Olesen89cab932010-12-18 00:06:56 +00001343 MF->verify(this, "Before greedy register allocator");
Jakob Stoklund Olesenaf249642010-12-17 23:16:35 +00001344
Jakob Stoklund Olesen4680dec2010-12-10 23:49:00 +00001345 RegAllocBase::init(getAnalysis<VirtRegMap>(), getAnalysis<LiveIntervals>());
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +00001346 Indexes = &getAnalysis<SlotIndexes>();
Jakob Stoklund Olesenf428eb62010-12-17 23:16:32 +00001347 DomTree = &getAnalysis<MachineDominatorTree>();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001348 ReservedRegs = TRI->getReservedRegs(*MF);
Jakob Stoklund Olesenf6dff842010-12-10 22:54:44 +00001349 SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +00001350 Loops = &getAnalysis<MachineLoopInfo>();
1351 LoopRanges = &getAnalysis<MachineLoopRanges>();
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +00001352 Bundles = &getAnalysis<EdgeBundles>();
1353 SpillPlacer = &getAnalysis<SpillPlacement>();
1354
Jakob Stoklund Olesen1b847de2011-02-19 00:53:42 +00001355 SA.reset(new SplitAnalysis(*VRM, *LIS, *Loops));
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +00001356 SE.reset(new SplitEditor(*SA, *LIS, *VRM, *DomTree));
Jakob Stoklund Olesen22a1df62011-03-01 21:10:07 +00001357 LRStage.clear();
1358 LRStage.resize(MRI->getNumVirtRegs());
Jakob Stoklund Oleseneda0fe82011-04-02 06:03:38 +00001359 IntfCache.init(MF, &PhysReg2LiveUnion[0], Indexes, TRI);
Jakob Stoklund Olesend0bb5e22010-12-15 23:46:13 +00001360
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001361 allocatePhysRegs();
1362 addMBBLiveIns(MF);
Jakob Stoklund Olesen8a61da82011-02-08 21:13:03 +00001363 LIS->addKillFlags();
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001364
1365 // Run rewriter
Jakob Stoklund Olesen533f58e2010-12-11 00:19:56 +00001366 {
1367 NamedRegionTimer T("Rewriter", TimerGroupName, TimePassesIsEnabled);
Jakob Stoklund Olesenba05c012011-02-18 22:03:18 +00001368 VRM->rewrite(Indexes);
Jakob Stoklund Olesen533f58e2010-12-11 00:19:56 +00001369 }
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001370
Jakob Stoklund Olesencfafc542011-04-05 21:40:37 +00001371 // Write out new DBG_VALUE instructions.
1372 getAnalysis<LiveDebugVariables>().emitDebugValues(VRM);
1373
Jakob Stoklund Olesencba2e062010-12-08 03:26:16 +00001374 // The pass output is in VirtRegMap. Release all the transient data.
1375 releaseMemory();
1376
1377 return true;
1378}