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