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