Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 1 | //===-- RegAllocLocal.cpp - A BasicBlock generic register allocator -------===// |
| 2 | // |
| 3 | // This register allocator allocates registers to a basic block at a time, |
| 4 | // attempting to keep values in registers and reusing registers as appropriate. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 8 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 9 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/SSARegMap.h" |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/FunctionFrameInfo.h" |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 12 | #include "llvm/Target/MachineInstrInfo.h" |
| 13 | #include "llvm/Target/TargetMachine.h" |
| 14 | #include "Support/Statistic.h" |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 15 | #include "Support/CommandLine.h" |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 16 | #include <iostream> |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 17 | #include <set> |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 18 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 19 | namespace { |
| 20 | Statistic<> NumSpilled ("ra-local", "Number of registers spilled"); |
| 21 | Statistic<> NumReloaded("ra-local", "Number of registers reloaded"); |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 22 | cl::opt<bool> DisableKill("no-kill", cl::Hidden, |
| 23 | cl::desc("Disable register kill in local-ra")); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 25 | class RA : public MachineFunctionPass { |
| 26 | const TargetMachine *TM; |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 27 | MachineFunction *MF; |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 28 | const MRegisterInfo *RegInfo; |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 30 | // StackSlotForVirtReg - Maps SSA Regs => frame index where these values are |
| 31 | // spilled |
| 32 | std::map<unsigned, int> StackSlotForVirtReg; |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 33 | |
| 34 | // Virt2PhysRegMap - This map contains entries for each virtual register |
| 35 | // that is currently available in a physical register. |
| 36 | // |
| 37 | std::map<unsigned, unsigned> Virt2PhysRegMap; |
| 38 | |
| 39 | // PhysRegsUsed - This map contains entries for each physical register that |
| 40 | // currently has a value (ie, it is in Virt2PhysRegMap). The value mapped |
| 41 | // to is the virtual register corresponding to the physical register (the |
| 42 | // inverse of the Virt2PhysRegMap), or 0. The value is set to 0 if this |
| 43 | // register is pinned because it is used by a future instruction. |
| 44 | // |
| 45 | std::map<unsigned, unsigned> PhysRegsUsed; |
| 46 | |
| 47 | // PhysRegsUseOrder - This contains a list of the physical registers that |
| 48 | // currently have a virtual register value in them. This list provides an |
| 49 | // ordering of registers, imposing a reallocation order. This list is only |
| 50 | // used if all registers are allocated and we have to spill one, in which |
| 51 | // case we spill the least recently used register. Entries at the front of |
| 52 | // the list are the least recently used registers, entries at the back are |
| 53 | // the most recently used. |
| 54 | // |
| 55 | std::vector<unsigned> PhysRegsUseOrder; |
| 56 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 57 | // LastUserOf map - This multimap contains the set of registers that each |
| 58 | // key instruction is the last user of. If an instruction has an entry in |
| 59 | // this map, that means that the specified operands are killed after the |
| 60 | // instruction is executed, thus they don't need to be spilled into memory |
| 61 | // |
| 62 | std::multimap<MachineInstr*, unsigned> LastUserOf; |
| 63 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 64 | void MarkPhysRegRecentlyUsed(unsigned Reg) { |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 65 | assert(!PhysRegsUseOrder.empty() && "No registers used!"); |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 66 | if (PhysRegsUseOrder.back() == Reg) return; // Already most recently used |
| 67 | |
| 68 | for (unsigned i = PhysRegsUseOrder.size(); i != 0; --i) |
| 69 | if (areRegsEqual(Reg, PhysRegsUseOrder[i-1])) { |
| 70 | unsigned RegMatch = PhysRegsUseOrder[i-1]; // remove from middle |
| 71 | PhysRegsUseOrder.erase(PhysRegsUseOrder.begin()+i-1); |
| 72 | // Add it to the end of the list |
| 73 | PhysRegsUseOrder.push_back(RegMatch); |
| 74 | if (RegMatch == Reg) |
| 75 | return; // Found an exact match, exit early |
| 76 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | public: |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 80 | virtual const char *getPassName() const { |
| 81 | return "Local Register Allocator"; |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | /// runOnMachineFunction - Register allocate the whole function |
| 86 | bool runOnMachineFunction(MachineFunction &Fn); |
| 87 | |
| 88 | /// AllocateBasicBlock - Register allocate the specified basic block. |
| 89 | void AllocateBasicBlock(MachineBasicBlock &MBB); |
| 90 | |
| 91 | /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions |
| 92 | /// in predecessor basic blocks. |
| 93 | void EliminatePHINodes(MachineBasicBlock &MBB); |
| 94 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 95 | /// CalculateLastUseOfVReg - Calculate an approximation of the killing |
| 96 | /// uses for the virtual registers in the function. Here we try to capture |
| 97 | /// registers that are defined and only used within the same basic block. |
| 98 | /// Because we don't have use-def chains yet, we have to do this the hard |
| 99 | /// way. |
| 100 | /// |
| 101 | void CalculateLastUseOfVReg(MachineBasicBlock &MBB, |
| 102 | std::map<unsigned, MachineInstr*> &LastUseOfVReg) const; |
| 103 | |
| 104 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 105 | /// areRegsEqual - This method returns true if the specified registers are |
| 106 | /// related to each other. To do this, it checks to see if they are equal |
| 107 | /// or if the first register is in the alias set of the second register. |
| 108 | /// |
| 109 | bool areRegsEqual(unsigned R1, unsigned R2) const { |
| 110 | if (R1 == R2) return true; |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 111 | if (const unsigned *AliasSet = RegInfo->getAliasSet(R2)) |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 112 | for (unsigned i = 0; AliasSet[i]; ++i) |
| 113 | if (AliasSet[i] == R1) return true; |
| 114 | return false; |
| 115 | } |
| 116 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 117 | /// getStackSpaceFor - This returns the frame index of the specified virtual |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 118 | /// register on the stack, allocating space if neccesary. |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 119 | int getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 120 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 121 | void removePhysReg(unsigned PhysReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 122 | |
| 123 | /// spillVirtReg - This method spills the value specified by PhysReg into |
| 124 | /// the virtual register slot specified by VirtReg. It then updates the RA |
| 125 | /// data structures to indicate the fact that PhysReg is now available. |
| 126 | /// |
| 127 | void spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I, |
| 128 | unsigned VirtReg, unsigned PhysReg); |
| 129 | |
Chris Lattner | c21be92 | 2002-12-16 17:44:42 +0000 | [diff] [blame] | 130 | /// spillPhysReg - This method spills the specified physical register into |
| 131 | /// the virtual register slot associated with it. |
| 132 | // |
| 133 | void spillPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I, |
| 134 | unsigned PhysReg) { |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 135 | std::map<unsigned, unsigned>::iterator PI = PhysRegsUsed.find(PhysReg); |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 136 | if (PI != PhysRegsUsed.end()) { // Only spill it if it's used! |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 137 | spillVirtReg(MBB, I, PI->second, PhysReg); |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 138 | } else if (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg)) { |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 139 | // If the selected register aliases any other registers, we must make |
| 140 | // sure that one of the aliases isn't alive... |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 141 | for (unsigned i = 0; AliasSet[i]; ++i) { |
| 142 | PI = PhysRegsUsed.find(AliasSet[i]); |
| 143 | if (PI != PhysRegsUsed.end()) // Spill aliased register... |
| 144 | spillVirtReg(MBB, I, PI->second, AliasSet[i]); |
| 145 | } |
| 146 | } |
Chris Lattner | c21be92 | 2002-12-16 17:44:42 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 149 | void AssignVirtToPhysReg(unsigned VirtReg, unsigned PhysReg); |
| 150 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 151 | /// isPhysRegAvailable - Return true if the specified physical register is |
| 152 | /// free and available for use. This also includes checking to see if |
| 153 | /// aliased registers are all free... |
| 154 | /// |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 155 | bool isPhysRegAvailable(unsigned PhysReg) const; |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 156 | |
| 157 | /// getFreeReg - Find a physical register to hold the specified virtual |
| 158 | /// register. If all compatible physical registers are used, this method |
| 159 | /// spills the last used virtual register to the stack, and uses that |
| 160 | /// register. |
| 161 | /// |
| 162 | unsigned getFreeReg(MachineBasicBlock &MBB, |
| 163 | MachineBasicBlock::iterator &I, |
| 164 | unsigned virtualReg); |
| 165 | |
| 166 | /// reloadVirtReg - This method loads the specified virtual register into a |
| 167 | /// physical register, returning the physical register chosen. This updates |
| 168 | /// the regalloc data structures to reflect the fact that the virtual reg is |
| 169 | /// now alive in a physical register, and the previous one isn't. |
| 170 | /// |
| 171 | unsigned reloadVirtReg(MachineBasicBlock &MBB, |
| 172 | MachineBasicBlock::iterator &I, unsigned VirtReg); |
| 173 | }; |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 176 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 177 | /// getStackSpaceFor - This allocates space for the specified virtual |
| 178 | /// register to be held on the stack. |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 179 | int RA::getStackSpaceFor(unsigned VirtReg, |
| 180 | const TargetRegisterClass *RC) { |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 181 | // Find the location VirtReg would belong... |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 182 | std::map<unsigned, int>::iterator I = |
| 183 | StackSlotForVirtReg.lower_bound(VirtReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 184 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 185 | if (I != StackSlotForVirtReg.end() && I->first == VirtReg) |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 186 | return I->second; // Already has space allocated? |
| 187 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 188 | // Allocate a new stack object for this spill location... |
| 189 | int FrameIdx = |
| 190 | MF->getFrameInfo()->CreateStackObject(RC->getSize(), RC->getAlignment()); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 191 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 192 | // Assign the slot... |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 193 | StackSlotForVirtReg.insert(I, std::make_pair(VirtReg, FrameIdx)); |
| 194 | return FrameIdx; |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 197 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 198 | /// removePhysReg - This method marks the specified physical register as no |
| 199 | /// longer being in use. |
| 200 | /// |
| 201 | void RA::removePhysReg(unsigned PhysReg) { |
| 202 | PhysRegsUsed.erase(PhysReg); // PhyReg no longer used |
| 203 | |
| 204 | std::vector<unsigned>::iterator It = |
| 205 | std::find(PhysRegsUseOrder.begin(), PhysRegsUseOrder.end(), PhysReg); |
| 206 | assert(It != PhysRegsUseOrder.end() && |
| 207 | "Spilled a physical register, but it was not in use list!"); |
| 208 | PhysRegsUseOrder.erase(It); |
| 209 | } |
| 210 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 211 | /// spillVirtReg - This method spills the value specified by PhysReg into the |
| 212 | /// virtual register slot specified by VirtReg. It then updates the RA data |
| 213 | /// structures to indicate the fact that PhysReg is now available. |
| 214 | /// |
| 215 | void RA::spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I, |
| 216 | unsigned VirtReg, unsigned PhysReg) { |
| 217 | // If this is just a marker register, we don't need to spill it. |
| 218 | if (VirtReg != 0) { |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 219 | const TargetRegisterClass *RegClass = |
| 220 | MF->getSSARegMap()->getRegClass(VirtReg); |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 221 | int FrameIndex = getStackSpaceFor(VirtReg, RegClass); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 222 | |
| 223 | // Add move instruction(s) |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 224 | RegInfo->storeRegToStackSlot(MBB, I, PhysReg, FrameIndex, RegClass); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 225 | ++NumSpilled; // Update statistics |
| 226 | Virt2PhysRegMap.erase(VirtReg); // VirtReg no longer available |
| 227 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 228 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 229 | removePhysReg(PhysReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 232 | |
| 233 | /// isPhysRegAvailable - Return true if the specified physical register is free |
| 234 | /// and available for use. This also includes checking to see if aliased |
| 235 | /// registers are all free... |
| 236 | /// |
| 237 | bool RA::isPhysRegAvailable(unsigned PhysReg) const { |
| 238 | if (PhysRegsUsed.count(PhysReg)) return false; |
| 239 | |
| 240 | // If the selected register aliases any other allocated registers, it is |
| 241 | // not free! |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 242 | if (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg)) |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 243 | for (unsigned i = 0; AliasSet[i]; ++i) |
| 244 | if (PhysRegsUsed.count(AliasSet[i])) // Aliased register in use? |
| 245 | return false; // Can't use this reg then. |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 251 | /// getFreeReg - Find a physical register to hold the specified virtual |
| 252 | /// register. If all compatible physical registers are used, this method spills |
| 253 | /// the last used virtual register to the stack, and uses that register. |
| 254 | /// |
| 255 | unsigned RA::getFreeReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I, |
| 256 | unsigned VirtReg) { |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 257 | const TargetRegisterClass *RC = MF->getSSARegMap()->getRegClass(VirtReg); |
| 258 | |
| 259 | // Get iterators defining the range of registers that are valid to allocate in |
| 260 | // this class, which also specifies the preferred allocation order. |
| 261 | TargetRegisterClass::iterator RI = RC->allocation_order_begin(*MF); |
| 262 | TargetRegisterClass::iterator RE = RC->allocation_order_end(*MF); |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 263 | |
| 264 | // First check to see if we have a free register of the requested type... |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 265 | unsigned PhysReg = 0; |
| 266 | for (; RI != RE; ++RI) { |
| 267 | unsigned R = *RI; |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 268 | if (isPhysRegAvailable(R)) { // Is reg unused? |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 269 | // Found an unused register! |
| 270 | PhysReg = R; |
| 271 | assert(PhysReg != 0 && "Cannot use register!"); |
| 272 | break; |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 273 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 276 | // If we didn't find an unused register, scavenge one now! |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 277 | if (PhysReg == 0) { |
Chris Lattner | c21be92 | 2002-12-16 17:44:42 +0000 | [diff] [blame] | 278 | assert(!PhysRegsUseOrder.empty() && "No allocated registers??"); |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 279 | |
| 280 | // Loop over all of the preallocated registers from the least recently used |
| 281 | // to the most recently used. When we find one that is capable of holding |
| 282 | // our register, use it. |
| 283 | for (unsigned i = 0; PhysReg == 0; ++i) { |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 284 | assert(i != PhysRegsUseOrder.size() && |
| 285 | "Couldn't find a register of the appropriate class!"); |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 286 | |
| 287 | unsigned R = PhysRegsUseOrder[i]; |
| 288 | // If the current register is compatible, use it. |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 289 | if (RegInfo->getRegClass(R) == RC) { |
| 290 | PhysReg = R; |
| 291 | break; |
| 292 | } else { |
| 293 | // If one of the registers aliased to the current register is |
| 294 | // compatible, use it. |
| 295 | if (const unsigned *AliasSet = RegInfo->getAliasSet(R)) |
| 296 | for (unsigned a = 0; AliasSet[a]; ++a) |
| 297 | if (RegInfo->getRegClass(AliasSet[a]) == RC) { |
| 298 | PhysReg = AliasSet[a]; // Take an aliased register |
| 299 | break; |
| 300 | } |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 301 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 304 | assert(PhysReg && "Physical register not assigned!?!?"); |
| 305 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 306 | // At this point PhysRegsUseOrder[i] is the least recently used register of |
| 307 | // compatible register class. Spill it to memory and reap its remains. |
Chris Lattner | c21be92 | 2002-12-16 17:44:42 +0000 | [diff] [blame] | 308 | spillPhysReg(MBB, I, PhysReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | // Now that we know which register we need to assign this to, do it now! |
| 312 | AssignVirtToPhysReg(VirtReg, PhysReg); |
| 313 | return PhysReg; |
| 314 | } |
| 315 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 316 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 317 | void RA::AssignVirtToPhysReg(unsigned VirtReg, unsigned PhysReg) { |
| 318 | assert(PhysRegsUsed.find(PhysReg) == PhysRegsUsed.end() && |
| 319 | "Phys reg already assigned!"); |
| 320 | // Update information to note the fact that this register was just used, and |
| 321 | // it holds VirtReg. |
| 322 | PhysRegsUsed[PhysReg] = VirtReg; |
| 323 | Virt2PhysRegMap[VirtReg] = PhysReg; |
| 324 | PhysRegsUseOrder.push_back(PhysReg); // New use of PhysReg |
| 325 | } |
| 326 | |
| 327 | |
| 328 | /// reloadVirtReg - This method loads the specified virtual register into a |
| 329 | /// physical register, returning the physical register chosen. This updates the |
| 330 | /// regalloc data structures to reflect the fact that the virtual reg is now |
| 331 | /// alive in a physical register, and the previous one isn't. |
| 332 | /// |
| 333 | unsigned RA::reloadVirtReg(MachineBasicBlock &MBB, |
| 334 | MachineBasicBlock::iterator &I, |
| 335 | unsigned VirtReg) { |
| 336 | std::map<unsigned, unsigned>::iterator It = Virt2PhysRegMap.find(VirtReg); |
| 337 | if (It != Virt2PhysRegMap.end()) { |
| 338 | MarkPhysRegRecentlyUsed(It->second); |
| 339 | return It->second; // Already have this value available! |
| 340 | } |
| 341 | |
| 342 | unsigned PhysReg = getFreeReg(MBB, I, VirtReg); |
| 343 | |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 344 | const TargetRegisterClass *RC = MF->getSSARegMap()->getRegClass(VirtReg); |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 345 | int FrameIndex = getStackSpaceFor(VirtReg, RC); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 346 | |
| 347 | // Add move instruction(s) |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 348 | RegInfo->loadRegFromStackSlot(MBB, I, PhysReg, FrameIndex, RC); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 349 | ++NumReloaded; // Update statistics |
| 350 | return PhysReg; |
| 351 | } |
| 352 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 353 | /// CalculateLastUseOfVReg - Calculate an approximation of the killing uses for |
| 354 | /// the virtual registers in the function. Here we try to capture registers |
| 355 | /// that are defined and only used within the same basic block. Because we |
| 356 | /// don't have use-def chains yet, we have to do this the hard way. |
| 357 | /// |
| 358 | void RA::CalculateLastUseOfVReg(MachineBasicBlock &MBB, |
| 359 | std::map<unsigned, MachineInstr*> &LastUseOfVReg) const { |
| 360 | // Calculate the last machine instruction in this basic block that uses the |
| 361 | // specified virtual register defined in this basic block. |
| 362 | std::map<unsigned, MachineInstr*> LastLocalUses; |
| 363 | |
| 364 | for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E;++I){ |
| 365 | MachineInstr *MI = *I; |
| 366 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 367 | MachineOperand &Op = MI->getOperand(i); |
| 368 | if (Op.isVirtualRegister()) { |
| 369 | if (Op.opIsDef()) { // Definition of a new virtual reg? |
| 370 | LastLocalUses[Op.getAllocatedRegNum()] = 0; // Record it |
| 371 | } else { // Use of a virtual reg. |
| 372 | std::map<unsigned, MachineInstr*>::iterator It = |
| 373 | LastLocalUses.find(Op.getAllocatedRegNum()); |
| 374 | if (It != LastLocalUses.end()) // Local use? |
| 375 | It->second = MI; // Update last use |
| 376 | else |
| 377 | LastUseOfVReg[Op.getAllocatedRegNum()] = 0; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // Move local uses over... if there are any uses of a local already in the |
| 384 | // lastuse map, the newly inserted entry is ignored. |
| 385 | LastUseOfVReg.insert(LastLocalUses.begin(), LastLocalUses.end()); |
| 386 | } |
| 387 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 388 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 389 | /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions in |
| 390 | /// predecessor basic blocks. |
| 391 | /// |
| 392 | void RA::EliminatePHINodes(MachineBasicBlock &MBB) { |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 393 | const MachineInstrInfo &MII = TM->getInstrInfo(); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 394 | |
| 395 | while (MBB.front()->getOpcode() == MachineInstrInfo::PHI) { |
| 396 | MachineInstr *MI = MBB.front(); |
| 397 | // Unlink the PHI node from the basic block... but don't delete the PHI yet |
| 398 | MBB.erase(MBB.begin()); |
| 399 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 400 | assert(MI->getOperand(0).isVirtualRegister() && |
| 401 | "PHI node doesn't write virt reg?"); |
| 402 | |
| 403 | unsigned virtualReg = MI->getOperand(0).getAllocatedRegNum(); |
| 404 | |
| 405 | for (int i = MI->getNumOperands() - 1; i >= 2; i-=2) { |
| 406 | MachineOperand &opVal = MI->getOperand(i-1); |
| 407 | |
| 408 | // Get the MachineBasicBlock equivalent of the BasicBlock that is the |
| 409 | // source path the phi |
| 410 | MachineBasicBlock &opBlock = *MI->getOperand(i).getMachineBasicBlock(); |
| 411 | |
| 412 | // Check to make sure we haven't already emitted the copy for this block. |
| 413 | // This can happen because PHI nodes may have multiple entries for the |
| 414 | // same basic block. It doesn't matter which entry we use though, because |
| 415 | // all incoming values are guaranteed to be the same for a particular bb. |
| 416 | // |
| 417 | // Note that this is N^2 in the number of phi node entries, but since the |
| 418 | // # of entries is tiny, this is not a problem. |
| 419 | // |
| 420 | bool HaveNotEmitted = true; |
| 421 | for (int op = MI->getNumOperands() - 1; op != i; op -= 2) |
| 422 | if (&opBlock == MI->getOperand(op).getMachineBasicBlock()) { |
| 423 | HaveNotEmitted = false; |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | if (HaveNotEmitted) { |
| 428 | MachineBasicBlock::iterator opI = opBlock.end(); |
| 429 | MachineInstr *opMI = *--opI; |
| 430 | |
| 431 | // must backtrack over ALL the branches in the previous block |
| 432 | while (MII.isBranch(opMI->getOpcode()) && opI != opBlock.begin()) |
| 433 | opMI = *--opI; |
| 434 | |
| 435 | // move back to the first branch instruction so new instructions |
| 436 | // are inserted right in front of it and not in front of a non-branch |
| 437 | if (!MII.isBranch(opMI->getOpcode())) |
| 438 | ++opI; |
| 439 | |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 440 | const TargetRegisterClass *RC = |
| 441 | MF->getSSARegMap()->getRegClass(virtualReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 442 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 443 | assert(opVal.isVirtualRegister() && |
| 444 | "Machine PHI Operands must all be virtual registers!"); |
| 445 | RegInfo->copyRegToReg(opBlock, opI, virtualReg, opVal.getReg(), RC); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
| 449 | // really delete the PHI instruction now! |
| 450 | delete MI; |
| 451 | } |
| 452 | } |
| 453 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 454 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 455 | void RA::AllocateBasicBlock(MachineBasicBlock &MBB) { |
| 456 | // loop over each instruction |
| 457 | MachineBasicBlock::iterator I = MBB.begin(); |
| 458 | for (; I != MBB.end(); ++I) { |
| 459 | MachineInstr *MI = *I; |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 460 | const MachineInstrDescriptor &MID = TM->getInstrInfo().get(MI->getOpcode()); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 461 | |
| 462 | // Loop over all of the operands of the instruction, spilling registers that |
| 463 | // are defined, and marking explicit destinations in the PhysRegsUsed map. |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 464 | |
| 465 | // FIXME: We don't need to spill a register if this is the last use of the |
| 466 | // value! |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 467 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) |
| 468 | if (MI->getOperand(i).opIsDef() && |
| 469 | MI->getOperand(i).isPhysicalRegister()) { |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 470 | unsigned Reg = MI->getOperand(i).getAllocatedRegNum(); |
| 471 | spillPhysReg(MBB, I, Reg); |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 472 | PhysRegsUsed[Reg] = 0; // It is free and reserved now |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 473 | PhysRegsUseOrder.push_back(Reg); |
| 474 | } |
| 475 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 476 | // Loop over the implicit defs, spilling them, as above. |
| 477 | if (const unsigned *ImplicitDefs = MID.ImplicitDefs) |
| 478 | for (unsigned i = 0; ImplicitDefs[i]; ++i) { |
| 479 | unsigned Reg = ImplicitDefs[i]; |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 480 | |
| 481 | // We don't want to spill implicit definitions if they were explicitly |
| 482 | // chosen. For this reason, check to see now if the register we are |
| 483 | // to spill has a vreg of 0. |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 484 | if (PhysRegsUsed.count(Reg) && PhysRegsUsed[Reg] != 0) |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 485 | spillPhysReg(MBB, I, Reg); |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 486 | else if (PhysRegsUsed.count(Reg)) { |
| 487 | // Remove the entry from PhysRegsUseOrder to avoid having two entries! |
| 488 | removePhysReg(Reg); |
| 489 | } |
| 490 | PhysRegsUseOrder.push_back(Reg); |
Chris Lattner | ff863ba | 2002-12-25 05:05:46 +0000 | [diff] [blame] | 491 | PhysRegsUsed[Reg] = 0; // It is free and reserved now |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 492 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 493 | |
Chris Lattner | ae64043 | 2002-12-17 02:50:10 +0000 | [diff] [blame] | 494 | // Loop over the implicit uses, making sure that they are at the head of the |
| 495 | // use order list, so they don't get reallocated. |
| 496 | if (const unsigned *ImplicitUses = MID.ImplicitUses) |
| 497 | for (unsigned i = 0; ImplicitUses[i]; ++i) |
| 498 | MarkPhysRegRecentlyUsed(ImplicitUses[i]); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 499 | |
| 500 | // Loop over all of the operands again, getting the used operands into |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 501 | // registers. This has the potiential to spill incoming values if we are |
| 502 | // out of registers. |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 503 | // |
| 504 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) |
| 505 | if (MI->getOperand(i).opIsUse() && |
| 506 | MI->getOperand(i).isVirtualRegister()) { |
| 507 | unsigned VirtSrcReg = MI->getOperand(i).getAllocatedRegNum(); |
| 508 | unsigned PhysSrcReg = reloadVirtReg(MBB, I, VirtSrcReg); |
| 509 | MI->SetMachineOperandReg(i, PhysSrcReg); // Assign the input register |
| 510 | } |
| 511 | |
| 512 | // Okay, we have allocated all of the source operands and spilled any values |
| 513 | // that would be destroyed by defs of this instruction. Loop over the |
| 514 | // implicit defs and assign them to a register, spilling the incoming value |
| 515 | // if we need to scavange a register. |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 516 | // |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 517 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) |
| 518 | if (MI->getOperand(i).opIsDef() && |
| 519 | !MI->getOperand(i).isPhysicalRegister()) { |
| 520 | unsigned DestVirtReg = MI->getOperand(i).getAllocatedRegNum(); |
| 521 | unsigned DestPhysReg; |
| 522 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 523 | if (TM->getInstrInfo().isTwoAddrInstr(MI->getOpcode()) && i == 0) { |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 524 | // must be same register number as the first operand |
| 525 | // This maps a = b + c into b += c, and saves b into a's spot |
| 526 | assert(MI->getOperand(1).isRegister() && |
| 527 | MI->getOperand(1).getAllocatedRegNum() && |
| 528 | MI->getOperand(1).opIsUse() && |
| 529 | "Two address instruction invalid!"); |
| 530 | DestPhysReg = MI->getOperand(1).getAllocatedRegNum(); |
| 531 | |
| 532 | // Spill the incoming value, because we are about to change the |
| 533 | // register contents. |
Chris Lattner | c21be92 | 2002-12-16 17:44:42 +0000 | [diff] [blame] | 534 | spillPhysReg(MBB, I, DestPhysReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 535 | AssignVirtToPhysReg(DestVirtReg, DestPhysReg); |
| 536 | } else { |
| 537 | DestPhysReg = getFreeReg(MBB, I, DestVirtReg); |
| 538 | } |
| 539 | MI->SetMachineOperandReg(i, DestPhysReg); // Assign the output register |
| 540 | } |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 541 | |
| 542 | if (!DisableKill) { |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 543 | // If this instruction is the last user of anything in registers, kill the |
| 544 | // value, freeing the register being used, so it doesn't need to be |
| 545 | // spilled to memory at the end of the block. |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 546 | std::multimap<MachineInstr*, unsigned>::iterator LUOI = |
| 547 | LastUserOf.lower_bound(MI); |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 548 | for (; LUOI != LastUserOf.end() && LUOI->first == MI; ++MI) { |
| 549 | unsigned VirtReg = LUOI->second; // entry found? |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 550 | unsigned PhysReg = Virt2PhysRegMap[VirtReg]; |
| 551 | if (PhysReg) { |
Chris Lattner | 0eb172c | 2002-12-24 00:04:55 +0000 | [diff] [blame] | 552 | DEBUG(std::cout << "V: " << VirtReg << " P: " << PhysReg |
| 553 | << " Last use of: " << *MI); |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 554 | removePhysReg(PhysReg); |
| 555 | } |
| 556 | Virt2PhysRegMap.erase(VirtReg); |
| 557 | } |
| 558 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | // Rewind the iterator to point to the first flow control instruction... |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 562 | const MachineInstrInfo &MII = TM->getInstrInfo(); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 563 | I = MBB.end(); |
| 564 | do { |
| 565 | --I; |
| 566 | } while ((MII.isReturn((*I)->getOpcode()) || |
| 567 | MII.isBranch((*I)->getOpcode())) && I != MBB.begin()); |
| 568 | |
| 569 | if (!MII.isReturn((*I)->getOpcode()) && !MII.isBranch((*I)->getOpcode())) |
| 570 | ++I; |
| 571 | |
| 572 | // Spill all physical registers holding virtual registers now. |
| 573 | while (!PhysRegsUsed.empty()) |
| 574 | spillVirtReg(MBB, I, PhysRegsUsed.begin()->second, |
| 575 | PhysRegsUsed.begin()->first); |
| 576 | |
| 577 | assert(Virt2PhysRegMap.empty() && "Virtual registers still in phys regs?"); |
| 578 | assert(PhysRegsUseOrder.empty() && "Physical regs still allocated?"); |
| 579 | } |
| 580 | |
Chris Lattner | 86c69a6 | 2002-12-17 03:16:10 +0000 | [diff] [blame] | 581 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 582 | /// runOnMachineFunction - Register allocate the whole function |
| 583 | /// |
| 584 | bool RA::runOnMachineFunction(MachineFunction &Fn) { |
| 585 | DEBUG(std::cerr << "Machine Function " << "\n"); |
| 586 | MF = &Fn; |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 587 | TM = &Fn.getTarget(); |
| 588 | RegInfo = TM->getRegisterInfo(); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 589 | |
| 590 | // First pass: eliminate PHI instructions by inserting copies into predecessor |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 591 | // blocks, and calculate a simple approximation of killing uses for virtual |
| 592 | // registers. |
| 593 | // |
| 594 | std::map<unsigned, MachineInstr*> LastUseOfVReg; |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 595 | for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end(); |
Chris Lattner | e7d361d | 2002-12-17 04:19:40 +0000 | [diff] [blame] | 596 | MBB != MBBe; ++MBB) { |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 597 | if (!DisableKill) |
| 598 | CalculateLastUseOfVReg(*MBB, LastUseOfVReg); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 599 | EliminatePHINodes(*MBB); |
Chris Lattner | e7d361d | 2002-12-17 04:19:40 +0000 | [diff] [blame] | 600 | } |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 601 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 602 | // At this point LastUseOfVReg has been filled in to contain the last |
| 603 | // MachineInstr user of the specified virtual register, if that user is |
| 604 | // within the same basic block as the definition (otherwise it contains |
| 605 | // null). Invert this mapping now: |
| 606 | if (!DisableKill) |
| 607 | for (std::map<unsigned, MachineInstr*>::iterator I = LastUseOfVReg.begin(), |
| 608 | E = LastUseOfVReg.end(); I != E; ++I) |
| 609 | if (I->second) |
| 610 | LastUserOf.insert(std::make_pair(I->second, I->first)); |
| 611 | |
| 612 | // We're done with the temporary list now. |
| 613 | LastUseOfVReg.clear(); |
| 614 | |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 615 | // Loop over all of the basic blocks, eliminating virtual register references |
| 616 | for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end(); |
| 617 | MBB != MBBe; ++MBB) |
| 618 | AllocateBasicBlock(*MBB); |
| 619 | |
Chris Lattner | 82bee0f | 2002-12-18 08:14:26 +0000 | [diff] [blame] | 620 | LastUserOf.clear(); |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 621 | StackSlotForVirtReg.clear(); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 622 | return true; |
| 623 | } |
| 624 | |
Chris Lattner | 580f9be | 2002-12-28 20:40:43 +0000 | [diff] [blame] | 625 | Pass *createLocalRegisterAllocator() { |
| 626 | return new RA(); |
Chris Lattner | b74e83c | 2002-12-16 16:15:28 +0000 | [diff] [blame] | 627 | } |