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