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