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