Chris Lattner | ed5171e | 2002-02-03 07:52:04 +0000 | [diff] [blame] | 1 | //===-- SparcRegInfo.cpp - Sparc Target Register Information --------------===// |
| 2 | // |
| 3 | // This file contains implementation of Sparc specific helper methods |
| 4 | // used for register allocation. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 8 | #include "SparcInternals.h" |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 9 | #include "SparcRegClassInfo.h" |
| 10 | #include "llvm/Target/Sparc.h" |
Chris Lattner | ed5171e | 2002-02-03 07:52:04 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/MachineCodeForMethod.h" |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 12 | #include "llvm/CodeGen/PhyRegAlloc.h" |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/LiveVar/ValueSet.h" |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 15 | #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" |
| 16 | #include "llvm/iTerminators.h" |
| 17 | #include "llvm/iOther.h" |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 18 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 19 | #include <iostream> |
| 20 | using std::cerr; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 22 | UltraSparcRegInfo::UltraSparcRegInfo(const UltraSparc &tgt) |
| 23 | : MachineRegInfo(tgt), UltraSparcInfo(&tgt), NumOfIntArgRegs(6), |
| 24 | NumOfFloatArgRegs(32), InvalidRegNum(1000) { |
| 25 | |
| 26 | MachineRegClassArr.push_back(new SparcIntRegClass(IntRegClassID)); |
| 27 | MachineRegClassArr.push_back(new SparcFloatRegClass(FloatRegClassID)); |
| 28 | MachineRegClassArr.push_back(new SparcIntCCRegClass(IntCCRegClassID)); |
| 29 | MachineRegClassArr.push_back(new SparcFloatCCRegClass(FloatCCRegClassID)); |
| 30 | |
| 31 | assert(SparcFloatRegOrder::StartOfNonVolatileRegs == 32 && |
| 32 | "32 Float regs are used for float arg passing"); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | // getZeroRegNum - returns the register that contains always zero this is the |
| 37 | // unified register number |
| 38 | // |
| 39 | int UltraSparcRegInfo::getZeroRegNum() const { return SparcIntRegOrder::g0; } |
| 40 | |
| 41 | // getCallAddressReg - returns the reg used for pushing the address when a |
| 42 | // method is called. This can be used for other purposes between calls |
| 43 | // |
| 44 | unsigned UltraSparcRegInfo::getCallAddressReg() const { |
| 45 | return SparcIntRegOrder::o7; |
| 46 | } |
| 47 | |
| 48 | // Returns the register containing the return address. |
| 49 | // It should be made sure that this register contains the return |
| 50 | // value when a return instruction is reached. |
| 51 | // |
| 52 | unsigned UltraSparcRegInfo::getReturnAddressReg() const { |
| 53 | return SparcIntRegOrder::i7; |
| 54 | } |
| 55 | |
| 56 | // given the unified register number, this gives the name |
| 57 | // for generating assembly code or debugging. |
| 58 | // |
| 59 | const std::string UltraSparcRegInfo::getUnifiedRegName(int reg) const { |
| 60 | if( reg < 32 ) |
| 61 | return SparcIntRegOrder::getRegName(reg); |
| 62 | else if ( reg < (64 + 32) ) |
| 63 | return SparcFloatRegOrder::getRegName( reg - 32); |
| 64 | else if( reg < (64+32+4) ) |
| 65 | return SparcFloatCCRegOrder::getRegName( reg -32 - 64); |
| 66 | else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr |
| 67 | return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4); |
| 68 | else if (reg== InvalidRegNum) //****** TODO: Remove */ |
| 69 | return "<*NoReg*>"; |
| 70 | else |
| 71 | assert(0 && "Invalid register number"); |
| 72 | return ""; |
| 73 | } |
| 74 | |
| 75 | unsigned UltraSparcRegInfo::getFramePointer() const { |
| 76 | return SparcIntRegOrder::i6; |
| 77 | } |
| 78 | |
| 79 | unsigned UltraSparcRegInfo::getStackPointer() const { |
| 80 | return SparcIntRegOrder::o6; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 85 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 86 | // Finds the return value of a sparc specific call instruction |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 87 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 88 | const Value * |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 89 | UltraSparcRegInfo::getCallInstRetVal(const MachineInstr *CallMI) const { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 90 | unsigned OpCode = CallMI->getOpCode(); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 91 | unsigned NumOfImpRefs = CallMI->getNumImplicitRefs(); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 92 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 93 | if (OpCode == CALL) { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 94 | |
| 95 | // The one before the last implicit operand is the return value of |
| 96 | // a CALL instr |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 97 | // |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 98 | if( NumOfImpRefs > 1 ) |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 99 | if (CallMI->implicitRefIsDefined(NumOfImpRefs-2)) |
| 100 | return CallMI->getImplicitRef(NumOfImpRefs-2); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 101 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 102 | } else if (OpCode == JMPLCALL) { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 103 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 104 | // The last implicit operand is the return value of a JMPL |
| 105 | // |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 106 | if(NumOfImpRefs > 0) |
| 107 | if (CallMI->implicitRefIsDefined(NumOfImpRefs-1)) |
| 108 | return CallMI->getImplicitRef(NumOfImpRefs-1); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 109 | } else |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 110 | assert(0 && "OpCode must be CALL/JMPL for a call instr"); |
| 111 | |
| 112 | return NULL; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 115 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 116 | |
| 117 | //--------------------------------------------------------------------------- |
| 118 | // Finds the return address of a call sparc specific call instruction |
| 119 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 120 | const Value * |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 121 | UltraSparcRegInfo::getCallInstRetAddr(const MachineInstr *CallMI) const { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 122 | unsigned OpCode = CallMI->getOpCode(); |
| 123 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 124 | if (OpCode == CALL) { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 125 | unsigned NumOfImpRefs = CallMI->getNumImplicitRefs(); |
| 126 | |
| 127 | assert( NumOfImpRefs && "CALL instr must have at least on ImpRef"); |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 128 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 129 | // The last implicit operand is the return address of a CALL instr |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 130 | // |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 131 | return CallMI->getImplicitRef(NumOfImpRefs-1); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 133 | } else if(OpCode == JMPLCALL) { |
| 134 | MachineOperand &MO = (MachineOperand &)CallMI->getOperand(2); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 135 | return MO.getVRegValue(); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 136 | } |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 137 | |
| 138 | assert(0 && "OpCode must be CALL/JMPL for a call instr"); |
| 139 | return 0; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 142 | // The following 3 methods are used to find the RegType (see enum above) |
| 143 | // of a LiveRange, Value and using the unified RegClassID |
| 144 | // |
| 145 | int UltraSparcRegInfo::getRegType(const LiveRange *LR) const { |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 146 | switch (LR->getRegClass()->getID()) { |
| 147 | case IntRegClassID: return IntRegType; |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame^] | 148 | case FloatRegClassID: { |
| 149 | const Type *Typ = LR->getType(); |
| 150 | if (Typ == Type::FloatTy) |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 151 | return FPSingleRegType; |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame^] | 152 | else if (Typ == Type::DoubleTy) |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 153 | return FPDoubleRegType; |
| 154 | assert(0 && "Unknown type in FloatRegClass"); |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame^] | 155 | } |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 156 | case IntCCRegClassID: return IntCCRegType; |
| 157 | case FloatCCRegClassID: return FloatCCRegType; |
| 158 | default: assert( 0 && "Unknown reg class ID"); |
| 159 | return 0; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | int UltraSparcRegInfo::getRegType(const Value *Val) const { |
| 164 | unsigned Typ; |
| 165 | |
| 166 | switch (getRegClassIDOfValue(Val)) { |
| 167 | case IntRegClassID: return IntRegType; |
| 168 | case FloatRegClassID: |
| 169 | Typ = Val->getType()->getPrimitiveID(); |
| 170 | if (Typ == Type::FloatTyID) |
| 171 | return FPSingleRegType; |
| 172 | else if (Typ == Type::DoubleTyID) |
| 173 | return FPDoubleRegType; |
| 174 | assert(0 && "Unknown type in FloatRegClass"); |
| 175 | |
| 176 | case IntCCRegClassID: return IntCCRegType; |
| 177 | case FloatCCRegClassID: return FloatCCRegType ; |
| 178 | default: assert(0 && "Unknown reg class ID"); |
| 179 | return 0; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | int UltraSparcRegInfo::getRegType(int reg) const { |
| 184 | if (reg < 32) |
| 185 | return IntRegType; |
| 186 | else if (reg < (32 + 32)) |
| 187 | return FPSingleRegType; |
| 188 | else if (reg < (64 + 32)) |
| 189 | return FPDoubleRegType; |
| 190 | else if (reg < (64+32+4)) |
| 191 | return FloatCCRegType; |
| 192 | else if (reg < (64+32+4+2)) |
| 193 | return IntCCRegType; |
| 194 | else |
| 195 | assert(0 && "Invalid register number in getRegType"); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 200 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 201 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 202 | //--------------------------------------------------------------------------- |
Vikram S. Adve | 53fec86 | 2001-10-22 13:41:12 +0000 | [diff] [blame] | 203 | // Finds the # of actual arguments of the call instruction |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 204 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 205 | unsigned |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 206 | UltraSparcRegInfo::getCallInstNumArgs(const MachineInstr *CallMI) const { |
| 207 | |
| 208 | unsigned OpCode = CallMI->getOpCode(); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 209 | unsigned NumOfImpRefs = CallMI->getNumImplicitRefs(); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 210 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 211 | if (OpCode == CALL) { |
| 212 | switch (NumOfImpRefs) { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 213 | case 0: assert(0 && "A CALL inst must have at least one ImpRef (RetAddr)"); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 214 | case 1: return 0; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 215 | default: // two or more implicit refs |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 216 | if (CallMI->implicitRefIsDefined(NumOfImpRefs-2)) |
| 217 | return NumOfImpRefs - 2; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 218 | else |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 219 | return NumOfImpRefs - 1; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 220 | } |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 221 | } else if (OpCode == JMPLCALL) { |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 222 | |
| 223 | // The last implicit operand is the return value of a JMPL instr |
| 224 | if( NumOfImpRefs > 0 ) { |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 225 | if (CallMI->implicitRefIsDefined(NumOfImpRefs-1)) |
| 226 | return NumOfImpRefs - 1; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 227 | else |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 228 | return NumOfImpRefs; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 229 | } |
| 230 | else |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 231 | return NumOfImpRefs; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 232 | } |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 233 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 234 | assert(0 && "OpCode must be CALL/JMPL for a call instr"); |
| 235 | return 0; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
Vikram S. Adve | 53fec86 | 2001-10-22 13:41:12 +0000 | [diff] [blame] | 239 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 240 | //--------------------------------------------------------------------------- |
| 241 | // Finds whether a call is an indirect call |
| 242 | //--------------------------------------------------------------------------- |
| 243 | bool UltraSparcRegInfo::isVarArgCall(const MachineInstr *CallMI) const { |
| 244 | |
| 245 | assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) ); |
| 246 | |
| 247 | const MachineOperand & calleeOp = CallMI->getOperand(0); |
| 248 | Value *calleeVal = calleeOp.getVRegValue(); |
| 249 | |
| 250 | PointerType *PT = cast<PointerType> (calleeVal->getType()); |
| 251 | MethodType *MT = cast<MethodType>(PT->getElementType()); |
| 252 | |
| 253 | return MT->isVarArg(); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | //--------------------------------------------------------------------------- |
| 260 | // Suggests a register for the ret address in the RET machine instruction. |
| 261 | // We always suggest %i7 by convention. |
| 262 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 263 | void UltraSparcRegInfo::suggestReg4RetAddr(const MachineInstr *RetMI, |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 264 | LiveRangeInfo& LRI) const { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 265 | |
Vikram S. Adve | 53fec86 | 2001-10-22 13:41:12 +0000 | [diff] [blame] | 266 | assert( (RetMI->getNumOperands() >= 2) |
| 267 | && "JMPL/RETURN must have 3 and 2 operands respectively"); |
| 268 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 269 | MachineOperand & MO = ( MachineOperand &) RetMI->getOperand(0); |
| 270 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 271 | // return address is always mapped to i7 |
| 272 | // |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 273 | MO.setRegForValue( getUnifiedRegNum( IntRegClassID, SparcIntRegOrder::i7) ); |
Vikram S. Adve | 53fec86 | 2001-10-22 13:41:12 +0000 | [diff] [blame] | 274 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 275 | // Possible Optimization: |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 276 | // Instead of setting the color, we can suggest one. In that case, |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 277 | // we have to test later whether it received the suggested color. |
| 278 | // In that case, a LR has to be created at the start of method. |
| 279 | // It has to be done as follows (remove the setRegVal above): |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 280 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 281 | // const Value *RetAddrVal = MO.getVRegValue(); |
| 282 | // assert( RetAddrVal && "LR for ret address must be created at start"); |
| 283 | // LiveRange * RetAddrLR = LRI.getLiveRangeForValue( RetAddrVal); |
| 284 | // RetAddrLR->setSuggestedColor(getUnifiedRegNum( IntRegClassID, |
| 285 | // SparcIntRegOrdr::i7) ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
| 289 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 290 | // Suggests a register for the ret address in the JMPL/CALL machine instr. |
| 291 | // Sparc ABI dictates that %o7 be used for this purpose. |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 292 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 293 | void UltraSparcRegInfo::suggestReg4CallAddr(const MachineInstr * CallMI, |
| 294 | LiveRangeInfo& LRI, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 295 | std::vector<RegClass *> RCList) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 296 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 297 | |
| 298 | const Value *RetAddrVal = getCallInstRetAddr( CallMI ); |
| 299 | |
| 300 | // RetAddrVal cannot be NULL (asserted in getCallInstRetAddr) |
| 301 | // create a new LR for the return address and color it |
| 302 | |
| 303 | LiveRange * RetAddrLR = new LiveRange(); |
Chris Lattner | d1b60fb | 2002-02-04 16:37:09 +0000 | [diff] [blame] | 304 | RetAddrLR->insert( RetAddrVal ); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 305 | unsigned RegClassID = getRegClassIDOfValue( RetAddrVal ); |
| 306 | RetAddrLR->setRegClass( RCList[RegClassID] ); |
| 307 | RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID,SparcIntRegOrder::o7)); |
| 308 | LRI.addLRToMap( RetAddrVal, RetAddrLR); |
| 309 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 312 | |
| 313 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 314 | |
| 315 | //--------------------------------------------------------------------------- |
| 316 | // This method will suggest colors to incoming args to a method. |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 317 | // According to the Sparc ABI, the first 6 incoming args are in |
| 318 | // %i0 - %i5 (if they are integer) OR in %f0 - %f31 (if they are float). |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 319 | // If the arg is passed on stack due to the lack of regs, NOTHING will be |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 320 | // done - it will be colored (or spilled) as a normal live range. |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 321 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 322 | void UltraSparcRegInfo::suggestRegs4MethodArgs(const Method *Meth, |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 323 | LiveRangeInfo& LRI) const |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 324 | { |
| 325 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 326 | // get the argument list |
| 327 | const Method::ArgumentListType& ArgList = Meth->getArgumentList(); |
| 328 | // get an iterator to arg list |
| 329 | Method::ArgumentListType::const_iterator ArgIt = ArgList.begin(); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 330 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 331 | // for each argument |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 332 | for( unsigned argNo=0; ArgIt != ArgList.end() ; ++ArgIt, ++argNo) { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 333 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 334 | // get the LR of arg |
| 335 | LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *ArgIt); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 336 | assert( LR && "No live range found for method arg"); |
| 337 | |
| 338 | unsigned RegType = getRegType( LR ); |
| 339 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 340 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 341 | // if the arg is in int class - allocate a reg for an int arg |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 342 | // |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 343 | if( RegType == IntRegType ) { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 344 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 345 | if( argNo < NumOfIntArgRegs) { |
| 346 | LR->setSuggestedColor( SparcIntRegOrder::i0 + argNo ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 347 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 348 | else { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 349 | // Do NOTHING as this will be colored as a normal value. |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 350 | if (DEBUG_RA) cerr << " Int Regr not suggested for method arg\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 351 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 352 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 353 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 354 | else if( RegType==FPSingleRegType && (argNo*2+1) < NumOfFloatArgRegs) |
| 355 | LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) ); |
| 356 | |
| 357 | |
| 358 | else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs) |
| 359 | LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) ); |
| 360 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 361 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 364 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 365 | |
| 366 | //--------------------------------------------------------------------------- |
| 367 | // This method is called after graph coloring to move incoming args to |
| 368 | // the correct hardware registers if they did not receive the correct |
| 369 | // (suggested) color through graph coloring. |
| 370 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 371 | void UltraSparcRegInfo::colorMethodArgs(const Method *Meth, |
| 372 | LiveRangeInfo &LRI, |
| 373 | AddedInstrns *FirstAI) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 374 | |
| 375 | // get the argument list |
| 376 | const Method::ArgumentListType& ArgList = Meth->getArgumentList(); |
| 377 | // get an iterator to arg list |
| 378 | Method::ArgumentListType::const_iterator ArgIt = ArgList.begin(); |
| 379 | |
| 380 | MachineInstr *AdMI; |
| 381 | |
| 382 | |
| 383 | // for each argument |
| 384 | for( unsigned argNo=0; ArgIt != ArgList.end() ; ++ArgIt, ++argNo) { |
| 385 | |
| 386 | // get the LR of arg |
| 387 | LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *ArgIt); |
| 388 | assert( LR && "No live range found for method arg"); |
| 389 | |
| 390 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 391 | unsigned RegType = getRegType( LR ); |
| 392 | unsigned RegClassID = (LR->getRegClass())->getID(); |
| 393 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 394 | // Find whether this argument is coming in a register (if not, on stack) |
| 395 | // Also find the correct register that the argument must go (UniArgReg) |
| 396 | // |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 397 | bool isArgInReg = false; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 398 | unsigned UniArgReg = InvalidRegNum; // reg that LR MUST be colored with |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 399 | |
| 400 | if( (RegType== IntRegType && argNo < NumOfIntArgRegs)) { |
| 401 | isArgInReg = true; |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 402 | UniArgReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::i0 + argNo ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 403 | } |
| 404 | else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs) { |
| 405 | isArgInReg = true; |
| 406 | UniArgReg = getUnifiedRegNum( RegClassID, |
| 407 | SparcFloatRegOrder::f0 + argNo*2 + 1 ) ; |
| 408 | } |
| 409 | else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs) { |
| 410 | isArgInReg = true; |
| 411 | UniArgReg = getUnifiedRegNum(RegClassID, SparcFloatRegOrder::f0+argNo*2); |
| 412 | } |
| 413 | |
| 414 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 415 | if( LR->hasColor() ) { // if this arg received a register |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 416 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 417 | unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() ); |
| 418 | |
| 419 | // if LR received the correct color, nothing to do |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 420 | // |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 421 | if( UniLRReg == UniArgReg ) |
| 422 | continue; |
| 423 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 424 | // We are here because the LR did not receive the suggested |
| 425 | // but LR received another register. |
| 426 | // Now we have to copy the %i reg (or stack pos of arg) |
| 427 | // to the register the LR was colored with. |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 428 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 429 | // if the arg is coming in UniArgReg register, it MUST go into |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 430 | // the UniLRReg register |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 431 | // |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 432 | if( isArgInReg ) |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 433 | AdMI = cpReg2RegMI( UniArgReg, UniLRReg, RegType ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 434 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 435 | else { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 436 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 437 | // Now the arg is coming on stack. Since the LR recieved a register, |
| 438 | // we just have to load the arg on stack into that register |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 439 | // |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 440 | const MachineFrameInfo& frameInfo = target.getFrameInfo(); |
| 441 | assert(frameInfo.argsOnStackHaveFixedSize()); |
| 442 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 443 | bool growUp; // find the offset of arg in stack frame |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 444 | int firstArg = |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 445 | frameInfo.getFirstIncomingArgOffset(MachineCodeForMethod::get(Meth), |
| 446 | growUp); |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 447 | int offsetFromFP = |
| 448 | growUp? firstArg + argNo * frameInfo.getSizeOfEachArgOnStack() |
| 449 | : firstArg - argNo * frameInfo.getSizeOfEachArgOnStack(); |
| 450 | |
| 451 | AdMI = cpMem2RegMI(getFramePointer(), offsetFromFP, |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 452 | UniLRReg, RegType ); |
| 453 | } |
| 454 | |
| 455 | FirstAI->InstrnsBefore.push_back( AdMI ); |
| 456 | |
| 457 | } // if LR received a color |
| 458 | |
| 459 | else { |
| 460 | |
| 461 | // Now, the LR did not receive a color. But it has a stack offset for |
| 462 | // spilling. |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 463 | // So, if the arg is coming in UniArgReg register, we can just move |
| 464 | // that on to the stack pos of LR |
| 465 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 466 | if( isArgInReg ) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 467 | cpReg2MemMI(UniArgReg, getFramePointer(), |
| 468 | LR->getSpillOffFromFP(), RegType ); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 469 | |
| 470 | FirstAI->InstrnsBefore.push_back( AdMI ); |
| 471 | } |
| 472 | |
| 473 | else { |
| 474 | |
| 475 | // Now the arg is coming on stack. Since the LR did NOT |
| 476 | // recieved a register as well, it is allocated a stack position. We |
| 477 | // can simply change the stack poistion of the LR. We can do this, |
| 478 | // since this method is called before any other method that makes |
| 479 | // uses of the stack pos of the LR (e.g., updateMachineInstr) |
| 480 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 481 | const MachineFrameInfo& frameInfo = target.getFrameInfo(); |
| 482 | assert(frameInfo.argsOnStackHaveFixedSize()); |
| 483 | |
| 484 | bool growUp; |
| 485 | int firstArg = frameInfo.getFirstIncomingArgOffset(MachineCodeForMethod::get(Meth), growUp); |
| 486 | int offsetFromFP = |
| 487 | growUp? firstArg + argNo * frameInfo.getSizeOfEachArgOnStack() |
| 488 | : firstArg - argNo * frameInfo.getSizeOfEachArgOnStack(); |
| 489 | |
| 490 | LR->modifySpillOffFromFP( offsetFromFP ); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 491 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 492 | |
| 493 | } |
| 494 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 495 | } // for each incoming argument |
| 496 | |
| 497 | } |
| 498 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 499 | |
| 500 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 501 | //--------------------------------------------------------------------------- |
| 502 | // This method is called before graph coloring to suggest colors to the |
| 503 | // outgoing call args and the return value of the call. |
| 504 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 505 | void UltraSparcRegInfo::suggestRegs4CallArgs(const MachineInstr *CallMI, |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 506 | LiveRangeInfo& LRI, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 507 | std::vector<RegClass *> RCList) const { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 508 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 509 | assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) ); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 510 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 511 | suggestReg4CallAddr(CallMI, LRI, RCList); |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 512 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 513 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 514 | // First color the return value of the call instruction. The return value |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 515 | // will be in %o0 if the value is an integer type, or in %f0 if the |
| 516 | // value is a float type. |
| 517 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 518 | // the return value cannot have a LR in machine instruction since it is |
| 519 | // only defined by the call instruction |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 520 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 521 | // if type is not void, create a new live range and set its |
| 522 | // register class and add to LRI |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 523 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 524 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 525 | const Value *RetVal = getCallInstRetVal( CallMI ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 526 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 527 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 528 | if (RetVal) { |
| 529 | assert ((!LRI.getLiveRangeForValue(RetVal)) && |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 530 | "LR for ret Value of call already definded!"); |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 531 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 532 | // create a new LR for the return value |
| 533 | LiveRange *RetValLR = new LiveRange(); |
Chris Lattner | d1b60fb | 2002-02-04 16:37:09 +0000 | [diff] [blame] | 534 | RetValLR->insert(RetVal); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 535 | unsigned RegClassID = getRegClassIDOfValue(RetVal); |
| 536 | RetValLR->setRegClass(RCList[RegClassID]); |
| 537 | LRI.addLRToMap(RetVal, RetValLR); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 538 | |
| 539 | // now suggest a register depending on the register class of ret arg |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 540 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 541 | if( RegClassID == IntRegClassID ) |
| 542 | RetValLR->setSuggestedColor(SparcIntRegOrder::o0); |
| 543 | else if (RegClassID == FloatRegClassID ) |
| 544 | RetValLR->setSuggestedColor(SparcFloatRegOrder::f0 ); |
| 545 | else assert( 0 && "Unknown reg class for return value of call\n"); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 546 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 547 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 548 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 549 | // Now suggest colors for arguments (operands) of the call instruction. |
| 550 | // Colors are suggested only if the arg number is smaller than the |
| 551 | // the number of registers allocated for argument passing. |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 552 | // Now, go thru call args - implicit operands of the call MI |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 553 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 554 | unsigned NumOfCallArgs = getCallInstNumArgs( CallMI ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 555 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 556 | for(unsigned argNo=0, i=0; i < NumOfCallArgs; ++i, ++argNo ) { |
| 557 | |
| 558 | const Value *CallArg = CallMI->getImplicitRef(i); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 559 | |
| 560 | // get the LR of call operand (parameter) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 561 | LiveRange *const LR = LRI.getLiveRangeForValue(CallArg); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 562 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 563 | // not possible to have a null LR since all args (even consts) |
| 564 | // must be defined before |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 565 | if (!LR) { |
| 566 | cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) << "\n"; |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 567 | assert(0 && "NO LR for call arg"); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | unsigned RegType = getRegType( LR ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 571 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 572 | // if the arg is in int class - allocate a reg for an int arg |
| 573 | if( RegType == IntRegType ) { |
| 574 | |
| 575 | if( argNo < NumOfIntArgRegs) |
| 576 | LR->setSuggestedColor( SparcIntRegOrder::o0 + argNo ); |
| 577 | |
| 578 | else if (DEBUG_RA) |
| 579 | // Do NOTHING as this will be colored as a normal value. |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 580 | cerr << " Regr not suggested for int call arg\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 581 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 582 | } |
| 583 | else if( RegType == FPSingleRegType && (argNo*2 +1)< NumOfFloatArgRegs) |
| 584 | LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) ); |
| 585 | |
| 586 | |
| 587 | else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs) |
| 588 | LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) ); |
| 589 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 590 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 591 | } // for all call arguments |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 592 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 596 | //--------------------------------------------------------------------------- |
| 597 | // After graph coloring, we have call this method to see whehter the return |
| 598 | // value and the call args received the correct colors. If not, we have |
| 599 | // to instert copy instructions. |
| 600 | //--------------------------------------------------------------------------- |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 601 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 602 | void UltraSparcRegInfo::colorCallArgs(const MachineInstr *CallMI, |
| 603 | LiveRangeInfo &LRI, |
| 604 | AddedInstrns *CallAI, |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 605 | PhyRegAlloc &PRA, |
| 606 | const BasicBlock *BB) const { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 607 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 608 | assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) ); |
| 609 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 610 | // Reset the optional args area in the stack frame |
| 611 | // since that is reused for each call |
| 612 | // |
| 613 | PRA.mcInfo.resetOptionalArgs(target); |
| 614 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 615 | // First color the return value of the call. |
| 616 | // If there is a LR for the return value, it means this |
| 617 | // method returns a value |
| 618 | |
| 619 | MachineInstr *AdMI; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 620 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 621 | const Value *RetVal = getCallInstRetVal( CallMI ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 622 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 623 | if (RetVal) { |
| 624 | LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 625 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 626 | if (!RetValLR) { |
| 627 | cerr << "\nNo LR for:" << RAV(RetVal) << "\n"; |
| 628 | assert(0 && "ERR:No LR for non-void return value"); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 629 | } |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 630 | |
| 631 | unsigned RegClassID = (RetValLR->getRegClass())->getID(); |
| 632 | bool recvCorrectColor = false; |
| 633 | |
| 634 | unsigned CorrectCol; // correct color for ret value |
| 635 | if(RegClassID == IntRegClassID) |
| 636 | CorrectCol = SparcIntRegOrder::o0; |
| 637 | else if(RegClassID == FloatRegClassID) |
| 638 | CorrectCol = SparcFloatRegOrder::f0; |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 639 | else { |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 640 | assert( 0 && "Unknown RegClass"); |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 641 | return; |
| 642 | } |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 643 | |
| 644 | // if the LR received the correct color, NOTHING to do |
| 645 | |
| 646 | if( RetValLR->hasColor() ) |
| 647 | if( RetValLR->getColor() == CorrectCol ) |
| 648 | recvCorrectColor = true; |
| 649 | |
| 650 | |
| 651 | // if we didn't receive the correct color for some reason, |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 652 | // put copy instruction |
| 653 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 654 | if( !recvCorrectColor ) { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 655 | |
| 656 | unsigned RegType = getRegType( RetValLR ); |
| 657 | |
| 658 | // the reg that LR must be colored with |
| 659 | unsigned UniRetReg = getUnifiedRegNum( RegClassID, CorrectCol); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 660 | |
| 661 | if( RetValLR->hasColor() ) { |
| 662 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 663 | unsigned |
| 664 | UniRetLRReg=getUnifiedRegNum(RegClassID,RetValLR->getColor()); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 665 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 666 | // the return value is coming in UniRetReg but has to go into |
| 667 | // the UniRetLRReg |
| 668 | |
| 669 | AdMI = cpReg2RegMI( UniRetReg, UniRetLRReg, RegType ); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 670 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 671 | } // if LR has color |
| 672 | else { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 673 | |
| 674 | // if the LR did NOT receive a color, we have to move the return |
| 675 | // value coming in UniRetReg to the stack pos of spilled LR |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 676 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 677 | AdMI = cpReg2MemMI(UniRetReg, getFramePointer(), |
| 678 | RetValLR->getSpillOffFromFP(), RegType ); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 679 | } |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 680 | |
| 681 | CallAI->InstrnsAfter.push_back( AdMI ); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 682 | |
| 683 | } // the LR didn't receive the suggested color |
| 684 | |
| 685 | } // if there a return value |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 686 | |
| 687 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 688 | //------------------------------------------- |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 689 | // Now color all args of the call instruction |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 690 | //------------------------------------------- |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 691 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 692 | std::vector<MachineInstr *> AddedInstrnsBefore; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 693 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 694 | unsigned NumOfCallArgs = getCallInstNumArgs( CallMI ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 695 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 696 | bool VarArgCall = isVarArgCall( CallMI ); |
| 697 | |
| 698 | if(VarArgCall) cerr << "\nVar arg call found!!\n"; |
| 699 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 700 | for(unsigned argNo=0, i=0; i < NumOfCallArgs; ++i, ++argNo ) { |
| 701 | |
| 702 | const Value *CallArg = CallMI->getImplicitRef(i); |
| 703 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 704 | // get the LR of call operand (parameter) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 705 | LiveRange *const LR = LRI.getLiveRangeForValue(CallArg); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 706 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 707 | unsigned RegType = getRegType( CallArg ); |
| 708 | unsigned RegClassID = getRegClassIDOfValue( CallArg); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 709 | |
| 710 | // find whether this argument is coming in a register (if not, on stack) |
| 711 | |
| 712 | bool isArgInReg = false; |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 713 | unsigned UniArgReg = InvalidRegNum; // reg that LR must be colored with |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 714 | |
| 715 | if( (RegType== IntRegType && argNo < NumOfIntArgRegs)) { |
| 716 | isArgInReg = true; |
| 717 | UniArgReg = getUnifiedRegNum(RegClassID, SparcIntRegOrder::o0 + argNo ); |
| 718 | } |
| 719 | else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs) { |
| 720 | isArgInReg = true; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 721 | |
| 722 | if( !VarArgCall ) |
| 723 | UniArgReg = getUnifiedRegNum(RegClassID, |
| 724 | SparcFloatRegOrder::f0 + (argNo*2 + 1) ); |
| 725 | else { |
| 726 | // a variable argument call - must pass float arg in %o's |
| 727 | if( argNo < NumOfIntArgRegs) |
| 728 | UniArgReg=getUnifiedRegNum(IntRegClassID,SparcIntRegOrder::o0+argNo); |
| 729 | else |
| 730 | isArgInReg = false; |
| 731 | } |
| 732 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 733 | } |
| 734 | else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs) { |
| 735 | isArgInReg = true; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 736 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 737 | if( !VarArgCall ) |
| 738 | UniArgReg =getUnifiedRegNum(RegClassID,SparcFloatRegOrder::f0+argNo*2); |
| 739 | else { |
| 740 | // a variable argument call - must pass float arg in %o's |
| 741 | if( argNo < NumOfIntArgRegs) |
| 742 | UniArgReg=getUnifiedRegNum(IntRegClassID,SparcIntRegOrder::o0+argNo); |
| 743 | else |
| 744 | isArgInReg = false; |
| 745 | } |
| 746 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 747 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 748 | // not possible to have a null LR since all args (even consts) |
| 749 | // must be defined before |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 750 | if (!LR) { |
| 751 | cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) << "\n"; |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 752 | assert(0 && "NO LR for call arg"); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 753 | } |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 754 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 755 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 756 | if (LR->hasColor()) { |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 757 | unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() ); |
| 758 | |
| 759 | // if LR received the correct color, nothing to do |
| 760 | if( UniLRReg == UniArgReg ) |
| 761 | continue; |
| 762 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 763 | // We are here because though the LR is allocated a register, it |
| 764 | // was not allocated the suggested register. So, we have to copy %ix reg |
| 765 | // (or stack pos of arg) to the register it was colored with |
| 766 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 767 | // the LR is colored with UniLRReg but has to go into UniArgReg |
| 768 | // to pass it as an argument |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 769 | |
Ruchira Sasanka | 9d47866 | 2001-11-12 20:54:19 +0000 | [diff] [blame] | 770 | if( isArgInReg ) { |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 771 | |
| 772 | if( VarArgCall && RegClassID == FloatRegClassID ) { |
| 773 | |
| 774 | |
| 775 | // for a variable argument call, the float reg must go in a %o reg. |
| 776 | // We have to move a float reg to an int reg via memory. |
| 777 | // The store instruction will be directly added to |
| 778 | // CallAI->InstrnsBefore since it does not need reordering |
| 779 | // |
| 780 | int TmpOff = PRA.mcInfo.pushTempValue(target, |
| 781 | getSpilledRegSize(RegType)); |
| 782 | |
| 783 | AdMI = cpReg2MemMI(UniLRReg, getFramePointer(), TmpOff, RegType ); |
| 784 | CallAI->InstrnsBefore.push_back( AdMI ); |
| 785 | |
| 786 | AdMI = cpMem2RegMI(getFramePointer(), TmpOff, UniArgReg, IntRegType); |
| 787 | AddedInstrnsBefore.push_back( AdMI ); |
| 788 | } |
| 789 | |
| 790 | else { |
| 791 | AdMI = cpReg2RegMI(UniLRReg, UniArgReg, RegType ); |
| 792 | AddedInstrnsBefore.push_back( AdMI ); |
| 793 | } |
| 794 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 795 | } else { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 796 | // Now, we have to pass the arg on stack. Since LR received a register |
| 797 | // we just have to move that register to the stack position where |
| 798 | // the argument must be passed |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 799 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 800 | int argOffset = PRA.mcInfo.allocateOptionalArg(target, LR->getType()); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 801 | |
Ruchira Sasanka | c56e5c1 | 2001-11-11 22:37:51 +0000 | [diff] [blame] | 802 | AdMI = cpReg2MemMI(UniLRReg, getStackPointer(), argOffset, RegType ); |
Ruchira Sasanka | 9d47866 | 2001-11-12 20:54:19 +0000 | [diff] [blame] | 803 | |
| 804 | // Now add the instruction. We can directly add to |
| 805 | // CallAI->InstrnsBefore since we are just saving a reg on stack |
| 806 | // |
| 807 | CallAI->InstrnsBefore.push_back( AdMI ); |
| 808 | |
| 809 | //cerr << "\nCaution: Passing a reg on stack"; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Ruchira Sasanka | 9d47866 | 2001-11-12 20:54:19 +0000 | [diff] [blame] | 812 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 813 | } else { // LR is not colored (i.e., spilled) |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 814 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 815 | if( isArgInReg ) { |
| 816 | |
| 817 | // Now the LR did NOT recieve a register but has a stack poistion. |
| 818 | // Since, the outgoing arg goes in a register we just have to insert |
| 819 | // a load instruction to load the LR to outgoing register |
| 820 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 821 | if( VarArgCall && RegClassID == FloatRegClassID ) |
| 822 | AdMI = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), |
| 823 | UniArgReg, IntRegType ); |
| 824 | else |
| 825 | AdMI = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), |
| 826 | UniArgReg, RegType ); |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 827 | |
Ruchira Sasanka | 91014f6 | 2001-11-12 20:31:47 +0000 | [diff] [blame] | 828 | cerr << "\nCaution: Loading a spilled val to a reg as a call arg"; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 829 | AddedInstrnsBefore.push_back( AdMI ); // Now add the instruction |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 830 | } |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 831 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 832 | else { |
| 833 | // Now, we have to pass the arg on stack. Since LR also did NOT |
| 834 | // receive a register we have to move an argument in memory to |
| 835 | // outgoing parameter on stack. |
| 836 | |
| 837 | // Optoimize: Optimize when reverse pointers in MahineInstr are |
| 838 | // introduced. |
| 839 | // call PRA.getUnusedRegAtMI(....) to get an unused reg. Only if this |
| 840 | // fails, then use the following code. Currently, we cannot call the |
| 841 | // above method since we cannot find LVSetBefore without the BB |
| 842 | |
Ruchira Sasanka | 295264d | 2001-11-15 20:25:07 +0000 | [diff] [blame] | 843 | int TReg = PRA.getUniRegNotUsedByThisInst( LR->getRegClass(), CallMI ); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 844 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 845 | int TmpOff = PRA.mcInfo.pushTempValue(target, |
| 846 | getSpilledRegSize(getRegType(LR)) ); |
| 847 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 848 | |
| 849 | int argOffset = PRA.mcInfo.allocateOptionalArg(target, LR->getType()); |
| 850 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 851 | MachineInstr *Ad1, *Ad2, *Ad3, *Ad4; |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 852 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 853 | // Sequence: |
| 854 | // (1) Save TReg on stack |
| 855 | // (2) Load LR value into TReg from stack pos of LR |
| 856 | // (3) Store Treg on outgoing Arg pos on stack |
| 857 | // (4) Load the old value of TReg from stack to TReg (restore it) |
| 858 | |
| 859 | Ad1 = cpReg2MemMI(TReg, getFramePointer(), TmpOff, RegType ); |
| 860 | Ad2 = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), |
| 861 | TReg, RegType ); |
Ruchira Sasanka | c56e5c1 | 2001-11-11 22:37:51 +0000 | [diff] [blame] | 862 | Ad3 = cpReg2MemMI(TReg, getStackPointer(), argOffset, RegType ); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 863 | Ad4 = cpMem2RegMI(getFramePointer(), TmpOff, TReg, RegType ); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 864 | |
| 865 | // We directly add to CallAI->InstrnsBefore instead of adding to |
| 866 | // AddedInstrnsBefore since these instructions must not be |
| 867 | // reordered. |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 868 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 869 | CallAI->InstrnsBefore.push_back( Ad1 ); |
| 870 | CallAI->InstrnsBefore.push_back( Ad2 ); |
| 871 | CallAI->InstrnsBefore.push_back( Ad3 ); |
| 872 | CallAI->InstrnsBefore.push_back( Ad4 ); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 873 | |
Ruchira Sasanka | 91014f6 | 2001-11-12 20:31:47 +0000 | [diff] [blame] | 874 | cerr << "\nCaution: Call arg moved from stack2stack for: " << *CallMI ; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 875 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 876 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 877 | } // for each parameter in call instruction |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 878 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 879 | |
| 880 | // if we added any instruction before the call instruction, verify |
| 881 | // that they are in the proper order and if not, reorder them |
| 882 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 883 | if (!AddedInstrnsBefore.empty()) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 884 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 885 | if (DEBUG_RA) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 886 | cerr << "\nCalling reorder with instrns: \n"; |
| 887 | for(unsigned i=0; i < AddedInstrnsBefore.size(); i++) |
| 888 | cerr << *(AddedInstrnsBefore[i]); |
| 889 | } |
| 890 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 891 | std::vector<MachineInstr *> TmpVec; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 892 | OrderAddedInstrns(AddedInstrnsBefore, TmpVec, PRA); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 893 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 894 | if (DEBUG_RA) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 895 | cerr << "\nAfter reordering instrns: \n"; |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 896 | for(unsigned i = 0; i < TmpVec.size(); i++) |
| 897 | cerr << *TmpVec[i]; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | // copy the results back from TmpVec to InstrnsBefore |
| 901 | for(unsigned i=0; i < TmpVec.size(); i++) |
| 902 | CallAI->InstrnsBefore.push_back( TmpVec[i] ); |
| 903 | } |
| 904 | |
| 905 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 906 | // now insert caller saving code for this call instruction |
| 907 | // |
| 908 | insertCallerSavingCode(CallMI, BB, PRA); |
| 909 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 910 | // Reset optional args area again to be safe |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 911 | PRA.mcInfo.resetOptionalArgs(target); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 914 | //--------------------------------------------------------------------------- |
| 915 | // This method is called for an LLVM return instruction to identify which |
| 916 | // values will be returned from this method and to suggest colors. |
| 917 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 918 | void UltraSparcRegInfo::suggestReg4RetValue(const MachineInstr *RetMI, |
| 919 | LiveRangeInfo &LRI) const { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 920 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 921 | assert( (UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode() ) ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 922 | |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 923 | suggestReg4RetAddr(RetMI, LRI); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 924 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 925 | // if there is an implicit ref, that has to be the ret value |
| 926 | if( RetMI->getNumImplicitRefs() > 0 ) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 927 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 928 | // The first implicit operand is the return value of a return instr |
| 929 | const Value *RetVal = RetMI->getImplicitRef(0); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 930 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 931 | LiveRange *const LR = LRI.getLiveRangeForValue( RetVal ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 932 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 933 | if (!LR) { |
| 934 | cerr << "\nNo LR for:" << RAV(RetVal) << "\n"; |
| 935 | assert(0 && "No LR for return value of non-void method"); |
| 936 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 937 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 938 | unsigned RegClassID = (LR->getRegClass())->getID(); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 939 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 940 | if (RegClassID == IntRegClassID) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 941 | LR->setSuggestedColor(SparcIntRegOrder::i0); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 942 | else if (RegClassID == FloatRegClassID) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 943 | LR->setSuggestedColor(SparcFloatRegOrder::f0); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 944 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 947 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 948 | |
| 949 | //--------------------------------------------------------------------------- |
| 950 | // Colors the return value of a method to %i0 or %f0, if possible. If it is |
| 951 | // not possilbe to directly color the LR, insert a copy instruction to move |
| 952 | // the LR to %i0 or %f0. When the LR is spilled, instead of the copy, we |
| 953 | // have to put a load instruction. |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 954 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 955 | void UltraSparcRegInfo::colorRetValue(const MachineInstr *RetMI, |
| 956 | LiveRangeInfo &LRI, |
| 957 | AddedInstrns *RetAI) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 958 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 959 | assert((UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode())); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 960 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 961 | // if there is an implicit ref, that has to be the ret value |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 962 | if(RetMI->getNumImplicitRefs() > 0) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 963 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 964 | // The first implicit operand is the return value of a return instr |
| 965 | const Value *RetVal = RetMI->getImplicitRef(0); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 966 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 967 | LiveRange *LR = LRI.getLiveRangeForValue(RetVal); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 968 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame] | 969 | if (!LR) { |
| 970 | cerr << "\nNo LR for:" << RAV(RetVal) << "\n"; |
| 971 | // assert( LR && "No LR for return value of non-void method"); |
| 972 | return; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 973 | } |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 974 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 975 | unsigned RegClassID = getRegClassIDOfValue(RetVal); |
| 976 | unsigned RegType = getRegType( RetVal ); |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 977 | |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 978 | unsigned CorrectCol; |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 979 | if(RegClassID == IntRegClassID) |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 980 | CorrectCol = SparcIntRegOrder::i0; |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 981 | else if(RegClassID == FloatRegClassID) |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 982 | CorrectCol = SparcFloatRegOrder::f0; |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 983 | else { |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 984 | assert (0 && "Unknown RegClass"); |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 985 | return; |
| 986 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 987 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 988 | // if the LR received the correct color, NOTHING to do |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 989 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 990 | if (LR->hasColor() && LR->getColor() == CorrectCol) |
| 991 | return; |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 992 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 993 | unsigned UniRetReg = getUnifiedRegNum(RegClassID, CorrectCol); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 994 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 995 | if (LR->hasColor()) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 996 | |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 997 | // We are here because the LR was allocted a regiter |
| 998 | // It may be the suggested register or not |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 999 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 1000 | // copy the LR of retun value to i0 or f0 |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1001 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 1002 | unsigned UniLRReg =getUnifiedRegNum( RegClassID, LR->getColor()); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1003 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 1004 | // the LR received UniLRReg but must be colored with UniRetReg |
| 1005 | // to pass as the return value |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1006 | RetAI->InstrnsBefore.push_back(cpReg2RegMI(UniLRReg, UniRetReg, RegType)); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1007 | } |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1008 | else { // if the LR is spilled |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1009 | MachineInstr *AdMI = cpMem2RegMI(getFramePointer(), |
| 1010 | LR->getSpillOffFromFP(), |
| 1011 | UniRetReg, RegType); |
| 1012 | RetAI->InstrnsBefore.push_back(AdMI); |
| 1013 | cerr << "\nCopied the return value from stack\n"; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1016 | } // if there is a return value |
| 1017 | |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | //--------------------------------------------------------------------------- |
| 1022 | // Copy from a register to register. Register number must be the unified |
| 1023 | // register number |
| 1024 | //--------------------------------------------------------------------------- |
| 1025 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1026 | MachineInstr * UltraSparcRegInfo::cpReg2RegMI(unsigned SrcReg, unsigned DestReg, |
| 1027 | int RegType) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1028 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1029 | assert( ((int)SrcReg != InvalidRegNum) && ((int)DestReg != InvalidRegNum) && |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1030 | "Invalid Register"); |
| 1031 | |
| 1032 | MachineInstr * MI = NULL; |
| 1033 | |
| 1034 | switch( RegType ) { |
| 1035 | |
| 1036 | case IntRegType: |
Ruchira Sasanka | 735d6e3 | 2001-10-18 22:38:52 +0000 | [diff] [blame] | 1037 | case IntCCRegType: |
| 1038 | case FloatCCRegType: |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1039 | MI = new MachineInstr(ADD, 3); |
| 1040 | MI->SetMachineOperand(0, SrcReg, false); |
| 1041 | MI->SetMachineOperand(1, SparcIntRegOrder::g0, false); |
| 1042 | MI->SetMachineOperand(2, DestReg, true); |
| 1043 | break; |
| 1044 | |
| 1045 | case FPSingleRegType: |
| 1046 | MI = new MachineInstr(FMOVS, 2); |
| 1047 | MI->SetMachineOperand(0, SrcReg, false); |
| 1048 | MI->SetMachineOperand(1, DestReg, true); |
| 1049 | break; |
| 1050 | |
| 1051 | case FPDoubleRegType: |
| 1052 | MI = new MachineInstr(FMOVD, 2); |
| 1053 | MI->SetMachineOperand(0, SrcReg, false); |
| 1054 | MI->SetMachineOperand(1, DestReg, true); |
| 1055 | break; |
| 1056 | |
| 1057 | default: |
| 1058 | assert(0 && "Unknow RegType"); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | return MI; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1062 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1063 | |
| 1064 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1065 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1066 | // Copy from a register to memory (i.e., Store). Register number must |
| 1067 | // be the unified register number |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1068 | //--------------------------------------------------------------------------- |
| 1069 | |
| 1070 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1071 | MachineInstr * UltraSparcRegInfo::cpReg2MemMI(unsigned SrcReg, |
| 1072 | unsigned DestPtrReg, |
| 1073 | int Offset, int RegType) const { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1074 | MachineInstr * MI = NULL; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1075 | switch( RegType ) { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1076 | case IntRegType: |
Ruchira Sasanka | 735d6e3 | 2001-10-18 22:38:52 +0000 | [diff] [blame] | 1077 | case FloatCCRegType: |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1078 | MI = new MachineInstr(STX, 3); |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1079 | MI->SetMachineOperand(0, SrcReg, false); |
| 1080 | MI->SetMachineOperand(1, DestPtrReg, false); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1081 | MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed, |
| 1082 | (int64_t) Offset, false); |
| 1083 | break; |
| 1084 | |
| 1085 | case FPSingleRegType: |
| 1086 | MI = new MachineInstr(ST, 3); |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1087 | MI->SetMachineOperand(0, SrcReg, false); |
| 1088 | MI->SetMachineOperand(1, DestPtrReg, false); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1089 | MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed, |
| 1090 | (int64_t) Offset, false); |
| 1091 | break; |
| 1092 | |
| 1093 | case FPDoubleRegType: |
| 1094 | MI = new MachineInstr(STD, 3); |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1095 | MI->SetMachineOperand(0, SrcReg, false); |
| 1096 | MI->SetMachineOperand(1, DestPtrReg, false); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1097 | MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed, |
| 1098 | (int64_t) Offset, false); |
| 1099 | break; |
| 1100 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1101 | case IntCCRegType: |
| 1102 | assert( 0 && "Cannot directly store %ccr to memory"); |
| 1103 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1104 | default: |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1105 | assert(0 && "Unknow RegType in cpReg2MemMI"); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | return MI; |
| 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1113 | // Copy from memory to a reg (i.e., Load) Register number must be the unified |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1114 | // register number |
| 1115 | //--------------------------------------------------------------------------- |
| 1116 | |
| 1117 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1118 | MachineInstr * UltraSparcRegInfo::cpMem2RegMI(unsigned SrcPtrReg, |
| 1119 | int Offset, |
| 1120 | unsigned DestReg, |
| 1121 | int RegType) const { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1122 | MachineInstr * MI = NULL; |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1123 | switch (RegType) { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1124 | case IntRegType: |
Ruchira Sasanka | 735d6e3 | 2001-10-18 22:38:52 +0000 | [diff] [blame] | 1125 | case FloatCCRegType: |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1126 | MI = new MachineInstr(LDX, 3); |
| 1127 | MI->SetMachineOperand(0, SrcPtrReg, false); |
| 1128 | MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed, |
| 1129 | (int64_t) Offset, false); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1130 | MI->SetMachineOperand(2, DestReg, true); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1131 | break; |
| 1132 | |
| 1133 | case FPSingleRegType: |
| 1134 | MI = new MachineInstr(LD, 3); |
| 1135 | MI->SetMachineOperand(0, SrcPtrReg, false); |
| 1136 | MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed, |
| 1137 | (int64_t) Offset, false); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1138 | MI->SetMachineOperand(2, DestReg, true); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1139 | |
| 1140 | break; |
| 1141 | |
| 1142 | case FPDoubleRegType: |
| 1143 | MI = new MachineInstr(LDD, 3); |
| 1144 | MI->SetMachineOperand(0, SrcPtrReg, false); |
| 1145 | MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed, |
| 1146 | (int64_t) Offset, false); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1147 | MI->SetMachineOperand(2, DestReg, true); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1148 | break; |
| 1149 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1150 | case IntCCRegType: |
| 1151 | assert( 0 && "Cannot directly load into %ccr from memory"); |
| 1152 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1153 | default: |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1154 | assert(0 && "Unknown RegType in cpMem2RegMI"); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | return MI; |
| 1158 | } |
| 1159 | |
| 1160 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1161 | |
| 1162 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1163 | |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1164 | //--------------------------------------------------------------------------- |
| 1165 | // Generate a copy instruction to copy a value to another. Temporarily |
| 1166 | // used by PhiElimination code. |
| 1167 | //--------------------------------------------------------------------------- |
| 1168 | |
| 1169 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1170 | MachineInstr *UltraSparcRegInfo::cpValue2Value(Value *Src, Value *Dest) const { |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1171 | int RegType = getRegType( Src ); |
| 1172 | |
| 1173 | assert( (RegType==getRegType(Src)) && "Src & Dest are diff types"); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1174 | |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1175 | MachineInstr * MI = NULL; |
| 1176 | |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1177 | switch( RegType ) { |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1178 | case IntRegType: |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1179 | MI = new MachineInstr(ADD, 3); |
| 1180 | MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false); |
| 1181 | MI->SetMachineOperand(1, SparcIntRegOrder::g0, false); |
| 1182 | MI->SetMachineOperand(2, MachineOperand:: MO_VirtualRegister, Dest, true); |
| 1183 | break; |
| 1184 | |
| 1185 | case FPSingleRegType: |
| 1186 | MI = new MachineInstr(FMOVS, 2); |
| 1187 | MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false); |
| 1188 | MI->SetMachineOperand(1, MachineOperand:: MO_VirtualRegister, Dest, true); |
| 1189 | break; |
| 1190 | |
| 1191 | |
| 1192 | case FPDoubleRegType: |
| 1193 | MI = new MachineInstr(FMOVD, 2); |
| 1194 | MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false); |
| 1195 | MI->SetMachineOperand(1, MachineOperand:: MO_VirtualRegister, Dest, true); |
| 1196 | break; |
| 1197 | |
| 1198 | default: |
| 1199 | assert(0 && "Unknow RegType in CpValu2Value"); |
| 1200 | } |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1201 | |
| 1202 | return MI; |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1203 | } |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1204 | |
| 1205 | |
| 1206 | |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1207 | |
| 1208 | |
| 1209 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1210 | //---------------------------------------------------------------------------- |
| 1211 | // This method inserts caller saving/restoring instructons before/after |
Ruchira Sasanka | bf91552 | 2002-01-07 21:03:42 +0000 | [diff] [blame] | 1212 | // a call machine instruction. The caller saving/restoring instructions are |
| 1213 | // inserted like: |
| 1214 | // |
| 1215 | // ** caller saving instructions |
| 1216 | // other instructions inserted for the call by ColorCallArg |
| 1217 | // CALL instruction |
| 1218 | // other instructions inserted for the call ColorCallArg |
| 1219 | // ** caller restoring instructions |
| 1220 | // |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1221 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1222 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1223 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1224 | void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, |
| 1225 | const BasicBlock *BB, |
| 1226 | PhyRegAlloc &PRA) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1227 | |
Ruchira Sasanka | bf91552 | 2002-01-07 21:03:42 +0000 | [diff] [blame] | 1228 | // has set to record which registers were saved/restored |
| 1229 | // |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1230 | std::hash_set<unsigned> PushedRegSet; |
Ruchira Sasanka | bf91552 | 2002-01-07 21:03:42 +0000 | [diff] [blame] | 1231 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1232 | // Now find the LR of the return value of the call |
| 1233 | // The last *implicit operand* is the return value of a call |
| 1234 | // Insert it to to he PushedRegSet since we must not save that register |
| 1235 | // and restore it after the call. |
| 1236 | // We do this because, we look at the LV set *after* the instruction |
| 1237 | // to determine, which LRs must be saved across calls. The return value |
| 1238 | // of the call is live in this set - but we must not save/restore it. |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1239 | |
| 1240 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1241 | const Value *RetVal = getCallInstRetVal( MInst ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1243 | if (RetVal) { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1244 | LiveRange *RetValLR = PRA.LRI.getLiveRangeForValue( RetVal ); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1245 | assert(RetValLR && "No LR for RetValue of call"); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1246 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1247 | if (RetValLR->hasColor()) |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1248 | PushedRegSet.insert( |
| 1249 | getUnifiedRegNum((RetValLR->getRegClass())->getID(), |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1250 | RetValLR->getColor() ) ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 1254 | const ValueSet *LVSetAft = PRA.LVI->getLiveVarSetAfterMInst(MInst, BB); |
| 1255 | ValueSet::const_iterator LIt = LVSetAft->begin(); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1256 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1257 | // for each live var in live variable set after machine inst |
| 1258 | for( ; LIt != LVSetAft->end(); ++LIt) { |
| 1259 | |
| 1260 | // get the live range corresponding to live var |
| 1261 | LiveRange *const LR = PRA.LRI.getLiveRangeForValue(*LIt ); |
| 1262 | |
| 1263 | // LR can be null if it is a const since a const |
| 1264 | // doesn't have a dominating def - see Assumptions above |
| 1265 | if( LR ) { |
| 1266 | |
| 1267 | if( LR->hasColor() ) { |
| 1268 | |
| 1269 | unsigned RCID = (LR->getRegClass())->getID(); |
| 1270 | unsigned Color = LR->getColor(); |
| 1271 | |
| 1272 | if ( isRegVolatile(RCID, Color) ) { |
| 1273 | |
| 1274 | // if the value is in both LV sets (i.e., live before and after |
| 1275 | // the call machine instruction) |
| 1276 | |
| 1277 | unsigned Reg = getUnifiedRegNum(RCID, Color); |
| 1278 | |
| 1279 | if( PushedRegSet.find(Reg) == PushedRegSet.end() ) { |
| 1280 | |
| 1281 | // if we haven't already pushed that register |
| 1282 | |
| 1283 | unsigned RegType = getRegType( LR ); |
| 1284 | |
| 1285 | // Now get two instructions - to push on stack and pop from stack |
| 1286 | // and add them to InstrnsBefore and InstrnsAfter of the |
| 1287 | // call instruction |
| 1288 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 1289 | |
| 1290 | int StackOff = PRA.mcInfo.pushTempValue(target, |
| 1291 | getSpilledRegSize(RegType)); |
| 1292 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 1293 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1294 | MachineInstr *AdIBefCC, *AdIAftCC, *AdICpCC; |
Vikram S. Adve | 9576b15 | 2001-11-06 05:01:54 +0000 | [diff] [blame] | 1295 | MachineInstr *AdIBef, *AdIAft; |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1296 | |
| 1297 | |
| 1298 | //---- Insert code for pushing the reg on stack ---------- |
| 1299 | |
| 1300 | if( RegType == IntCCRegType ) { |
| 1301 | |
| 1302 | // Handle IntCCRegType specially since we cannot directly |
| 1303 | // push %ccr on to the stack |
| 1304 | |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 1305 | const ValueSet *LVSetBef = |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1306 | PRA.LVI->getLiveVarSetBeforeMInst(MInst, BB); |
| 1307 | |
| 1308 | // get a free INTEGER register |
| 1309 | int FreeIntReg = |
Ruchira Sasanka | 295264d | 2001-11-15 20:25:07 +0000 | [diff] [blame] | 1310 | PRA.getUsableUniRegAtMI(LR->getRegClass(), IntRegType, MInst, |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1311 | LVSetBef, AdIBefCC, AdIAftCC); |
| 1312 | |
| 1313 | // insert the instructions in reverse order since we are |
| 1314 | // adding them to the front of InstrnsBefore |
| 1315 | |
| 1316 | if(AdIAftCC) |
| 1317 | (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdIAftCC); |
| 1318 | |
| 1319 | AdICpCC = cpCCR2IntMI(FreeIntReg); |
| 1320 | (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdICpCC); |
| 1321 | |
| 1322 | if(AdIBefCC) |
| 1323 | (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdIBefCC); |
| 1324 | |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1325 | if(DEBUG_RA) { |
| 1326 | cerr << "\n!! Inserted caller saving (push) inst for %ccr:"; |
| 1327 | if(AdIBefCC) cerr << "\t" << *(AdIBefCC); |
| 1328 | cerr << "\t" << *AdICpCC; |
| 1329 | if(AdIAftCC) cerr << "\t" << *(AdIAftCC); |
| 1330 | } |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1331 | |
| 1332 | } else { |
| 1333 | // for any other register type, just add the push inst |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1334 | AdIBef = cpReg2MemMI(Reg, getFramePointer(), StackOff, RegType ); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1335 | ((PRA.AddedInstrMap[MInst])->InstrnsBefore).push_front(AdIBef); |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | //---- Insert code for popping the reg from the stack ---------- |
| 1340 | |
| 1341 | if( RegType == IntCCRegType ) { |
| 1342 | |
| 1343 | // Handle IntCCRegType specially since we cannot directly |
| 1344 | // pop %ccr on from the stack |
| 1345 | |
| 1346 | // get a free INT register |
| 1347 | int FreeIntReg = |
Ruchira Sasanka | 295264d | 2001-11-15 20:25:07 +0000 | [diff] [blame] | 1348 | PRA.getUsableUniRegAtMI(LR->getRegClass(), IntRegType, MInst, |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1349 | LVSetAft, AdIBefCC, AdIAftCC); |
| 1350 | |
| 1351 | if(AdIBefCC) |
| 1352 | (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdIBefCC); |
| 1353 | |
| 1354 | AdICpCC = cpInt2CCRMI(FreeIntReg); |
| 1355 | (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdICpCC); |
| 1356 | |
| 1357 | if(AdIAftCC) |
| 1358 | (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdIAftCC); |
| 1359 | |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1360 | if(DEBUG_RA) { |
| 1361 | |
| 1362 | cerr << "\n!! Inserted caller saving (pop) inst for %ccr:"; |
| 1363 | if(AdIBefCC) cerr << "\t" << *(AdIBefCC); |
| 1364 | cerr << "\t" << *AdICpCC; |
| 1365 | if(AdIAftCC) cerr << "\t" << *(AdIAftCC); |
| 1366 | } |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1367 | |
| 1368 | } else { |
| 1369 | // for any other register type, just add the pop inst |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1370 | AdIAft = cpMem2RegMI(getFramePointer(), StackOff, Reg, RegType ); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1371 | ((PRA.AddedInstrMap[MInst])->InstrnsAfter).push_back(AdIAft); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1372 | } |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1373 | |
| 1374 | PushedRegSet.insert( Reg ); |
| 1375 | |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1376 | if(DEBUG_RA) { |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1377 | cerr << "\nFor call inst:" << *MInst; |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1378 | cerr << " -inserted caller saving instrs:\n\t "; |
Vikram S. Adve | 9576b15 | 2001-11-06 05:01:54 +0000 | [diff] [blame] | 1379 | if( RegType == IntCCRegType ) |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1380 | cerr << *AdIBefCC << "\t" << *AdIAftCC ; |
Vikram S. Adve | 9576b15 | 2001-11-06 05:01:54 +0000 | [diff] [blame] | 1381 | else |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1382 | cerr << *AdIBef << "\t" << *AdIAft ; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1383 | } |
| 1384 | } // if not already pushed |
| 1385 | |
| 1386 | } // if LR has a volatile color |
| 1387 | |
| 1388 | } // if LR has color |
| 1389 | |
| 1390 | } // if there is a LR for Var |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1391 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1392 | } // for each value in the LV set after instruction |
| 1393 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1396 | //--------------------------------------------------------------------------- |
| 1397 | // Copies %ccr into an integer register. IntReg is the UNIFIED register |
| 1398 | // number. |
| 1399 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1400 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1401 | MachineInstr * UltraSparcRegInfo::cpCCR2IntMI(unsigned IntReg) const { |
| 1402 | MachineInstr * MI = new MachineInstr(RDCCR, 2); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1403 | MI->SetMachineOperand(0, SparcIntCCRegOrder::ccr, false); |
| 1404 | MI->SetMachineOperand(1, IntReg, true); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1405 | return MI; |
| 1406 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1407 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1408 | //--------------------------------------------------------------------------- |
| 1409 | // Copies an integer register into %ccr. IntReg is the UNIFIED register |
| 1410 | // number. |
| 1411 | //--------------------------------------------------------------------------- |
| 1412 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1413 | MachineInstr *UltraSparcRegInfo::cpInt2CCRMI(unsigned IntReg) const { |
| 1414 | MachineInstr *MI = new MachineInstr(WRCCR, 3); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1415 | MI->SetMachineOperand(0, IntReg, false); |
| 1416 | MI->SetMachineOperand(1, SparcIntRegOrder::g0, false); |
| 1417 | MI->SetMachineOperand(2, SparcIntCCRegOrder::ccr, true); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1418 | return MI; |
| 1419 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1420 | |
| 1421 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1422 | |
| 1423 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1424 | //--------------------------------------------------------------------------- |
| 1425 | // Print the register assigned to a LR |
| 1426 | //--------------------------------------------------------------------------- |
| 1427 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1428 | void UltraSparcRegInfo::printReg(const LiveRange *LR) { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1429 | unsigned RegClassID = (LR->getRegClass())->getID(); |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1430 | cerr << " *Node " << (LR->getUserIGNode())->getIndex(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1431 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1432 | if (!LR->hasColor()) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1433 | cerr << " - could not find a color\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1434 | return; |
| 1435 | } |
| 1436 | |
| 1437 | // if a color is found |
| 1438 | |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1439 | cerr << " colored with color "<< LR->getColor(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1440 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1441 | if (RegClassID == IntRegClassID) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1442 | cerr<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) << "]\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1443 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1444 | } else if (RegClassID == FloatRegClassID) { |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1445 | cerr << "[" << SparcFloatRegOrder::getRegName(LR->getColor()); |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame^] | 1446 | if( LR->getType() == Type::DoubleTy) |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1447 | cerr << "+" << SparcFloatRegOrder::getRegName(LR->getColor()+1); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1448 | cerr << "]\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1449 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1450 | } |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1451 | |
| 1452 | //--------------------------------------------------------------------------- |
| 1453 | // This method examines instructions inserted by RegAlloc code before a |
| 1454 | // machine instruction to detect invalid orders that destroy values before |
| 1455 | // they are used. If it detects such conditions, it reorders the instructions. |
| 1456 | // |
| 1457 | // The unordered instructions come in the UnordVec. These instructions are |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1458 | // instructions inserted by RegAlloc. All such instruction MUST have |
| 1459 | // their USES BEFORE THE DEFS after reordering. |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1460 | |
| 1461 | // The UnordVec & OrdVec must be DISTINCT. The OrdVec must be empty when |
| 1462 | // this method is called. |
| 1463 | |
| 1464 | // This method uses two vectors for efficiency in accessing |
| 1465 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1466 | // Since instructions are inserted in RegAlloc, this assumes that the |
| 1467 | // first operand is the source reg and the last operand is the dest reg. |
| 1468 | |
| 1469 | // All the uses are before THE def to a register |
| 1470 | |
| 1471 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1472 | //--------------------------------------------------------------------------- |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1473 | void UltraSparcRegInfo::OrderAddedInstrns(std::vector<MachineInstr *> &UnordVec, |
| 1474 | std::vector<MachineInstr *> &OrdVec, |
| 1475 | PhyRegAlloc &PRA) const{ |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1476 | |
| 1477 | /* |
| 1478 | Problem: We can have instructions inserted by RegAlloc like |
| 1479 | 1. add %ox %g0 %oy |
| 1480 | 2. add %oy %g0 %oz, where z!=x or z==x |
| 1481 | |
| 1482 | This is wrong since %oy used by 2 is overwritten by 1 |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1483 | |
| 1484 | Solution: |
| 1485 | We re-order the instructions so that the uses are before the defs |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1486 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1487 | Algorithm: |
| 1488 | |
| 1489 | do |
| 1490 | for each instruction 'DefInst' in the UnOrdVec |
| 1491 | for each instruction 'UseInst' that follows the DefInst |
| 1492 | if the reg defined by DefInst is used by UseInst |
| 1493 | mark DefInst as not movable in this iteration |
| 1494 | If DefInst is not marked as not-movable, move DefInst to OrdVec |
| 1495 | while all instructions in DefInst are moved to OrdVec |
| 1496 | |
| 1497 | For moving, we call the move2OrdVec(). It checks whether there is a def |
| 1498 | in it for the uses in the instruction to be added to OrdVec. If there |
| 1499 | are no preceding defs, it just appends the instruction. If there is a |
| 1500 | preceding def, it puts two instructions to save the reg on stack before |
| 1501 | the load and puts a restore at use. |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1502 | |
| 1503 | */ |
| 1504 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1505 | bool CouldMoveAll; |
| 1506 | bool DebugPrint = false; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1507 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1508 | do { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1509 | CouldMoveAll = true; |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1510 | std::vector<MachineInstr *>::iterator DefIt = UnordVec.begin(); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1511 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1512 | for( ; DefIt != UnordVec.end(); ++DefIt ) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1513 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1514 | // for each instruction in the UnordVec do ... |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1515 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1516 | MachineInstr *DefInst = *DefIt; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1517 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1518 | if( DefInst == NULL) continue; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1519 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1520 | //cerr << "\nInst in UnordVec = " << *DefInst; |
| 1521 | |
| 1522 | // last operand is the def (unless for a store which has no def reg) |
| 1523 | MachineOperand& DefOp = DefInst->getOperand(DefInst->getNumOperands()-1); |
| 1524 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1525 | if( DefOp.opIsDef() && |
| 1526 | DefOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1527 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1528 | // If the operand in DefInst is a def ... |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1529 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1530 | bool DefEqUse = false; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1531 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1532 | std::vector<MachineInstr *>::iterator UseIt = DefIt; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1533 | UseIt++; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1534 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1535 | for( ; UseIt != UnordVec.end(); ++UseIt ) { |
| 1536 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1537 | MachineInstr *UseInst = *UseIt; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1538 | if( UseInst == NULL) continue; |
| 1539 | |
| 1540 | // for each inst (UseInst) that is below the DefInst do ... |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1541 | MachineOperand& UseOp = UseInst->getOperand(0); |
| 1542 | |
| 1543 | if( ! UseOp.opIsDef() && |
| 1544 | UseOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
| 1545 | |
| 1546 | // if use is a register ... |
| 1547 | |
| 1548 | if( DefOp.getMachineRegNum() == UseOp.getMachineRegNum() ) { |
| 1549 | |
| 1550 | // if Def and this use are the same, it means that this use |
| 1551 | // is destroyed by a def before it is used |
| 1552 | |
| 1553 | // cerr << "\nCouldn't move " << *DefInst; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1554 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1555 | DefEqUse = true; |
| 1556 | CouldMoveAll = false; |
| 1557 | DebugPrint = true; |
| 1558 | break; |
| 1559 | } // if two registers are equal |
| 1560 | |
| 1561 | } // if use is a register |
| 1562 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1563 | }// for all use instructions |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1564 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1565 | if( ! DefEqUse ) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1566 | |
| 1567 | // after examining all the instructions that follow the DefInst |
| 1568 | // if there are no dependencies, we can move it to the OrdVec |
| 1569 | |
| 1570 | // cerr << "Moved to Ord: " << *DefInst; |
| 1571 | |
| 1572 | moveInst2OrdVec(OrdVec, DefInst, PRA); |
| 1573 | |
| 1574 | //OrdVec.push_back(DefInst); |
| 1575 | |
| 1576 | // mark the pos of DefInst with NULL to indicate that it is |
| 1577 | // empty |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1578 | *DefIt = NULL; |
| 1579 | } |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1580 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1581 | } // if Def is a machine register |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1582 | |
| 1583 | } // for all instructions in the UnordVec |
| 1584 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1585 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1586 | } while(!CouldMoveAll); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1587 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1588 | if (DebugPrint) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1589 | cerr << "\nAdded instructions were reordered to:\n"; |
| 1590 | for(unsigned int i=0; i < OrdVec.size(); i++) |
| 1591 | cerr << *(OrdVec[i]); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1592 | } |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1593 | } |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1599 | void UltraSparcRegInfo::moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec, |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1600 | MachineInstr *UnordInst, |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1601 | PhyRegAlloc &PRA) const { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1602 | MachineOperand& UseOp = UnordInst->getOperand(0); |
| 1603 | |
| 1604 | if( ! UseOp.opIsDef() && |
| 1605 | UseOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
| 1606 | |
| 1607 | // for the use of UnordInst, see whether there is a defining instr |
| 1608 | // before in the OrdVec |
| 1609 | bool DefEqUse = false; |
| 1610 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1611 | std::vector<MachineInstr *>::iterator OrdIt = OrdVec.begin(); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1612 | |
| 1613 | for( ; OrdIt != OrdVec.end(); ++OrdIt ) { |
| 1614 | |
| 1615 | MachineInstr *OrdInst = *OrdIt ; |
| 1616 | |
| 1617 | MachineOperand& DefOp = |
| 1618 | OrdInst->getOperand(OrdInst->getNumOperands()-1); |
| 1619 | |
| 1620 | if( DefOp.opIsDef() && |
| 1621 | DefOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
| 1622 | |
| 1623 | //cerr << "\nDefining Ord Inst: " << *OrdInst; |
| 1624 | |
| 1625 | if( DefOp.getMachineRegNum() == UseOp.getMachineRegNum() ) { |
| 1626 | |
| 1627 | // we are here because there is a preceding def in the OrdVec |
| 1628 | // for the use in this intr we are going to insert. This |
| 1629 | // happened because the original code was like: |
| 1630 | // 1. add %ox %g0 %oy |
| 1631 | // 2. add %oy %g0 %ox |
| 1632 | // In Round1, we added 2 to OrdVec but 1 remained in UnordVec |
| 1633 | // Now we are processing %ox of 1. |
| 1634 | // We have to |
| 1635 | |
| 1636 | const int UReg = DefOp.getMachineRegNum(); |
| 1637 | const int RegType = getRegType(UReg); |
| 1638 | MachineInstr *AdIBef, *AdIAft; |
| 1639 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 1640 | const int StackOff = PRA.mcInfo.pushTempValue(target, |
| 1641 | getSpilledRegSize(RegType)); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1642 | |
| 1643 | // Save the UReg (%ox) on stack before it's destroyed |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1644 | AdIBef=cpReg2MemMI(UReg, getFramePointer(), StackOff, RegType); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1645 | OrdIt = OrdVec.insert( OrdIt, AdIBef); |
| 1646 | OrdIt++; // points to current instr we processed |
| 1647 | |
| 1648 | // Load directly into DReg (%oy) |
| 1649 | MachineOperand& DOp= |
| 1650 | (UnordInst->getOperand(UnordInst->getNumOperands()-1)); |
| 1651 | assert(DOp.opIsDef() && "Last operand is not the def"); |
| 1652 | const int DReg = DOp.getMachineRegNum(); |
| 1653 | |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1654 | AdIAft=cpMem2RegMI(getFramePointer(), StackOff, DReg, RegType); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1655 | OrdVec.push_back(AdIAft); |
| 1656 | |
| 1657 | cerr << "\nFixed CIRCULAR references by reordering"; |
| 1658 | |
| 1659 | if( DEBUG_RA ) { |
| 1660 | cerr << "\nBefore CIRCULAR Reordering:\n"; |
| 1661 | cerr << *UnordInst; |
| 1662 | cerr << *OrdInst; |
| 1663 | |
| 1664 | cerr << "\nAfter CIRCULAR Reordering - All Inst so far:\n"; |
| 1665 | for(unsigned i=0; i < OrdVec.size(); i++) |
| 1666 | cerr << *(OrdVec[i]); |
| 1667 | } |
| 1668 | |
| 1669 | // Do not copy the UseInst to OrdVec |
| 1670 | DefEqUse = true; |
| 1671 | break; |
| 1672 | |
| 1673 | }// if two registers are equal |
| 1674 | |
| 1675 | } // if Def is a register |
| 1676 | |
| 1677 | } // for each instr in OrdVec |
| 1678 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1679 | if(!DefEqUse) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1680 | |
| 1681 | // We didn't find a def in the OrdVec, so just append this inst |
| 1682 | OrdVec.push_back( UnordInst ); |
| 1683 | //cerr << "Reordered Inst (Moved Dn): " << *UnordInst; |
| 1684 | } |
| 1685 | |
| 1686 | }// if the operand in UnordInst is a use |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1687 | } |