Chris Lattner | 179cdfb | 2002-08-09 20:08:03 +0000 | [diff] [blame] | 1 | //===-- PhyRegAlloc.cpp ---------------------------------------------------===// |
Vikram S. Adve | 12af164 | 2001-11-08 04:48:50 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 179cdfb | 2002-08-09 20:08:03 +0000 | [diff] [blame] | 3 | // Register allocation for LLVM. |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 6 | |
Chris Lattner | 6dd98a6 | 2002-02-04 00:33:08 +0000 | [diff] [blame] | 7 | #include "llvm/CodeGen/RegisterAllocation.h" |
Chris Lattner | 4309e73 | 2003-01-15 19:57:07 +0000 | [diff] [blame] | 8 | #include "RegAllocCommon.h" |
Chris Lattner | 9d4ed15 | 2003-01-15 21:14:01 +0000 | [diff] [blame] | 9 | #include "RegClass.h" |
Chris Lattner | cb6b4bd | 2002-10-29 16:51:05 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/IGNode.h" |
Vikram S. Adve | 12af164 | 2001-11-08 04:48:50 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/PhyRegAlloc.h" |
Chris Lattner | f6ee49f | 2003-01-15 18:08:07 +0000 | [diff] [blame] | 12 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/MachineInstrAnnot.h" |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | e90fcb7 | 2002-12-28 20:35:34 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunctionInfo.h" |
Chris Lattner | 92ba2aa | 2003-01-14 23:05:08 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/FunctionLiveVarInfo.h" |
Chris Lattner | 14ab1ce | 2002-02-04 17:48:00 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/LoopInfo.h" |
Vikram S. Adve | 12af164 | 2001-11-08 04:48:50 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 8bd66e6 | 2002-12-28 21:00:25 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetInstrInfo.h" |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 21 | #include "llvm/Function.h" |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 22 | #include "llvm/Type.h" |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 23 | #include "llvm/iOther.h" |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 24 | #include "Support/STLExtras.h" |
Chris Lattner | 4bc2348 | 2002-09-15 07:07:55 +0000 | [diff] [blame] | 25 | #include "Support/CommandLine.h" |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 26 | #include <math.h> |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 27 | using std::cerr; |
Anand Shukla | cfb22d3 | 2002-06-25 20:55:50 +0000 | [diff] [blame] | 28 | using std::vector; |
Vikram S. Adve | 12af164 | 2001-11-08 04:48:50 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 70e60cb | 2002-05-22 17:08:27 +0000 | [diff] [blame] | 30 | RegAllocDebugLevel_t DEBUG_RA; |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 5ff62e9 | 2002-07-22 02:10:13 +0000 | [diff] [blame] | 32 | static cl::opt<RegAllocDebugLevel_t, true> |
| 33 | DRA_opt("dregalloc", cl::Hidden, cl::location(DEBUG_RA), |
| 34 | cl::desc("enable register allocation debugging information"), |
| 35 | cl::values( |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 36 | clEnumValN(RA_DEBUG_None , "n", "disable debug output"), |
| 37 | clEnumValN(RA_DEBUG_Results, "y", "debug output for allocation results"), |
| 38 | clEnumValN(RA_DEBUG_Coloring, "c", "debug output for graph coloring step"), |
| 39 | clEnumValN(RA_DEBUG_Interference,"ig","debug output for interference graphs"), |
| 40 | clEnumValN(RA_DEBUG_LiveRanges , "lr","debug output for live ranges"), |
| 41 | clEnumValN(RA_DEBUG_Verbose, "v", "extra debug output"), |
Chris Lattner | 5ff62e9 | 2002-07-22 02:10:13 +0000 | [diff] [blame] | 42 | 0)); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 44 | //---------------------------------------------------------------------------- |
| 45 | // RegisterAllocation pass front end... |
| 46 | //---------------------------------------------------------------------------- |
| 47 | namespace { |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 48 | class RegisterAllocator : public FunctionPass { |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 49 | TargetMachine &Target; |
| 50 | public: |
| 51 | inline RegisterAllocator(TargetMachine &T) : Target(T) {} |
Chris Lattner | 96c466b | 2002-04-29 14:57:45 +0000 | [diff] [blame] | 52 | |
| 53 | const char *getPassName() const { return "Register Allocation"; } |
Chris Lattner | 6dd98a6 | 2002-02-04 00:33:08 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 55 | bool runOnFunction(Function &F) { |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 56 | if (DEBUG_RA) |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 57 | cerr << "\n********* Function "<< F.getName() << " ***********\n"; |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 59 | PhyRegAlloc PRA(&F, Target, &getAnalysis<FunctionLiveVarInfo>(), |
Chris Lattner | 1b7f7dc | 2002-04-28 16:21:30 +0000 | [diff] [blame] | 60 | &getAnalysis<LoopInfo>()); |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 61 | PRA.allocateRegisters(); |
| 62 | |
| 63 | if (DEBUG_RA) cerr << "\nRegister allocation complete!\n"; |
| 64 | return false; |
| 65 | } |
Chris Lattner | 4911c35 | 2002-02-04 17:39:42 +0000 | [diff] [blame] | 66 | |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 67 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Chris Lattner | dd5b495 | 2002-08-08 19:01:28 +0000 | [diff] [blame] | 68 | AU.addRequired<LoopInfo>(); |
| 69 | AU.addRequired<FunctionLiveVarInfo>(); |
Chris Lattner | 4911c35 | 2002-02-04 17:39:42 +0000 | [diff] [blame] | 70 | } |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 71 | }; |
Chris Lattner | 6dd98a6 | 2002-02-04 00:33:08 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 74 | Pass *getRegisterAllocator(TargetMachine &T) { |
Chris Lattner | 2f9b28e | 2002-02-04 15:54:09 +0000 | [diff] [blame] | 75 | return new RegisterAllocator(T); |
| 76 | } |
Chris Lattner | 6dd98a6 | 2002-02-04 00:33:08 +0000 | [diff] [blame] | 77 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 78 | //---------------------------------------------------------------------------- |
| 79 | // Constructor: Init local composite objects and create register classes. |
| 80 | //---------------------------------------------------------------------------- |
Chris Lattner | 1b7f7dc | 2002-04-28 16:21:30 +0000 | [diff] [blame] | 81 | PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm, |
| 82 | FunctionLiveVarInfo *Lvi, LoopInfo *LDC) |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 83 | : TM(tm), Fn(F), MF(MachineFunction::get(F)), LVI(Lvi), |
| 84 | LRI(F, tm, RegClassList), MRI(tm.getRegInfo()), |
| 85 | NumOfRegClasses(MRI.getNumOfRegClasses()), LoopDepthCalc(LDC) { |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 86 | |
| 87 | // create each RegisterClass and put in RegClassList |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 88 | // |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 89 | for (unsigned rc=0; rc != NumOfRegClasses; rc++) |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 90 | RegClassList.push_back(new RegClass(F, MRI.getMachineRegClass(rc), |
| 91 | &ResColList)); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 94 | |
| 95 | //---------------------------------------------------------------------------- |
| 96 | // Destructor: Deletes register classes |
| 97 | //---------------------------------------------------------------------------- |
| 98 | PhyRegAlloc::~PhyRegAlloc() { |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 99 | for ( unsigned rc=0; rc < NumOfRegClasses; rc++) |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 100 | delete RegClassList[rc]; |
Chris Lattner | 0b0ffa0 | 2002-04-09 05:13:04 +0000 | [diff] [blame] | 101 | |
| 102 | AddedInstrMap.clear(); |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 105 | //---------------------------------------------------------------------------- |
| 106 | // This method initally creates interference graphs (one in each reg class) |
| 107 | // and IGNodeList (one in each IG). The actual nodes will be pushed later. |
| 108 | //---------------------------------------------------------------------------- |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 109 | void PhyRegAlloc::createIGNodeListsAndIGs() { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 110 | if (DEBUG_RA >= RA_DEBUG_LiveRanges) cerr << "Creating LR lists ...\n"; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 111 | |
| 112 | // hash map iterator |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 113 | LiveRangeMapType::const_iterator HMI = LRI.getLiveRangeMap()->begin(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 114 | |
| 115 | // hash map end |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 116 | LiveRangeMapType::const_iterator HMIEnd = LRI.getLiveRangeMap()->end(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 117 | |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 118 | for (; HMI != HMIEnd ; ++HMI ) { |
| 119 | if (HMI->first) { |
| 120 | LiveRange *L = HMI->second; // get the LiveRange |
| 121 | if (!L) { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 122 | if (DEBUG_RA) |
| 123 | cerr << "\n**** ?!?WARNING: NULL LIVE RANGE FOUND FOR: " |
| 124 | << RAV(HMI->first) << "****\n"; |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 125 | continue; |
| 126 | } |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 127 | |
| 128 | // if the Value * is not null, and LR is not yet written to the IGNodeList |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 129 | if (!(L->getUserIGNode()) ) { |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 130 | RegClass *const RC = // RegClass of first value in the LR |
| 131 | RegClassList[ L->getRegClass()->getID() ]; |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 132 | RC->addLRToIG(L); // add this LR to an IG |
| 133 | } |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 136 | |
| 137 | // init RegClassList |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 138 | for ( unsigned rc=0; rc < NumOfRegClasses ; rc++) |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 139 | RegClassList[rc]->createInterferenceGraph(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 140 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 141 | if (DEBUG_RA >= RA_DEBUG_LiveRanges) cerr << "LRLists Created!\n"; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 145 | //---------------------------------------------------------------------------- |
| 146 | // This method will add all interferences at for a given instruction. |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 147 | // Interence occurs only if the LR of Def (Inst or Arg) is of the same reg |
| 148 | // class as that of live var. The live var passed to this function is the |
| 149 | // LVset AFTER the instruction |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 150 | //---------------------------------------------------------------------------- |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 151 | |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 152 | void PhyRegAlloc::addInterference(const Value *Def, |
| 153 | const ValueSet *LVSet, |
| 154 | bool isCallInst) { |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 155 | |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 156 | ValueSet::const_iterator LIt = LVSet->begin(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 157 | |
| 158 | // get the live range of instruction |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 159 | // |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 160 | const LiveRange *const LROfDef = LRI.getLiveRangeForValue( Def ); |
| 161 | |
| 162 | IGNode *const IGNodeOfDef = LROfDef->getUserIGNode(); |
| 163 | assert( IGNodeOfDef ); |
| 164 | |
| 165 | RegClass *const RCOfDef = LROfDef->getRegClass(); |
| 166 | |
| 167 | // for each live var in live variable set |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 168 | // |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 169 | for ( ; LIt != LVSet->end(); ++LIt) { |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 170 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 171 | if (DEBUG_RA >= RA_DEBUG_Verbose) |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 172 | cerr << "< Def=" << RAV(Def) << ", Lvar=" << RAV(*LIt) << "> "; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 173 | |
| 174 | // get the live range corresponding to live var |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 175 | // |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 176 | LiveRange *LROfVar = LRI.getLiveRangeForValue(*LIt); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 177 | |
| 178 | // LROfVar can be null if it is a const since a const |
| 179 | // doesn't have a dominating def - see Assumptions above |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 180 | // |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 181 | if (LROfVar) |
| 182 | if (LROfDef != LROfVar) // do not set interf for same LR |
| 183 | if (RCOfDef == LROfVar->getRegClass()) // 2 reg classes are the same |
| 184 | RCOfDef->setInterference( LROfDef, LROfVar); |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 185 | } |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 188 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 189 | |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 190 | //---------------------------------------------------------------------------- |
| 191 | // For a call instruction, this method sets the CallInterference flag in |
| 192 | // the LR of each variable live int the Live Variable Set live after the |
| 193 | // call instruction (except the return value of the call instruction - since |
| 194 | // the return value does not interfere with that call itself). |
| 195 | //---------------------------------------------------------------------------- |
| 196 | |
| 197 | void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 198 | const ValueSet *LVSetAft) { |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 199 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 200 | if (DEBUG_RA >= RA_DEBUG_Interference) |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 201 | cerr << "\n For call inst: " << *MInst; |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 202 | |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 203 | // for each live var in live variable set after machine inst |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 204 | // |
Vikram S. Adve | 65b2f40 | 2003-07-02 01:24:00 +0000 | [diff] [blame] | 205 | for (ValueSet::const_iterator LIt = LVSetAft->begin(), LEnd = LVSetAft->end(); |
| 206 | LIt != LEnd; ++LIt) { |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 207 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 208 | // get the live range corresponding to live var |
| 209 | // |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 210 | LiveRange *const LR = LRI.getLiveRangeForValue(*LIt ); |
| 211 | |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 212 | // LR can be null if it is a const since a const |
| 213 | // doesn't have a dominating def - see Assumptions above |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 214 | // |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 215 | if (LR ) { |
| 216 | if (DEBUG_RA >= RA_DEBUG_Interference) { |
| 217 | cerr << "\n\tLR after Call: "; |
| 218 | printSet(*LR); |
| 219 | } |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 220 | LR->setCallInterference(); |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 221 | if (DEBUG_RA >= RA_DEBUG_Interference) { |
| 222 | cerr << "\n ++After adding call interference for LR: " ; |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 223 | printSet(*LR); |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | } |
| 228 | |
Vikram S. Adve | 1a53f03 | 2002-03-31 18:54:37 +0000 | [diff] [blame] | 229 | // Now find the LR of the return value of the call |
| 230 | // We do this because, we look at the LV set *after* the instruction |
| 231 | // to determine, which LRs must be saved across calls. The return value |
| 232 | // of the call is live in this set - but it does not interfere with call |
| 233 | // (i.e., we can allocate a volatile register to the return value) |
| 234 | // |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 235 | CallArgsDescriptor* argDesc = CallArgsDescriptor::get(MInst); |
| 236 | |
| 237 | if (const Value *RetVal = argDesc->getReturnValue()) { |
Vikram S. Adve | 1a53f03 | 2002-03-31 18:54:37 +0000 | [diff] [blame] | 238 | LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal ); |
| 239 | assert( RetValLR && "No LR for RetValue of call"); |
| 240 | RetValLR->clearCallInterference(); |
| 241 | } |
| 242 | |
| 243 | // If the CALL is an indirect call, find the LR of the function pointer. |
| 244 | // That has a call interference because it conflicts with outgoing args. |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 245 | if (const Value *AddrVal = argDesc->getIndirectFuncPtr()) { |
Vikram S. Adve | 1a53f03 | 2002-03-31 18:54:37 +0000 | [diff] [blame] | 246 | LiveRange *AddrValLR = LRI.getLiveRangeForValue( AddrVal ); |
| 247 | assert( AddrValLR && "No LR for indirect addr val of call"); |
| 248 | AddrValLR->setCallInterference(); |
| 249 | } |
| 250 | |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 254 | |
| 255 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 256 | //---------------------------------------------------------------------------- |
| 257 | // This method will walk thru code and create interferences in the IG of |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 258 | // each RegClass. Also, this method calculates the spill cost of each |
| 259 | // Live Range (it is done in this method to save another pass over the code). |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 260 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 261 | void PhyRegAlloc::buildInterferenceGraphs() |
| 262 | { |
| 263 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 264 | if (DEBUG_RA >= RA_DEBUG_Interference) |
| 265 | cerr << "Creating interference graphs ...\n"; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 266 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 267 | unsigned BBLoopDepthCost; |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 268 | for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 269 | BBI != BBE; ++BBI) { |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 270 | const MachineBasicBlock &MBB = *BBI; |
| 271 | const BasicBlock *BB = MBB.getBasicBlock(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 272 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 273 | // find the 10^(loop_depth) of this BB |
| 274 | // |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 275 | BBLoopDepthCost = (unsigned)pow(10.0, LoopDepthCalc->getLoopDepth(BB)); |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 276 | |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 277 | // get the iterator for machine instructions |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 278 | // |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 279 | MachineBasicBlock::const_iterator MII = MBB.begin(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 280 | |
| 281 | // iterate over all the machine instructions in BB |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 282 | // |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 283 | for ( ; MII != MBB.end(); ++MII) { |
| 284 | const MachineInstr *MInst = *MII; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 285 | |
| 286 | // get the LV set after the instruction |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 287 | // |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 288 | const ValueSet &LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, BB); |
| 289 | bool isCallInst = TM.getInstrInfo().isCall(MInst->getOpCode()); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 290 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 291 | if (isCallInst ) { |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 292 | // set the isCallInterference flag of each live range wich extends |
| 293 | // accross this call instruction. This information is used by graph |
| 294 | // coloring algo to avoid allocating volatile colors to live ranges |
| 295 | // that span across calls (since they have to be saved/restored) |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 296 | // |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 297 | setCallInterferences(MInst, &LVSetAI); |
Ruchira Sasanka | 958faf3 | 2001-10-19 17:21:03 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 300 | // iterate over all MI operands to find defs |
| 301 | // |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 302 | for (MachineInstr::const_val_op_iterator OpI = MInst->begin(), |
| 303 | OpE = MInst->end(); OpI != OpE; ++OpI) { |
Vikram S. Adve | 5f2180c | 2003-05-27 00:05:23 +0000 | [diff] [blame] | 304 | if (OpI.isDefOnly() || OpI.isDefAndUse()) // create a new LR since def |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 305 | addInterference(*OpI, &LVSetAI, isCallInst); |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 306 | |
| 307 | // Calculate the spill cost of each live range |
| 308 | // |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 309 | LiveRange *LR = LRI.getLiveRangeForValue(*OpI); |
| 310 | if (LR) LR->addSpillCost(BBLoopDepthCost); |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 311 | } |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 312 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 313 | |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 314 | // if there are multiple defs in this instruction e.g. in SETX |
| 315 | // |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 316 | if (TM.getInstrInfo().isPseudoInstr(MInst->getOpCode())) |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 317 | addInterf4PseudoInstr(MInst); |
| 318 | |
| 319 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 320 | // Also add interference for any implicit definitions in a machine |
| 321 | // instr (currently, only calls have this). |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 322 | // |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 323 | unsigned NumOfImpRefs = MInst->getNumImplicitRefs(); |
Vikram S. Adve | 5f2180c | 2003-05-27 00:05:23 +0000 | [diff] [blame] | 324 | for (unsigned z=0; z < NumOfImpRefs; z++) |
| 325 | if (MInst->getImplicitOp(z).opIsDefOnly() || |
| 326 | MInst->getImplicitOp(z).opIsDefAndUse()) |
| 327 | addInterference( MInst->getImplicitRef(z), &LVSetAI, isCallInst ); |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 328 | |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 329 | } // for all machine instructions in BB |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 330 | } // for all BBs in function |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 331 | |
| 332 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 333 | // add interferences for function arguments. Since there are no explict |
| 334 | // defs in the function for args, we have to add them manually |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 335 | // |
| 336 | addInterferencesForArgs(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 337 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 338 | if (DEBUG_RA >= RA_DEBUG_Interference) |
| 339 | cerr << "Interference graphs calculated!\n"; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 342 | |
| 343 | |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 344 | //-------------------------------------------------------------------------- |
| 345 | // Pseudo instructions will be exapnded to multiple instructions by the |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 346 | // assembler. Consequently, all the opernds must get distinct registers. |
| 347 | // Therefore, we mark all operands of a pseudo instruction as they interfere |
| 348 | // with one another. |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 349 | //-------------------------------------------------------------------------- |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 350 | void PhyRegAlloc::addInterf4PseudoInstr(const MachineInstr *MInst) { |
| 351 | |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 352 | bool setInterf = false; |
| 353 | |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 354 | // iterate over MI operands to find defs |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 355 | // |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 356 | for (MachineInstr::const_val_op_iterator It1 = MInst->begin(), |
| 357 | ItE = MInst->end(); It1 != ItE; ++It1) { |
| 358 | const LiveRange *LROfOp1 = LRI.getLiveRangeForValue(*It1); |
Vikram S. Adve | 5f2180c | 2003-05-27 00:05:23 +0000 | [diff] [blame] | 359 | assert((LROfOp1 || !It1.isUseOnly())&& "No LR for Def in PSEUDO insruction"); |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 360 | |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 361 | MachineInstr::const_val_op_iterator It2 = It1; |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 362 | for (++It2; It2 != ItE; ++It2) { |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 363 | const LiveRange *LROfOp2 = LRI.getLiveRangeForValue(*It2); |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 364 | |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 365 | if (LROfOp2) { |
| 366 | RegClass *RCOfOp1 = LROfOp1->getRegClass(); |
| 367 | RegClass *RCOfOp2 = LROfOp2->getRegClass(); |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 368 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 369 | if (RCOfOp1 == RCOfOp2 ){ |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 370 | RCOfOp1->setInterference( LROfOp1, LROfOp2 ); |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 371 | setInterf = true; |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 372 | } |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 373 | } // if Op2 has a LR |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 374 | } // for all other defs in machine instr |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 375 | } // for all operands in an instruction |
| 376 | |
Chris Lattner | 2f898d2 | 2002-02-05 06:02:59 +0000 | [diff] [blame] | 377 | if (!setInterf && MInst->getNumOperands() > 2) { |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 378 | cerr << "\nInterf not set for any operand in pseudo instr:\n"; |
| 379 | cerr << *MInst; |
| 380 | assert(0 && "Interf not set for pseudo instr with > 2 operands" ); |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 381 | } |
Ruchira Sasanka | 22ccb1b | 2001-11-14 15:33:58 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 385 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 386 | //---------------------------------------------------------------------------- |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 387 | // This method will add interferences for incoming arguments to a function. |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 388 | //---------------------------------------------------------------------------- |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 389 | |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 390 | void PhyRegAlloc::addInterferencesForArgs() { |
| 391 | // get the InSet of root BB |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 392 | const ValueSet &InSet = LVI->getInSetOfBB(&Fn->front()); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 393 | |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 394 | for (Function::const_aiterator AI = Fn->abegin(); AI != Fn->aend(); ++AI) { |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 395 | // add interferences between args and LVars at start |
| 396 | addInterference(AI, &InSet, false); |
| 397 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 398 | if (DEBUG_RA >= RA_DEBUG_Interference) |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 399 | cerr << " - %% adding interference for argument " << RAV(AI) << "\n"; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 404 | //---------------------------------------------------------------------------- |
| 405 | // This method is called after register allocation is complete to set the |
| 406 | // allocated reisters in the machine code. This code will add register numbers |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 407 | // to MachineOperands that contain a Value. Also it calls target specific |
| 408 | // methods to produce caller saving instructions. At the end, it adds all |
| 409 | // additional instructions produced by the register allocator to the |
| 410 | // instruction stream. |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 411 | //---------------------------------------------------------------------------- |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 412 | |
| 413 | //----------------------------- |
| 414 | // Utility functions used below |
| 415 | //----------------------------- |
| 416 | inline void |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 417 | InsertBefore(MachineInstr* newMI, |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 418 | MachineBasicBlock& MBB, |
Chris Lattner | 32be9f6 | 2002-10-28 01:41:27 +0000 | [diff] [blame] | 419 | MachineBasicBlock::iterator& MII) |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 420 | { |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 421 | MII = MBB.insert(MII, newMI); |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 422 | ++MII; |
| 423 | } |
| 424 | |
| 425 | inline void |
| 426 | InsertAfter(MachineInstr* newMI, |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 427 | MachineBasicBlock& MBB, |
Chris Lattner | 32be9f6 | 2002-10-28 01:41:27 +0000 | [diff] [blame] | 428 | MachineBasicBlock::iterator& MII) |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 429 | { |
| 430 | ++MII; // insert before the next instruction |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 431 | MII = MBB.insert(MII, newMI); |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | inline void |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 435 | DeleteInstruction(MachineBasicBlock& MBB, |
| 436 | MachineBasicBlock::iterator& MII) |
| 437 | { |
| 438 | MII = MBB.erase(MII); |
| 439 | } |
| 440 | |
| 441 | inline void |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 442 | SubstituteInPlace(MachineInstr* newMI, |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 443 | MachineBasicBlock& MBB, |
Chris Lattner | 32be9f6 | 2002-10-28 01:41:27 +0000 | [diff] [blame] | 444 | MachineBasicBlock::iterator MII) |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 445 | { |
| 446 | *MII = newMI; |
| 447 | } |
| 448 | |
| 449 | inline void |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 450 | PrependInstructions(vector<MachineInstr *> &IBef, |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 451 | MachineBasicBlock& MBB, |
Chris Lattner | 32be9f6 | 2002-10-28 01:41:27 +0000 | [diff] [blame] | 452 | MachineBasicBlock::iterator& MII, |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 453 | const std::string& msg) |
| 454 | { |
| 455 | if (!IBef.empty()) |
| 456 | { |
| 457 | MachineInstr* OrigMI = *MII; |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 458 | std::vector<MachineInstr *>::iterator AdIt; |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 459 | for (AdIt = IBef.begin(); AdIt != IBef.end() ; ++AdIt) |
| 460 | { |
| 461 | if (DEBUG_RA) { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 462 | if (OrigMI) cerr << "For MInst:\n " << *OrigMI; |
| 463 | cerr << msg << "PREPENDed instr:\n " << **AdIt << "\n"; |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 464 | } |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 465 | InsertBefore(*AdIt, MBB, MII); |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | inline void |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 471 | AppendInstructions(std::vector<MachineInstr *> &IAft, |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 472 | MachineBasicBlock& MBB, |
Chris Lattner | 32be9f6 | 2002-10-28 01:41:27 +0000 | [diff] [blame] | 473 | MachineBasicBlock::iterator& MII, |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 474 | const std::string& msg) |
| 475 | { |
| 476 | if (!IAft.empty()) |
| 477 | { |
| 478 | MachineInstr* OrigMI = *MII; |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 479 | std::vector<MachineInstr *>::iterator AdIt; |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 480 | for ( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt ) |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 481 | { |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 482 | if (DEBUG_RA) { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 483 | if (OrigMI) cerr << "For MInst:\n " << *OrigMI; |
| 484 | cerr << msg << "APPENDed instr:\n " << **AdIt << "\n"; |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 485 | } |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 486 | InsertAfter(*AdIt, MBB, MII); |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 492 | void PhyRegAlloc::updateInstruction(MachineInstr* MInst, BasicBlock* BB) |
| 493 | { |
| 494 | unsigned Opcode = MInst->getOpCode(); |
| 495 | |
| 496 | // Reset tmp stack positions so they can be reused for each machine instr. |
| 497 | MF.getInfo()->popAllTempValues(); |
| 498 | |
| 499 | // First, set the registers for operands in the machine instruction |
| 500 | // if a register was successfully allocated. Do this first because we |
| 501 | // will need to know which registers are already used by this instr'n. |
| 502 | // |
| 503 | for (unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) |
| 504 | { |
| 505 | MachineOperand& Op = MInst->getOperand(OpNum); |
| 506 | if (Op.getType() == MachineOperand::MO_VirtualRegister || |
| 507 | Op.getType() == MachineOperand::MO_CCRegister) |
| 508 | { |
| 509 | const Value *const Val = Op.getVRegValue(); |
| 510 | if (const LiveRange* LR = LRI.getLiveRangeForValue(Val)) |
| 511 | if (LR->hasColor()) |
| 512 | MInst->SetRegForOperand(OpNum, |
| 513 | MRI.getUnifiedRegNum(LR->getRegClass()->getID(), |
| 514 | LR->getColor())); |
| 515 | } |
| 516 | } // for each operand |
| 517 | |
| 518 | // Mark that the operands have been updated. setRelRegsUsedByThisInst() |
| 519 | // is called to find registers used by each MachineInst, and it should not |
| 520 | // be used for an instruction until this is done. This flag just serves |
| 521 | // as a sanity check. |
| 522 | OperandsColoredMap[MInst] = true; |
| 523 | |
| 524 | // Now insert special instructions (if necessary) for call/return |
| 525 | // instructions. Do this before inserting spill code since some |
| 526 | // registers must be used by outgoing call arguments or the return value |
| 527 | // of a call, and spill code should not use those registers. |
| 528 | // |
| 529 | if (TM.getInstrInfo().isCall(Opcode) || |
| 530 | TM.getInstrInfo().isReturn(Opcode)) { |
| 531 | AddedInstrns &AI = AddedInstrMap[MInst]; |
| 532 | |
| 533 | if (TM.getInstrInfo().isCall(Opcode)) |
| 534 | MRI.colorCallArgs(MInst, LRI, &AI, *this, BB); |
| 535 | else if (TM.getInstrInfo().isReturn(Opcode)) |
| 536 | MRI.colorRetValue(MInst, LRI, &AI); |
| 537 | } |
| 538 | |
| 539 | // Now insert spill code for remaining operands not allocated to |
| 540 | // registers. This must be done even for call return instructions |
| 541 | // since those are not handled by the special code above. |
| 542 | for (unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) |
| 543 | { |
| 544 | MachineOperand& Op = MInst->getOperand(OpNum); |
| 545 | if (Op.getType() == MachineOperand::MO_VirtualRegister || |
| 546 | Op.getType() == MachineOperand::MO_CCRegister) |
| 547 | { |
| 548 | const Value* Val = Op.getVRegValue(); |
| 549 | if (const LiveRange *LR = LRI.getLiveRangeForValue(Val)) |
| 550 | if (! LR->hasColor()) |
| 551 | insertCode4SpilledLR(LR, MInst, BB, OpNum); |
| 552 | } |
| 553 | } // for each operand |
| 554 | } |
| 555 | |
| 556 | void PhyRegAlloc::updateMachineCode() |
| 557 | { |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 558 | // Insert any instructions needed at method entry |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 559 | MachineBasicBlock::iterator MII = MF.front().begin(); |
| 560 | PrependInstructions(AddedInstrAtEntry.InstrnsBefore, MF.front(), MII, |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 561 | "At function entry: \n"); |
| 562 | assert(AddedInstrAtEntry.InstrnsAfter.empty() && |
| 563 | "InstrsAfter should be unnecessary since we are just inserting at " |
| 564 | "the function entry point here."); |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 565 | |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 566 | for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 567 | BBI != BBE; ++BBI) { |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 568 | |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 569 | MachineBasicBlock &MBB = *BBI; |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 570 | |
| 571 | // Iterate over all machine instructions in BB and mark operands with |
| 572 | // their assigned registers or insert spill code, as appropriate. |
| 573 | // Also, fix operands of call/return instructions. |
| 574 | // |
| 575 | for (MachineBasicBlock::iterator MII = MBB.begin(); MII != MBB.end(); ++MII) |
| 576 | if (!TM.getInstrInfo().isDummyPhiInstr((*MII)->getOpCode())) // ignore Phis |
| 577 | updateInstruction(*MII, MBB.getBasicBlock()); |
| 578 | |
| 579 | // Now, move code out of delay slots of branches and returns if needed. |
| 580 | // (Also, move "after" code from calls to the last delay slot instruction.) |
| 581 | // Moving code out of delay slots is needed in 2 situations: |
| 582 | // (1) If this is a branch and it needs instructions inserted after it, |
| 583 | // move any existing instructions out of the delay slot so that the |
| 584 | // instructions can go into the delay slot. This only supports the |
| 585 | // case that #instrsAfter <= #delay slots. |
| 586 | // |
| 587 | // (2) If any instruction in the delay slot needs |
| 588 | // instructions inserted, move it out of the delay slot and before the |
| 589 | // branch because putting code before or after it would be VERY BAD! |
| 590 | // |
| 591 | // If the annul bit of the branch is set, neither of these is legal! |
| 592 | // If so, we need to handle spill differently but annulling is not yet used. |
| 593 | // |
| 594 | for (MachineBasicBlock::iterator MII = MBB.begin(); |
| 595 | MII != MBB.end(); ++MII) |
| 596 | if (unsigned delaySlots = |
| 597 | TM.getInstrInfo().getNumDelaySlots((*MII)->getOpCode())) |
| 598 | { |
| 599 | assert(delaySlots==1 && "Not handling multiple delay slots!"); |
| 600 | |
| 601 | MachineInstr *MInst = *MII; |
| 602 | MachineInstr *MDelayInst = *(MII+1); |
| 603 | |
| 604 | // Check the 2 conditions above: |
| 605 | // (1) Does a branch need instructions added after it? |
| 606 | // (2) O/w does delay slot instr. need instrns before or after? |
| 607 | bool isBranch = (TM.getInstrInfo().isBranch((*MII)->getOpCode()) || |
| 608 | TM.getInstrInfo().isReturn((*MII)->getOpCode())); |
| 609 | bool cond1 = isBranch && AddedInstrMap[MInst].InstrnsAfter.size() > 0; |
| 610 | bool cond2 = (AddedInstrMap.count(MDelayInst) || |
| 611 | AddedInstrMap[MDelayInst].InstrnsAfter.size() > 0); |
| 612 | |
| 613 | if (cond1 || cond2) |
| 614 | { |
| 615 | // Move delay slot instrn before the preceding branch. |
| 616 | // InsertBefore() modifies MII to point to the branch again. |
| 617 | assert(((*MII)->getOpCodeFlags() & AnnulFlag) == 0 && |
| 618 | "FIXME: Annul bit must be turned off here!"); |
| 619 | InsertBefore(MDelayInst, MBB, MII); |
| 620 | |
| 621 | // In case (1), delete it and don't replace with anything! |
| 622 | // Otherwise (i.e., case (2) only) replace it with a NOP. |
| 623 | if (cond1) { |
| 624 | assert(AddedInstrMap[MInst].InstrnsAfter.size() <= delaySlots && |
| 625 | "Cannot put more than #delaySlots spill instrns after " |
| 626 | "branch or return! Need to handle spill differently."); |
| 627 | DeleteInstruction(MBB, MII); // MII now points to next inst. |
| 628 | } |
| 629 | else { |
| 630 | MachineInstr* nopI =BuildMI(TM.getInstrInfo().getNOPOpCode(),1); |
| 631 | SubstituteInPlace(nopI, MBB, MII+1); // replace with NOP |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | // If this is not a branch or return (probably a call), |
| 636 | // the Instrnsafter, if any, must really go after the last |
| 637 | // delay slot. Move the InstrAfter to the instr. in that slot. |
| 638 | // We must do this after the previous code because the instructions |
| 639 | // in delay slots may get moved out by that code. |
| 640 | // |
| 641 | if (!isBranch) |
| 642 | move2DelayedInstr(MInst, *(MII+delaySlots)); |
| 643 | } |
| 644 | |
| 645 | // Finally iterate over all instructions in BB and insert before/after |
| 646 | // |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 647 | for (MachineBasicBlock::iterator MII = MBB.begin(); |
| 648 | MII != MBB.end(); ++MII) { |
| 649 | |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 650 | MachineInstr *MInst = *MII; |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 651 | unsigned Opcode = MInst->getOpCode(); |
| 652 | |
Ruchira Sasanka | 65480b7 | 2001-11-10 21:21:36 +0000 | [diff] [blame] | 653 | // do not process Phis |
Vikram S. Adve | 23a4c8f | 2002-03-18 03:37:19 +0000 | [diff] [blame] | 654 | if (TM.getInstrInfo().isDummyPhiInstr(Opcode)) |
Ruchira Sasanka | 65480b7 | 2001-11-10 21:21:36 +0000 | [diff] [blame] | 655 | continue; |
| 656 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 657 | // Now add instructions that the register allocator inserts before/after |
| 658 | // this machine instructions (done only for calls/rets/incoming args) |
| 659 | // We do this here, to ensure that spill for an instruction is inserted |
| 660 | // closest as possible to an instruction (see above insertCode4Spill...) |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 661 | |
Ruchira Sasanka | f221a2e | 2001-11-13 23:09:30 +0000 | [diff] [blame] | 662 | // If there are instructions to be added, *before* this machine |
| 663 | // instruction, add them now. |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 664 | // |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 665 | if (AddedInstrMap.count(MInst)) { |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 666 | PrependInstructions(AddedInstrMap[MInst].InstrnsBefore, MBB, MII,""); |
Ruchira Sasanka | f221a2e | 2001-11-13 23:09:30 +0000 | [diff] [blame] | 667 | } |
Vikram S. Adve | 4876209 | 2002-04-25 04:34:15 +0000 | [diff] [blame] | 668 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 669 | // If there are instructions to be added *after* this machine |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 670 | // instruction, add them now. All cases with delay slots have been |
| 671 | // c |
Chris Lattner | 0b0ffa0 | 2002-04-09 05:13:04 +0000 | [diff] [blame] | 672 | if (!AddedInstrMap[MInst].InstrnsAfter.empty()) { |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 673 | AppendInstructions(AddedInstrMap[MInst].InstrnsAfter, MBB, MII,""); |
Ruchira Sasanka | 0931a01 | 2001-09-15 19:06:58 +0000 | [diff] [blame] | 674 | } |
Vikram S. Adve | cb202e3 | 2002-10-11 16:12:40 +0000 | [diff] [blame] | 675 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 676 | } // for each machine instruction |
Ruchira Sasanka | 0931a01 | 2001-09-15 19:06:58 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 681 | |
| 682 | //---------------------------------------------------------------------------- |
| 683 | // This method inserts spill code for AN operand whose LR was spilled. |
| 684 | // This method may be called several times for a single machine instruction |
| 685 | // if it contains many spilled operands. Each time it is called, it finds |
| 686 | // a register which is not live at that instruction and also which is not |
| 687 | // used by other spilled operands of the same instruction. Then it uses |
| 688 | // this register temporarily to accomodate the spilled value. |
| 689 | //---------------------------------------------------------------------------- |
| 690 | void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR, |
| 691 | MachineInstr *MInst, |
| 692 | const BasicBlock *BB, |
| 693 | const unsigned OpNum) { |
| 694 | |
Vikram S. Adve | ad9c978 | 2002-09-28 17:02:40 +0000 | [diff] [blame] | 695 | assert((! TM.getInstrInfo().isCall(MInst->getOpCode()) || OpNum == 0) && |
| 696 | "Outgoing arg of a call must be handled elsewhere (func arg ok)"); |
| 697 | assert(! TM.getInstrInfo().isReturn(MInst->getOpCode()) && |
| 698 | "Return value of a ret must be handled elsewhere"); |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 699 | |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 700 | MachineOperand& Op = MInst->getOperand(OpNum); |
Vikram S. Adve | 5f2180c | 2003-05-27 00:05:23 +0000 | [diff] [blame] | 701 | bool isDef = Op.opIsDefOnly(); |
| 702 | bool isDefAndUse = Op.opIsDefAndUse(); |
Chris Lattner | 9d4ed15 | 2003-01-15 21:14:01 +0000 | [diff] [blame] | 703 | unsigned RegType = MRI.getRegType(LR); |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 704 | int SpillOff = LR->getSpillOffFromFP(); |
| 705 | RegClass *RC = LR->getRegClass(); |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 706 | const ValueSet &LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 707 | |
Chris Lattner | e90fcb7 | 2002-12-28 20:35:34 +0000 | [diff] [blame] | 708 | MF.getInfo()->pushTempValue(MRI.getSpilledRegSize(RegType) ); |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 709 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 710 | vector<MachineInstr*> MIBef, MIAft; |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 711 | vector<MachineInstr*> AdIMid; |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 712 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 713 | // Choose a register to hold the spilled value. This may insert code |
| 714 | // before and after MInst to free up the value. If so, this code should |
| 715 | // be first and last in the spill sequence before/after MInst. |
| 716 | int TmpRegU = getUsableUniRegAtMI(RegType, &LVSetBef, MInst, MIBef, MIAft); |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 717 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 718 | // Set the operand first so that it this register does not get used |
| 719 | // as a scratch register for later calls to getUsableUniRegAtMI below |
| 720 | MInst->SetRegForOperand(OpNum, TmpRegU); |
| 721 | |
| 722 | // get the added instructions for this instruction |
Chris Lattner | 0b0ffa0 | 2002-04-09 05:13:04 +0000 | [diff] [blame] | 723 | AddedInstrns &AI = AddedInstrMap[MInst]; |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 724 | |
| 725 | // We may need a scratch register to copy the spilled value to/from memory. |
| 726 | // This may itself have to insert code to free up a scratch register. |
| 727 | // Any such code should go before (after) the spill code for a load (store). |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 728 | // The scratch reg is not marked as used because it is only used |
| 729 | // for the copy and not used across MInst. |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 730 | int scratchRegType = -1; |
| 731 | int scratchReg = -1; |
| 732 | if (MRI.regTypeNeedsScratchReg(RegType, scratchRegType)) |
| 733 | { |
Chris Lattner | 27a0893 | 2002-10-22 23:16:21 +0000 | [diff] [blame] | 734 | scratchReg = getUsableUniRegAtMI(scratchRegType, &LVSetBef, |
| 735 | MInst, MIBef, MIAft); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 736 | assert(scratchReg != MRI.getInvalidRegNum()); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | if (!isDef || isDefAndUse) { |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 740 | // for a USE, we have to load the value of LR from stack to a TmpReg |
| 741 | // and use the TmpReg as one operand of instruction |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 742 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 743 | // actual loading instruction(s) |
| 744 | MRI.cpMem2RegMI(AdIMid, MRI.getFramePointer(), SpillOff, TmpRegU, RegType, |
| 745 | scratchReg); |
Ruchira Sasanka | 226f1f0 | 2001-11-08 19:11:30 +0000 | [diff] [blame] | 746 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 747 | // the actual load should be after the instructions to free up TmpRegU |
| 748 | MIBef.insert(MIBef.end(), AdIMid.begin(), AdIMid.end()); |
| 749 | AdIMid.clear(); |
| 750 | } |
| 751 | |
| 752 | if (isDef) { // if this is a Def |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 753 | // for a DEF, we have to store the value produced by this instruction |
| 754 | // on the stack position allocated for this LR |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 755 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 756 | // actual storing instruction(s) |
| 757 | MRI.cpReg2MemMI(AdIMid, TmpRegU, MRI.getFramePointer(), SpillOff, RegType, |
| 758 | scratchReg); |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 759 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 760 | MIAft.insert(MIAft.begin(), AdIMid.begin(), AdIMid.end()); |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 761 | } // if !DEF |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 762 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 763 | // Finally, insert the entire spill code sequences before/after MInst |
| 764 | AI.InstrnsBefore.insert(AI.InstrnsBefore.end(), MIBef.begin(), MIBef.end()); |
| 765 | AI.InstrnsAfter.insert(AI.InstrnsAfter.begin(), MIAft.begin(), MIAft.end()); |
| 766 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 767 | if (DEBUG_RA) { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 768 | cerr << "\nFor Inst:\n " << *MInst; |
| 769 | cerr << "SPILLED LR# " << LR->getUserIGNode()->getIndex(); |
| 770 | cerr << "; added Instructions:"; |
Anand Shukla | d58290e | 2002-07-09 19:18:56 +0000 | [diff] [blame] | 771 | for_each(MIBef.begin(), MIBef.end(), std::mem_fun(&MachineInstr::dump)); |
| 772 | for_each(MIAft.begin(), MIAft.end(), std::mem_fun(&MachineInstr::dump)); |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 773 | } |
Ruchira Sasanka | 5a61d85 | 2001-11-08 16:43:25 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 777 | //---------------------------------------------------------------------------- |
| 778 | // We can use the following method to get a temporary register to be used |
| 779 | // BEFORE any given machine instruction. If there is a register available, |
| 780 | // this method will simply return that register and set MIBef = MIAft = NULL. |
| 781 | // Otherwise, it will return a register and MIAft and MIBef will contain |
| 782 | // two instructions used to free up this returned register. |
Ruchira Sasanka | 80b1a1a | 2001-11-03 20:41:22 +0000 | [diff] [blame] | 783 | // Returned register number is the UNIFIED register number |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 784 | //---------------------------------------------------------------------------- |
| 785 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 786 | int PhyRegAlloc::getUsableUniRegAtMI(const int RegType, |
| 787 | const ValueSet *LVSetBef, |
| 788 | MachineInstr *MInst, |
| 789 | std::vector<MachineInstr*>& MIBef, |
| 790 | std::vector<MachineInstr*>& MIAft) { |
| 791 | |
Chris Lattner | 133f079 | 2002-10-28 04:45:29 +0000 | [diff] [blame] | 792 | RegClass* RC = getRegClassByID(MRI.getRegClassIDOfRegType(RegType)); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 793 | |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 794 | int RegU = getUnusedUniRegAtMI(RC, MInst, LVSetBef); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 795 | |
| 796 | if (RegU == -1) { |
Ruchira Sasanka | 80b1a1a | 2001-11-03 20:41:22 +0000 | [diff] [blame] | 797 | // we couldn't find an unused register. Generate code to free up a reg by |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 798 | // saving it on stack and restoring after the instruction |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 799 | |
Chris Lattner | e90fcb7 | 2002-12-28 20:35:34 +0000 | [diff] [blame] | 800 | int TmpOff = MF.getInfo()->pushTempValue(MRI.getSpilledRegSize(RegType)); |
Vikram S. Adve | 12af164 | 2001-11-08 04:48:50 +0000 | [diff] [blame] | 801 | |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 802 | RegU = getUniRegNotUsedByThisInst(RC, MInst); |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 803 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 804 | // Check if we need a scratch register to copy this register to memory. |
| 805 | int scratchRegType = -1; |
| 806 | if (MRI.regTypeNeedsScratchReg(RegType, scratchRegType)) |
| 807 | { |
Chris Lattner | 133f079 | 2002-10-28 04:45:29 +0000 | [diff] [blame] | 808 | int scratchReg = getUsableUniRegAtMI(scratchRegType, LVSetBef, |
| 809 | MInst, MIBef, MIAft); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 810 | assert(scratchReg != MRI.getInvalidRegNum()); |
| 811 | |
| 812 | // We may as well hold the value in the scratch register instead |
| 813 | // of copying it to memory and back. But we have to mark the |
| 814 | // register as used by this instruction, so it does not get used |
| 815 | // as a scratch reg. by another operand or anyone else. |
Chris Lattner | 27a0893 | 2002-10-22 23:16:21 +0000 | [diff] [blame] | 816 | MInst->insertUsedReg(scratchReg); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 817 | MRI.cpReg2RegMI(MIBef, RegU, scratchReg, RegType); |
| 818 | MRI.cpReg2RegMI(MIAft, scratchReg, RegU, RegType); |
| 819 | } |
| 820 | else |
| 821 | { // the register can be copied directly to/from memory so do it. |
| 822 | MRI.cpReg2MemMI(MIBef, RegU, MRI.getFramePointer(), TmpOff, RegType); |
| 823 | MRI.cpMem2RegMI(MIAft, MRI.getFramePointer(), TmpOff, RegU, RegType); |
| 824 | } |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 825 | } |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 826 | |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 827 | return RegU; |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | //---------------------------------------------------------------------------- |
| 831 | // This method is called to get a new unused register that can be used to |
| 832 | // accomodate a spilled value. |
| 833 | // This method may be called several times for a single machine instruction |
| 834 | // if it contains many spilled operands. Each time it is called, it finds |
| 835 | // a register which is not live at that instruction and also which is not |
| 836 | // used by other spilled operands of the same instruction. |
Ruchira Sasanka | 80b1a1a | 2001-11-03 20:41:22 +0000 | [diff] [blame] | 837 | // Return register number is relative to the register class. NOT |
| 838 | // unified number |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 839 | //---------------------------------------------------------------------------- |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 840 | |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 841 | int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC, |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 842 | const MachineInstr *MInst, |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 843 | const ValueSet *LVSetBef) { |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 844 | |
| 845 | unsigned NumAvailRegs = RC->getNumOfAvailRegs(); |
| 846 | |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 847 | std::vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr(); |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 848 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 849 | for (unsigned i=0; i < NumAvailRegs; i++) // Reset array |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 850 | IsColorUsedArr[i] = false; |
| 851 | |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 852 | ValueSet::const_iterator LIt = LVSetBef->begin(); |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 853 | |
| 854 | // for each live var in live variable set after machine inst |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 855 | for ( ; LIt != LVSetBef->end(); ++LIt) { |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 856 | |
| 857 | // get the live range corresponding to live var |
| 858 | LiveRange *const LRofLV = LRI.getLiveRangeForValue(*LIt ); |
| 859 | |
| 860 | // LR can be null if it is a const since a const |
| 861 | // doesn't have a dominating def - see Assumptions above |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 862 | if (LRofLV && LRofLV->getRegClass() == RC && LRofLV->hasColor() ) |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 863 | IsColorUsedArr[ LRofLV->getColor() ] = true; |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | // It is possible that one operand of this MInst was already spilled |
| 867 | // and it received some register temporarily. If that's the case, |
| 868 | // it is recorded in machine operand. We must skip such registers. |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 869 | // |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 870 | setRelRegsUsedByThisInst(RC, MInst); |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 871 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 872 | for (unsigned c=0; c < NumAvailRegs; c++) // find first unused color |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 873 | if (!IsColorUsedArr[c]) |
| 874 | return MRI.getUnifiedRegNum(RC->getID(), c); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 875 | |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 876 | return -1; |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 880 | //---------------------------------------------------------------------------- |
| 881 | // Get any other register in a register class, other than what is used |
| 882 | // by operands of a machine instruction. Returns the unified reg number. |
| 883 | //---------------------------------------------------------------------------- |
| 884 | int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC, |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 885 | const MachineInstr *MInst) { |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 886 | |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 887 | vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr(); |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 888 | unsigned NumAvailRegs = RC->getNumOfAvailRegs(); |
| 889 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 890 | for (unsigned i=0; i < NumAvailRegs ; i++) // Reset array |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 891 | IsColorUsedArr[i] = false; |
| 892 | |
| 893 | setRelRegsUsedByThisInst(RC, MInst); |
| 894 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 895 | for (unsigned c=0; c < RC->getNumOfAvailRegs(); c++)// find first unused color |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 896 | if (!IsColorUsedArr[c]) |
| 897 | return MRI.getUnifiedRegNum(RC->getID(), c); |
| 898 | |
| 899 | assert(0 && "FATAL: No free register could be found in reg class!!"); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 900 | return 0; |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 904 | //---------------------------------------------------------------------------- |
| 905 | // This method modifies the IsColorUsedArr of the register class passed to it. |
| 906 | // It sets the bits corresponding to the registers used by this machine |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 907 | // instructions. Both explicit and implicit operands are set. |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 908 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 909 | void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 910 | const MachineInstr *MInst ) |
| 911 | { |
| 912 | assert(OperandsColoredMap[MInst] == true && |
| 913 | "Illegal to call setRelRegsUsedByThisInst() until colored operands " |
| 914 | "are marked for an instruction."); |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 915 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 916 | vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr(); |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 917 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 918 | // Add the registers already marked as used by the instruction. |
| 919 | // This should include any scratch registers that are used to save |
| 920 | // values across the instruction (e.g., for saving state register values). |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 921 | const std::set<int> ®sUsed = MInst->getRegsUsed(); |
| 922 | for (std::set<int>::iterator I=regsUsed.begin(), E=regsUsed.end(); I != E; ++I) |
| 923 | { |
| 924 | int i = *I; |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 925 | unsigned classId = 0; |
Chris Lattner | 27a0893 | 2002-10-22 23:16:21 +0000 | [diff] [blame] | 926 | int classRegNum = MRI.getClassRegNum(i, classId); |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 927 | if (RC->getID() == classId) |
| 928 | { |
| 929 | assert(classRegNum < (int) IsColorUsedArr.size() && |
| 930 | "Illegal register number for this reg class?"); |
| 931 | IsColorUsedArr[classRegNum] = true; |
| 932 | } |
Ruchira Sasanka | f6dfca1 | 2001-11-15 15:00:53 +0000 | [diff] [blame] | 933 | } |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 934 | |
Vikram S. Adve | f5af636 | 2002-07-08 23:15:32 +0000 | [diff] [blame] | 935 | // If there are implicit references, mark their allocated regs as well |
| 936 | // |
| 937 | for (unsigned z=0; z < MInst->getNumImplicitRefs(); z++) |
| 938 | if (const LiveRange* |
| 939 | LRofImpRef = LRI.getLiveRangeForValue(MInst->getImplicitRef(z))) |
| 940 | if (LRofImpRef->hasColor()) |
| 941 | // this implicit reference is in a LR that received a color |
| 942 | IsColorUsedArr[LRofImpRef->getColor()] = true; |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 946 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 947 | // If there are delay slots for an instruction, the instructions |
| 948 | // added after it must really go after the delayed instruction(s). |
| 949 | // So, we move the InstrAfter of that instruction to the |
| 950 | // corresponding delayed instruction using the following method. |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 951 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 952 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 953 | void PhyRegAlloc::move2DelayedInstr(const MachineInstr *OrigMI, |
| 954 | const MachineInstr *DelayedMI) |
| 955 | { |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 956 | // "added after" instructions of the original instr |
Vikram S. Adve | dabb41d | 2002-05-19 15:29:31 +0000 | [diff] [blame] | 957 | std::vector<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI].InstrnsAfter; |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 958 | |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 959 | // "added after" instructions of the delayed instr |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 960 | std::vector<MachineInstr *> &DelayedAft =AddedInstrMap[DelayedMI].InstrnsAfter; |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 961 | |
| 962 | // go thru all the "added after instructions" of the original instruction |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 963 | // and append them to the "added after instructions" of the delayed |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 964 | // instructions |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 965 | DelayedAft.insert(DelayedAft.end(), OrigAft.begin(), OrigAft.end()); |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 966 | |
| 967 | // empty the "added after instructions" of the original instruction |
| 968 | OrigAft.clear(); |
Ruchira Sasanka | 251d8db | 2001-10-23 21:38:00 +0000 | [diff] [blame] | 969 | } |
Ruchira Sasanka | 0931a01 | 2001-09-15 19:06:58 +0000 | [diff] [blame] | 970 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 971 | //---------------------------------------------------------------------------- |
| 972 | // This method prints the code with registers after register allocation is |
| 973 | // complete. |
| 974 | //---------------------------------------------------------------------------- |
| 975 | void PhyRegAlloc::printMachineCode() |
| 976 | { |
| 977 | |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 978 | cerr << "\n;************** Function " << Fn->getName() |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 979 | << " *****************\n"; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 980 | |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 981 | for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 982 | BBI != BBE; ++BBI) { |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 983 | cerr << "\n"; printLabel(BBI->getBasicBlock()); cerr << ": "; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 984 | |
| 985 | // get the iterator for machine instructions |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 986 | MachineBasicBlock& MBB = *BBI; |
| 987 | MachineBasicBlock::iterator MII = MBB.begin(); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 988 | |
| 989 | // iterate over all the machine instructions in BB |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 990 | for ( ; MII != MBB.end(); ++MII) { |
Chris Lattner | d9512ca | 2002-10-29 17:35:39 +0000 | [diff] [blame] | 991 | MachineInstr *MInst = *MII; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 992 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 993 | cerr << "\n\t"; |
Chris Lattner | d9512ca | 2002-10-29 17:35:39 +0000 | [diff] [blame] | 994 | cerr << TM.getInstrInfo().getName(MInst->getOpCode()); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 995 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 996 | for (unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) { |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 997 | MachineOperand& Op = MInst->getOperand(OpNum); |
| 998 | |
Chris Lattner | 133f079 | 2002-10-28 04:45:29 +0000 | [diff] [blame] | 999 | if (Op.getType() == MachineOperand::MO_VirtualRegister || |
| 1000 | Op.getType() == MachineOperand::MO_CCRegister /*|| |
| 1001 | Op.getType() == MachineOperand::MO_PCRelativeDisp*/ ) { |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1002 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1003 | const Value *const Val = Op.getVRegValue () ; |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1004 | // ****this code is temporary till NULL Values are fixed |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1005 | if (! Val ) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1006 | cerr << "\t<*NULL*>"; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1007 | continue; |
| 1008 | } |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1009 | |
| 1010 | // if a label or a constant |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1011 | if (isa<BasicBlock>(Val)) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1012 | cerr << "\t"; printLabel( Op.getVRegValue () ); |
| 1013 | } else { |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1014 | // else it must be a register value |
| 1015 | const int RegNum = Op.getAllocatedRegNum(); |
| 1016 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1017 | cerr << "\t" << "%" << MRI.getUnifiedRegName( RegNum ); |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 1018 | if (Val->hasName() ) |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1019 | cerr << "(" << Val->getName() << ")"; |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 1020 | else |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1021 | cerr << "(" << Val << ")"; |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 1022 | |
Vikram S. Adve | 5f2180c | 2003-05-27 00:05:23 +0000 | [diff] [blame] | 1023 | if (Op.opIsDefOnly() || Op.opIsDefAndUse()) |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1024 | cerr << "*"; |
Ruchira Sasanka | ba9d5db | 2001-11-15 20:23:19 +0000 | [diff] [blame] | 1025 | |
| 1026 | const LiveRange *LROfVal = LRI.getLiveRangeForValue(Val); |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1027 | if (LROfVal ) |
| 1028 | if (LROfVal->hasSpillOffset() ) |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1029 | cerr << "$"; |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | } |
Chris Lattner | 133f079 | 2002-10-28 04:45:29 +0000 | [diff] [blame] | 1033 | else if (Op.getType() == MachineOperand::MO_MachineRegister) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1034 | cerr << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum()); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | else |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1038 | cerr << "\t" << Op; // use dump field |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1041 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1042 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1043 | unsigned NumOfImpRefs = MInst->getNumImplicitRefs(); |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1044 | if (NumOfImpRefs > 0) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1045 | cerr << "\tImplicit:"; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1046 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1047 | for (unsigned z=0; z < NumOfImpRefs; z++) |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 1048 | cerr << RAV(MInst->getImplicitRef(z)) << "\t"; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1049 | } |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1050 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1051 | } // for all machine instructions |
| 1052 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1053 | cerr << "\n"; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1054 | |
| 1055 | } // for all BBs |
| 1056 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1057 | cerr << "\n"; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1060 | |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1061 | //---------------------------------------------------------------------------- |
| 1062 | |
| 1063 | //---------------------------------------------------------------------------- |
| 1064 | void PhyRegAlloc::colorIncomingArgs() |
| 1065 | { |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1066 | MRI.colorMethodArgs(Fn, LRI, &AddedInstrAtEntry); |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1069 | |
| 1070 | //---------------------------------------------------------------------------- |
| 1071 | // Used to generate a label for a basic block |
| 1072 | //---------------------------------------------------------------------------- |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1073 | void PhyRegAlloc::printLabel(const Value *Val) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1074 | if (Val->hasName()) |
| 1075 | cerr << Val->getName(); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1076 | else |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1077 | cerr << "Label" << Val; |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1081 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1082 | // This method calls setSugColorUsable method of each live range. This |
| 1083 | // will determine whether the suggested color of LR is really usable. |
| 1084 | // A suggested color is not usable when the suggested color is volatile |
| 1085 | // AND when there are call interferences |
| 1086 | //---------------------------------------------------------------------------- |
| 1087 | |
| 1088 | void PhyRegAlloc::markUnusableSugColors() |
| 1089 | { |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1090 | // hash map iterator |
| 1091 | LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); |
| 1092 | LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end(); |
| 1093 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1094 | for (; HMI != HMIEnd ; ++HMI ) { |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 1095 | if (HMI->first) { |
| 1096 | LiveRange *L = HMI->second; // get the LiveRange |
| 1097 | if (L) { |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1098 | if (L->hasSuggestedColor()) { |
Chris Lattner | dd1e40b | 2002-02-03 07:46:34 +0000 | [diff] [blame] | 1099 | int RCID = L->getRegClass()->getID(); |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1100 | if (MRI.isRegVolatile( RCID, L->getSuggestedColor()) && |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1101 | L->isCallInterference() ) |
| 1102 | L->setSuggestedColorUsable( false ); |
| 1103 | else |
| 1104 | L->setSuggestedColorUsable( true ); |
| 1105 | } |
| 1106 | } // if L->hasSuggestedColor() |
| 1107 | } |
| 1108 | } // for all LR's in hash map |
| 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 1113 | //---------------------------------------------------------------------------- |
| 1114 | // The following method will set the stack offsets of the live ranges that |
| 1115 | // are decided to be spillled. This must be called just after coloring the |
| 1116 | // LRs using the graph coloring algo. For each live range that is spilled, |
| 1117 | // this method allocate a new spill position on the stack. |
| 1118 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1119 | |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 1120 | void PhyRegAlloc::allocateStackSpace4SpilledLRs() { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1121 | if (DEBUG_RA) cerr << "\nSetting LR stack offsets for spills...\n"; |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1122 | |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 1123 | LiveRangeMapType::const_iterator HMI = LRI.getLiveRangeMap()->begin(); |
| 1124 | LiveRangeMapType::const_iterator HMIEnd = LRI.getLiveRangeMap()->end(); |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 1125 | |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1126 | for ( ; HMI != HMIEnd ; ++HMI) { |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 1127 | if (HMI->first && HMI->second) { |
| 1128 | LiveRange *L = HMI->second; // get the LiveRange |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1129 | if (!L->hasColor()) { // NOTE: ** allocating the size of long Type ** |
Chris Lattner | e90fcb7 | 2002-12-28 20:35:34 +0000 | [diff] [blame] | 1130 | int stackOffset = MF.getInfo()->allocateSpilledValue(Type::LongTy); |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1131 | L->setSpillOffFromFP(stackOffset); |
| 1132 | if (DEBUG_RA) |
| 1133 | cerr << " LR# " << L->getUserIGNode()->getIndex() |
| 1134 | << ": stack-offset = " << stackOffset << "\n"; |
| 1135 | } |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 1136 | } |
| 1137 | } // for all LR's in hash map |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 1138 | } |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1139 | |
| 1140 | |
| 1141 | |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1142 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1143 | // The entry pont to Register Allocation |
| 1144 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1145 | |
| 1146 | void PhyRegAlloc::allocateRegisters() |
| 1147 | { |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1148 | |
| 1149 | // make sure that we put all register classes into the RegClassList |
| 1150 | // before we call constructLiveRanges (now done in the constructor of |
| 1151 | // PhyRegAlloc class). |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1152 | // |
| 1153 | LRI.constructLiveRanges(); // create LR info |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1154 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1155 | if (DEBUG_RA >= RA_DEBUG_LiveRanges) |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1156 | LRI.printLiveRanges(); |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1157 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1158 | createIGNodeListsAndIGs(); // create IGNode list and IGs |
| 1159 | |
| 1160 | buildInterferenceGraphs(); // build IGs in all reg classes |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1161 | |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1162 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1163 | if (DEBUG_RA >= RA_DEBUG_LiveRanges) { |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1164 | // print all LRs in all reg classes |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1165 | for ( unsigned rc=0; rc < NumOfRegClasses ; rc++) |
| 1166 | RegClassList[rc]->printIGNodeList(); |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1167 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1168 | // print IGs in all register classes |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1169 | for ( unsigned rc=0; rc < NumOfRegClasses ; rc++) |
| 1170 | RegClassList[rc]->printIG(); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1171 | } |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1172 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1173 | LRI.coalesceLRs(); // coalesce all live ranges |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1174 | |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1175 | if (DEBUG_RA >= RA_DEBUG_LiveRanges) { |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1176 | // print all LRs in all reg classes |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1177 | for (unsigned rc=0; rc < NumOfRegClasses; rc++) |
| 1178 | RegClassList[rc]->printIGNodeList(); |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1179 | |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1180 | // print IGs in all register classes |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1181 | for (unsigned rc=0; rc < NumOfRegClasses; rc++) |
| 1182 | RegClassList[rc]->printIG(); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1185 | |
| 1186 | // mark un-usable suggested color before graph coloring algorithm. |
| 1187 | // When this is done, the graph coloring algo will not reserve |
| 1188 | // suggested color unnecessarily - they can be used by another LR |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1189 | // |
Ruchira Sasanka | 0e62aa6 | 2001-10-19 21:39:31 +0000 | [diff] [blame] | 1190 | markUnusableSugColors(); |
| 1191 | |
| 1192 | // color all register classes using the graph coloring algo |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1193 | for (unsigned rc=0; rc < NumOfRegClasses ; rc++) |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1194 | RegClassList[rc]->colorAllRegs(); |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1195 | |
Chris Lattner | e90fcb7 | 2002-12-28 20:35:34 +0000 | [diff] [blame] | 1196 | // Atter graph coloring, if some LRs did not receive a color (i.e, spilled) |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 1197 | // a poistion for such spilled LRs |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1198 | // |
Ruchira Sasanka | 174bded | 2001-10-28 18:12:02 +0000 | [diff] [blame] | 1199 | allocateStackSpace4SpilledLRs(); |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1200 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 1201 | // Reset the temp. area on the stack before use by the first instruction. |
| 1202 | // This will also happen after updating each instruction. |
| 1203 | MF.getInfo()->popAllTempValues(); |
Ruchira Sasanka | f90870f | 2001-11-15 22:02:06 +0000 | [diff] [blame] | 1204 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1205 | // color incoming args - if the correct color was not received |
| 1206 | // insert code to copy to the correct register |
| 1207 | // |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1208 | colorIncomingArgs(); |
Ruchira Sasanka | a5ab964 | 2001-09-30 23:11:59 +0000 | [diff] [blame] | 1209 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1210 | // Now update the machine code with register names and add any |
| 1211 | // additional code inserted by the register allocator to the instruction |
| 1212 | // stream |
| 1213 | // |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1214 | updateMachineCode(); |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 1215 | |
Chris Lattner | 045e7c8 | 2001-09-19 16:26:23 +0000 | [diff] [blame] | 1216 | if (DEBUG_RA) { |
Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame] | 1217 | cerr << "\n**** Machine Code After Register Allocation:\n\n"; |
Chris Lattner | f726e77 | 2002-10-28 19:22:04 +0000 | [diff] [blame] | 1218 | MF.dump(); |
Chris Lattner | 045e7c8 | 2001-09-19 16:26:23 +0000 | [diff] [blame] | 1219 | } |
Ruchira Sasanka | 6b0a8b5 | 2001-09-15 21:11:11 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Ruchira Sasanka | e727f85 | 2001-09-18 22:43:57 +0000 | [diff] [blame] | 1222 | |
| 1223 | |