Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1 | //===------ RegAllocPBQP.cpp ---- PBQP Register Allocator -------*- C++ -*-===// |
| 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 | //===----------------------------------------------------------------------===// |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 9 | // |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 10 | // This file contains a Partitioned Boolean Quadratic Programming (PBQP) based |
| 11 | // register allocator for LLVM. This allocator works by constructing a PBQP |
| 12 | // problem representing the register allocation problem under consideration, |
| 13 | // solving this using a PBQP solver, and mapping the solution back to a |
| 14 | // register assignment. If any variables are selected for spilling then spill |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 15 | // code is inserted and the process repeated. |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 16 | // |
| 17 | // The PBQP solver (pbqp.c) provided for this allocator uses a heuristic tuned |
| 18 | // for register allocation. For more information on PBQP for register |
Misha Brukman | ce07e99 | 2009-01-08 16:40:25 +0000 | [diff] [blame] | 19 | // allocation, see the following papers: |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 20 | // |
| 21 | // (1) Hames, L. and Scholz, B. 2006. Nearly optimal register allocation with |
| 22 | // PBQP. In Proceedings of the 7th Joint Modular Languages Conference |
| 23 | // (JMLC'06). LNCS, vol. 4228. Springer, New York, NY, USA. 346-361. |
| 24 | // |
| 25 | // (2) Scholz, B., Eckstein, E. 2002. Register allocation for irregular |
| 26 | // architectures. In Proceedings of the Joint Conference on Languages, |
| 27 | // Compilers and Tools for Embedded Systems (LCTES'02), ACM Press, New York, |
| 28 | // NY, USA, 139-148. |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 29 | // |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 30 | //===----------------------------------------------------------------------===// |
| 31 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "regalloc" |
| 33 | |
Lang Hames | 54cc2ef | 2010-07-19 15:22:28 +0000 | [diff] [blame] | 34 | #include "RenderMachineFunction.h" |
Lang Hames | 12f35c5 | 2010-07-18 00:57:59 +0000 | [diff] [blame] | 35 | #include "Splitter.h" |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 36 | #include "VirtRegMap.h" |
Lang Hames | 87e3bca | 2009-05-06 02:36:21 +0000 | [diff] [blame] | 37 | #include "VirtRegRewriter.h" |
Lang Hames | a937f22 | 2009-12-14 06:49:42 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/CalcSpillWeights.h" |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 39 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 40 | #include "llvm/CodeGen/LiveStackAnalysis.h" |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/RegAllocPBQP.h" |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/MachineLoopInfo.h" |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 44 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 45 | #include "llvm/CodeGen/PBQP/HeuristicSolver.h" |
| 46 | #include "llvm/CodeGen/PBQP/Graph.h" |
| 47 | #include "llvm/CodeGen/PBQP/Heuristics/Briggs.h" |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 48 | #include "llvm/CodeGen/RegAllocRegistry.h" |
| 49 | #include "llvm/CodeGen/RegisterCoalescer.h" |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 50 | #include "llvm/Support/Debug.h" |
Daniel Dunbar | ce63ffb | 2009-07-25 00:23:56 +0000 | [diff] [blame] | 51 | #include "llvm/Support/raw_ostream.h" |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 52 | #include "llvm/Target/TargetInstrInfo.h" |
| 53 | #include "llvm/Target/TargetMachine.h" |
| 54 | #include <limits> |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 55 | #include <memory> |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 56 | #include <set> |
| 57 | #include <vector> |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 58 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 59 | namespace llvm { |
| 60 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 61 | static RegisterRegAlloc |
Duncan Sands | 1aecd15 | 2010-02-18 14:10:41 +0000 | [diff] [blame] | 62 | registerPBQPRepAlloc("pbqp", "PBQP register allocator", |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 63 | llvm::createPBQPRegisterAllocator); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 64 | |
Lang Hames | 8481e3b | 2009-08-19 01:36:14 +0000 | [diff] [blame] | 65 | static cl::opt<bool> |
| 66 | pbqpCoalescing("pbqp-coalescing", |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 67 | cl::desc("Attempt coalescing during PBQP register allocation."), |
| 68 | cl::init(false), cl::Hidden); |
Lang Hames | 8481e3b | 2009-08-19 01:36:14 +0000 | [diff] [blame] | 69 | |
Lang Hames | 12f35c5 | 2010-07-18 00:57:59 +0000 | [diff] [blame] | 70 | static cl::opt<bool> |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 71 | pbqpBuilder("pbqp-builder", |
| 72 | cl::desc("Use new builder system."), |
| 73 | cl::init(false), cl::Hidden); |
| 74 | |
| 75 | |
| 76 | static cl::opt<bool> |
Lang Hames | 12f35c5 | 2010-07-18 00:57:59 +0000 | [diff] [blame] | 77 | pbqpPreSplitting("pbqp-pre-splitting", |
| 78 | cl::desc("Pre-splite before PBQP register allocation."), |
| 79 | cl::init(false), cl::Hidden); |
| 80 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 81 | char RegAllocPBQP::ID = 0; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 82 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 83 | unsigned PBQPRAProblem::getVRegForNode(PBQP::Graph::ConstNodeItr node) const { |
| 84 | Node2VReg::const_iterator vregItr = node2VReg.find(node); |
| 85 | assert(vregItr != node2VReg.end() && "No vreg for node."); |
| 86 | return vregItr->second; |
| 87 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 88 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 89 | PBQP::Graph::NodeItr PBQPRAProblem::getNodeForVReg(unsigned vreg) const { |
| 90 | VReg2Node::const_iterator nodeItr = vreg2Node.find(vreg); |
| 91 | assert(nodeItr != vreg2Node.end() && "No node for vreg."); |
| 92 | return nodeItr->second; |
| 93 | |
| 94 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 95 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 96 | const PBQPRAProblem::AllowedSet& |
| 97 | PBQPRAProblem::getAllowedSet(unsigned vreg) const { |
| 98 | AllowedSetMap::const_iterator allowedSetItr = allowedSets.find(vreg); |
| 99 | assert(allowedSetItr != allowedSets.end() && "No pregs for vreg."); |
| 100 | const AllowedSet &allowedSet = allowedSetItr->second; |
| 101 | return allowedSet; |
| 102 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 103 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 104 | unsigned PBQPRAProblem::getPRegForOption(unsigned vreg, unsigned option) const { |
| 105 | assert(isPRegOption(vreg, option) && "Not a preg option."); |
| 106 | |
| 107 | const AllowedSet& allowedSet = getAllowedSet(vreg); |
| 108 | assert(option <= allowedSet.size() && "Option outside allowed set."); |
| 109 | return allowedSet[option - 1]; |
| 110 | } |
| 111 | |
Lang Hames | e9c9356 | 2010-09-21 13:19:36 +0000 | [diff] [blame^] | 112 | std::auto_ptr<PBQPRAProblem> PBQPBuilder::build(MachineFunction *mf, |
| 113 | const LiveIntervals *lis, |
| 114 | const MachineLoopInfo *loopInfo, |
| 115 | const RegSet &vregs) { |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 116 | |
| 117 | typedef std::vector<const LiveInterval*> LIVector; |
| 118 | |
| 119 | MachineRegisterInfo *mri = &mf->getRegInfo(); |
| 120 | const TargetRegisterInfo *tri = mf->getTarget().getRegisterInfo(); |
| 121 | |
| 122 | std::auto_ptr<PBQPRAProblem> p(new PBQPRAProblem()); |
| 123 | PBQP::Graph &g = p->getGraph(); |
| 124 | RegSet pregs; |
| 125 | |
| 126 | // Collect the set of preg intervals, record that they're used in the MF. |
| 127 | for (LiveIntervals::const_iterator itr = lis->begin(), end = lis->end(); |
| 128 | itr != end; ++itr) { |
| 129 | if (TargetRegisterInfo::isPhysicalRegister(itr->first)) { |
| 130 | pregs.insert(itr->first); |
| 131 | mri->setPhysRegUsed(itr->first); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 132 | } |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 133 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 134 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 135 | BitVector reservedRegs = tri->getReservedRegs(*mf); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 136 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 137 | // Iterate over vregs. |
| 138 | for (RegSet::const_iterator vregItr = vregs.begin(), vregEnd = vregs.end(); |
| 139 | vregItr != vregEnd; ++vregItr) { |
| 140 | unsigned vreg = *vregItr; |
| 141 | const TargetRegisterClass *trc = mri->getRegClass(vreg); |
| 142 | const LiveInterval *vregLI = &lis->getInterval(vreg); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 143 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 144 | // Compute an initial allowed set for the current vreg. |
| 145 | typedef std::vector<unsigned> VRAllowed; |
| 146 | VRAllowed vrAllowed; |
| 147 | for (TargetRegisterClass::iterator aoItr = trc->allocation_order_begin(*mf), |
| 148 | aoEnd = trc->allocation_order_end(*mf); |
| 149 | aoItr != aoEnd; ++aoItr) { |
| 150 | unsigned preg = *aoItr; |
| 151 | if (!reservedRegs.test(preg)) { |
| 152 | vrAllowed.push_back(preg); |
Lang Hames | d0f6f01 | 2010-07-17 06:31:41 +0000 | [diff] [blame] | 153 | } |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 154 | } |
Lang Hames | d0f6f01 | 2010-07-17 06:31:41 +0000 | [diff] [blame] | 155 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 156 | // Remove any physical registers which overlap. |
| 157 | for (RegSet::const_iterator pregItr = pregs.begin(), |
| 158 | pregEnd = pregs.end(); |
| 159 | pregItr != pregEnd; ++pregItr) { |
| 160 | unsigned preg = *pregItr; |
| 161 | const LiveInterval *pregLI = &lis->getInterval(preg); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 162 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 163 | if (pregLI->empty()) |
| 164 | continue; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 165 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 166 | if (!vregLI->overlaps(*pregLI)) |
| 167 | continue; |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 168 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 169 | // Remove the register from the allowed set. |
| 170 | VRAllowed::iterator eraseItr = |
| 171 | std::find(vrAllowed.begin(), vrAllowed.end(), preg); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 172 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 173 | if (eraseItr != vrAllowed.end()) { |
| 174 | vrAllowed.erase(eraseItr); |
| 175 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 176 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 177 | // Also remove any aliases. |
| 178 | const unsigned *aliasItr = tri->getAliasSet(preg); |
| 179 | if (aliasItr != 0) { |
| 180 | for (; *aliasItr != 0; ++aliasItr) { |
| 181 | VRAllowed::iterator eraseItr = |
| 182 | std::find(vrAllowed.begin(), vrAllowed.end(), *aliasItr); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 183 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 184 | if (eraseItr != vrAllowed.end()) { |
| 185 | vrAllowed.erase(eraseItr); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 190 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 191 | // Construct the node. |
| 192 | PBQP::Graph::NodeItr node = |
| 193 | g.addNode(PBQP::Vector(vrAllowed.size() + 1, 0)); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 194 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 195 | // Record the mapping and allowed set in the problem. |
| 196 | p->recordVReg(vreg, node, vrAllowed.begin(), vrAllowed.end()); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 197 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 198 | PBQP::PBQPNum spillCost = (vregLI->weight != 0.0) ? |
| 199 | vregLI->weight : std::numeric_limits<PBQP::PBQPNum>::min(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 200 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 201 | addSpillCosts(g.getNodeCosts(node), spillCost); |
| 202 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 203 | |
Lang Hames | 481630d | 2010-09-18 09:49:08 +0000 | [diff] [blame] | 204 | for (RegSet::const_iterator vr1Itr = vregs.begin(), vrEnd = vregs.end(); |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 205 | vr1Itr != vrEnd; ++vr1Itr) { |
| 206 | unsigned vr1 = *vr1Itr; |
| 207 | const LiveInterval &l1 = lis->getInterval(vr1); |
| 208 | const PBQPRAProblem::AllowedSet &vr1Allowed = p->getAllowedSet(vr1); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 209 | |
Benjamin Kramer | 9e8d1f9 | 2010-09-18 14:41:26 +0000 | [diff] [blame] | 210 | for (RegSet::const_iterator vr2Itr = llvm::next(vr1Itr); |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 211 | vr2Itr != vrEnd; ++vr2Itr) { |
| 212 | unsigned vr2 = *vr2Itr; |
| 213 | const LiveInterval &l2 = lis->getInterval(vr2); |
| 214 | const PBQPRAProblem::AllowedSet &vr2Allowed = p->getAllowedSet(vr2); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 215 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 216 | assert(!l2.empty() && "Empty interval in vreg set?"); |
| 217 | if (l1.overlaps(l2)) { |
| 218 | PBQP::Graph::EdgeItr edge = |
| 219 | g.addEdge(p->getNodeForVReg(vr1), p->getNodeForVReg(vr2), |
| 220 | PBQP::Matrix(vr1Allowed.size()+1, vr2Allowed.size()+1, 0)); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 221 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 222 | addInterferenceCosts(g.getEdgeCosts(edge), vr1Allowed, vr2Allowed, tri); |
| 223 | } |
| 224 | } |
| 225 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 226 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 227 | return p; |
| 228 | } |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 229 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 230 | void PBQPBuilder::addSpillCosts(PBQP::Vector &costVec, |
| 231 | PBQP::PBQPNum spillCost) { |
| 232 | costVec[0] = spillCost; |
| 233 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 234 | |
Lang Hames | e9c9356 | 2010-09-21 13:19:36 +0000 | [diff] [blame^] | 235 | void PBQPBuilder::addInterferenceCosts( |
| 236 | PBQP::Matrix &costMat, |
| 237 | const PBQPRAProblem::AllowedSet &vr1Allowed, |
| 238 | const PBQPRAProblem::AllowedSet &vr2Allowed, |
| 239 | const TargetRegisterInfo *tri) { |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 240 | assert(costMat.getRows() == vr1Allowed.size() + 1 && "Matrix height mismatch."); |
| 241 | assert(costMat.getCols() == vr2Allowed.size() + 1 && "Matrix width mismatch."); |
| 242 | |
| 243 | for (unsigned i = 0; i < vr1Allowed.size(); ++i) { |
| 244 | unsigned preg1 = vr1Allowed[i]; |
| 245 | |
| 246 | for (unsigned j = 0; j < vr2Allowed.size(); ++j) { |
| 247 | unsigned preg2 = vr2Allowed[j]; |
| 248 | |
| 249 | if (tri->regsOverlap(preg1, preg2)) { |
| 250 | costMat[i + 1][j + 1] = std::numeric_limits<PBQP::PBQPNum>::infinity(); |
| 251 | } |
| 252 | } |
| 253 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Lang Hames | e9c9356 | 2010-09-21 13:19:36 +0000 | [diff] [blame^] | 256 | std::auto_ptr<PBQPRAProblem> PBQPBuilderWithCoalescing::build( |
| 257 | MachineFunction *mf, |
| 258 | const LiveIntervals *lis, |
| 259 | const MachineLoopInfo *loopInfo, |
| 260 | const RegSet &vregs) { |
| 261 | |
| 262 | std::auto_ptr<PBQPRAProblem> p = PBQPBuilder::build(mf, lis, loopInfo, vregs); |
| 263 | PBQP::Graph &g = p->getGraph(); |
| 264 | |
| 265 | const TargetMachine &tm = mf->getTarget(); |
| 266 | CoalescerPair cp(*tm.getInstrInfo(), *tm.getRegisterInfo()); |
| 267 | |
| 268 | // Scan the machine function and add a coalescing cost whenever CoalescerPair |
| 269 | // gives the Ok. |
| 270 | for (MachineFunction::const_iterator mbbItr = mf->begin(), |
| 271 | mbbEnd = mf->end(); |
| 272 | mbbItr != mbbEnd; ++mbbItr) { |
| 273 | const MachineBasicBlock *mbb = &*mbbItr; |
| 274 | |
| 275 | for (MachineBasicBlock::const_iterator miItr = mbb->begin(), |
| 276 | miEnd = mbb->end(); |
| 277 | miItr != miEnd; ++miItr) { |
| 278 | const MachineInstr *mi = &*miItr; |
| 279 | |
| 280 | if (!mi->isCopy() && !mi->isSubregToReg()) |
| 281 | continue; // Not coalescable. |
| 282 | |
| 283 | if (!cp.setRegisters(mi)) |
| 284 | continue; // Not coalescable. |
| 285 | |
| 286 | if (cp.getSrcReg() == cp.getDstReg()) |
| 287 | continue; // Already coalesced. |
| 288 | |
| 289 | if (cp.isCoalescable(mi)) { |
| 290 | |
| 291 | unsigned dst = cp.getDstReg(), |
| 292 | src = cp.getSrcReg(); |
| 293 | |
| 294 | |
| 295 | |
| 296 | PBQP::PBQPNum cBenefit = std::pow(10.0f, loopInfo->getLoopDepth(mbb)); |
| 297 | |
| 298 | if (cp.isPhys()) { |
| 299 | if (!lis->isAllocatable(dst)) |
| 300 | continue; |
| 301 | |
| 302 | const PBQPRAProblem::AllowedSet &allowed = p->getAllowedSet(src); |
| 303 | unsigned pregOpt = 0; |
| 304 | while (pregOpt < allowed.size() && allowed[pregOpt] != dst) |
| 305 | ++pregOpt; |
| 306 | if (pregOpt < allowed.size()) { |
| 307 | ++pregOpt; // +1 to account for spill option. |
| 308 | PBQP::Graph::NodeItr node = p->getNodeForVReg(src); |
| 309 | addPhysRegCoalesce(g.getNodeCosts(node), pregOpt, cBenefit); |
| 310 | } |
| 311 | } else { |
| 312 | const PBQPRAProblem::AllowedSet *allowed1 = &p->getAllowedSet(dst); |
| 313 | const PBQPRAProblem::AllowedSet *allowed2 = &p->getAllowedSet(src); |
| 314 | PBQP::Graph::NodeItr node1 = p->getNodeForVReg(dst); |
| 315 | PBQP::Graph::NodeItr node2 = p->getNodeForVReg(src); |
| 316 | PBQP::Graph::EdgeItr edge = g.findEdge(node1, node2); |
| 317 | if (edge == g.edgesEnd()) { |
| 318 | edge = g.addEdge(node1, node2, PBQP::Matrix(allowed1->size() + 1, |
| 319 | allowed2->size() + 1, |
| 320 | 0)); |
| 321 | } else { |
| 322 | if (g.getEdgeNode1(edge) == node2) { |
| 323 | std::swap(node1, node2); |
| 324 | std::swap(allowed1, allowed2); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | addVirtRegCoalesce(g.getEdgeCosts(edge), *allowed1, *allowed2, |
| 329 | cBenefit); |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return p; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | void PBQPBuilderWithCoalescing::addPhysRegCoalesce(PBQP::Vector &costVec, |
| 340 | unsigned pregOption, |
| 341 | PBQP::PBQPNum benefit) { |
| 342 | costVec[pregOption] += -benefit; |
| 343 | } |
| 344 | |
| 345 | void PBQPBuilderWithCoalescing::addVirtRegCoalesce( |
| 346 | PBQP::Matrix &costMat, |
| 347 | const PBQPRAProblem::AllowedSet &vr1Allowed, |
| 348 | const PBQPRAProblem::AllowedSet &vr2Allowed, |
| 349 | PBQP::PBQPNum benefit) { |
| 350 | |
| 351 | assert(costMat.getRows() == vr1Allowed.size() + 1 && "Size mismatch."); |
| 352 | assert(costMat.getCols() == vr2Allowed.size() + 1 && "Size mismatch."); |
| 353 | |
| 354 | for (unsigned i = 0; i < vr1Allowed.size(); ++i) { |
| 355 | unsigned preg1 = vr1Allowed[i]; |
| 356 | for (unsigned j = 0; j < vr2Allowed.size(); ++j) { |
| 357 | unsigned preg2 = vr2Allowed[j]; |
| 358 | |
| 359 | if (preg1 == preg2) { |
| 360 | costMat[i + 1][j + 1] += -benefit; |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 365 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 366 | |
| 367 | void RegAllocPBQP::getAnalysisUsage(AnalysisUsage &au) const { |
| 368 | au.addRequired<SlotIndexes>(); |
| 369 | au.addPreserved<SlotIndexes>(); |
| 370 | au.addRequired<LiveIntervals>(); |
| 371 | //au.addRequiredID(SplitCriticalEdgesID); |
| 372 | au.addRequired<RegisterCoalescer>(); |
| 373 | au.addRequired<CalculateSpillWeights>(); |
| 374 | au.addRequired<LiveStacks>(); |
| 375 | au.addPreserved<LiveStacks>(); |
| 376 | au.addRequired<MachineLoopInfo>(); |
| 377 | au.addPreserved<MachineLoopInfo>(); |
| 378 | if (pbqpPreSplitting) |
| 379 | au.addRequired<LoopSplitter>(); |
| 380 | au.addRequired<VirtRegMap>(); |
| 381 | au.addRequired<RenderMachineFunction>(); |
| 382 | MachineFunctionPass::getAnalysisUsage(au); |
| 383 | } |
| 384 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 385 | template <typename RegContainer> |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 386 | PBQP::Vector RegAllocPBQP::buildCostVector(unsigned vReg, |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 387 | const RegContainer &allowed, |
| 388 | const CoalesceMap &coalesces, |
| 389 | PBQP::PBQPNum spillCost) const { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 390 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 391 | typedef typename RegContainer::const_iterator AllowedItr; |
| 392 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 393 | // Allocate vector. Additional element (0th) used for spill option |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 394 | PBQP::Vector v(allowed.size() + 1, 0); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 395 | |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 396 | v[0] = spillCost; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 397 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 398 | // Iterate over the allowed registers inserting coalesce benefits if there |
| 399 | // are any. |
| 400 | unsigned ai = 0; |
| 401 | for (AllowedItr itr = allowed.begin(), end = allowed.end(); |
| 402 | itr != end; ++itr, ++ai) { |
| 403 | |
| 404 | unsigned pReg = *itr; |
| 405 | |
| 406 | CoalesceMap::const_iterator cmItr = |
| 407 | coalesces.find(RegPair(vReg, pReg)); |
| 408 | |
| 409 | // No coalesce - on to the next preg. |
| 410 | if (cmItr == coalesces.end()) |
| 411 | continue; |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 412 | |
| 413 | // We have a coalesce - insert the benefit. |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 414 | v[ai + 1] = -cmItr->second; |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 417 | return v; |
| 418 | } |
| 419 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 420 | template <typename RegContainer> |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 421 | PBQP::Matrix* RegAllocPBQP::buildInterferenceMatrix( |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 422 | const RegContainer &allowed1, const RegContainer &allowed2) const { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 423 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 424 | typedef typename RegContainer::const_iterator RegContainerIterator; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 425 | |
| 426 | // Construct a PBQP matrix representing the cost of allocation options. The |
| 427 | // rows and columns correspond to the allocation options for the two live |
| 428 | // intervals. Elements will be infinite where corresponding registers alias, |
| 429 | // since we cannot allocate aliasing registers to interfering live intervals. |
| 430 | // All other elements (non-aliasing combinations) will have zero cost. Note |
| 431 | // that the spill option (element 0,0) has zero cost, since we can allocate |
| 432 | // both intervals to memory safely (the cost for each individual allocation |
| 433 | // to memory is accounted for by the cost vectors for each live interval). |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 434 | PBQP::Matrix *m = |
| 435 | new PBQP::Matrix(allowed1.size() + 1, allowed2.size() + 1, 0); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 436 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 437 | // Assume this is a zero matrix until proven otherwise. Zero matrices occur |
| 438 | // between interfering live ranges with non-overlapping register sets (e.g. |
| 439 | // non-overlapping reg classes, or disjoint sets of allowed regs within the |
| 440 | // same class). The term "overlapping" is used advisedly: sets which do not |
| 441 | // intersect, but contain registers which alias, will have non-zero matrices. |
| 442 | // We optimize zero matrices away to improve solver speed. |
| 443 | bool isZeroMatrix = true; |
| 444 | |
| 445 | |
| 446 | // Row index. Starts at 1, since the 0th row is for the spill option, which |
| 447 | // is always zero. |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 448 | unsigned ri = 1; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 449 | |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 450 | // Iterate over allowed sets, insert infinities where required. |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 451 | for (RegContainerIterator a1Itr = allowed1.begin(), a1End = allowed1.end(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 452 | a1Itr != a1End; ++a1Itr) { |
| 453 | |
| 454 | // Column index, starts at 1 as for row index. |
| 455 | unsigned ci = 1; |
| 456 | unsigned reg1 = *a1Itr; |
| 457 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 458 | for (RegContainerIterator a2Itr = allowed2.begin(), a2End = allowed2.end(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 459 | a2Itr != a2End; ++a2Itr) { |
| 460 | |
| 461 | unsigned reg2 = *a2Itr; |
| 462 | |
| 463 | // If the row/column regs are identical or alias insert an infinity. |
Lang Hames | 3f2f3f5 | 2009-09-03 02:52:02 +0000 | [diff] [blame] | 464 | if (tri->regsOverlap(reg1, reg2)) { |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 465 | (*m)[ri][ci] = std::numeric_limits<PBQP::PBQPNum>::infinity(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 466 | isZeroMatrix = false; |
| 467 | } |
| 468 | |
| 469 | ++ci; |
| 470 | } |
| 471 | |
| 472 | ++ri; |
| 473 | } |
| 474 | |
| 475 | // If this turns out to be a zero matrix... |
| 476 | if (isZeroMatrix) { |
| 477 | // free it and return null. |
| 478 | delete m; |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | // ...otherwise return the cost matrix. |
| 483 | return m; |
| 484 | } |
| 485 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 486 | template <typename RegContainer> |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 487 | PBQP::Matrix* RegAllocPBQP::buildCoalescingMatrix( |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 488 | const RegContainer &allowed1, const RegContainer &allowed2, |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 489 | PBQP::PBQPNum cBenefit) const { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 490 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 491 | typedef typename RegContainer::const_iterator RegContainerIterator; |
| 492 | |
| 493 | // Construct a PBQP Matrix representing the benefits of coalescing. As with |
| 494 | // interference matrices the rows and columns represent allowed registers |
| 495 | // for the LiveIntervals which are (potentially) to be coalesced. The amount |
| 496 | // -cBenefit will be placed in any element representing the same register |
| 497 | // for both intervals. |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 498 | PBQP::Matrix *m = |
| 499 | new PBQP::Matrix(allowed1.size() + 1, allowed2.size() + 1, 0); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 500 | |
| 501 | // Reset costs to zero. |
| 502 | m->reset(0); |
| 503 | |
| 504 | // Assume the matrix is zero till proven otherwise. Zero matrices will be |
| 505 | // optimized away as in the interference case. |
| 506 | bool isZeroMatrix = true; |
| 507 | |
| 508 | // Row index. Starts at 1, since the 0th row is for the spill option, which |
| 509 | // is always zero. |
| 510 | unsigned ri = 1; |
| 511 | |
| 512 | // Iterate over the allowed sets, insert coalescing benefits where |
| 513 | // appropriate. |
| 514 | for (RegContainerIterator a1Itr = allowed1.begin(), a1End = allowed1.end(); |
| 515 | a1Itr != a1End; ++a1Itr) { |
| 516 | |
| 517 | // Column index, starts at 1 as for row index. |
| 518 | unsigned ci = 1; |
| 519 | unsigned reg1 = *a1Itr; |
| 520 | |
| 521 | for (RegContainerIterator a2Itr = allowed2.begin(), a2End = allowed2.end(); |
| 522 | a2Itr != a2End; ++a2Itr) { |
| 523 | |
| 524 | // If the row and column represent the same register insert a beneficial |
| 525 | // cost to preference this allocation - it would allow us to eliminate a |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 526 | // move instruction. |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 527 | if (reg1 == *a2Itr) { |
| 528 | (*m)[ri][ci] = -cBenefit; |
| 529 | isZeroMatrix = false; |
| 530 | } |
| 531 | |
| 532 | ++ci; |
| 533 | } |
| 534 | |
| 535 | ++ri; |
| 536 | } |
| 537 | |
| 538 | // If this turns out to be a zero matrix... |
| 539 | if (isZeroMatrix) { |
| 540 | // ...free it and return null. |
| 541 | delete m; |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | return m; |
| 546 | } |
| 547 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 548 | RegAllocPBQP::CoalesceMap RegAllocPBQP::findCoalesces() { |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 549 | |
| 550 | typedef MachineFunction::const_iterator MFIterator; |
| 551 | typedef MachineBasicBlock::const_iterator MBBIterator; |
| 552 | typedef LiveInterval::const_vni_iterator VNIIterator; |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 553 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 554 | CoalesceMap coalescesFound; |
| 555 | |
| 556 | // To find coalesces we need to iterate over the function looking for |
| 557 | // copy instructions. |
| 558 | for (MFIterator bbItr = mf->begin(), bbEnd = mf->end(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 559 | bbItr != bbEnd; ++bbItr) { |
| 560 | |
| 561 | const MachineBasicBlock *mbb = &*bbItr; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 562 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 563 | for (MBBIterator iItr = mbb->begin(), iEnd = mbb->end(); |
| 564 | iItr != iEnd; ++iItr) { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 565 | |
| 566 | const MachineInstr *instr = &*iItr; |
| 567 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 568 | // If this isn't a copy then continue to the next instruction. |
Jakob Stoklund Olesen | 04c528a | 2010-07-16 04:45:42 +0000 | [diff] [blame] | 569 | if (!instr->isCopy()) |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 570 | continue; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 571 | |
Jakob Stoklund Olesen | 04c528a | 2010-07-16 04:45:42 +0000 | [diff] [blame] | 572 | unsigned srcReg = instr->getOperand(1).getReg(); |
| 573 | unsigned dstReg = instr->getOperand(0).getReg(); |
| 574 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 575 | // If the registers are already the same our job is nice and easy. |
| 576 | if (dstReg == srcReg) |
| 577 | continue; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 578 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 579 | bool srcRegIsPhysical = TargetRegisterInfo::isPhysicalRegister(srcReg), |
| 580 | dstRegIsPhysical = TargetRegisterInfo::isPhysicalRegister(dstReg); |
| 581 | |
| 582 | // If both registers are physical then we can't coalesce. |
| 583 | if (srcRegIsPhysical && dstRegIsPhysical) |
| 584 | continue; |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 585 | |
Rafael Espindola | cbeb3db | 2010-07-12 01:45:38 +0000 | [diff] [blame] | 586 | // If it's a copy that includes two virtual register but the source and |
| 587 | // destination classes differ then we can't coalesce. |
| 588 | if (!srcRegIsPhysical && !dstRegIsPhysical && |
| 589 | mri->getRegClass(srcReg) != mri->getRegClass(dstReg)) |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 590 | continue; |
| 591 | |
Rafael Espindola | cbeb3db | 2010-07-12 01:45:38 +0000 | [diff] [blame] | 592 | // If one is physical and one is virtual, check that the physical is |
| 593 | // allocatable in the class of the virtual. |
| 594 | if (srcRegIsPhysical && !dstRegIsPhysical) { |
| 595 | const TargetRegisterClass *dstRegClass = mri->getRegClass(dstReg); |
Lang Hames | 0b23dc0 | 2010-02-09 00:50:27 +0000 | [diff] [blame] | 596 | if (std::find(dstRegClass->allocation_order_begin(*mf), |
| 597 | dstRegClass->allocation_order_end(*mf), srcReg) == |
| 598 | dstRegClass->allocation_order_end(*mf)) |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 599 | continue; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 600 | } |
Rafael Espindola | cbeb3db | 2010-07-12 01:45:38 +0000 | [diff] [blame] | 601 | if (!srcRegIsPhysical && dstRegIsPhysical) { |
| 602 | const TargetRegisterClass *srcRegClass = mri->getRegClass(srcReg); |
Lang Hames | 0b23dc0 | 2010-02-09 00:50:27 +0000 | [diff] [blame] | 603 | if (std::find(srcRegClass->allocation_order_begin(*mf), |
| 604 | srcRegClass->allocation_order_end(*mf), dstReg) == |
| 605 | srcRegClass->allocation_order_end(*mf)) |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 606 | continue; |
| 607 | } |
| 608 | |
| 609 | // If we've made it here we have a copy with compatible register classes. |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 610 | // We can probably coalesce, but we need to consider overlap. |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 611 | const LiveInterval *srcLI = &lis->getInterval(srcReg), |
| 612 | *dstLI = &lis->getInterval(dstReg); |
| 613 | |
| 614 | if (srcLI->overlaps(*dstLI)) { |
| 615 | // Even in the case of an overlap we might still be able to coalesce, |
| 616 | // but we need to make sure that no definition of either range occurs |
| 617 | // while the other range is live. |
| 618 | |
| 619 | // Otherwise start by assuming we're ok. |
| 620 | bool badDef = false; |
| 621 | |
| 622 | // Test all defs of the source range. |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 623 | for (VNIIterator |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 624 | vniItr = srcLI->vni_begin(), vniEnd = srcLI->vni_end(); |
| 625 | vniItr != vniEnd; ++vniItr) { |
| 626 | |
Lang Hames | 0b23dc0 | 2010-02-09 00:50:27 +0000 | [diff] [blame] | 627 | // If we find a poorly defined def we err on the side of caution. |
| 628 | if (!(*vniItr)->def.isValid()) { |
| 629 | badDef = true; |
| 630 | break; |
| 631 | } |
| 632 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 633 | // If we find a def that kills the coalescing opportunity then |
| 634 | // record it and break from the loop. |
| 635 | if (dstLI->liveAt((*vniItr)->def)) { |
| 636 | badDef = true; |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | // If we have a bad def give up, continue to the next instruction. |
| 642 | if (badDef) |
| 643 | continue; |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 644 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 645 | // Otherwise test definitions of the destination range. |
| 646 | for (VNIIterator |
| 647 | vniItr = dstLI->vni_begin(), vniEnd = dstLI->vni_end(); |
| 648 | vniItr != vniEnd; ++vniItr) { |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 649 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 650 | // We want to make sure we skip the copy instruction itself. |
Lang Hames | 52c1afc | 2009-08-10 23:43:28 +0000 | [diff] [blame] | 651 | if ((*vniItr)->getCopy() == instr) |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 652 | continue; |
| 653 | |
Lang Hames | 0b23dc0 | 2010-02-09 00:50:27 +0000 | [diff] [blame] | 654 | if (!(*vniItr)->def.isValid()) { |
| 655 | badDef = true; |
| 656 | break; |
| 657 | } |
| 658 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 659 | if (srcLI->liveAt((*vniItr)->def)) { |
| 660 | badDef = true; |
| 661 | break; |
| 662 | } |
| 663 | } |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 664 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 665 | // As before a bad def we give up and continue to the next instr. |
| 666 | if (badDef) |
| 667 | continue; |
| 668 | } |
| 669 | |
| 670 | // If we make it to here then either the ranges didn't overlap, or they |
| 671 | // did, but none of their definitions would prevent us from coalescing. |
| 672 | // We're good to go with the coalesce. |
| 673 | |
Chris Lattner | 87565c1 | 2010-05-15 17:10:24 +0000 | [diff] [blame] | 674 | float cBenefit = std::pow(10.0f, (float)loopInfo->getLoopDepth(mbb)) / 5.0; |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 675 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 676 | coalescesFound[RegPair(srcReg, dstReg)] = cBenefit; |
| 677 | coalescesFound[RegPair(dstReg, srcReg)] = cBenefit; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | } |
| 681 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 682 | return coalescesFound; |
| 683 | } |
| 684 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 685 | void RegAllocPBQP::findVRegIntervalsToAlloc() { |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 686 | |
| 687 | // Iterate over all live ranges. |
| 688 | for (LiveIntervals::iterator itr = lis->begin(), end = lis->end(); |
| 689 | itr != end; ++itr) { |
| 690 | |
| 691 | // Ignore physical ones. |
| 692 | if (TargetRegisterInfo::isPhysicalRegister(itr->first)) |
| 693 | continue; |
| 694 | |
| 695 | LiveInterval *li = itr->second; |
| 696 | |
| 697 | // If this live interval is non-empty we will use pbqp to allocate it. |
| 698 | // Empty intervals we allocate in a simple post-processing stage in |
| 699 | // finalizeAlloc. |
| 700 | if (!li->empty()) { |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 701 | vregsToAlloc.insert(li->reg); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 702 | } |
| 703 | else { |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 704 | emptyIntervalVRegs.insert(li->reg); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 705 | } |
| 706 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 709 | PBQP::Graph RegAllocPBQP::constructPBQPProblem() { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 710 | |
| 711 | typedef std::vector<const LiveInterval*> LIVector; |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 712 | typedef std::vector<unsigned> RegVector; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 713 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 714 | // This will store the physical intervals for easy reference. |
| 715 | LIVector physIntervals; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 716 | |
| 717 | // Start by clearing the old node <-> live interval mappings & allowed sets |
| 718 | li2Node.clear(); |
| 719 | node2LI.clear(); |
| 720 | allowedSets.clear(); |
| 721 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 722 | // Populate physIntervals, update preg use: |
| 723 | for (LiveIntervals::iterator itr = lis->begin(), end = lis->end(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 724 | itr != end; ++itr) { |
| 725 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 726 | if (TargetRegisterInfo::isPhysicalRegister(itr->first)) { |
| 727 | physIntervals.push_back(itr->second); |
| 728 | mri->setPhysRegUsed(itr->second->reg); |
| 729 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 732 | // Iterate over vreg intervals, construct live interval <-> node number |
| 733 | // mappings. |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 734 | for (RegSet::const_iterator itr = vregsToAlloc.begin(), |
| 735 | end = vregsToAlloc.end(); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 736 | itr != end; ++itr) { |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 737 | const LiveInterval *li = &lis->getInterval(*itr); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 738 | |
| 739 | li2Node[li] = node2LI.size(); |
| 740 | node2LI.push_back(li); |
| 741 | } |
| 742 | |
| 743 | // Get the set of potential coalesces. |
Lang Hames | 8481e3b | 2009-08-19 01:36:14 +0000 | [diff] [blame] | 744 | CoalesceMap coalesces; |
| 745 | |
| 746 | if (pbqpCoalescing) { |
| 747 | coalesces = findCoalesces(); |
| 748 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 749 | |
| 750 | // Construct a PBQP solver for this problem |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 751 | PBQP::Graph problem; |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 752 | problemNodes.resize(vregsToAlloc.size()); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 753 | |
| 754 | // Resize allowedSets container appropriately. |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 755 | allowedSets.resize(vregsToAlloc.size()); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 756 | |
Jim Grosbach | 269354e | 2010-09-01 21:23:03 +0000 | [diff] [blame] | 757 | BitVector ReservedRegs = tri->getReservedRegs(*mf); |
| 758 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 759 | // Iterate over virtual register intervals to compute allowed sets... |
| 760 | for (unsigned node = 0; node < node2LI.size(); ++node) { |
| 761 | |
| 762 | // Grab pointers to the interval and its register class. |
| 763 | const LiveInterval *li = node2LI[node]; |
| 764 | const TargetRegisterClass *liRC = mri->getRegClass(li->reg); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 765 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 766 | // Start by assuming all allocable registers in the class are allowed... |
Jim Grosbach | 269354e | 2010-09-01 21:23:03 +0000 | [diff] [blame] | 767 | RegVector liAllowed; |
| 768 | TargetRegisterClass::iterator aob = liRC->allocation_order_begin(*mf); |
| 769 | TargetRegisterClass::iterator aoe = liRC->allocation_order_end(*mf); |
| 770 | for (TargetRegisterClass::iterator it = aob; it != aoe; ++it) |
| 771 | if (!ReservedRegs.test(*it)) |
| 772 | liAllowed.push_back(*it); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 773 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 774 | // Eliminate the physical registers which overlap with this range, along |
| 775 | // with all their aliases. |
| 776 | for (LIVector::iterator pItr = physIntervals.begin(), |
| 777 | pEnd = physIntervals.end(); pItr != pEnd; ++pItr) { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 778 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 779 | if (!li->overlaps(**pItr)) |
| 780 | continue; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 781 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 782 | unsigned pReg = (*pItr)->reg; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 783 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 784 | // If we get here then the live intervals overlap, but we're still ok |
| 785 | // if they're coalescable. |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 786 | if (coalesces.find(RegPair(li->reg, pReg)) != coalesces.end()) { |
| 787 | DEBUG(dbgs() << "CoalescingOverride: (" << li->reg << ", " << pReg << ")\n"); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 788 | continue; |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 789 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 790 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 791 | // If we get here then we have a genuine exclusion. |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 792 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 793 | // Remove the overlapping reg... |
| 794 | RegVector::iterator eraseItr = |
| 795 | std::find(liAllowed.begin(), liAllowed.end(), pReg); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 796 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 797 | if (eraseItr != liAllowed.end()) |
| 798 | liAllowed.erase(eraseItr); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 799 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 800 | const unsigned *aliasItr = tri->getAliasSet(pReg); |
| 801 | |
| 802 | if (aliasItr != 0) { |
| 803 | // ...and its aliases. |
| 804 | for (; *aliasItr != 0; ++aliasItr) { |
| 805 | RegVector::iterator eraseItr = |
| 806 | std::find(liAllowed.begin(), liAllowed.end(), *aliasItr); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 807 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 808 | if (eraseItr != liAllowed.end()) { |
| 809 | liAllowed.erase(eraseItr); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 810 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 811 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 812 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Copy the allowed set into a member vector for use when constructing cost |
| 816 | // vectors & matrices, and mapping PBQP solutions back to assignments. |
| 817 | allowedSets[node] = AllowedSet(liAllowed.begin(), liAllowed.end()); |
| 818 | |
| 819 | // Set the spill cost to the interval weight, or epsilon if the |
| 820 | // interval weight is zero |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 821 | PBQP::PBQPNum spillCost = (li->weight != 0.0) ? |
| 822 | li->weight : std::numeric_limits<PBQP::PBQPNum>::min(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 823 | |
| 824 | // Build a cost vector for this interval. |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 825 | problemNodes[node] = |
| 826 | problem.addNode( |
| 827 | buildCostVector(li->reg, allowedSets[node], coalesces, spillCost)); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 828 | |
| 829 | } |
| 830 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 831 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 832 | // Now add the cost matrices... |
| 833 | for (unsigned node1 = 0; node1 < node2LI.size(); ++node1) { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 834 | const LiveInterval *li = node2LI[node1]; |
| 835 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 836 | // Test for live range overlaps and insert interference matrices. |
| 837 | for (unsigned node2 = node1 + 1; node2 < node2LI.size(); ++node2) { |
| 838 | const LiveInterval *li2 = node2LI[node2]; |
| 839 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 840 | CoalesceMap::const_iterator cmItr = |
| 841 | coalesces.find(RegPair(li->reg, li2->reg)); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 842 | |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 843 | PBQP::Matrix *m = 0; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 844 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 845 | if (cmItr != coalesces.end()) { |
| 846 | m = buildCoalescingMatrix(allowedSets[node1], allowedSets[node2], |
| 847 | cmItr->second); |
| 848 | } |
| 849 | else if (li->overlaps(*li2)) { |
| 850 | m = buildInterferenceMatrix(allowedSets[node1], allowedSets[node2]); |
| 851 | } |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 852 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 853 | if (m != 0) { |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 854 | problem.addEdge(problemNodes[node1], |
| 855 | problemNodes[node2], |
| 856 | *m); |
| 857 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 858 | delete m; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 863 | assert(problem.getNumNodes() == allowedSets.size()); |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 864 | /* |
| 865 | std::cerr << "Allocating for " << problem.getNumNodes() << " nodes, " |
| 866 | << problem.getNumEdges() << " edges.\n"; |
| 867 | |
| 868 | problem.printDot(std::cerr); |
| 869 | */ |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 870 | // We're done, PBQP problem constructed - return it. |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 871 | return problem; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 874 | void RegAllocPBQP::addStackInterval(const LiveInterval *spilled, |
Evan Cheng | c781a24 | 2009-05-03 18:32:42 +0000 | [diff] [blame] | 875 | MachineRegisterInfo* mri) { |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 876 | int stackSlot = vrm->getStackSlot(spilled->reg); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 877 | |
| 878 | if (stackSlot == VirtRegMap::NO_STACK_SLOT) |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 879 | return; |
| 880 | |
Evan Cheng | c781a24 | 2009-05-03 18:32:42 +0000 | [diff] [blame] | 881 | const TargetRegisterClass *RC = mri->getRegClass(spilled->reg); |
| 882 | LiveInterval &stackInterval = lss->getOrCreateInterval(stackSlot, RC); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 883 | |
| 884 | VNInfo *vni; |
| 885 | if (stackInterval.getNumValNums() != 0) |
| 886 | vni = stackInterval.getValNumInfo(0); |
| 887 | else |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 888 | vni = stackInterval.getNextValue( |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 889 | SlotIndex(), 0, false, lss->getVNInfoAllocator()); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 890 | |
| 891 | LiveInterval &rhsInterval = lis->getInterval(spilled->reg); |
| 892 | stackInterval.MergeRangesInAsValue(rhsInterval, vni); |
| 893 | } |
| 894 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 895 | bool RegAllocPBQP::mapPBQPToRegAlloc(const PBQP::Solution &solution) { |
Lang Hames | e98b4b0 | 2009-11-15 04:39:51 +0000 | [diff] [blame] | 896 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 897 | // Set to true if we have any spills |
| 898 | bool anotherRoundNeeded = false; |
| 899 | |
| 900 | // Clear the existing allocation. |
| 901 | vrm->clearAllVirt(); |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 902 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 903 | // Iterate over the nodes mapping the PBQP solution to a register assignment. |
| 904 | for (unsigned node = 0; node < node2LI.size(); ++node) { |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 905 | unsigned virtReg = node2LI[node]->reg, |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 906 | allocSelection = solution.getSelection(problemNodes[node]); |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 907 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 908 | |
| 909 | // If the PBQP solution is non-zero it's a physical register... |
| 910 | if (allocSelection != 0) { |
| 911 | // Get the physical reg, subtracting 1 to account for the spill option. |
| 912 | unsigned physReg = allowedSets[node][allocSelection - 1]; |
| 913 | |
David Greene | 3093154 | 2010-01-05 01:25:43 +0000 | [diff] [blame] | 914 | DEBUG(dbgs() << "VREG " << virtReg << " -> " |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 915 | << tri->getName(physReg) << " (Option: " << allocSelection << ")\n"); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 916 | |
| 917 | assert(physReg != 0); |
| 918 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 919 | // Add to the virt reg map and update the used phys regs. |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 920 | vrm->assignVirt2Phys(virtReg, physReg); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 921 | } |
| 922 | // ...Otherwise it's a spill. |
| 923 | else { |
| 924 | |
| 925 | // Make sure we ignore this virtual reg on the next round |
| 926 | // of allocation |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 927 | vregsToAlloc.erase(virtReg); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 928 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 929 | // Insert spill ranges for this live range |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 930 | const LiveInterval *spillInterval = node2LI[node]; |
| 931 | double oldSpillWeight = spillInterval->weight; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 932 | SmallVector<LiveInterval*, 8> spillIs; |
Lang Hames | 3319839 | 2010-09-02 08:27:00 +0000 | [diff] [blame] | 933 | rmf->rememberUseDefs(spillInterval); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 934 | std::vector<LiveInterval*> newSpills = |
Evan Cheng | c781a24 | 2009-05-03 18:32:42 +0000 | [diff] [blame] | 935 | lis->addIntervalsForSpills(*spillInterval, spillIs, loopInfo, *vrm); |
| 936 | addStackInterval(spillInterval, mri); |
Lang Hames | 3319839 | 2010-09-02 08:27:00 +0000 | [diff] [blame] | 937 | rmf->rememberSpills(spillInterval, newSpills); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 938 | |
Daniel Dunbar | bc84ad9 | 2009-08-20 20:01:34 +0000 | [diff] [blame] | 939 | (void) oldSpillWeight; |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 940 | DEBUG(dbgs() << "VREG " << virtReg << " -> SPILLED (Option: 0, Cost: " |
Lang Hames | 233fd9c | 2009-08-18 23:34:50 +0000 | [diff] [blame] | 941 | << oldSpillWeight << ", New vregs: "); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 942 | |
| 943 | // Copy any newly inserted live intervals into the list of regs to |
| 944 | // allocate. |
| 945 | for (std::vector<LiveInterval*>::const_iterator |
| 946 | itr = newSpills.begin(), end = newSpills.end(); |
| 947 | itr != end; ++itr) { |
| 948 | |
| 949 | assert(!(*itr)->empty() && "Empty spill range."); |
| 950 | |
David Greene | 3093154 | 2010-01-05 01:25:43 +0000 | [diff] [blame] | 951 | DEBUG(dbgs() << (*itr)->reg << " "); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 952 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 953 | vregsToAlloc.insert((*itr)->reg); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 954 | } |
| 955 | |
David Greene | 3093154 | 2010-01-05 01:25:43 +0000 | [diff] [blame] | 956 | DEBUG(dbgs() << ")\n"); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 957 | |
| 958 | // We need another round if spill intervals were added. |
| 959 | anotherRoundNeeded |= !newSpills.empty(); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | return !anotherRoundNeeded; |
| 964 | } |
| 965 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 966 | bool RegAllocPBQP::mapPBQPToRegAlloc2(const PBQPRAProblem &problem, |
| 967 | const PBQP::Solution &solution) { |
| 968 | // Set to true if we have any spills |
| 969 | bool anotherRoundNeeded = false; |
| 970 | |
| 971 | // Clear the existing allocation. |
| 972 | vrm->clearAllVirt(); |
| 973 | |
| 974 | const PBQP::Graph &g = problem.getGraph(); |
| 975 | // Iterate over the nodes mapping the PBQP solution to a register |
| 976 | // assignment. |
| 977 | for (PBQP::Graph::ConstNodeItr node = g.nodesBegin(), |
| 978 | nodeEnd = g.nodesEnd(); |
| 979 | node != nodeEnd; ++node) { |
| 980 | unsigned vreg = problem.getVRegForNode(node); |
| 981 | unsigned alloc = solution.getSelection(node); |
| 982 | |
| 983 | if (problem.isPRegOption(vreg, alloc)) { |
| 984 | unsigned preg = problem.getPRegForOption(vreg, alloc); |
| 985 | DEBUG(dbgs() << "VREG " << vreg << " -> " << tri->getName(preg) << "\n"); |
| 986 | assert(preg != 0 && "Invalid preg selected."); |
| 987 | vrm->assignVirt2Phys(vreg, preg); |
| 988 | } else if (problem.isSpillOption(vreg, alloc)) { |
| 989 | vregsToAlloc.erase(vreg); |
| 990 | const LiveInterval* spillInterval = &lis->getInterval(vreg); |
| 991 | double oldWeight = spillInterval->weight; |
| 992 | SmallVector<LiveInterval*, 8> spillIs; |
| 993 | rmf->rememberUseDefs(spillInterval); |
| 994 | std::vector<LiveInterval*> newSpills = |
| 995 | lis->addIntervalsForSpills(*spillInterval, spillIs, loopInfo, *vrm); |
| 996 | addStackInterval(spillInterval, mri); |
| 997 | rmf->rememberSpills(spillInterval, newSpills); |
| 998 | |
| 999 | (void) oldWeight; |
| 1000 | DEBUG(dbgs() << "VREG " << vreg << " -> SPILLED (Cost: " |
| 1001 | << oldWeight << ", New vregs: "); |
| 1002 | |
| 1003 | // Copy any newly inserted live intervals into the list of regs to |
| 1004 | // allocate. |
| 1005 | for (std::vector<LiveInterval*>::const_iterator |
| 1006 | itr = newSpills.begin(), end = newSpills.end(); |
| 1007 | itr != end; ++itr) { |
| 1008 | assert(!(*itr)->empty() && "Empty spill range."); |
| 1009 | DEBUG(dbgs() << (*itr)->reg << " "); |
| 1010 | vregsToAlloc.insert((*itr)->reg); |
| 1011 | } |
| 1012 | |
| 1013 | DEBUG(dbgs() << ")\n"); |
| 1014 | |
| 1015 | // We need another round if spill intervals were added. |
| 1016 | anotherRoundNeeded |= !newSpills.empty(); |
| 1017 | } else { |
| 1018 | assert(false && "Unknown allocation option."); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | return !anotherRoundNeeded; |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | void RegAllocPBQP::finalizeAlloc() const { |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1027 | typedef LiveIntervals::iterator LIIterator; |
| 1028 | typedef LiveInterval::Ranges::const_iterator LRIterator; |
| 1029 | |
| 1030 | // First allocate registers for the empty intervals. |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1031 | for (RegSet::const_iterator |
| 1032 | itr = emptyIntervalVRegs.begin(), end = emptyIntervalVRegs.end(); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1033 | itr != end; ++itr) { |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1034 | LiveInterval *li = &lis->getInterval(*itr); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1035 | |
Evan Cheng | 90f95f8 | 2009-06-14 20:22:55 +0000 | [diff] [blame] | 1036 | unsigned physReg = vrm->getRegAllocPref(li->reg); |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 1037 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1038 | if (physReg == 0) { |
| 1039 | const TargetRegisterClass *liRC = mri->getRegClass(li->reg); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1040 | physReg = *liRC->allocation_order_begin(*mf); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1041 | } |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1042 | |
| 1043 | vrm->assignVirt2Phys(li->reg, physReg); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1044 | } |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1045 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1046 | // Finally iterate over the basic blocks to compute and set the live-in sets. |
| 1047 | SmallVector<MachineBasicBlock*, 8> liveInMBBs; |
| 1048 | MachineBasicBlock *entryMBB = &*mf->begin(); |
| 1049 | |
| 1050 | for (LIIterator liItr = lis->begin(), liEnd = lis->end(); |
| 1051 | liItr != liEnd; ++liItr) { |
| 1052 | |
| 1053 | const LiveInterval *li = liItr->second; |
| 1054 | unsigned reg = 0; |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1055 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1056 | // Get the physical register for this interval |
| 1057 | if (TargetRegisterInfo::isPhysicalRegister(li->reg)) { |
| 1058 | reg = li->reg; |
| 1059 | } |
| 1060 | else if (vrm->isAssignedReg(li->reg)) { |
| 1061 | reg = vrm->getPhys(li->reg); |
| 1062 | } |
| 1063 | else { |
| 1064 | // Ranges which are assigned a stack slot only are ignored. |
| 1065 | continue; |
| 1066 | } |
| 1067 | |
Lang Hames | b0e519f | 2009-05-17 23:50:36 +0000 | [diff] [blame] | 1068 | if (reg == 0) { |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 1069 | // Filter out zero regs - they're for intervals that were spilled. |
Lang Hames | b0e519f | 2009-05-17 23:50:36 +0000 | [diff] [blame] | 1070 | continue; |
| 1071 | } |
| 1072 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1073 | // Iterate over the ranges of the current interval... |
| 1074 | for (LRIterator lrItr = li->begin(), lrEnd = li->end(); |
| 1075 | lrItr != lrEnd; ++lrItr) { |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1076 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1077 | // Find the set of basic blocks which this range is live into... |
| 1078 | if (lis->findLiveInMBBs(lrItr->start, lrItr->end, liveInMBBs)) { |
| 1079 | // And add the physreg for this interval to their live-in sets. |
| 1080 | for (unsigned i = 0; i < liveInMBBs.size(); ++i) { |
| 1081 | if (liveInMBBs[i] != entryMBB) { |
| 1082 | if (!liveInMBBs[i]->isLiveIn(reg)) { |
| 1083 | liveInMBBs[i]->addLiveIn(reg); |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | liveInMBBs.clear(); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1091 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1094 | bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) { |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1095 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1096 | mf = &MF; |
| 1097 | tm = &mf->getTarget(); |
| 1098 | tri = tm->getRegisterInfo(); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1099 | tii = tm->getInstrInfo(); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 1100 | mri = &mf->getRegInfo(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1101 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1102 | lis = &getAnalysis<LiveIntervals>(); |
| 1103 | lss = &getAnalysis<LiveStacks>(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1104 | loopInfo = &getAnalysis<MachineLoopInfo>(); |
Lang Hames | 3319839 | 2010-09-02 08:27:00 +0000 | [diff] [blame] | 1105 | rmf = &getAnalysis<RenderMachineFunction>(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1106 | |
Owen Anderson | 49c8aa0 | 2009-03-13 05:55:11 +0000 | [diff] [blame] | 1107 | vrm = &getAnalysis<VirtRegMap>(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1108 | |
Lang Hames | 54cc2ef | 2010-07-19 15:22:28 +0000 | [diff] [blame] | 1109 | |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 1110 | DEBUG(dbgs() << "PBQP Register Allocating for " << mf->getFunction()->getName() << "\n"); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1111 | |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1112 | // Allocator main loop: |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1113 | // |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1114 | // * Map current regalloc problem to a PBQP problem |
| 1115 | // * Solve the PBQP problem |
| 1116 | // * Map the solution back to a register allocation |
| 1117 | // * Spill if necessary |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1118 | // |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1119 | // This process is continued till no more spills are generated. |
| 1120 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1121 | // Find the vreg intervals in need of allocation. |
| 1122 | findVRegIntervalsToAlloc(); |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1123 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1124 | // If there are non-empty intervals allocate them using pbqp. |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1125 | if (!vregsToAlloc.empty()) { |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1126 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1127 | bool pbqpAllocComplete = false; |
| 1128 | unsigned round = 0; |
| 1129 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1130 | if (!pbqpBuilder) { |
| 1131 | while (!pbqpAllocComplete) { |
| 1132 | DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n"); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1133 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1134 | PBQP::Graph problem = constructPBQPProblem(); |
| 1135 | PBQP::Solution solution = |
| 1136 | PBQP::HeuristicSolver<PBQP::Heuristics::Briggs>::solve(problem); |
Lang Hames | 233fd9c | 2009-08-18 23:34:50 +0000 | [diff] [blame] | 1137 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1138 | pbqpAllocComplete = mapPBQPToRegAlloc(solution); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1139 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1140 | ++round; |
| 1141 | } |
| 1142 | } else { |
| 1143 | while (!pbqpAllocComplete) { |
| 1144 | DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n"); |
| 1145 | |
| 1146 | std::auto_ptr<PBQPRAProblem> problem = |
Lang Hames | e9c9356 | 2010-09-21 13:19:36 +0000 | [diff] [blame^] | 1147 | builder->build(mf, lis, loopInfo, vregsToAlloc); |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1148 | PBQP::Solution solution = |
Lang Hames | e9c9356 | 2010-09-21 13:19:36 +0000 | [diff] [blame^] | 1149 | PBQP::HeuristicSolver<PBQP::Heuristics::Briggs>::solve( |
| 1150 | problem->getGraph()); |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1151 | |
| 1152 | pbqpAllocComplete = mapPBQPToRegAlloc2(*problem, solution); |
| 1153 | |
| 1154 | ++round; |
| 1155 | } |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1156 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1159 | // Finalise allocation, allocate empty ranges. |
| 1160 | finalizeAlloc(); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1161 | |
Lang Hames | c4bcc77 | 2010-07-20 07:41:44 +0000 | [diff] [blame] | 1162 | rmf->renderMachineFunction("After PBQP register allocation.", vrm); |
| 1163 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1164 | vregsToAlloc.clear(); |
| 1165 | emptyIntervalVRegs.clear(); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1166 | li2Node.clear(); |
| 1167 | node2LI.clear(); |
| 1168 | allowedSets.clear(); |
Lang Hames | 030c4bf | 2010-01-26 04:49:58 +0000 | [diff] [blame] | 1169 | problemNodes.clear(); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1170 | |
David Greene | 3093154 | 2010-01-05 01:25:43 +0000 | [diff] [blame] | 1171 | DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *vrm << "\n"); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1172 | |
Lang Hames | 87e3bca | 2009-05-06 02:36:21 +0000 | [diff] [blame] | 1173 | // Run rewriter |
| 1174 | std::auto_ptr<VirtRegRewriter> rewriter(createVirtRegRewriter()); |
| 1175 | |
| 1176 | rewriter->runOnMachineFunction(*mf, *vrm, lis); |
Lang Hames | 27601ef | 2008-11-16 12:12:54 +0000 | [diff] [blame] | 1177 | |
Misha Brukman | 2a835f9 | 2009-01-08 15:50:22 +0000 | [diff] [blame] | 1178 | return true; |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1181 | FunctionPass* createPBQPRegisterAllocator() { |
Lang Hames | e9c9356 | 2010-09-21 13:19:36 +0000 | [diff] [blame^] | 1182 | if (pbqpCoalescing) { |
| 1183 | return new RegAllocPBQP( |
| 1184 | std::auto_ptr<PBQPBuilder>(new PBQPBuilderWithCoalescing())); |
| 1185 | } // else |
| 1186 | return new RegAllocPBQP( |
| 1187 | std::auto_ptr<PBQPBuilder>(new PBQPBuilder())); |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Lang Hames | eb6c8f5 | 2010-09-18 09:07:10 +0000 | [diff] [blame] | 1190 | } |
Evan Cheng | b1290a6 | 2008-10-02 18:29:27 +0000 | [diff] [blame] | 1191 | |
| 1192 | #undef DEBUG_TYPE |