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(); |
Chris Lattner | d1b60fb | 2002-02-04 16:37:09 +0000 | [diff] [blame] | 305 | RetAddrLR->insert( RetAddrVal ); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 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(); |
Chris Lattner | d1b60fb | 2002-02-04 16:37:09 +0000 | [diff] [blame] | 535 | RetValLR->insert(RetVal); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 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 |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 566 | if (!LR) { |
| 567 | cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) << "\n"; |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 568 | assert(0 && "NO LR for call arg"); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | unsigned RegType = getRegType( LR ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 572 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 573 | // if the arg is in int class - allocate a reg for an int arg |
| 574 | if( RegType == IntRegType ) { |
| 575 | |
| 576 | if( argNo < NumOfIntArgRegs) |
| 577 | LR->setSuggestedColor( SparcIntRegOrder::o0 + argNo ); |
| 578 | |
| 579 | else if (DEBUG_RA) |
| 580 | // Do NOTHING as this will be colored as a normal value. |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 581 | cerr << " Regr not suggested for int call arg\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 582 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 583 | } |
| 584 | else if( RegType == FPSingleRegType && (argNo*2 +1)< NumOfFloatArgRegs) |
| 585 | LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) ); |
| 586 | |
| 587 | |
| 588 | else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs) |
| 589 | LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) ); |
| 590 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 591 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 592 | } // for all call arguments |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 593 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 597 | //--------------------------------------------------------------------------- |
| 598 | // After graph coloring, we have call this method to see whehter the return |
| 599 | // value and the call args received the correct colors. If not, we have |
| 600 | // to instert copy instructions. |
| 601 | //--------------------------------------------------------------------------- |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 602 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 603 | void UltraSparcRegInfo::colorCallArgs(const MachineInstr *CallMI, |
| 604 | LiveRangeInfo &LRI, |
| 605 | AddedInstrns *CallAI, |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 606 | PhyRegAlloc &PRA, |
| 607 | const BasicBlock *BB) const { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 608 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 609 | assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) ); |
| 610 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 611 | // Reset the optional args area in the stack frame |
| 612 | // since that is reused for each call |
| 613 | // |
| 614 | PRA.mcInfo.resetOptionalArgs(target); |
| 615 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 616 | // First color the return value of the call. |
| 617 | // If there is a LR for the return value, it means this |
| 618 | // method returns a value |
| 619 | |
| 620 | MachineInstr *AdMI; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 621 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 622 | const Value *RetVal = getCallInstRetVal( CallMI ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 623 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 624 | if (RetVal) { |
| 625 | LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 626 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 627 | if (!RetValLR) { |
| 628 | cerr << "\nNo LR for:" << RAV(RetVal) << "\n"; |
| 629 | assert(0 && "ERR:No LR for non-void return value"); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 630 | } |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 631 | |
| 632 | unsigned RegClassID = (RetValLR->getRegClass())->getID(); |
| 633 | bool recvCorrectColor = false; |
| 634 | |
| 635 | unsigned CorrectCol; // correct color for ret value |
| 636 | if(RegClassID == IntRegClassID) |
| 637 | CorrectCol = SparcIntRegOrder::o0; |
| 638 | else if(RegClassID == FloatRegClassID) |
| 639 | CorrectCol = SparcFloatRegOrder::f0; |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 640 | else { |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 641 | assert( 0 && "Unknown RegClass"); |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 642 | return; |
| 643 | } |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 644 | |
| 645 | // if the LR received the correct color, NOTHING to do |
| 646 | |
| 647 | if( RetValLR->hasColor() ) |
| 648 | if( RetValLR->getColor() == CorrectCol ) |
| 649 | recvCorrectColor = true; |
| 650 | |
| 651 | |
| 652 | // if we didn't receive the correct color for some reason, |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 653 | // put copy instruction |
| 654 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 655 | if( !recvCorrectColor ) { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 656 | |
| 657 | unsigned RegType = getRegType( RetValLR ); |
| 658 | |
| 659 | // the reg that LR must be colored with |
| 660 | unsigned UniRetReg = getUnifiedRegNum( RegClassID, CorrectCol); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 661 | |
| 662 | if( RetValLR->hasColor() ) { |
| 663 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 664 | unsigned |
| 665 | UniRetLRReg=getUnifiedRegNum(RegClassID,RetValLR->getColor()); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 666 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 667 | // the return value is coming in UniRetReg but has to go into |
| 668 | // the UniRetLRReg |
| 669 | |
| 670 | AdMI = cpReg2RegMI( UniRetReg, UniRetLRReg, RegType ); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 671 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 672 | } // if LR has color |
| 673 | else { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 674 | |
| 675 | // if the LR did NOT receive a color, we have to move the return |
| 676 | // value coming in UniRetReg to the stack pos of spilled LR |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 677 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 678 | AdMI = cpReg2MemMI(UniRetReg, getFramePointer(), |
| 679 | RetValLR->getSpillOffFromFP(), RegType ); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 680 | } |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 681 | |
| 682 | CallAI->InstrnsAfter.push_back( AdMI ); |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 683 | |
| 684 | } // the LR didn't receive the suggested color |
| 685 | |
| 686 | } // if there a return value |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 687 | |
| 688 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 689 | //------------------------------------------- |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 690 | // Now color all args of the call instruction |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 691 | //------------------------------------------- |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 692 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 693 | std::vector<MachineInstr *> AddedInstrnsBefore; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 694 | |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 695 | unsigned NumOfCallArgs = getCallInstNumArgs( CallMI ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 696 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 697 | bool VarArgCall = isVarArgCall( CallMI ); |
| 698 | |
| 699 | if(VarArgCall) cerr << "\nVar arg call found!!\n"; |
| 700 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 701 | for(unsigned argNo=0, i=0; i < NumOfCallArgs; ++i, ++argNo ) { |
| 702 | |
| 703 | const Value *CallArg = CallMI->getImplicitRef(i); |
| 704 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 705 | // get the LR of call operand (parameter) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 706 | LiveRange *const LR = LRI.getLiveRangeForValue(CallArg); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 707 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 708 | unsigned RegType = getRegType( CallArg ); |
| 709 | unsigned RegClassID = getRegClassIDOfValue( CallArg); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 710 | |
| 711 | // find whether this argument is coming in a register (if not, on stack) |
| 712 | |
| 713 | bool isArgInReg = false; |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 714 | unsigned UniArgReg = InvalidRegNum; // reg that LR must be colored with |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 715 | |
| 716 | if( (RegType== IntRegType && argNo < NumOfIntArgRegs)) { |
| 717 | isArgInReg = true; |
| 718 | UniArgReg = getUnifiedRegNum(RegClassID, SparcIntRegOrder::o0 + argNo ); |
| 719 | } |
| 720 | else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs) { |
| 721 | isArgInReg = true; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 722 | |
| 723 | if( !VarArgCall ) |
| 724 | UniArgReg = getUnifiedRegNum(RegClassID, |
| 725 | SparcFloatRegOrder::f0 + (argNo*2 + 1) ); |
| 726 | else { |
| 727 | // a variable argument call - must pass float arg in %o's |
| 728 | if( argNo < NumOfIntArgRegs) |
| 729 | UniArgReg=getUnifiedRegNum(IntRegClassID,SparcIntRegOrder::o0+argNo); |
| 730 | else |
| 731 | isArgInReg = false; |
| 732 | } |
| 733 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 734 | } |
| 735 | else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs) { |
| 736 | isArgInReg = true; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 737 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 738 | if( !VarArgCall ) |
| 739 | UniArgReg =getUnifiedRegNum(RegClassID,SparcFloatRegOrder::f0+argNo*2); |
| 740 | else { |
| 741 | // a variable argument call - must pass float arg in %o's |
| 742 | if( argNo < NumOfIntArgRegs) |
| 743 | UniArgReg=getUnifiedRegNum(IntRegClassID,SparcIntRegOrder::o0+argNo); |
| 744 | else |
| 745 | isArgInReg = false; |
| 746 | } |
| 747 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 748 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 749 | // not possible to have a null LR since all args (even consts) |
| 750 | // must be defined before |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 751 | if (!LR) { |
| 752 | cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) << "\n"; |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 753 | assert(0 && "NO LR for call arg"); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 754 | } |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 755 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 756 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 757 | if (LR->hasColor()) { |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 758 | unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() ); |
| 759 | |
| 760 | // if LR received the correct color, nothing to do |
| 761 | if( UniLRReg == UniArgReg ) |
| 762 | continue; |
| 763 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 764 | // We are here because though the LR is allocated a register, it |
| 765 | // was not allocated the suggested register. So, we have to copy %ix reg |
| 766 | // (or stack pos of arg) to the register it was colored with |
| 767 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 768 | // the LR is colored with UniLRReg but has to go into UniArgReg |
| 769 | // to pass it as an argument |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 770 | |
Ruchira Sasanka | 9d47866 | 2001-11-12 20:54:19 +0000 | [diff] [blame] | 771 | if( isArgInReg ) { |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 772 | |
| 773 | if( VarArgCall && RegClassID == FloatRegClassID ) { |
| 774 | |
| 775 | |
| 776 | // for a variable argument call, the float reg must go in a %o reg. |
| 777 | // We have to move a float reg to an int reg via memory. |
| 778 | // The store instruction will be directly added to |
| 779 | // CallAI->InstrnsBefore since it does not need reordering |
| 780 | // |
| 781 | int TmpOff = PRA.mcInfo.pushTempValue(target, |
| 782 | getSpilledRegSize(RegType)); |
| 783 | |
| 784 | AdMI = cpReg2MemMI(UniLRReg, getFramePointer(), TmpOff, RegType ); |
| 785 | CallAI->InstrnsBefore.push_back( AdMI ); |
| 786 | |
| 787 | AdMI = cpMem2RegMI(getFramePointer(), TmpOff, UniArgReg, IntRegType); |
| 788 | AddedInstrnsBefore.push_back( AdMI ); |
| 789 | } |
| 790 | |
| 791 | else { |
| 792 | AdMI = cpReg2RegMI(UniLRReg, UniArgReg, RegType ); |
| 793 | AddedInstrnsBefore.push_back( AdMI ); |
| 794 | } |
| 795 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 796 | } else { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 797 | // Now, we have to pass the arg on stack. Since LR received a register |
| 798 | // we just have to move that register to the stack position where |
| 799 | // the argument must be passed |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 800 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 801 | int argOffset = PRA.mcInfo.allocateOptionalArg(target, LR->getType()); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 802 | |
Ruchira Sasanka | c56e5c1 | 2001-11-11 22:37:51 +0000 | [diff] [blame] | 803 | AdMI = cpReg2MemMI(UniLRReg, getStackPointer(), argOffset, RegType ); |
Ruchira Sasanka | 9d47866 | 2001-11-12 20:54:19 +0000 | [diff] [blame] | 804 | |
| 805 | // Now add the instruction. We can directly add to |
| 806 | // CallAI->InstrnsBefore since we are just saving a reg on stack |
| 807 | // |
| 808 | CallAI->InstrnsBefore.push_back( AdMI ); |
| 809 | |
| 810 | //cerr << "\nCaution: Passing a reg on stack"; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Ruchira Sasanka | 9d47866 | 2001-11-12 20:54:19 +0000 | [diff] [blame] | 813 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 814 | } else { // LR is not colored (i.e., spilled) |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 815 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 816 | if( isArgInReg ) { |
| 817 | |
| 818 | // Now the LR did NOT recieve a register but has a stack poistion. |
| 819 | // Since, the outgoing arg goes in a register we just have to insert |
| 820 | // a load instruction to load the LR to outgoing register |
| 821 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 822 | if( VarArgCall && RegClassID == FloatRegClassID ) |
| 823 | AdMI = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), |
| 824 | UniArgReg, IntRegType ); |
| 825 | else |
| 826 | AdMI = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), |
| 827 | UniArgReg, RegType ); |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 828 | |
Ruchira Sasanka | 91014f6 | 2001-11-12 20:31:47 +0000 | [diff] [blame] | 829 | 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] | 830 | AddedInstrnsBefore.push_back( AdMI ); // Now add the instruction |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 831 | } |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 832 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 833 | else { |
| 834 | // Now, we have to pass the arg on stack. Since LR also did NOT |
| 835 | // receive a register we have to move an argument in memory to |
| 836 | // outgoing parameter on stack. |
| 837 | |
| 838 | // Optoimize: Optimize when reverse pointers in MahineInstr are |
| 839 | // introduced. |
| 840 | // call PRA.getUnusedRegAtMI(....) to get an unused reg. Only if this |
| 841 | // fails, then use the following code. Currently, we cannot call the |
| 842 | // above method since we cannot find LVSetBefore without the BB |
| 843 | |
Ruchira Sasanka | 295264d | 2001-11-15 20:25:07 +0000 | [diff] [blame] | 844 | int TReg = PRA.getUniRegNotUsedByThisInst( LR->getRegClass(), CallMI ); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 845 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 846 | int TmpOff = PRA.mcInfo.pushTempValue(target, |
| 847 | getSpilledRegSize(getRegType(LR)) ); |
| 848 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 849 | |
| 850 | int argOffset = PRA.mcInfo.allocateOptionalArg(target, LR->getType()); |
| 851 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 852 | MachineInstr *Ad1, *Ad2, *Ad3, *Ad4; |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 853 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 854 | // Sequence: |
| 855 | // (1) Save TReg on stack |
| 856 | // (2) Load LR value into TReg from stack pos of LR |
| 857 | // (3) Store Treg on outgoing Arg pos on stack |
| 858 | // (4) Load the old value of TReg from stack to TReg (restore it) |
| 859 | |
| 860 | Ad1 = cpReg2MemMI(TReg, getFramePointer(), TmpOff, RegType ); |
| 861 | Ad2 = cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), |
| 862 | TReg, RegType ); |
Ruchira Sasanka | c56e5c1 | 2001-11-11 22:37:51 +0000 | [diff] [blame] | 863 | Ad3 = cpReg2MemMI(TReg, getStackPointer(), argOffset, RegType ); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 864 | Ad4 = cpMem2RegMI(getFramePointer(), TmpOff, TReg, RegType ); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 865 | |
| 866 | // We directly add to CallAI->InstrnsBefore instead of adding to |
| 867 | // AddedInstrnsBefore since these instructions must not be |
| 868 | // reordered. |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 869 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 870 | CallAI->InstrnsBefore.push_back( Ad1 ); |
| 871 | CallAI->InstrnsBefore.push_back( Ad2 ); |
| 872 | CallAI->InstrnsBefore.push_back( Ad3 ); |
| 873 | CallAI->InstrnsBefore.push_back( Ad4 ); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 874 | |
Ruchira Sasanka | 91014f6 | 2001-11-12 20:31:47 +0000 | [diff] [blame] | 875 | cerr << "\nCaution: Call arg moved from stack2stack for: " << *CallMI ; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 876 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 877 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 878 | } // for each parameter in call instruction |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 879 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 880 | |
| 881 | // if we added any instruction before the call instruction, verify |
| 882 | // that they are in the proper order and if not, reorder them |
| 883 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 884 | if (!AddedInstrnsBefore.empty()) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 885 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 886 | if (DEBUG_RA) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 887 | cerr << "\nCalling reorder with instrns: \n"; |
| 888 | for(unsigned i=0; i < AddedInstrnsBefore.size(); i++) |
| 889 | cerr << *(AddedInstrnsBefore[i]); |
| 890 | } |
| 891 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 892 | std::vector<MachineInstr *> TmpVec; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 893 | OrderAddedInstrns(AddedInstrnsBefore, TmpVec, PRA); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 894 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 895 | if (DEBUG_RA) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 896 | cerr << "\nAfter reordering instrns: \n"; |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 897 | for(unsigned i = 0; i < TmpVec.size(); i++) |
| 898 | cerr << *TmpVec[i]; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | // copy the results back from TmpVec to InstrnsBefore |
| 902 | for(unsigned i=0; i < TmpVec.size(); i++) |
| 903 | CallAI->InstrnsBefore.push_back( TmpVec[i] ); |
| 904 | } |
| 905 | |
| 906 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 907 | // now insert caller saving code for this call instruction |
| 908 | // |
| 909 | insertCallerSavingCode(CallMI, BB, PRA); |
| 910 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 911 | // Reset optional args area again to be safe |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 912 | PRA.mcInfo.resetOptionalArgs(target); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 915 | //--------------------------------------------------------------------------- |
| 916 | // This method is called for an LLVM return instruction to identify which |
| 917 | // values will be returned from this method and to suggest colors. |
| 918 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 919 | void UltraSparcRegInfo::suggestReg4RetValue(const MachineInstr *RetMI, |
| 920 | LiveRangeInfo &LRI) const { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 921 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 922 | assert( (UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode() ) ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 923 | |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 924 | suggestReg4RetAddr(RetMI, LRI); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 925 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 926 | // if there is an implicit ref, that has to be the ret value |
| 927 | if( RetMI->getNumImplicitRefs() > 0 ) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 928 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 929 | // The first implicit operand is the return value of a return instr |
| 930 | const Value *RetVal = RetMI->getImplicitRef(0); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 931 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 932 | LiveRange *const LR = LRI.getLiveRangeForValue( RetVal ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 933 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 934 | if (!LR) { |
| 935 | cerr << "\nNo LR for:" << RAV(RetVal) << "\n"; |
| 936 | assert(0 && "No LR for return value of non-void method"); |
| 937 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 938 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 939 | unsigned RegClassID = (LR->getRegClass())->getID(); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 940 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 941 | if (RegClassID == IntRegClassID) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 942 | LR->setSuggestedColor(SparcIntRegOrder::i0); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 943 | else if (RegClassID == FloatRegClassID) |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 944 | LR->setSuggestedColor(SparcFloatRegOrder::f0); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 945 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 948 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 949 | |
| 950 | //--------------------------------------------------------------------------- |
| 951 | // Colors the return value of a method to %i0 or %f0, if possible. If it is |
| 952 | // not possilbe to directly color the LR, insert a copy instruction to move |
| 953 | // the LR to %i0 or %f0. When the LR is spilled, instead of the copy, we |
| 954 | // have to put a load instruction. |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 955 | //--------------------------------------------------------------------------- |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 956 | void UltraSparcRegInfo::colorRetValue(const MachineInstr *RetMI, |
| 957 | LiveRangeInfo &LRI, |
| 958 | AddedInstrns *RetAI) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 959 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 960 | assert((UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode())); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 961 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 962 | // 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] | 963 | if(RetMI->getNumImplicitRefs() > 0) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 964 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 965 | // The first implicit operand is the return value of a return instr |
| 966 | const Value *RetVal = RetMI->getImplicitRef(0); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 967 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 968 | LiveRange *LR = LRI.getLiveRangeForValue(RetVal); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 969 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 970 | if (!LR) { |
| 971 | cerr << "\nNo LR for:" << RAV(RetVal) << "\n"; |
| 972 | // assert( LR && "No LR for return value of non-void method"); |
| 973 | return; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 974 | } |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 975 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 976 | unsigned RegClassID = getRegClassIDOfValue(RetVal); |
| 977 | unsigned RegType = getRegType( RetVal ); |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 978 | |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 979 | unsigned CorrectCol; |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 980 | if(RegClassID == IntRegClassID) |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 981 | CorrectCol = SparcIntRegOrder::i0; |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 982 | else if(RegClassID == FloatRegClassID) |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 983 | CorrectCol = SparcFloatRegOrder::f0; |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 984 | else { |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 985 | assert (0 && "Unknown RegClass"); |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 986 | return; |
| 987 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 988 | |
Ruchira Sasanka | c74a720 | 2001-10-24 15:56:58 +0000 | [diff] [blame] | 989 | // if the LR received the correct color, NOTHING to do |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 990 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 991 | if (LR->hasColor() && LR->getColor() == CorrectCol) |
| 992 | return; |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 993 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 994 | unsigned UniRetReg = getUnifiedRegNum(RegClassID, CorrectCol); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 995 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 996 | if (LR->hasColor()) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 997 | |
Ruchira Sasanka | 88dedc1 | 2001-10-23 21:40:39 +0000 | [diff] [blame] | 998 | // We are here because the LR was allocted a regiter |
| 999 | // It may be the suggested register or not |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1000 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 1001 | // copy the LR of retun value to i0 or f0 |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1002 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 1003 | unsigned UniLRReg =getUnifiedRegNum( RegClassID, LR->getColor()); |
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 | // the LR received UniLRReg but must be colored with UniRetReg |
| 1006 | // to pass as the return value |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1007 | RetAI->InstrnsBefore.push_back(cpReg2RegMI(UniLRReg, UniRetReg, RegType)); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1008 | } |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1009 | else { // if the LR is spilled |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1010 | MachineInstr *AdMI = cpMem2RegMI(getFramePointer(), |
| 1011 | LR->getSpillOffFromFP(), |
| 1012 | UniRetReg, RegType); |
| 1013 | RetAI->InstrnsBefore.push_back(AdMI); |
| 1014 | cerr << "\nCopied the return value from stack\n"; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1017 | } // if there is a return value |
| 1018 | |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | //--------------------------------------------------------------------------- |
| 1023 | // Copy from a register to register. Register number must be the unified |
| 1024 | // register number |
| 1025 | //--------------------------------------------------------------------------- |
| 1026 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1027 | MachineInstr * UltraSparcRegInfo::cpReg2RegMI(unsigned SrcReg, unsigned DestReg, |
| 1028 | int RegType) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1029 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1030 | assert( ((int)SrcReg != InvalidRegNum) && ((int)DestReg != InvalidRegNum) && |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1031 | "Invalid Register"); |
| 1032 | |
| 1033 | MachineInstr * MI = NULL; |
| 1034 | |
| 1035 | switch( RegType ) { |
| 1036 | |
| 1037 | case IntRegType: |
Ruchira Sasanka | 735d6e3 | 2001-10-18 22:38:52 +0000 | [diff] [blame] | 1038 | case IntCCRegType: |
| 1039 | case FloatCCRegType: |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1040 | MI = new MachineInstr(ADD, 3); |
| 1041 | MI->SetMachineOperand(0, SrcReg, false); |
| 1042 | MI->SetMachineOperand(1, SparcIntRegOrder::g0, false); |
| 1043 | MI->SetMachineOperand(2, DestReg, true); |
| 1044 | break; |
| 1045 | |
| 1046 | case FPSingleRegType: |
| 1047 | MI = new MachineInstr(FMOVS, 2); |
| 1048 | MI->SetMachineOperand(0, SrcReg, false); |
| 1049 | MI->SetMachineOperand(1, DestReg, true); |
| 1050 | break; |
| 1051 | |
| 1052 | case FPDoubleRegType: |
| 1053 | MI = new MachineInstr(FMOVD, 2); |
| 1054 | MI->SetMachineOperand(0, SrcReg, false); |
| 1055 | MI->SetMachineOperand(1, DestReg, true); |
| 1056 | break; |
| 1057 | |
| 1058 | default: |
| 1059 | assert(0 && "Unknow RegType"); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | return MI; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1063 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1064 | |
| 1065 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1066 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1067 | // Copy from a register to memory (i.e., Store). Register number must |
| 1068 | // be the unified register number |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1069 | //--------------------------------------------------------------------------- |
| 1070 | |
| 1071 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1072 | MachineInstr * UltraSparcRegInfo::cpReg2MemMI(unsigned SrcReg, |
| 1073 | unsigned DestPtrReg, |
| 1074 | int Offset, int RegType) const { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1075 | MachineInstr * MI = NULL; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1076 | switch( RegType ) { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1077 | case IntRegType: |
Ruchira Sasanka | 735d6e3 | 2001-10-18 22:38:52 +0000 | [diff] [blame] | 1078 | case FloatCCRegType: |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1079 | MI = new MachineInstr(STX, 3); |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1080 | MI->SetMachineOperand(0, SrcReg, false); |
| 1081 | MI->SetMachineOperand(1, DestPtrReg, false); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1082 | MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed, |
| 1083 | (int64_t) Offset, false); |
| 1084 | break; |
| 1085 | |
| 1086 | case FPSingleRegType: |
| 1087 | MI = new MachineInstr(ST, 3); |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1088 | MI->SetMachineOperand(0, SrcReg, false); |
| 1089 | MI->SetMachineOperand(1, DestPtrReg, false); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1090 | MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed, |
| 1091 | (int64_t) Offset, false); |
| 1092 | break; |
| 1093 | |
| 1094 | case FPDoubleRegType: |
| 1095 | MI = new MachineInstr(STD, 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 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1102 | case IntCCRegType: |
| 1103 | assert( 0 && "Cannot directly store %ccr to memory"); |
| 1104 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1105 | default: |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1106 | assert(0 && "Unknow RegType in cpReg2MemMI"); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | return MI; |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | 7dcd612 | 2001-10-24 22:05:34 +0000 | [diff] [blame] | 1114 | // 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] | 1115 | // register number |
| 1116 | //--------------------------------------------------------------------------- |
| 1117 | |
| 1118 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1119 | MachineInstr * UltraSparcRegInfo::cpMem2RegMI(unsigned SrcPtrReg, |
| 1120 | int Offset, |
| 1121 | unsigned DestReg, |
| 1122 | int RegType) const { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1123 | MachineInstr * MI = NULL; |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1124 | switch (RegType) { |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1125 | case IntRegType: |
Ruchira Sasanka | 735d6e3 | 2001-10-18 22:38:52 +0000 | [diff] [blame] | 1126 | case FloatCCRegType: |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1127 | MI = new MachineInstr(LDX, 3); |
| 1128 | MI->SetMachineOperand(0, SrcPtrReg, false); |
| 1129 | MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed, |
| 1130 | (int64_t) Offset, false); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1131 | MI->SetMachineOperand(2, DestReg, true); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1132 | break; |
| 1133 | |
| 1134 | case FPSingleRegType: |
| 1135 | MI = new MachineInstr(LD, 3); |
| 1136 | MI->SetMachineOperand(0, SrcPtrReg, false); |
| 1137 | MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed, |
| 1138 | (int64_t) Offset, false); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1139 | MI->SetMachineOperand(2, DestReg, true); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1140 | |
| 1141 | break; |
| 1142 | |
| 1143 | case FPDoubleRegType: |
| 1144 | MI = new MachineInstr(LDD, 3); |
| 1145 | MI->SetMachineOperand(0, SrcPtrReg, false); |
| 1146 | MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed, |
| 1147 | (int64_t) Offset, false); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1148 | MI->SetMachineOperand(2, DestReg, true); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1149 | break; |
| 1150 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1151 | case IntCCRegType: |
| 1152 | assert( 0 && "Cannot directly load into %ccr from memory"); |
| 1153 | |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1154 | default: |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1155 | assert(0 && "Unknown RegType in cpMem2RegMI"); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | return MI; |
| 1159 | } |
| 1160 | |
| 1161 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1162 | |
| 1163 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1164 | |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1165 | //--------------------------------------------------------------------------- |
| 1166 | // Generate a copy instruction to copy a value to another. Temporarily |
| 1167 | // used by PhiElimination code. |
| 1168 | //--------------------------------------------------------------------------- |
| 1169 | |
| 1170 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1171 | MachineInstr *UltraSparcRegInfo::cpValue2Value(Value *Src, Value *Dest) const { |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1172 | int RegType = getRegType( Src ); |
| 1173 | |
| 1174 | assert( (RegType==getRegType(Src)) && "Src & Dest are diff types"); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1175 | |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1176 | MachineInstr * MI = NULL; |
| 1177 | |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1178 | switch( RegType ) { |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1179 | case IntRegType: |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1180 | MI = new MachineInstr(ADD, 3); |
| 1181 | MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false); |
| 1182 | MI->SetMachineOperand(1, SparcIntRegOrder::g0, false); |
| 1183 | MI->SetMachineOperand(2, MachineOperand:: MO_VirtualRegister, Dest, true); |
| 1184 | break; |
| 1185 | |
| 1186 | case FPSingleRegType: |
| 1187 | MI = new MachineInstr(FMOVS, 2); |
| 1188 | MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false); |
| 1189 | MI->SetMachineOperand(1, MachineOperand:: MO_VirtualRegister, Dest, true); |
| 1190 | break; |
| 1191 | |
| 1192 | |
| 1193 | case FPDoubleRegType: |
| 1194 | MI = new MachineInstr(FMOVD, 2); |
| 1195 | MI->SetMachineOperand(0, MachineOperand:: MO_VirtualRegister, Src, false); |
| 1196 | MI->SetMachineOperand(1, MachineOperand:: MO_VirtualRegister, Dest, true); |
| 1197 | break; |
| 1198 | |
| 1199 | default: |
| 1200 | assert(0 && "Unknow RegType in CpValu2Value"); |
| 1201 | } |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1202 | |
| 1203 | return MI; |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 1204 | } |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1205 | |
| 1206 | |
| 1207 | |
Ruchira Sasanka | 67a463a | 2001-11-12 14:45:33 +0000 | [diff] [blame] | 1208 | |
| 1209 | |
| 1210 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1211 | //---------------------------------------------------------------------------- |
| 1212 | // This method inserts caller saving/restoring instructons before/after |
Ruchira Sasanka | bf91552 | 2002-01-07 21:03:42 +0000 | [diff] [blame] | 1213 | // a call machine instruction. The caller saving/restoring instructions are |
| 1214 | // inserted like: |
| 1215 | // |
| 1216 | // ** caller saving instructions |
| 1217 | // other instructions inserted for the call by ColorCallArg |
| 1218 | // CALL instruction |
| 1219 | // other instructions inserted for the call ColorCallArg |
| 1220 | // ** caller restoring instructions |
| 1221 | // |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1222 | //---------------------------------------------------------------------------- |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 1223 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1224 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1225 | void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, |
| 1226 | const BasicBlock *BB, |
| 1227 | PhyRegAlloc &PRA) const { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1228 | |
Ruchira Sasanka | bf91552 | 2002-01-07 21:03:42 +0000 | [diff] [blame] | 1229 | // has set to record which registers were saved/restored |
| 1230 | // |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1231 | std::hash_set<unsigned> PushedRegSet; |
Ruchira Sasanka | bf91552 | 2002-01-07 21:03:42 +0000 | [diff] [blame] | 1232 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1233 | // Now find the LR of the return value of the call |
| 1234 | // The last *implicit operand* is the return value of a call |
| 1235 | // Insert it to to he PushedRegSet since we must not save that register |
| 1236 | // and restore it after the call. |
| 1237 | // We do this because, we look at the LV set *after* the instruction |
| 1238 | // to determine, which LRs must be saved across calls. The return value |
| 1239 | // 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] | 1240 | |
| 1241 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1242 | const Value *RetVal = getCallInstRetVal( MInst ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1243 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1244 | if (RetVal) { |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1245 | LiveRange *RetValLR = PRA.LRI.getLiveRangeForValue( RetVal ); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1246 | assert(RetValLR && "No LR for RetValue of call"); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1247 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1248 | if (RetValLR->hasColor()) |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1249 | PushedRegSet.insert( |
| 1250 | getUnifiedRegNum((RetValLR->getRegClass())->getID(), |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1251 | RetValLR->getColor() ) ); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1255 | const LiveVarSet *LVSetAft = PRA.LVI->getLiveVarSetAfterMInst(MInst, BB); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1256 | LiveVarSet::const_iterator LIt = LVSetAft->begin(); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1257 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1258 | // for each live var in live variable set after machine inst |
| 1259 | for( ; LIt != LVSetAft->end(); ++LIt) { |
| 1260 | |
| 1261 | // get the live range corresponding to live var |
| 1262 | LiveRange *const LR = PRA.LRI.getLiveRangeForValue(*LIt ); |
| 1263 | |
| 1264 | // LR can be null if it is a const since a const |
| 1265 | // doesn't have a dominating def - see Assumptions above |
| 1266 | if( LR ) { |
| 1267 | |
| 1268 | if( LR->hasColor() ) { |
| 1269 | |
| 1270 | unsigned RCID = (LR->getRegClass())->getID(); |
| 1271 | unsigned Color = LR->getColor(); |
| 1272 | |
| 1273 | if ( isRegVolatile(RCID, Color) ) { |
| 1274 | |
| 1275 | // if the value is in both LV sets (i.e., live before and after |
| 1276 | // the call machine instruction) |
| 1277 | |
| 1278 | unsigned Reg = getUnifiedRegNum(RCID, Color); |
| 1279 | |
| 1280 | if( PushedRegSet.find(Reg) == PushedRegSet.end() ) { |
| 1281 | |
| 1282 | // if we haven't already pushed that register |
| 1283 | |
| 1284 | unsigned RegType = getRegType( LR ); |
| 1285 | |
| 1286 | // Now get two instructions - to push on stack and pop from stack |
| 1287 | // and add them to InstrnsBefore and InstrnsAfter of the |
| 1288 | // call instruction |
| 1289 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 1290 | |
| 1291 | int StackOff = PRA.mcInfo.pushTempValue(target, |
| 1292 | getSpilledRegSize(RegType)); |
| 1293 | |
Vikram S. Adve | 1c0fba6 | 2001-11-08 04:56:41 +0000 | [diff] [blame] | 1294 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1295 | MachineInstr *AdIBefCC, *AdIAftCC, *AdICpCC; |
Vikram S. Adve | 9576b15 | 2001-11-06 05:01:54 +0000 | [diff] [blame] | 1296 | MachineInstr *AdIBef, *AdIAft; |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1297 | |
| 1298 | |
| 1299 | //---- Insert code for pushing the reg on stack ---------- |
| 1300 | |
| 1301 | if( RegType == IntCCRegType ) { |
| 1302 | |
| 1303 | // Handle IntCCRegType specially since we cannot directly |
| 1304 | // push %ccr on to the stack |
| 1305 | |
| 1306 | const LiveVarSet *LVSetBef = |
| 1307 | PRA.LVI->getLiveVarSetBeforeMInst(MInst, BB); |
| 1308 | |
| 1309 | // get a free INTEGER register |
| 1310 | int FreeIntReg = |
Ruchira Sasanka | 295264d | 2001-11-15 20:25:07 +0000 | [diff] [blame] | 1311 | PRA.getUsableUniRegAtMI(LR->getRegClass(), IntRegType, MInst, |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1312 | LVSetBef, AdIBefCC, AdIAftCC); |
| 1313 | |
| 1314 | // insert the instructions in reverse order since we are |
| 1315 | // adding them to the front of InstrnsBefore |
| 1316 | |
| 1317 | if(AdIAftCC) |
| 1318 | (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdIAftCC); |
| 1319 | |
| 1320 | AdICpCC = cpCCR2IntMI(FreeIntReg); |
| 1321 | (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdICpCC); |
| 1322 | |
| 1323 | if(AdIBefCC) |
| 1324 | (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdIBefCC); |
| 1325 | |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1326 | if(DEBUG_RA) { |
| 1327 | cerr << "\n!! Inserted caller saving (push) inst for %ccr:"; |
| 1328 | if(AdIBefCC) cerr << "\t" << *(AdIBefCC); |
| 1329 | cerr << "\t" << *AdICpCC; |
| 1330 | if(AdIAftCC) cerr << "\t" << *(AdIAftCC); |
| 1331 | } |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1332 | |
| 1333 | } else { |
| 1334 | // for any other register type, just add the push inst |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1335 | AdIBef = cpReg2MemMI(Reg, getFramePointer(), StackOff, RegType ); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1336 | ((PRA.AddedInstrMap[MInst])->InstrnsBefore).push_front(AdIBef); |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | //---- Insert code for popping the reg from the stack ---------- |
| 1341 | |
| 1342 | if( RegType == IntCCRegType ) { |
| 1343 | |
| 1344 | // Handle IntCCRegType specially since we cannot directly |
| 1345 | // pop %ccr on from the stack |
| 1346 | |
| 1347 | // get a free INT register |
| 1348 | int FreeIntReg = |
Ruchira Sasanka | 295264d | 2001-11-15 20:25:07 +0000 | [diff] [blame] | 1349 | PRA.getUsableUniRegAtMI(LR->getRegClass(), IntRegType, MInst, |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1350 | LVSetAft, AdIBefCC, AdIAftCC); |
| 1351 | |
| 1352 | if(AdIBefCC) |
| 1353 | (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdIBefCC); |
| 1354 | |
| 1355 | AdICpCC = cpInt2CCRMI(FreeIntReg); |
| 1356 | (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdICpCC); |
| 1357 | |
| 1358 | if(AdIAftCC) |
| 1359 | (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdIAftCC); |
| 1360 | |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1361 | if(DEBUG_RA) { |
| 1362 | |
| 1363 | cerr << "\n!! Inserted caller saving (pop) inst for %ccr:"; |
| 1364 | if(AdIBefCC) cerr << "\t" << *(AdIBefCC); |
| 1365 | cerr << "\t" << *AdICpCC; |
| 1366 | if(AdIAftCC) cerr << "\t" << *(AdIAftCC); |
| 1367 | } |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1368 | |
| 1369 | } else { |
| 1370 | // for any other register type, just add the pop inst |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1371 | AdIAft = cpMem2RegMI(getFramePointer(), StackOff, Reg, RegType ); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1372 | ((PRA.AddedInstrMap[MInst])->InstrnsAfter).push_back(AdIAft); |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1373 | } |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1374 | |
| 1375 | PushedRegSet.insert( Reg ); |
| 1376 | |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1377 | if(DEBUG_RA) { |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1378 | cerr << "\nFor call inst:" << *MInst; |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1379 | cerr << " -inserted caller saving instrs:\n\t "; |
Vikram S. Adve | 9576b15 | 2001-11-06 05:01:54 +0000 | [diff] [blame] | 1380 | if( RegType == IntCCRegType ) |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1381 | cerr << *AdIBefCC << "\t" << *AdIAftCC ; |
Vikram S. Adve | 9576b15 | 2001-11-06 05:01:54 +0000 | [diff] [blame] | 1382 | else |
Ruchira Sasanka | aa12a78 | 2001-11-10 00:26:55 +0000 | [diff] [blame] | 1383 | cerr << *AdIBef << "\t" << *AdIAft ; |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1384 | } |
| 1385 | } // if not already pushed |
| 1386 | |
| 1387 | } // if LR has a volatile color |
| 1388 | |
| 1389 | } // if LR has color |
| 1390 | |
| 1391 | } // if there is a LR for Var |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1392 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1393 | } // for each value in the LV set after instruction |
| 1394 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1397 | //--------------------------------------------------------------------------- |
| 1398 | // Copies %ccr into an integer register. IntReg is the UNIFIED register |
| 1399 | // number. |
| 1400 | //--------------------------------------------------------------------------- |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1401 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1402 | MachineInstr * UltraSparcRegInfo::cpCCR2IntMI(unsigned IntReg) const { |
| 1403 | MachineInstr * MI = new MachineInstr(RDCCR, 2); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1404 | MI->SetMachineOperand(0, SparcIntCCRegOrder::ccr, false); |
| 1405 | MI->SetMachineOperand(1, IntReg, true); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1406 | return MI; |
| 1407 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1408 | |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1409 | //--------------------------------------------------------------------------- |
| 1410 | // Copies an integer register into %ccr. IntReg is the UNIFIED register |
| 1411 | // number. |
| 1412 | //--------------------------------------------------------------------------- |
| 1413 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1414 | MachineInstr *UltraSparcRegInfo::cpInt2CCRMI(unsigned IntReg) const { |
| 1415 | MachineInstr *MI = new MachineInstr(WRCCR, 3); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1416 | MI->SetMachineOperand(0, IntReg, false); |
| 1417 | MI->SetMachineOperand(1, SparcIntRegOrder::g0, false); |
| 1418 | MI->SetMachineOperand(2, SparcIntCCRegOrder::ccr, true); |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 1419 | return MI; |
| 1420 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 1421 | |
| 1422 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 1423 | |
| 1424 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1425 | //--------------------------------------------------------------------------- |
| 1426 | // Print the register assigned to a LR |
| 1427 | //--------------------------------------------------------------------------- |
| 1428 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1429 | void UltraSparcRegInfo::printReg(const LiveRange *LR) { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1430 | unsigned RegClassID = (LR->getRegClass())->getID(); |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1431 | cerr << " *Node " << (LR->getUserIGNode())->getIndex(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1432 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1433 | if (!LR->hasColor()) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1434 | cerr << " - could not find a color\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1435 | return; |
| 1436 | } |
| 1437 | |
| 1438 | // if a color is found |
| 1439 | |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1440 | cerr << " colored with color "<< LR->getColor(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1441 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1442 | if (RegClassID == IntRegClassID) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1443 | cerr<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) << "]\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1444 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1445 | } else if (RegClassID == FloatRegClassID) { |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1446 | cerr << "[" << SparcFloatRegOrder::getRegName(LR->getColor()); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1447 | if( LR->getTypeID() == Type::DoubleTyID ) |
Chris Lattner | 1e23ed7 | 2001-10-15 18:15:27 +0000 | [diff] [blame] | 1448 | cerr << "+" << SparcFloatRegOrder::getRegName(LR->getColor()+1); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1449 | cerr << "]\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1450 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 1451 | } |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1452 | |
| 1453 | //--------------------------------------------------------------------------- |
| 1454 | // This method examines instructions inserted by RegAlloc code before a |
| 1455 | // machine instruction to detect invalid orders that destroy values before |
| 1456 | // they are used. If it detects such conditions, it reorders the instructions. |
| 1457 | // |
| 1458 | // The unordered instructions come in the UnordVec. These instructions are |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1459 | // instructions inserted by RegAlloc. All such instruction MUST have |
| 1460 | // their USES BEFORE THE DEFS after reordering. |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1461 | |
| 1462 | // The UnordVec & OrdVec must be DISTINCT. The OrdVec must be empty when |
| 1463 | // this method is called. |
| 1464 | |
| 1465 | // This method uses two vectors for efficiency in accessing |
| 1466 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1467 | // Since instructions are inserted in RegAlloc, this assumes that the |
| 1468 | // first operand is the source reg and the last operand is the dest reg. |
| 1469 | |
| 1470 | // All the uses are before THE def to a register |
| 1471 | |
| 1472 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1473 | //--------------------------------------------------------------------------- |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1474 | void UltraSparcRegInfo::OrderAddedInstrns(std::vector<MachineInstr *> &UnordVec, |
| 1475 | std::vector<MachineInstr *> &OrdVec, |
| 1476 | PhyRegAlloc &PRA) const{ |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1477 | |
| 1478 | /* |
| 1479 | Problem: We can have instructions inserted by RegAlloc like |
| 1480 | 1. add %ox %g0 %oy |
| 1481 | 2. add %oy %g0 %oz, where z!=x or z==x |
| 1482 | |
| 1483 | This is wrong since %oy used by 2 is overwritten by 1 |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1484 | |
| 1485 | Solution: |
| 1486 | 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] | 1487 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1488 | Algorithm: |
| 1489 | |
| 1490 | do |
| 1491 | for each instruction 'DefInst' in the UnOrdVec |
| 1492 | for each instruction 'UseInst' that follows the DefInst |
| 1493 | if the reg defined by DefInst is used by UseInst |
| 1494 | mark DefInst as not movable in this iteration |
| 1495 | If DefInst is not marked as not-movable, move DefInst to OrdVec |
| 1496 | while all instructions in DefInst are moved to OrdVec |
| 1497 | |
| 1498 | For moving, we call the move2OrdVec(). It checks whether there is a def |
| 1499 | in it for the uses in the instruction to be added to OrdVec. If there |
| 1500 | are no preceding defs, it just appends the instruction. If there is a |
| 1501 | preceding def, it puts two instructions to save the reg on stack before |
| 1502 | the load and puts a restore at use. |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1503 | |
| 1504 | */ |
| 1505 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1506 | bool CouldMoveAll; |
| 1507 | bool DebugPrint = false; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1508 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1509 | do { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1510 | CouldMoveAll = true; |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1511 | std::vector<MachineInstr *>::iterator DefIt = UnordVec.begin(); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1512 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1513 | for( ; DefIt != UnordVec.end(); ++DefIt ) { |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1514 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1515 | // for each instruction in the UnordVec do ... |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1516 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1517 | MachineInstr *DefInst = *DefIt; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1518 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1519 | if( DefInst == NULL) continue; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1520 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1521 | //cerr << "\nInst in UnordVec = " << *DefInst; |
| 1522 | |
| 1523 | // last operand is the def (unless for a store which has no def reg) |
| 1524 | MachineOperand& DefOp = DefInst->getOperand(DefInst->getNumOperands()-1); |
| 1525 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1526 | if( DefOp.opIsDef() && |
| 1527 | DefOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1528 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1529 | // If the operand in DefInst is a def ... |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1530 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1531 | bool DefEqUse = false; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1532 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1533 | std::vector<MachineInstr *>::iterator UseIt = DefIt; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1534 | UseIt++; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1535 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1536 | for( ; UseIt != UnordVec.end(); ++UseIt ) { |
| 1537 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1538 | MachineInstr *UseInst = *UseIt; |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1539 | if( UseInst == NULL) continue; |
| 1540 | |
| 1541 | // for each inst (UseInst) that is below the DefInst do ... |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1542 | MachineOperand& UseOp = UseInst->getOperand(0); |
| 1543 | |
| 1544 | if( ! UseOp.opIsDef() && |
| 1545 | UseOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
| 1546 | |
| 1547 | // if use is a register ... |
| 1548 | |
| 1549 | if( DefOp.getMachineRegNum() == UseOp.getMachineRegNum() ) { |
| 1550 | |
| 1551 | // if Def and this use are the same, it means that this use |
| 1552 | // is destroyed by a def before it is used |
| 1553 | |
| 1554 | // cerr << "\nCouldn't move " << *DefInst; |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1555 | |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1556 | DefEqUse = true; |
| 1557 | CouldMoveAll = false; |
| 1558 | DebugPrint = true; |
| 1559 | break; |
| 1560 | } // if two registers are equal |
| 1561 | |
| 1562 | } // if use is a register |
| 1563 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1564 | }// for all use instructions |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1565 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1566 | if( ! DefEqUse ) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1567 | |
| 1568 | // after examining all the instructions that follow the DefInst |
| 1569 | // if there are no dependencies, we can move it to the OrdVec |
| 1570 | |
| 1571 | // cerr << "Moved to Ord: " << *DefInst; |
| 1572 | |
| 1573 | moveInst2OrdVec(OrdVec, DefInst, PRA); |
| 1574 | |
| 1575 | //OrdVec.push_back(DefInst); |
| 1576 | |
| 1577 | // mark the pos of DefInst with NULL to indicate that it is |
| 1578 | // empty |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1579 | *DefIt = NULL; |
| 1580 | } |
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 Def is a machine register |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1583 | |
| 1584 | } // for all instructions in the UnordVec |
| 1585 | |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1586 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1587 | } while(!CouldMoveAll); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1588 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1589 | if (DebugPrint) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1590 | cerr << "\nAdded instructions were reordered to:\n"; |
| 1591 | for(unsigned int i=0; i < OrdVec.size(); i++) |
| 1592 | cerr << *(OrdVec[i]); |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1593 | } |
Ruchira Sasanka | 868cf82 | 2001-11-09 23:49:14 +0000 | [diff] [blame] | 1594 | } |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1600 | void UltraSparcRegInfo::moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec, |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1601 | MachineInstr *UnordInst, |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1602 | PhyRegAlloc &PRA) const { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1603 | MachineOperand& UseOp = UnordInst->getOperand(0); |
| 1604 | |
| 1605 | if( ! UseOp.opIsDef() && |
| 1606 | UseOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
| 1607 | |
| 1608 | // for the use of UnordInst, see whether there is a defining instr |
| 1609 | // before in the OrdVec |
| 1610 | bool DefEqUse = false; |
| 1611 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1612 | std::vector<MachineInstr *>::iterator OrdIt = OrdVec.begin(); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1613 | |
| 1614 | for( ; OrdIt != OrdVec.end(); ++OrdIt ) { |
| 1615 | |
| 1616 | MachineInstr *OrdInst = *OrdIt ; |
| 1617 | |
| 1618 | MachineOperand& DefOp = |
| 1619 | OrdInst->getOperand(OrdInst->getNumOperands()-1); |
| 1620 | |
| 1621 | if( DefOp.opIsDef() && |
| 1622 | DefOp.getOperandType() == MachineOperand::MO_MachineRegister) { |
| 1623 | |
| 1624 | //cerr << "\nDefining Ord Inst: " << *OrdInst; |
| 1625 | |
| 1626 | if( DefOp.getMachineRegNum() == UseOp.getMachineRegNum() ) { |
| 1627 | |
| 1628 | // we are here because there is a preceding def in the OrdVec |
| 1629 | // for the use in this intr we are going to insert. This |
| 1630 | // happened because the original code was like: |
| 1631 | // 1. add %ox %g0 %oy |
| 1632 | // 2. add %oy %g0 %ox |
| 1633 | // In Round1, we added 2 to OrdVec but 1 remained in UnordVec |
| 1634 | // Now we are processing %ox of 1. |
| 1635 | // We have to |
| 1636 | |
| 1637 | const int UReg = DefOp.getMachineRegNum(); |
| 1638 | const int RegType = getRegType(UReg); |
| 1639 | MachineInstr *AdIBef, *AdIAft; |
| 1640 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 1641 | const int StackOff = PRA.mcInfo.pushTempValue(target, |
| 1642 | getSpilledRegSize(RegType)); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1643 | |
| 1644 | // Save the UReg (%ox) on stack before it's destroyed |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1645 | AdIBef=cpReg2MemMI(UReg, getFramePointer(), StackOff, RegType); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1646 | OrdIt = OrdVec.insert( OrdIt, AdIBef); |
| 1647 | OrdIt++; // points to current instr we processed |
| 1648 | |
| 1649 | // Load directly into DReg (%oy) |
| 1650 | MachineOperand& DOp= |
| 1651 | (UnordInst->getOperand(UnordInst->getNumOperands()-1)); |
| 1652 | assert(DOp.opIsDef() && "Last operand is not the def"); |
| 1653 | const int DReg = DOp.getMachineRegNum(); |
| 1654 | |
Ruchira Sasanka | 6beb013 | 2001-11-11 21:49:37 +0000 | [diff] [blame] | 1655 | AdIAft=cpMem2RegMI(getFramePointer(), StackOff, DReg, RegType); |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1656 | OrdVec.push_back(AdIAft); |
| 1657 | |
| 1658 | cerr << "\nFixed CIRCULAR references by reordering"; |
| 1659 | |
| 1660 | if( DEBUG_RA ) { |
| 1661 | cerr << "\nBefore CIRCULAR Reordering:\n"; |
| 1662 | cerr << *UnordInst; |
| 1663 | cerr << *OrdInst; |
| 1664 | |
| 1665 | cerr << "\nAfter CIRCULAR Reordering - All Inst so far:\n"; |
| 1666 | for(unsigned i=0; i < OrdVec.size(); i++) |
| 1667 | cerr << *(OrdVec[i]); |
| 1668 | } |
| 1669 | |
| 1670 | // Do not copy the UseInst to OrdVec |
| 1671 | DefEqUse = true; |
| 1672 | break; |
| 1673 | |
| 1674 | }// if two registers are equal |
| 1675 | |
| 1676 | } // if Def is a register |
| 1677 | |
| 1678 | } // for each instr in OrdVec |
| 1679 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 1680 | if(!DefEqUse) { |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1681 | |
| 1682 | // We didn't find a def in the OrdVec, so just append this inst |
| 1683 | OrdVec.push_back( UnordInst ); |
| 1684 | //cerr << "Reordered Inst (Moved Dn): " << *UnordInst; |
| 1685 | } |
| 1686 | |
| 1687 | }// if the operand in UnordInst is a use |
Ruchira Sasanka | ae4bcd7 | 2001-11-10 21:20:43 +0000 | [diff] [blame] | 1688 | } |