Jakob Stoklund Olesen | ccc9581 | 2012-01-11 22:28:30 +0000 | [diff] [blame] | 1 | //===-- RegAllocBasic.cpp - Basic Register Allocator ----------------------===// |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 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 RABasic function pass, which provides a minimal |
| 11 | // implementation of the basic register allocator. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "regalloc" |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 16 | #include "AllocationOrder.h" |
Jakob Stoklund Olesen | 5f2316a | 2011-06-03 20:34:53 +0000 | [diff] [blame] | 17 | #include "RegAllocBase.h" |
Jakob Stoklund Olesen | cfafc54 | 2011-04-05 21:40:37 +0000 | [diff] [blame] | 18 | #include "LiveDebugVariables.h" |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 19 | #include "Spiller.h" |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 20 | #include "VirtRegMap.h" |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 21 | #include "LiveRegMatrix.h" |
Andrew Trick | 8a83d54 | 2010-11-11 17:46:29 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/AliasAnalysis.h" |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 23 | #include "llvm/Function.h" |
| 24 | #include "llvm/PassAnalysisSupport.h" |
| 25 | #include "llvm/CodeGen/CalcSpillWeights.h" |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Pete Cooper | 789d5d8 | 2012-04-02 22:44:18 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/LiveRangeEdit.h" |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/LiveStackAnalysis.h" |
| 29 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 30 | #include "llvm/CodeGen/MachineInstr.h" |
| 31 | #include "llvm/CodeGen/MachineLoopInfo.h" |
| 32 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 33 | #include "llvm/CodeGen/Passes.h" |
| 34 | #include "llvm/CodeGen/RegAllocRegistry.h" |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetMachine.h" |
| 36 | #include "llvm/Target/TargetOptions.h" |
Andrew Trick | e16eecc | 2010-10-26 18:34:01 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetRegisterInfo.h" |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Debug.h" |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 39 | #include "llvm/Support/raw_ostream.h" |
Andrew Trick | e16eecc | 2010-10-26 18:34:01 +0000 | [diff] [blame] | 40 | |
Jakob Stoklund Olesen | 953af2c | 2010-12-07 23:18:47 +0000 | [diff] [blame] | 41 | #include <cstdlib> |
Jakob Stoklund Olesen | 98d9648 | 2011-02-22 23:01:52 +0000 | [diff] [blame] | 42 | #include <queue> |
Andrew Trick | e16eecc | 2010-10-26 18:34:01 +0000 | [diff] [blame] | 43 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 44 | using namespace llvm; |
| 45 | |
| 46 | static RegisterRegAlloc basicRegAlloc("basic", "basic register allocator", |
| 47 | createBasicRegisterAllocator); |
| 48 | |
Benjamin Kramer | c62feda | 2010-11-25 16:42:51 +0000 | [diff] [blame] | 49 | namespace { |
Jakob Stoklund Olesen | 98d9648 | 2011-02-22 23:01:52 +0000 | [diff] [blame] | 50 | struct CompSpillWeight { |
| 51 | bool operator()(LiveInterval *A, LiveInterval *B) const { |
| 52 | return A->weight < B->weight; |
| 53 | } |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | namespace { |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 58 | /// RABasic provides a minimal implementation of the basic register allocation |
| 59 | /// algorithm. It prioritizes live virtual registers by spill weight and spills |
| 60 | /// whenever a register is unavailable. This is not practical in production but |
| 61 | /// provides a useful baseline both for measuring other allocators and comparing |
| 62 | /// the speed of the basic algorithm against other styles of allocators. |
| 63 | class RABasic : public MachineFunctionPass, public RegAllocBase |
| 64 | { |
| 65 | // context |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 66 | MachineFunction *MF; |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 67 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 68 | // state |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 69 | std::auto_ptr<Spiller> SpillerInstance; |
Jakob Stoklund Olesen | 98d9648 | 2011-02-22 23:01:52 +0000 | [diff] [blame] | 70 | std::priority_queue<LiveInterval*, std::vector<LiveInterval*>, |
| 71 | CompSpillWeight> Queue; |
Jakob Stoklund Olesen | a94e635 | 2012-02-08 18:54:35 +0000 | [diff] [blame] | 72 | |
| 73 | // Scratch space. Allocated here to avoid repeated malloc calls in |
| 74 | // selectOrSplit(). |
| 75 | BitVector UsableRegs; |
| 76 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 77 | public: |
| 78 | RABasic(); |
| 79 | |
| 80 | /// Return the pass name. |
| 81 | virtual const char* getPassName() const { |
| 82 | return "Basic Register Allocator"; |
| 83 | } |
| 84 | |
| 85 | /// RABasic analysis usage. |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 86 | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 87 | |
| 88 | virtual void releaseMemory(); |
| 89 | |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 90 | virtual Spiller &spiller() { return *SpillerInstance; } |
Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 91 | |
Jakob Stoklund Olesen | d0bec3e | 2010-12-08 22:22:41 +0000 | [diff] [blame] | 92 | virtual float getPriority(LiveInterval *LI) { return LI->weight; } |
| 93 | |
Jakob Stoklund Olesen | 98d9648 | 2011-02-22 23:01:52 +0000 | [diff] [blame] | 94 | virtual void enqueue(LiveInterval *LI) { |
| 95 | Queue.push(LI); |
| 96 | } |
| 97 | |
| 98 | virtual LiveInterval *dequeue() { |
| 99 | if (Queue.empty()) |
| 100 | return 0; |
| 101 | LiveInterval *LI = Queue.top(); |
| 102 | Queue.pop(); |
| 103 | return LI; |
| 104 | } |
| 105 | |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 106 | virtual unsigned selectOrSplit(LiveInterval &VirtReg, |
| 107 | SmallVectorImpl<LiveInterval*> &SplitVRegs); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 108 | |
| 109 | /// Perform register allocation. |
| 110 | virtual bool runOnMachineFunction(MachineFunction &mf); |
| 111 | |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 112 | // Helper for spilling all live virtual registers currently unified under preg |
| 113 | // that interfere with the most recently queried lvr. Return true if spilling |
| 114 | // was successful, and append any new spilled/split intervals to splitLVRs. |
| 115 | bool spillInterferences(LiveInterval &VirtReg, unsigned PhysReg, |
| 116 | SmallVectorImpl<LiveInterval*> &SplitVRegs); |
| 117 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 118 | static char ID; |
| 119 | }; |
| 120 | |
| 121 | char RABasic::ID = 0; |
| 122 | |
| 123 | } // end anonymous namespace |
| 124 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 125 | RABasic::RABasic(): MachineFunctionPass(ID) { |
Jakob Stoklund Olesen | cfafc54 | 2011-04-05 21:40:37 +0000 | [diff] [blame] | 126 | initializeLiveDebugVariablesPass(*PassRegistry::getPassRegistry()); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 127 | initializeLiveIntervalsPass(*PassRegistry::getPassRegistry()); |
| 128 | initializeSlotIndexesPass(*PassRegistry::getPassRegistry()); |
Rafael Espindola | 5b22021 | 2011-06-26 22:34:10 +0000 | [diff] [blame] | 129 | initializeRegisterCoalescerPass(*PassRegistry::getPassRegistry()); |
Andrew Trick | 42b7a71 | 2012-01-17 06:55:03 +0000 | [diff] [blame] | 130 | initializeMachineSchedulerPass(*PassRegistry::getPassRegistry()); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 131 | initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry()); |
| 132 | initializeLiveStacksPass(*PassRegistry::getPassRegistry()); |
Jakob Stoklund Olesen | 964bc25 | 2010-11-03 20:39:26 +0000 | [diff] [blame] | 133 | initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry()); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 134 | initializeMachineLoopInfoPass(*PassRegistry::getPassRegistry()); |
| 135 | initializeVirtRegMapPass(*PassRegistry::getPassRegistry()); |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 136 | initializeLiveRegMatrixPass(*PassRegistry::getPassRegistry()); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 139 | void RABasic::getAnalysisUsage(AnalysisUsage &AU) const { |
| 140 | AU.setPreservesCFG(); |
| 141 | AU.addRequired<AliasAnalysis>(); |
| 142 | AU.addPreserved<AliasAnalysis>(); |
| 143 | AU.addRequired<LiveIntervals>(); |
Jakob Stoklund Olesen | 05ec712 | 2012-06-08 23:44:45 +0000 | [diff] [blame] | 144 | AU.addPreserved<LiveIntervals>(); |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 145 | AU.addPreserved<SlotIndexes>(); |
Jakob Stoklund Olesen | cfafc54 | 2011-04-05 21:40:37 +0000 | [diff] [blame] | 146 | AU.addRequired<LiveDebugVariables>(); |
| 147 | AU.addPreserved<LiveDebugVariables>(); |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 148 | AU.addRequired<CalculateSpillWeights>(); |
| 149 | AU.addRequired<LiveStacks>(); |
| 150 | AU.addPreserved<LiveStacks>(); |
| 151 | AU.addRequiredID(MachineDominatorsID); |
| 152 | AU.addPreservedID(MachineDominatorsID); |
| 153 | AU.addRequired<MachineLoopInfo>(); |
| 154 | AU.addPreserved<MachineLoopInfo>(); |
| 155 | AU.addRequired<VirtRegMap>(); |
| 156 | AU.addPreserved<VirtRegMap>(); |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 157 | AU.addRequired<LiveRegMatrix>(); |
| 158 | AU.addPreserved<LiveRegMatrix>(); |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 159 | MachineFunctionPass::getAnalysisUsage(AU); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void RABasic::releaseMemory() { |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 163 | SpillerInstance.reset(0); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 166 | |
| 167 | // Spill or split all live virtual registers currently unified under PhysReg |
| 168 | // that interfere with VirtReg. The newly spilled or split live intervals are |
| 169 | // returned by appending them to SplitVRegs. |
| 170 | bool RABasic::spillInterferences(LiveInterval &VirtReg, unsigned PhysReg, |
| 171 | SmallVectorImpl<LiveInterval*> &SplitVRegs) { |
| 172 | // Record each interference and determine if all are spillable before mutating |
| 173 | // either the union or live intervals. |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 174 | SmallVector<LiveInterval*, 8> Intfs; |
| 175 | |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 176 | // Collect interferences assigned to any alias of the physical register. |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 177 | for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) { |
| 178 | LiveIntervalUnion::Query &Q = Matrix->query(VirtReg, *Units); |
| 179 | Q.collectInterferingVRegs(); |
| 180 | if (Q.seenUnspillableVReg()) |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 181 | return false; |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 182 | for (unsigned i = Q.interferingVRegs().size(); i; --i) { |
| 183 | LiveInterval *Intf = Q.interferingVRegs()[i - 1]; |
| 184 | if (!Intf->isSpillable() || Intf->weight > VirtReg.weight) |
| 185 | return false; |
| 186 | Intfs.push_back(Intf); |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | DEBUG(dbgs() << "spilling " << TRI->getName(PhysReg) << |
| 190 | " interferences with " << VirtReg << "\n"); |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 191 | assert(!Intfs.empty() && "expected interference"); |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 192 | |
| 193 | // Spill each interfering vreg allocated to PhysReg or an alias. |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 194 | for (unsigned i = 0, e = Intfs.size(); i != e; ++i) { |
| 195 | LiveInterval &Spill = *Intfs[i]; |
| 196 | |
| 197 | // Skip duplicates. |
| 198 | if (!VRM->hasPhys(Spill.reg)) |
| 199 | continue; |
| 200 | |
| 201 | // Deallocate the interfering vreg by removing it from the union. |
| 202 | // A LiveInterval instance may not be in a union during modification! |
| 203 | Matrix->unassign(Spill); |
| 204 | |
| 205 | // Spill the extracted interval. |
| 206 | LiveRangeEdit LRE(&Spill, SplitVRegs, *MF, *LIS, VRM); |
| 207 | spiller().spill(LRE); |
| 208 | } |
Jakob Stoklund Olesen | a8bd9a6 | 2012-01-11 22:52:14 +0000 | [diff] [blame] | 209 | return true; |
| 210 | } |
| 211 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 212 | // Driver for the register assignment and splitting heuristics. |
| 213 | // Manages iteration over the LiveIntervalUnions. |
Andrew Trick | 13bdbb0 | 2010-11-20 02:43:55 +0000 | [diff] [blame] | 214 | // |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 215 | // This is a minimal implementation of register assignment and splitting that |
| 216 | // spills whenever we run out of registers. |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 217 | // |
| 218 | // selectOrSplit can only be called once per live virtual register. We then do a |
| 219 | // single interference test for each register the correct class until we find an |
| 220 | // available register. So, the number of interference tests in the worst case is |
| 221 | // |vregs| * |machineregs|. And since the number of interference tests is |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 222 | // minimal, there is no value in caching them outside the scope of |
| 223 | // selectOrSplit(). |
| 224 | unsigned RABasic::selectOrSplit(LiveInterval &VirtReg, |
| 225 | SmallVectorImpl<LiveInterval*> &SplitVRegs) { |
Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 226 | // Populate a list of physical register spill candidates. |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 227 | SmallVector<unsigned, 8> PhysRegSpillCands; |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 228 | |
Andrew Trick | 13bdbb0 | 2010-11-20 02:43:55 +0000 | [diff] [blame] | 229 | // Check for an available register in this class. |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 230 | AllocationOrder Order(VirtReg.reg, *VRM, RegClassInfo); |
| 231 | while (unsigned PhysReg = Order.next()) { |
| 232 | // Check for interference in PhysReg |
| 233 | switch (Matrix->checkInterference(VirtReg, PhysReg)) { |
| 234 | case LiveRegMatrix::IK_Free: |
| 235 | // PhysReg is available, allocate it. |
| 236 | return PhysReg; |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 237 | |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 238 | case LiveRegMatrix::IK_VirtReg: |
| 239 | // Only virtual registers in the way, we may be able to spill them. |
| 240 | PhysRegSpillCands.push_back(PhysReg); |
Jakob Stoklund Olesen | a94e635 | 2012-02-08 18:54:35 +0000 | [diff] [blame] | 241 | continue; |
| 242 | |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 243 | default: |
| 244 | // RegMask or RegUnit interference. |
| 245 | continue; |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 246 | } |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 247 | } |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 248 | |
Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 249 | // Try to spill another interfering reg with less spill weight. |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 250 | for (SmallVectorImpl<unsigned>::iterator PhysRegI = PhysRegSpillCands.begin(), |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 251 | PhysRegE = PhysRegSpillCands.end(); PhysRegI != PhysRegE; ++PhysRegI) { |
| 252 | if (!spillInterferences(VirtReg, *PhysRegI, SplitVRegs)) |
| 253 | continue; |
Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 254 | |
Jakob Stoklund Olesen | 812cda9 | 2012-06-20 22:52:24 +0000 | [diff] [blame] | 255 | assert(!Matrix->checkInterference(VirtReg, *PhysRegI) && |
Jakob Stoklund Olesen | 2b38c51 | 2010-12-07 18:51:27 +0000 | [diff] [blame] | 256 | "Interference after spill."); |
Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 257 | // Tell the caller to allocate to this newly freed physical register. |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 258 | return *PhysRegI; |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 259 | } |
Jakob Stoklund Olesen | bf4e10f | 2011-05-06 21:58:30 +0000 | [diff] [blame] | 260 | |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 261 | // No other spill candidates were found, so spill the current VirtReg. |
| 262 | DEBUG(dbgs() << "spilling: " << VirtReg << '\n'); |
Jakob Stoklund Olesen | bf4e10f | 2011-05-06 21:58:30 +0000 | [diff] [blame] | 263 | if (!VirtReg.isSpillable()) |
| 264 | return ~0u; |
Jakob Stoklund Olesen | 20942dc | 2012-05-19 05:25:46 +0000 | [diff] [blame] | 265 | LiveRangeEdit LRE(&VirtReg, SplitVRegs, *MF, *LIS, VRM); |
Jakob Stoklund Olesen | 47dbf6c | 2011-03-10 01:51:42 +0000 | [diff] [blame] | 266 | spiller().spill(LRE); |
Andrew Trick | 13bdbb0 | 2010-11-20 02:43:55 +0000 | [diff] [blame] | 267 | |
Andrew Trick | f4baeaf | 2010-11-10 19:18:47 +0000 | [diff] [blame] | 268 | // The live virtual register requesting allocation was spilled, so tell |
| 269 | // the caller not to allocate anything during this round. |
| 270 | return 0; |
Andrew Trick | e141a49 | 2010-11-08 18:02:08 +0000 | [diff] [blame] | 271 | } |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 272 | |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 273 | bool RABasic::runOnMachineFunction(MachineFunction &mf) { |
| 274 | DEBUG(dbgs() << "********** BASIC REGISTER ALLOCATION **********\n" |
| 275 | << "********** Function: " |
| 276 | << ((Value*)mf.getFunction())->getName() << '\n'); |
| 277 | |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 278 | MF = &mf; |
Jakob Stoklund Olesen | d4348a2 | 2012-06-20 22:52:29 +0000 | [diff] [blame] | 279 | RegAllocBase::init(getAnalysis<VirtRegMap>(), |
| 280 | getAnalysis<LiveIntervals>(), |
| 281 | getAnalysis<LiveRegMatrix>()); |
Jakob Stoklund Olesen | 8427596 | 2011-03-31 23:02:17 +0000 | [diff] [blame] | 282 | SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM)); |
Andrew Trick | 13bdbb0 | 2010-11-20 02:43:55 +0000 | [diff] [blame] | 283 | |
Andrew Trick | e16eecc | 2010-10-26 18:34:01 +0000 | [diff] [blame] | 284 | allocatePhysRegs(); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 285 | |
| 286 | // Diagnostic output before rewriting |
Andrew Trick | 18c57a8 | 2010-11-30 23:18:47 +0000 | [diff] [blame] | 287 | DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *VRM << "\n"); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 288 | |
Andrew Trick | e16eecc | 2010-10-26 18:34:01 +0000 | [diff] [blame] | 289 | releaseMemory(); |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 290 | return true; |
| 291 | } |
| 292 | |
Andrew Trick | 13bdbb0 | 2010-11-20 02:43:55 +0000 | [diff] [blame] | 293 | FunctionPass* llvm::createBasicRegisterAllocator() |
Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 294 | { |
| 295 | return new RABasic(); |
| 296 | } |