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