Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 1 | //===-- SparcInternals.h ----------------------------------------*- C++ -*-===// |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 3 | // This file defines stuff that is to be private to the Sparc backend, but is |
| 4 | // shared among different portions of the backend. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 7 | |
| 8 | #ifndef SPARC_INTERNALS_H |
| 9 | #define SPARC_INTERNALS_H |
| 10 | |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 12 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | d0f166a | 2002-12-29 03:13:05 +0000 | [diff] [blame] | 13 | #include "llvm/Target/TargetSchedInfo.h" |
Chris Lattner | 8bd66e6 | 2002-12-28 21:00:25 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | dde1262 | 2002-12-29 02:50:33 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetCacheInfo.h" |
Chris Lattner | d0f166a | 2002-12-29 03:13:05 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetRegInfo.h" |
Chris Lattner | dde1262 | 2002-12-29 02:50:33 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetOptInfo.h" |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 18 | #include "llvm/Type.h" |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 19 | #include "SparcRegClassInfo.h" |
John Criswell | 7a73b80 | 2003-06-30 21:59:07 +0000 | [diff] [blame] | 20 | #include "Config/sys/types.h" |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 4387e31 | 2002-02-03 23:42:19 +0000 | [diff] [blame] | 22 | class LiveRange; |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 23 | class UltraSparc; |
Chris Lattner | 9aa697b | 2002-04-09 05:16:36 +0000 | [diff] [blame] | 24 | class Pass; |
Chris Lattner | 4387e31 | 2002-02-03 23:42:19 +0000 | [diff] [blame] | 25 | |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 26 | enum SparcInstrSchedClass { |
| 27 | SPARC_NONE, /* Instructions with no scheduling restrictions */ |
| 28 | SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */ |
| 29 | SPARC_IEU0, /* Integer class IEU0 */ |
| 30 | SPARC_IEU1, /* Integer class IEU1 */ |
| 31 | SPARC_FPM, /* FP Multiply or Divide instructions */ |
| 32 | SPARC_FPA, /* All other FP instructions */ |
| 33 | SPARC_CTI, /* Control-transfer instructions */ |
| 34 | SPARC_LD, /* Load instructions */ |
| 35 | SPARC_ST, /* Store instructions */ |
| 36 | SPARC_SINGLE, /* Instructions that must issue by themselves */ |
| 37 | |
| 38 | SPARC_INV, /* This should stay at the end for the next value */ |
| 39 | SPARC_NUM_SCHED_CLASSES = SPARC_INV |
| 40 | }; |
| 41 | |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 42 | |
| 43 | //--------------------------------------------------------------------------- |
| 44 | // enum SparcMachineOpCode. |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 45 | // const TargetInstrDescriptor SparcMachineInstrDesc[] |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 46 | // |
| 47 | // Purpose: |
| 48 | // Description of UltraSparc machine instructions. |
| 49 | // |
| 50 | //--------------------------------------------------------------------------- |
| 51 | |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 52 | namespace V9 { |
| 53 | enum SparcMachineOpCode { |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 54 | #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
| 55 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \ |
| 56 | ENUM, |
| 57 | #include "SparcInstr.def" |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 58 | |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 59 | // End-of-array marker |
| 60 | INVALID_OPCODE, |
| 61 | NUM_REAL_OPCODES = PHI, // number of valid opcodes |
| 62 | NUM_TOTAL_OPCODES = INVALID_OPCODE |
| 63 | }; |
| 64 | } |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 65 | |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 66 | |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 67 | // Array of machine instruction descriptions... |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 68 | extern const TargetInstrDescriptor SparcMachineInstrDesc[]; |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | //--------------------------------------------------------------------------- |
| 72 | // class UltraSparcInstrInfo |
| 73 | // |
| 74 | // Purpose: |
| 75 | // Information about individual instructions. |
| 76 | // Most information is stored in the SparcMachineInstrDesc array above. |
| 77 | // Other information is computed on demand, and most such functions |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 78 | // default to member functions in base class TargetInstrInfo. |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 79 | //--------------------------------------------------------------------------- |
| 80 | |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 81 | struct UltraSparcInstrInfo : public TargetInstrInfo { |
Chris Lattner | 047bbaf | 2002-10-29 15:45:20 +0000 | [diff] [blame] | 82 | UltraSparcInstrInfo(); |
Vikram S. Adve | 4c5fe2d | 2001-11-14 18:48:36 +0000 | [diff] [blame] | 83 | |
| 84 | // |
Vikram S. Adve | dd55899 | 2002-03-18 03:02:42 +0000 | [diff] [blame] | 85 | // All immediate constants are in position 1 except the |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 86 | // store instructions and SETxx. |
Vikram S. Adve | 4c5fe2d | 2001-11-14 18:48:36 +0000 | [diff] [blame] | 87 | // |
Vikram S. Adve | dd55899 | 2002-03-18 03:02:42 +0000 | [diff] [blame] | 88 | virtual int getImmedConstantPos(MachineOpCode opCode) const { |
Vikram S. Adve | 4c5fe2d | 2001-11-14 18:48:36 +0000 | [diff] [blame] | 89 | bool ignore; |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 90 | if (this->maxImmedConstant(opCode, ignore) != 0) { |
| 91 | // 1st store opcode |
Misha Brukman | 3c4cf15 | 2003-05-27 22:44:44 +0000 | [diff] [blame] | 92 | assert(! this->isStore((MachineOpCode) V9::STBr - 1)); |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 93 | // last store opcode |
Misha Brukman | 3c4cf15 | 2003-05-27 22:44:44 +0000 | [diff] [blame] | 94 | assert(! this->isStore((MachineOpCode) V9::STXFSRi + 1)); |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 95 | |
| 96 | if (opCode == V9::SETSW || opCode == V9::SETUW || |
| 97 | opCode == V9::SETX || opCode == V9::SETHI) |
| 98 | return 0; |
Misha Brukman | 3c4cf15 | 2003-05-27 22:44:44 +0000 | [diff] [blame] | 99 | if (opCode >= V9::STBr && opCode <= V9::STXFSRi) |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 100 | return 2; |
| 101 | return 1; |
| 102 | } |
Vikram S. Adve | 4c5fe2d | 2001-11-14 18:48:36 +0000 | [diff] [blame] | 103 | else |
| 104 | return -1; |
| 105 | } |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 106 | |
| 107 | /// createNOPinstr - returns the target's implementation of NOP, which is |
| 108 | /// usually a pseudo-instruction, implemented by a degenerate version of |
Misha Brukman | 79caf1f | 2003-05-27 22:01:10 +0000 | [diff] [blame] | 109 | /// another instruction, e.g. X86: xchg ax, ax; SparcV9: sethi 0, g0 |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 110 | /// |
| 111 | MachineInstr* createNOPinstr() const { |
Misha Brukman | 79caf1f | 2003-05-27 22:01:10 +0000 | [diff] [blame] | 112 | return BuildMI(V9::SETHI, 2).addZImm(0).addReg(SparcIntRegClass::g0); |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Misha Brukman | 12745c5 | 2003-05-24 01:08:43 +0000 | [diff] [blame] | 115 | /// isNOPinstr - not having a special NOP opcode, we need to know if a given |
| 116 | /// instruction is interpreted as an `official' NOP instr, i.e., there may be |
| 117 | /// more than one way to `do nothing' but only one canonical way to slack off. |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 118 | /// |
| 119 | bool isNOPinstr(const MachineInstr &MI) const { |
| 120 | // Make sure the instruction is EXACTLY `sethi g0, 0' |
| 121 | if (MI.getOpcode() == V9::SETHI && MI.getNumOperands() == 2) { |
| 122 | const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1); |
Misha Brukman | 79caf1f | 2003-05-27 22:01:10 +0000 | [diff] [blame] | 123 | if (op0.isImmediate() && op0.getImmedValue() == 0 && |
| 124 | op1.isMachineRegister() && |
| 125 | op1.getMachineRegNum() == SparcIntRegClass::g0) |
Misha Brukman | e9d8838 | 2003-05-24 00:09:50 +0000 | [diff] [blame] | 126 | { |
| 127 | return true; |
| 128 | } |
| 129 | } |
| 130 | return false; |
| 131 | } |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 132 | |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 133 | virtual bool hasResultInterlock(MachineOpCode opCode) const |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 134 | { |
| 135 | // All UltraSPARC instructions have interlocks (note that delay slots |
| 136 | // are not considered here). |
| 137 | // However, instructions that use the result of an FCMP produce a |
| 138 | // 9-cycle stall if they are issued less than 3 cycles after the FCMP. |
| 139 | // Force the compiler to insert a software interlock (i.e., gap of |
| 140 | // 2 other groups, including NOPs if necessary). |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 141 | return (opCode == V9::FCMPS || opCode == V9::FCMPD || opCode == V9::FCMPQ); |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Vikram S. Adve | 5684c4e | 2001-10-18 00:02:06 +0000 | [diff] [blame] | 144 | //------------------------------------------------------------------------- |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 145 | // Queries about representation of LLVM quantities (e.g., constants) |
| 146 | //------------------------------------------------------------------------- |
| 147 | |
| 148 | virtual bool ConstantMayNotFitInImmedField(const Constant* CV, |
| 149 | const Instruction* I) const; |
| 150 | |
| 151 | //------------------------------------------------------------------------- |
Vikram S. Adve | 5684c4e | 2001-10-18 00:02:06 +0000 | [diff] [blame] | 152 | // Code generation support for creating individual machine instructions |
| 153 | //------------------------------------------------------------------------- |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 154 | |
| 155 | // Get certain common op codes for the current target. This and all the |
| 156 | // Create* methods below should be moved to a machine code generation class |
| 157 | // |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 158 | virtual MachineOpCode getNOPOpCode() const { return V9::NOP; } |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 159 | |
Vikram S. Adve | ada280f | 2003-07-29 19:54:41 +0000 | [diff] [blame] | 160 | // Get the value of an integral constant in the form that must |
| 161 | // be put into the machine register. The specified constant is interpreted |
| 162 | // as (i.e., converted if necessary to) the specified destination type. The |
| 163 | // result is always returned as an uint64_t, since the representation of |
| 164 | // int64_t and uint64_t are identical. The argument can be any known const. |
| 165 | // |
| 166 | // isValidConstant is set to true if a valid constant was found. |
| 167 | // |
| 168 | virtual uint64_t ConvertConstantToIntType(const TargetMachine &target, |
| 169 | const Value *V, |
| 170 | const Type *destType, |
| 171 | bool &isValidConstant) const; |
| 172 | |
Vikram S. Adve | 5684c4e | 2001-10-18 00:02:06 +0000 | [diff] [blame] | 173 | // Create an instruction sequence to put the constant `val' into |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 174 | // the virtual register `dest'. `val' may be a Constant or a |
| 175 | // GlobalValue, viz., the constant address of a global variable or function. |
| 176 | // The generated instructions are returned in `mvec'. |
| 177 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
| 178 | // Any stack space required is allocated via mcff. |
Vikram S. Adve | 5684c4e | 2001-10-18 00:02:06 +0000 | [diff] [blame] | 179 | // |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 180 | virtual void CreateCodeToLoadConst(const TargetMachine& target, |
| 181 | Function* F, |
Vikram S. Adve | dd55899 | 2002-03-18 03:02:42 +0000 | [diff] [blame] | 182 | Value* val, |
Vikram S. Adve | 5684c4e | 2001-10-18 00:02:06 +0000 | [diff] [blame] | 183 | Instruction* dest, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 184 | std::vector<MachineInstr*>& mvec, |
| 185 | MachineCodeForInstruction& mcfi) const; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 186 | |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 187 | // Create an instruction sequence to copy an integer value `val' |
| 188 | // to a floating point value `dest' by copying to memory and back. |
| 189 | // val must be an integral type. dest must be a Float or Double. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 190 | // The generated instructions are returned in `mvec'. |
| 191 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
| 192 | // Any stack space required is allocated via mcff. |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 193 | // |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 194 | virtual void CreateCodeToCopyIntToFloat(const TargetMachine& target, |
| 195 | Function* F, |
| 196 | Value* val, |
| 197 | Instruction* dest, |
| 198 | std::vector<MachineInstr*>& mvec, |
| 199 | MachineCodeForInstruction& mcfi) const; |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 200 | |
| 201 | // Similarly, create an instruction sequence to copy an FP value |
| 202 | // `val' to an integer value `dest' by copying to memory and back. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 203 | // The generated instructions are returned in `mvec'. |
| 204 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
| 205 | // Any stack space required is allocated via mcff. |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 206 | // |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 207 | virtual void CreateCodeToCopyFloatToInt(const TargetMachine& target, |
| 208 | Function* F, |
| 209 | Value* val, |
| 210 | Instruction* dest, |
| 211 | std::vector<MachineInstr*>& mvec, |
| 212 | MachineCodeForInstruction& mcfi) const; |
| 213 | |
| 214 | // Create instruction(s) to copy src to dest, for arbitrary types |
| 215 | // The generated instructions are returned in `mvec'. |
| 216 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
| 217 | // Any stack space required is allocated via mcff. |
| 218 | // |
Vikram S. Adve | dd55899 | 2002-03-18 03:02:42 +0000 | [diff] [blame] | 219 | virtual void CreateCopyInstructionsByType(const TargetMachine& target, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 220 | Function* F, |
| 221 | Value* src, |
| 222 | Instruction* dest, |
| 223 | std::vector<MachineInstr*>& mvec, |
| 224 | MachineCodeForInstruction& mcfi) const; |
| 225 | |
| 226 | // Create instruction sequence to produce a sign-extended register value |
| 227 | // from an arbitrary sized value (sized in bits, not bytes). |
Vikram S. Adve | f36f06b | 2002-09-05 18:34:31 +0000 | [diff] [blame] | 228 | // The generated instructions are appended to `mvec'. |
| 229 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 230 | // Any stack space required is allocated via mcff. |
| 231 | // |
| 232 | virtual void CreateSignExtensionInstructions(const TargetMachine& target, |
| 233 | Function* F, |
Vikram S. Adve | f36f06b | 2002-09-05 18:34:31 +0000 | [diff] [blame] | 234 | Value* srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 235 | Value* destVal, |
| 236 | unsigned int numLowBits, |
Vikram S. Adve | f36f06b | 2002-09-05 18:34:31 +0000 | [diff] [blame] | 237 | std::vector<MachineInstr*>& mvec, |
| 238 | MachineCodeForInstruction& mcfi) const; |
| 239 | |
| 240 | // Create instruction sequence to produce a zero-extended register value |
| 241 | // from an arbitrary sized value (sized in bits, not bytes). |
| 242 | // The generated instructions are appended to `mvec'. |
| 243 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
| 244 | // Any stack space required is allocated via mcff. |
| 245 | // |
| 246 | virtual void CreateZeroExtensionInstructions(const TargetMachine& target, |
| 247 | Function* F, |
| 248 | Value* srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 249 | Value* destVal, |
| 250 | unsigned int numLowBits, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 251 | std::vector<MachineInstr*>& mvec, |
| 252 | MachineCodeForInstruction& mcfi) const; |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 255 | |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 256 | //---------------------------------------------------------------------------- |
| 257 | // class UltraSparcRegInfo |
| 258 | // |
Chris Lattner | d0f166a | 2002-12-29 03:13:05 +0000 | [diff] [blame] | 259 | // This class implements the virtual class TargetRegInfo for Sparc. |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 260 | // |
Ruchira Sasanka | 20c82b1 | 2001-10-28 18:15:12 +0000 | [diff] [blame] | 261 | //---------------------------------------------------------------------------- |
| 262 | |
Chris Lattner | d0f166a | 2002-12-29 03:13:05 +0000 | [diff] [blame] | 263 | class UltraSparcRegInfo : public TargetRegInfo { |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 264 | |
Vikram S. Adve | 46d3f8e | 2003-07-06 19:53:59 +0000 | [diff] [blame] | 265 | private: |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 266 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 267 | // Number of registers used for passing int args (usually 6: %o0 - %o5) |
| 268 | // |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 269 | unsigned const NumOfIntArgRegs; |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 270 | |
| 271 | // Number of registers used for passing float args (usually 32: %f0 - %f31) |
| 272 | // |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 273 | unsigned const NumOfFloatArgRegs; |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 274 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 275 | // ======================== Private Methods ============================= |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 276 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 277 | // The following methods are used to color special live ranges (e.g. |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 278 | // function args and return values etc.) with specific hardware registers |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 279 | // as required. See SparcRegInfo.cpp for the implementation. |
| 280 | // |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 281 | void suggestReg4RetAddr(MachineInstr *RetMI, |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 282 | LiveRangeInfo &LRI) const; |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 283 | |
Vikram S. Adve | 106604e | 2002-09-28 16:56:59 +0000 | [diff] [blame] | 284 | void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI) const; |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 285 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 286 | // Helper used by the all the getRegType() functions. |
Vikram S. Adve | 78a4f23 | 2003-05-27 00:02:22 +0000 | [diff] [blame] | 287 | int getRegTypeForClassAndType(unsigned regClassID, const Type* type) const; |
Ruchira Sasanka | 3839e6e | 2001-11-03 19:59:59 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 289 | public: |
Misha Brukman | d3d97be | 2003-05-30 20:12:42 +0000 | [diff] [blame] | 290 | // Type of registers available in Sparc. There can be several reg types |
| 291 | // in the same class. For instace, the float reg class has Single/Double |
| 292 | // types |
| 293 | // |
| 294 | enum RegTypes { |
| 295 | IntRegType, |
| 296 | FPSingleRegType, |
| 297 | FPDoubleRegType, |
| 298 | IntCCRegType, |
| 299 | FloatCCRegType, |
| 300 | SpecialRegType |
| 301 | }; |
| 302 | |
Misha Brukman | de11f2d | 2003-07-07 16:52:39 +0000 | [diff] [blame] | 303 | // The actual register classes in the Sparc |
| 304 | // |
| 305 | // **** WARNING: If this enum order is changed, also modify |
| 306 | // getRegisterClassOfValue method below since it assumes this particular |
| 307 | // order for efficiency. |
| 308 | // |
| 309 | enum RegClassIDs { |
| 310 | IntRegClassID, // Integer |
| 311 | FloatRegClassID, // Float (both single/double) |
| 312 | IntCCRegClassID, // Int Condition Code |
| 313 | FloatCCRegClassID, // Float Condition code |
| 314 | SpecialRegClassID // Special (unallocated) registers |
| 315 | }; |
| 316 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 317 | UltraSparcRegInfo(const UltraSparc &tgt); |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 318 | |
Vikram S. Adve | dd55899 | 2002-03-18 03:02:42 +0000 | [diff] [blame] | 319 | // To find the register class used for a specified Type |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 320 | // |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 321 | unsigned getRegClassIDOfType(const Type *type, |
| 322 | bool isCCReg = false) const; |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 323 | |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 324 | // To find the register class to which a specified register belongs |
| 325 | // |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 326 | unsigned getRegClassIDOfRegType(int regType) const; |
Vikram S. Adve | dd55899 | 2002-03-18 03:02:42 +0000 | [diff] [blame] | 327 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 328 | // getZeroRegNum - returns the register that contains always zero this is the |
| 329 | // unified register number |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 330 | // |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 331 | virtual int getZeroRegNum() const; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 332 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 333 | // getCallAddressReg - returns the reg used for pushing the address when a |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 334 | // function is called. This can be used for other purposes between calls |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 335 | // |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 336 | unsigned getCallAddressReg() const; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 337 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 338 | // Returns the register containing the return address. |
| 339 | // It should be made sure that this register contains the return |
| 340 | // value when a return instruction is reached. |
| 341 | // |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 342 | unsigned getReturnAddressReg() const; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 343 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 344 | // Number of registers used for passing int args (usually 6: %o0 - %o5) |
| 345 | // and float args (usually 32: %f0 - %f31) |
| 346 | // |
Vikram S. Adve | 5b1b47b | 2003-05-25 15:59:47 +0000 | [diff] [blame] | 347 | unsigned const getNumOfIntArgRegs() const { return NumOfIntArgRegs; } |
| 348 | unsigned const getNumOfFloatArgRegs() const { return NumOfFloatArgRegs; } |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 349 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 350 | // Compute which register can be used for an argument, if any |
| 351 | // |
| 352 | int regNumForIntArg(bool inCallee, bool isVarArgsCall, |
| 353 | unsigned argNo, unsigned& regClassId) const; |
| 354 | |
| 355 | int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall, |
| 356 | unsigned argNo, unsigned& regClassId) const; |
| 357 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 358 | // The following methods are used to color special live ranges (e.g. |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 359 | // function args and return values etc.) with specific hardware registers |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 360 | // as required. See SparcRegInfo.cpp for the implementation for Sparc. |
| 361 | // |
Chris Lattner | b7653df | 2002-04-08 22:03:57 +0000 | [diff] [blame] | 362 | void suggestRegs4MethodArgs(const Function *Meth, |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 363 | LiveRangeInfo& LRI) const; |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 364 | |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 365 | void suggestRegs4CallArgs(MachineInstr *CallMI, |
Vikram S. Adve | 106604e | 2002-09-28 16:56:59 +0000 | [diff] [blame] | 366 | LiveRangeInfo& LRI) const; |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 367 | |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 368 | void suggestReg4RetValue(MachineInstr *RetMI, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 369 | LiveRangeInfo& LRI) const; |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 370 | |
Vikram S. Adve | ada280f | 2003-07-29 19:54:41 +0000 | [diff] [blame] | 371 | void colorMethodArgs(const Function *Meth, LiveRangeInfo& LRI, |
| 372 | std::vector<MachineInstr*>& InstrnsBefore, |
| 373 | std::vector<MachineInstr*>& InstrnsAfter) const; |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 374 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 375 | // method used for printing a register for debugging purposes |
| 376 | // |
Vikram S. Adve | 78a4f23 | 2003-05-27 00:02:22 +0000 | [diff] [blame] | 377 | void printReg(const LiveRange *LR) const; |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 378 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 379 | // returns the # of bytes of stack space allocated for each register |
| 380 | // type. For Sparc, currently we allocate 8 bytes on stack for all |
| 381 | // register types. We can optimize this later if necessary to save stack |
| 382 | // space (However, should make sure that stack alignment is correct) |
| 383 | // |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 384 | inline int getSpilledRegSize(int RegType) const { |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 385 | return 8; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 388 | |
Vikram S. Adve | a44c6c0 | 2002-03-31 19:04:50 +0000 | [diff] [blame] | 389 | // To obtain the return value and the indirect call address (if any) |
| 390 | // contained in a CALL machine instruction |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 391 | // |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 392 | const Value * getCallInstRetVal(const MachineInstr *CallMI) const; |
Vikram S. Adve | a44c6c0 | 2002-03-31 19:04:50 +0000 | [diff] [blame] | 393 | const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const; |
Ruchira Sasanka | b3b6f53 | 2001-10-21 16:43:41 +0000 | [diff] [blame] | 394 | |
Ruchira Sasanka | 2563a98 | 2002-01-07 20:28:49 +0000 | [diff] [blame] | 395 | // The following methods are used to generate "copy" machine instructions |
| 396 | // for an architecture. |
| 397 | // |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 398 | // The function regTypeNeedsScratchReg() can be used to check whether a |
| 399 | // scratch register is needed to copy a register of type `regType' to |
| 400 | // or from memory. If so, such a scratch register can be provided by |
| 401 | // the caller (e.g., if it knows which regsiters are free); otherwise |
| 402 | // an arbitrary one will be chosen and spilled by the copy instructions. |
| 403 | // |
| 404 | bool regTypeNeedsScratchReg(int RegType, |
| 405 | int& scratchRegClassId) const; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 406 | |
Vikram S. Adve | fe09fb2 | 2002-07-08 23:34:10 +0000 | [diff] [blame] | 407 | void cpReg2RegMI(std::vector<MachineInstr*>& mvec, |
| 408 | unsigned SrcReg, unsigned DestReg, |
| 409 | int RegType) const; |
| 410 | |
| 411 | void cpReg2MemMI(std::vector<MachineInstr*>& mvec, |
| 412 | unsigned SrcReg, unsigned DestPtrReg, |
| 413 | int Offset, int RegType, int scratchReg = -1) const; |
| 414 | |
| 415 | void cpMem2RegMI(std::vector<MachineInstr*>& mvec, |
| 416 | unsigned SrcPtrReg, int Offset, unsigned DestReg, |
| 417 | int RegType, int scratchReg = -1) const; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 418 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 419 | void cpValue2Value(Value *Src, Value *Dest, |
Anand Shukla | cfb22d3 | 2002-06-25 20:55:50 +0000 | [diff] [blame] | 420 | std::vector<MachineInstr*>& mvec) const; |
Ruchira Sasanka | ef1b0cb | 2001-11-03 17:13:27 +0000 | [diff] [blame] | 421 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 422 | // Get the register type for a register identified different ways. |
Vikram S. Adve | 7dc7de5 | 2003-07-25 21:12:15 +0000 | [diff] [blame] | 423 | // Note that getRegTypeForLR(LR) != getRegTypeForDataType(LR->getType())! |
| 424 | // The reg class of a LR depends both on the Value types in it and whether |
| 425 | // they are CC registers or not (for example). |
| 426 | int getRegTypeForDataType(const Type* type) const; |
| 427 | int getRegTypeForLR(const LiveRange *LR) const; |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 428 | int getRegType(int unifiedRegNum) const; |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 429 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 430 | virtual unsigned getFramePointer() const; |
| 431 | virtual unsigned getStackPointer() const; |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 432 | }; |
| 433 | |
| 434 | |
| 435 | |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 436 | |
| 437 | //--------------------------------------------------------------------------- |
| 438 | // class UltraSparcSchedInfo |
| 439 | // |
| 440 | // Purpose: |
| 441 | // Interface to instruction scheduling information for UltraSPARC. |
| 442 | // The parameter values above are based on UltraSPARC IIi. |
| 443 | //--------------------------------------------------------------------------- |
| 444 | |
| 445 | |
Chris Lattner | d0f166a | 2002-12-29 03:13:05 +0000 | [diff] [blame] | 446 | class UltraSparcSchedInfo: public TargetSchedInfo { |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 447 | public: |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 448 | UltraSparcSchedInfo(const TargetMachine &tgt); |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 449 | protected: |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 450 | virtual void initializeResources(); |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 451 | }; |
| 452 | |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 453 | |
| 454 | //--------------------------------------------------------------------------- |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 455 | // class UltraSparcFrameInfo |
| 456 | // |
| 457 | // Purpose: |
| 458 | // Interface to stack frame layout info for the UltraSPARC. |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 459 | // Starting offsets for each area of the stack frame are aligned at |
| 460 | // a multiple of getStackFrameSizeAlignment(). |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 461 | //--------------------------------------------------------------------------- |
| 462 | |
Chris Lattner | da62ac6 | 2002-12-28 20:20:24 +0000 | [diff] [blame] | 463 | class UltraSparcFrameInfo: public TargetFrameInfo { |
| 464 | const TargetMachine ⌖ |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 465 | public: |
Chris Lattner | da62ac6 | 2002-12-28 20:20:24 +0000 | [diff] [blame] | 466 | UltraSparcFrameInfo(const TargetMachine &TM) |
| 467 | : TargetFrameInfo(StackGrowsDown, StackFrameSizeAlignment, 0), target(TM) {} |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 468 | |
| 469 | public: |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 470 | // These methods provide constant parameters of the frame layout. |
| 471 | // |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 472 | int getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;} |
| 473 | int getMinStackFrameSize() const { return MinStackFrameSize; } |
| 474 | int getNumFixedOutgoingArgs() const { return NumFixedOutgoingArgs; } |
| 475 | int getSizeOfEachArgOnStack() const { return SizeOfEachArgOnStack; } |
| 476 | bool argsOnStackHaveFixedSize() const { return true; } |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 477 | |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 478 | // This method adjusts a stack offset to meet alignment rules of target. |
| 479 | // The fixed OFFSET (0x7ff) must be subtracted and the result aligned. |
| 480 | virtual int adjustAlignment (int unalignedOffset, |
| 481 | bool growUp, |
| 482 | unsigned int align) const { |
| 483 | return unalignedOffset + (growUp? +1:-1)*((unalignedOffset-OFFSET) % align); |
| 484 | } |
| 485 | |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 486 | // These methods compute offsets using the frame contents for a |
Chris Lattner | f57b845 | 2002-04-27 06:56:12 +0000 | [diff] [blame] | 487 | // particular function. The frame contents are obtained from the |
| 488 | // MachineCodeInfoForMethod object for the given function. |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 489 | // |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 490 | int getFirstIncomingArgOffset (MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 491 | bool& growUp) const |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 492 | { |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 493 | growUp = true; // arguments area grows upwards |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 494 | return FirstIncomingArgOffsetFromFP; |
| 495 | } |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 496 | int getFirstOutgoingArgOffset (MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 497 | bool& growUp) const |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 498 | { |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 499 | growUp = true; // arguments area grows upwards |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 500 | return FirstOutgoingArgOffsetFromSP; |
| 501 | } |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 502 | int getFirstOptionalOutgoingArgOffset(MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 503 | bool& growUp)const |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 504 | { |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 505 | growUp = true; // arguments area grows upwards |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 506 | return FirstOptionalOutgoingArgOffsetFromSP; |
| 507 | } |
| 508 | |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 509 | int getFirstAutomaticVarOffset (MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 510 | bool& growUp) const; |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 511 | int getRegSpillAreaOffset (MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 512 | bool& growUp) const; |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 513 | int getTmpAreaOffset (MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 514 | bool& growUp) const; |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 515 | int getDynamicAreaOffset (MachineFunction& mcInfo, |
Vikram S. Adve | 6d78311 | 2002-04-25 04:40:24 +0000 | [diff] [blame] | 516 | bool& growUp) const; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 517 | |
| 518 | // |
| 519 | // These methods specify the base register used for each stack area |
| 520 | // (generally FP or SP) |
| 521 | // |
| 522 | virtual int getIncomingArgBaseRegNum() const { |
| 523 | return (int) target.getRegInfo().getFramePointer(); |
| 524 | } |
| 525 | virtual int getOutgoingArgBaseRegNum() const { |
| 526 | return (int) target.getRegInfo().getStackPointer(); |
| 527 | } |
| 528 | virtual int getOptionalOutgoingArgBaseRegNum() const { |
| 529 | return (int) target.getRegInfo().getStackPointer(); |
| 530 | } |
| 531 | virtual int getAutomaticVarBaseRegNum() const { |
| 532 | return (int) target.getRegInfo().getFramePointer(); |
| 533 | } |
| 534 | virtual int getRegSpillAreaBaseRegNum() const { |
| 535 | return (int) target.getRegInfo().getFramePointer(); |
| 536 | } |
| 537 | virtual int getDynamicAreaBaseRegNum() const { |
| 538 | return (int) target.getRegInfo().getStackPointer(); |
| 539 | } |
Chris Lattner | da62ac6 | 2002-12-28 20:20:24 +0000 | [diff] [blame] | 540 | |
| 541 | virtual int getIncomingArgOffset(MachineFunction& mcInfo, |
| 542 | unsigned argNum) const { |
| 543 | assert(argsOnStackHaveFixedSize()); |
| 544 | |
| 545 | unsigned relativeOffset = argNum * getSizeOfEachArgOnStack(); |
| 546 | bool growUp; // do args grow up or down |
| 547 | int firstArg = getFirstIncomingArgOffset(mcInfo, growUp); |
| 548 | return growUp ? firstArg + relativeOffset : firstArg - relativeOffset; |
| 549 | } |
| 550 | |
| 551 | virtual int getOutgoingArgOffset(MachineFunction& mcInfo, |
| 552 | unsigned argNum) const { |
| 553 | assert(argsOnStackHaveFixedSize()); |
| 554 | //assert(((int) argNum - this->getNumFixedOutgoingArgs()) |
| 555 | // <= (int) mcInfo.getInfo()->getMaxOptionalNumArgs()); |
| 556 | |
| 557 | unsigned relativeOffset = argNum * getSizeOfEachArgOnStack(); |
| 558 | bool growUp; // do args grow up or down |
| 559 | int firstArg = getFirstOutgoingArgOffset(mcInfo, growUp); |
| 560 | return growUp ? firstArg + relativeOffset : firstArg - relativeOffset; |
| 561 | } |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 562 | |
| 563 | private: |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 564 | /*---------------------------------------------------------------------- |
| 565 | This diagram shows the stack frame layout used by llc on Sparc V9. |
| 566 | Note that only the location of automatic variables, spill area, |
| 567 | temporary storage, and dynamically allocated stack area are chosen |
| 568 | by us. The rest conform to the Sparc V9 ABI. |
| 569 | All stack addresses are offset by OFFSET = 0x7ff (2047). |
| 570 | |
Chris Lattner | da62ac6 | 2002-12-28 20:20:24 +0000 | [diff] [blame] | 571 | Alignment assumptions and other invariants: |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 572 | (1) %sp+OFFSET and %fp+OFFSET are always aligned on 16-byte boundary |
| 573 | (2) Variables in automatic, spill, temporary, or dynamic regions |
| 574 | are aligned according to their size as in all memory accesses. |
| 575 | (3) Everything below the dynamically allocated stack area is only used |
| 576 | during a call to another function, so it is never needed when |
| 577 | the current function is active. This is why space can be allocated |
| 578 | dynamically by incrementing %sp any time within the function. |
| 579 | |
| 580 | STACK FRAME LAYOUT: |
| 581 | |
| 582 | ... |
| 583 | %fp+OFFSET+176 Optional extra incoming arguments# 1..N |
| 584 | %fp+OFFSET+168 Incoming argument #6 |
| 585 | ... ... |
| 586 | %fp+OFFSET+128 Incoming argument #1 |
| 587 | ... ... |
| 588 | ---%fp+OFFSET-0--------Bottom of caller's stack frame-------------------- |
| 589 | %fp+OFFSET-8 Automatic variables <-- ****TOP OF STACK FRAME**** |
| 590 | Spill area |
| 591 | Temporary storage |
| 592 | ... |
| 593 | |
| 594 | %sp+OFFSET+176+8N Bottom of dynamically allocated stack area |
| 595 | %sp+OFFSET+168+8N Optional extra outgoing argument# N |
| 596 | ... ... |
| 597 | %sp+OFFSET+176 Optional extra outgoing argument# 1 |
| 598 | %sp+OFFSET+168 Outgoing argument #6 |
| 599 | ... ... |
| 600 | %sp+OFFSET+128 Outgoing argument #1 |
| 601 | %sp+OFFSET+120 Save area for %i7 |
| 602 | ... ... |
| 603 | %sp+OFFSET+0 Save area for %l0 <-- ****BOTTOM OF STACK FRAME**** |
| 604 | |
| 605 | *----------------------------------------------------------------------*/ |
| 606 | |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 607 | // All stack addresses must be offset by 0x7ff (2047) on Sparc V9. |
| 608 | static const int OFFSET = (int) 0x7ff; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 609 | static const int StackFrameSizeAlignment = 16; |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 610 | static const int MinStackFrameSize = 176; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 611 | static const int NumFixedOutgoingArgs = 6; |
| 612 | static const int SizeOfEachArgOnStack = 8; |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 613 | static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET; |
| 614 | static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET; |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 615 | static const int StaticAreaOffsetFromFP = 0 + OFFSET; |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 616 | static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET; |
| 617 | static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET; |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 618 | }; |
| 619 | |
| 620 | |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 621 | //--------------------------------------------------------------------------- |
| 622 | // class UltraSparcCacheInfo |
| 623 | // |
| 624 | // Purpose: |
| 625 | // Interface to cache parameters for the UltraSPARC. |
| 626 | // Just use defaults for now. |
| 627 | //--------------------------------------------------------------------------- |
| 628 | |
Chris Lattner | dde1262 | 2002-12-29 02:50:33 +0000 | [diff] [blame] | 629 | struct UltraSparcCacheInfo: public TargetCacheInfo { |
| 630 | UltraSparcCacheInfo(const TargetMachine &T) : TargetCacheInfo(T) {} |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 631 | }; |
| 632 | |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 633 | |
| 634 | //--------------------------------------------------------------------------- |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 635 | // class UltraSparcOptInfo |
| 636 | // |
| 637 | // Purpose: |
| 638 | // Interface to machine-level optimization routines for the UltraSPARC. |
| 639 | //--------------------------------------------------------------------------- |
| 640 | |
Chris Lattner | dde1262 | 2002-12-29 02:50:33 +0000 | [diff] [blame] | 641 | struct UltraSparcOptInfo: public TargetOptInfo { |
| 642 | UltraSparcOptInfo(const TargetMachine &T) : TargetOptInfo(T) {} |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 643 | |
| 644 | virtual bool IsUselessCopy (const MachineInstr* MI) const; |
| 645 | }; |
| 646 | |
Misha Brukman | 79caf1f | 2003-05-27 22:01:10 +0000 | [diff] [blame] | 647 | /// createAddRegNumToValuesPass - this pass adds unsigned register numbers to |
| 648 | /// instructions, since that's not done by the Sparc InstSelector, but that's |
| 649 | /// how the target-independent register allocator in the JIT likes to see |
| 650 | /// instructions. This pass enables the usage of the JIT register allocator(s). |
| 651 | Pass *createAddRegNumToValuesPass(); |
| 652 | |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 653 | //--------------------------------------------------------------------------- |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 654 | // class UltraSparcMachine |
| 655 | // |
| 656 | // Purpose: |
| 657 | // Primary interface to machine description for the UltraSPARC. |
| 658 | // Primarily just initializes machine-dependent parameters in |
| 659 | // class TargetMachine, and creates machine-dependent subclasses |
Vikram S. Adve | 339084b | 2001-09-18 13:04:24 +0000 | [diff] [blame] | 660 | // for classes such as InstrInfo, SchedInfo and RegInfo. |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 661 | //--------------------------------------------------------------------------- |
| 662 | |
| 663 | class UltraSparc : public TargetMachine { |
Vikram S. Adve | 339084b | 2001-09-18 13:04:24 +0000 | [diff] [blame] | 664 | UltraSparcInstrInfo instrInfo; |
| 665 | UltraSparcSchedInfo schedInfo; |
| 666 | UltraSparcRegInfo regInfo; |
Vikram S. Adve | c152163 | 2001-10-22 13:31:53 +0000 | [diff] [blame] | 667 | UltraSparcFrameInfo frameInfo; |
Vikram S. Adve | 5afff3b | 2001-11-09 02:15:52 +0000 | [diff] [blame] | 668 | UltraSparcCacheInfo cacheInfo; |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 669 | UltraSparcOptInfo optInfo; |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 670 | public: |
| 671 | UltraSparc(); |
Vikram S. Adve | d55697c | 2002-09-20 00:52:09 +0000 | [diff] [blame] | 672 | |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 673 | virtual const TargetInstrInfo &getInstrInfo() const { return instrInfo; } |
Chris Lattner | d0f166a | 2002-12-29 03:13:05 +0000 | [diff] [blame] | 674 | virtual const TargetSchedInfo &getSchedInfo() const { return schedInfo; } |
| 675 | virtual const TargetRegInfo &getRegInfo() const { return regInfo; } |
Chris Lattner | da62ac6 | 2002-12-28 20:20:24 +0000 | [diff] [blame] | 676 | virtual const TargetFrameInfo &getFrameInfo() const { return frameInfo; } |
Chris Lattner | dde1262 | 2002-12-29 02:50:33 +0000 | [diff] [blame] | 677 | virtual const TargetCacheInfo &getCacheInfo() const { return cacheInfo; } |
| 678 | virtual const TargetOptInfo &getOptInfo() const { return optInfo; } |
Chris Lattner | 32f600a | 2001-09-19 13:47:12 +0000 | [diff] [blame] | 679 | |
Chris Lattner | 6334205 | 2002-10-29 21:12:46 +0000 | [diff] [blame] | 680 | virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out); |
Misha Brukman | 79caf1f | 2003-05-27 22:01:10 +0000 | [diff] [blame] | 681 | virtual bool addPassesToJITCompile(PassManager &PM); |
| 682 | virtual bool addPassesToEmitMachineCode(PassManager &PM, |
| 683 | MachineCodeEmitter &MCE); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 684 | |
Chris Lattner | c66583e | 2002-10-29 22:01:44 +0000 | [diff] [blame] | 685 | // getPrologEpilogInsertionPass - Inserts prolog/epilog code. |
| 686 | Pass* getPrologEpilogInsertionPass(); |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 687 | |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 688 | // getFunctionAsmPrinterPass - Writes out machine code for a single function |
Chris Lattner | c66583e | 2002-10-29 22:01:44 +0000 | [diff] [blame] | 689 | Pass* getFunctionAsmPrinterPass(std::ostream &Out); |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 690 | |
| 691 | // getModuleAsmPrinterPass - Writes generated machine code to assembly file. |
Chris Lattner | c66583e | 2002-10-29 22:01:44 +0000 | [diff] [blame] | 692 | Pass* getModuleAsmPrinterPass(std::ostream &Out); |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 693 | |
| 694 | // getEmitBytecodeToAsmPass - Emits final LLVM bytecode to assembly file. |
Chris Lattner | c66583e | 2002-10-29 22:01:44 +0000 | [diff] [blame] | 695 | Pass* getEmitBytecodeToAsmPass(std::ostream &Out); |
Chris Lattner | 6edfcc5 | 2002-02-03 07:51:17 +0000 | [diff] [blame] | 696 | }; |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 697 | |
Chris Lattner | fb4d20b | 2003-06-16 15:31:09 +0000 | [diff] [blame] | 698 | Pass *getFunctionInfo(std::ostream &out); |
| 699 | |
Chris Lattner | c6495ee | 2001-09-14 03:56:45 +0000 | [diff] [blame] | 700 | #endif |