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