blob: aea653ebdb2897de623684f5635445e85a593567 [file] [log] [blame]
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001//***************************************************************************
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 Lattnerc6495ee2001-09-14 03:56:45 +000010
11#ifndef SPARC_INTERNALS_H
12#define SPARC_INTERNALS_H
13
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000014#include "llvm/Target/TargetMachine.h"
Vikram S. Adve339084b2001-09-18 13:04:24 +000015#include "llvm/Target/MachineSchedInfo.h"
Vikram S. Adve5afff3b2001-11-09 02:15:52 +000016#include "llvm/Target/MachineFrameInfo.h"
17#include "llvm/Target/MachineCacheInfo.h"
Chris Lattner699683c2002-02-04 05:59:25 +000018#include "llvm/Target/MachineRegInfo.h"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000019#include "llvm/Type.h"
Chris Lattner46cbff62001-09-14 16:56:32 +000020#include <sys/types.h>
Chris Lattnerc6495ee2001-09-14 03:56:45 +000021
Chris Lattner4387e312002-02-03 23:42:19 +000022class LiveRange;
Chris Lattnerf6e0e282001-09-14 04:32:55 +000023class UltraSparc;
Chris Lattner4387e312002-02-03 23:42:19 +000024class PhyRegAlloc;
Chris Lattner9aa697b2002-04-09 05:16:36 +000025class Pass;
Chris Lattner4387e312002-02-03 23:42:19 +000026
Chris Lattner9aa697b2002-04-09 05:16:36 +000027Pass *createPrologEpilogCodeInserter(TargetMachine &TM);
Chris Lattnerf6e0e282001-09-14 04:32:55 +000028
Chris Lattnerc6495ee2001-09-14 03:56:45 +000029// OpCodeMask definitions for the Sparc V9
30//
31const OpCodeMask Immed = 0x00002000; // immed or reg operand?
32const OpCodeMask Annul = 0x20000000; // annul delay instr?
33const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
34
35
36enum 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 Lattnerc6495ee2001-09-14 03:56:45 +000052
53//---------------------------------------------------------------------------
54// enum SparcMachineOpCode.
55// const MachineInstrDescriptor SparcMachineInstrDesc[]
56//
57// Purpose:
58// Description of UltraSparc machine instructions.
59//
60//---------------------------------------------------------------------------
61
Chris Lattnerc6495ee2001-09-14 03:56:45 +000062enum SparcMachineOpCode {
Chris Lattner9a3d63b2001-09-19 15:56:23 +000063#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
64 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
65 ENUM,
66#include "SparcInstr.def"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000067
Chris Lattnerc6495ee2001-09-14 03:56:45 +000068 // End-of-array marker
69 INVALID_OPCODE,
Vikram S. Advec1521632001-10-22 13:31:53 +000070 NUM_REAL_OPCODES = PHI, // number of valid opcodes
Chris Lattnerc6495ee2001-09-14 03:56:45 +000071 NUM_TOTAL_OPCODES = INVALID_OPCODE
72};
73
Chris Lattnerc6495ee2001-09-14 03:56:45 +000074
Chris Lattner9a3d63b2001-09-19 15:56:23 +000075// Array of machine instruction descriptions...
76extern const MachineInstrDescriptor SparcMachineInstrDesc[];
Chris Lattnerc6495ee2001-09-14 03:56:45 +000077
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
89class UltraSparcInstrInfo : public MachineInstrInfo {
90public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000091 /*ctor*/ UltraSparcInstrInfo(const TargetMachine& tgt);
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000092
93 //
Vikram S. Advedd558992002-03-18 03:02:42 +000094 // All immediate constants are in position 1 except the
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000095 // store instructions.
96 //
Vikram S. Advedd558992002-03-18 03:02:42 +000097 virtual int getImmedConstantPos(MachineOpCode opCode) const {
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000098 bool ignore;
99 if (this->maxImmedConstant(opCode, ignore) != 0)
100 {
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000101 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. Adve4c5fe2d2001-11-14 18:48:36 +0000104 }
105 else
106 return -1;
107 }
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000108
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000109 virtual bool hasResultInterlock (MachineOpCode opCode) const
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000110 {
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. Adve5684c4e2001-10-18 00:02:06 +0000120 //-------------------------------------------------------------------------
121 // Code generation support for creating individual machine instructions
122 //-------------------------------------------------------------------------
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000123
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000124 // Create an instruction sequence to put the constant `val' into
Vikram S. Adve242a8082002-05-19 15:25:51 +0000125 // 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. Adve5684c4e2001-10-18 00:02:06 +0000130 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000131 virtual void CreateCodeToLoadConst(const TargetMachine& target,
132 Function* F,
Vikram S. Advedd558992002-03-18 03:02:42 +0000133 Value* val,
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000134 Instruction* dest,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000135 std::vector<MachineInstr*>& mvec,
136 MachineCodeForInstruction& mcfi) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000137
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000138 // 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. Adve242a8082002-05-19 15:25:51 +0000141 // 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. Adve7f37fe52001-11-08 04:55:13 +0000144 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000145 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. Adve5afff3b2001-11-09 02:15:52 +0000151
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. Adve242a8082002-05-19 15:25:51 +0000154 // 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. Adve5afff3b2001-11-09 02:15:52 +0000157 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000158 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. Advedd558992002-03-18 03:02:42 +0000170 virtual void CreateCopyInstructionsByType(const TargetMachine& target,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000171 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 Lattnerc6495ee2001-09-14 03:56:45 +0000188};
189
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000190
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000191//----------------------------------------------------------------------------
192// class UltraSparcRegInfo
193//
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000194// This class implements the virtual class MachineRegInfo for Sparc.
195//
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000196//----------------------------------------------------------------------------
197
Chris Lattner699683c2002-02-04 05:59:25 +0000198class UltraSparcRegInfo : public MachineRegInfo {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000199 // The actual register classes in the Sparc
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000200 //
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000201 enum RegClassIDs {
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000202 IntRegClassID, // Integer
203 FloatRegClassID, // Float (both single/double)
204 IntCCRegClassID, // Int Condition Code
205 FloatCCRegClassID // Float Condition code
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000206 };
207
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000208
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 Sasanka2563a982002-01-07 20:28:49 +0000212 //
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000213 enum RegTypes {
214 IntRegType,
215 FPSingleRegType,
216 FPDoubleRegType,
217 IntCCRegType,
218 FloatCCRegType
219 };
220
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000221 // **** WARNING: If the above enum order is changed, also modify
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000222 // getRegisterClassOfValue method below since it assumes this particular
223 // order for efficiency.
224
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000225
226 // reverse pointer to get info about the ultra sparc machine
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000227 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000228 const UltraSparc *const UltraSparcInfo;
229
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000230 // Number of registers used for passing int args (usually 6: %o0 - %o5)
231 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000232 unsigned const NumOfIntArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000233
234 // Number of registers used for passing float args (usually 32: %f0 - %f31)
235 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000236 unsigned const NumOfFloatArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000237
238 // An out of bound register number that can be used to initialize register
239 // numbers. Useful for error detection.
240 //
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000241 int const InvalidRegNum;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000242
243
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000244 // ======================== Private Methods =============================
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000245
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000246 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000247 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000248 // as required. See SparcRegInfo.cpp for the implementation.
249 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000250 void suggestReg4RetAddr(MachineInstr *RetMI,
Chris Lattner699683c2002-02-04 05:59:25 +0000251 LiveRangeInfo &LRI) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000252
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000253 void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner697954c2002-01-20 22:54:45 +0000254 std::vector<RegClass *> RCList) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000255
256 void InitializeOutgoingArg(MachineInstr* CallMI, AddedInstrns *CallAI,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000257 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. Advefe09fb22002-07-08 23:34:10 +0000264 // 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. Adve242a8082002-05-19 15:25:51 +0000268 int getRegType(unsigned regClassID, const Type* type) const;
Chris Lattner699683c2002-02-04 05:59:25 +0000269 int getRegType(const LiveRange *LR) const;
270 int getRegType(const Value *Val) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000271 int getRegType(int unifiedRegNum) const;
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000272
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000273 // Used to generate a copy instruction based on the register class of
274 // value.
275 //
Chris Lattner699683c2002-02-04 05:59:25 +0000276 MachineInstr *cpValue2RegMI(Value *Val, unsigned DestReg,
277 int RegType) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000278
279
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000280 // The following 2 methods are used to order the instructions addeed by
Chris Lattnerf57b8452002-04-27 06:56:12 +0000281 // the register allocator in association with function calling. See
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000282 // SparcRegInfo.cpp for more details
283 //
Chris Lattner697954c2002-01-20 22:54:45 +0000284 void moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec,
285 MachineInstr *UnordInst,
286 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000287
Chris Lattner697954c2002-01-20 22:54:45 +0000288 void OrderAddedInstrns(std::vector<MachineInstr *> &UnordVec,
289 std::vector<MachineInstr *> &OrdVec,
290 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000291
292
Vikram S. Adve6d783112002-04-25 04:40:24 +0000293 // 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 Sasankaae4bcd72001-11-10 21:20:43 +0000298
Vikram S. Adve6d783112002-04-25 04:40:24 +0000299 int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
300 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
301 unsigned& regClassId) const;
302
Chris Lattner699683c2002-02-04 05:59:25 +0000303public:
304 UltraSparcRegInfo(const UltraSparc &tgt);
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000305
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000306 // To get complete machine information structure using the machine register
307 // information
308 //
Chris Lattner699683c2002-02-04 05:59:25 +0000309 inline const UltraSparc &getUltraSparcInfo() const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000310 return *UltraSparcInfo;
311 }
312
Vikram S. Advedd558992002-03-18 03:02:42 +0000313 // To find the register class used for a specified Type
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000314 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000315 unsigned getRegClassIDOfType(const Type *type,
316 bool isCCReg = false) const;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000317
Vikram S. Advedd558992002-03-18 03:02:42 +0000318 // 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. Advefe09fb22002-07-08 23:34:10 +0000325 // 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. Advedd558992002-03-18 03:02:42 +0000329
Chris Lattner699683c2002-02-04 05:59:25 +0000330 // getZeroRegNum - returns the register that contains always zero this is the
331 // unified register number
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000332 //
Chris Lattner699683c2002-02-04 05:59:25 +0000333 virtual int getZeroRegNum() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000334
Chris Lattner699683c2002-02-04 05:59:25 +0000335 // getCallAddressReg - returns the reg used for pushing the address when a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000336 // function is called. This can be used for other purposes between calls
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000337 //
Chris Lattner699683c2002-02-04 05:59:25 +0000338 unsigned getCallAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000339
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000340 // 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 Lattner699683c2002-02-04 05:59:25 +0000344 unsigned getReturnAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000345
Vikram S. Adve242a8082002-05-19 15:25:51 +0000346 // 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 Sasanka2563a982002-01-07 20:28:49 +0000352 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000353 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000354 // as required. See SparcRegInfo.cpp for the implementation for Sparc.
355 //
Chris Lattnerb7653df2002-04-08 22:03:57 +0000356 void suggestRegs4MethodArgs(const Function *Meth,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000357 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000358
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000359 void suggestRegs4CallArgs(MachineInstr *CallMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000360 LiveRangeInfo& LRI,
361 std::vector<RegClass *> RCL) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000362
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000363 void suggestReg4RetValue(MachineInstr *RetMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000364 LiveRangeInfo& LRI) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000365
Chris Lattnerb7653df2002-04-08 22:03:57 +0000366 void colorMethodArgs(const Function *Meth, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000367 AddedInstrns *FirstAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000368
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000369 void colorCallArgs(MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000370 AddedInstrns *CallAI, PhyRegAlloc &PRA,
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000371 const BasicBlock *BB) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000372
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000373 void colorRetValue(MachineInstr *RetI, LiveRangeInfo& LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000374 AddedInstrns *RetAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000375
376
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000377 // method used for printing a register for debugging purposes
378 //
Chris Lattner699683c2002-02-04 05:59:25 +0000379 static void printReg(const LiveRange *LR);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000380
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000381 // 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 Sasanka2563a982002-01-07 20:28:49 +0000384 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000385 // 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 Lattnerc6495ee2001-09-14 03:56:45 +0000390 return reg;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000391 }
392 else if (regClassID == FloatRegClassID) {
393 assert(reg < 64 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000394 return reg + 32; // we have 32 int regs
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000395 }
396 else if (regClassID == FloatCCRegClassID) {
397 assert(reg < 4 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000398 return reg + 32 + 64; // 32 int, 64 float
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000399 }
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 Sasankac4d4b762001-10-16 01:23:19 +0000405 return InvalidRegNum;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000406 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000407 else
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000408 assert(0 && "Invalid register class");
Chris Lattner6dad5062001-11-07 13:49:12 +0000409 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000410 }
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000411
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"); }
Chris Lattnerb82d97e2002-07-25 06:08:32 +0000421 return 0;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000422 }
423
424 // Returns the assembly-language name of the specified machine register.
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000425 //
Chris Lattner699683c2002-02-04 05:59:25 +0000426 virtual const std::string getUnifiedRegName(int reg) const;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000427
428
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000429 // returns the # of bytes of stack space allocated for each register
430 // type. For Sparc, currently we allocate 8 bytes on stack for all
431 // register types. We can optimize this later if necessary to save stack
432 // space (However, should make sure that stack alignment is correct)
433 //
Chris Lattner699683c2002-02-04 05:59:25 +0000434 inline int getSpilledRegSize(int RegType) const {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000435 return 8;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000436 }
437
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000438
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000439 // To obtain the return value and the indirect call address (if any)
440 // contained in a CALL machine instruction
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000441 //
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000442 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000443 const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000444
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000445 // The following methods are used to generate "copy" machine instructions
446 // for an architecture.
447 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000448 // The function regTypeNeedsScratchReg() can be used to check whether a
449 // scratch register is needed to copy a register of type `regType' to
450 // or from memory. If so, such a scratch register can be provided by
451 // the caller (e.g., if it knows which regsiters are free); otherwise
452 // an arbitrary one will be chosen and spilled by the copy instructions.
453 //
454 bool regTypeNeedsScratchReg(int RegType,
455 int& scratchRegClassId) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000456
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000457 void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
458 unsigned SrcReg, unsigned DestReg,
459 int RegType) const;
460
461 void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
462 unsigned SrcReg, unsigned DestPtrReg,
463 int Offset, int RegType, int scratchReg = -1) const;
464
465 void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
466 unsigned SrcPtrReg, int Offset, unsigned DestReg,
467 int RegType, int scratchReg = -1) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000468
Vikram S. Adve242a8082002-05-19 15:25:51 +0000469 void cpValue2Value(Value *Src, Value *Dest,
Anand Shuklacfb22d32002-06-25 20:55:50 +0000470 std::vector<MachineInstr*>& mvec) const;
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000471
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000472 // To see whether a register is a volatile (i.e., whehter it must be
473 // preserved acorss calls)
474 //
Chris Lattner699683c2002-02-04 05:59:25 +0000475 inline bool isRegVolatile(int RegClassID, int Reg) const {
476 return MachineRegClassArr[RegClassID]->isRegVolatile(Reg);
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000477 }
478
479
Chris Lattner699683c2002-02-04 05:59:25 +0000480 virtual unsigned getFramePointer() const;
481 virtual unsigned getStackPointer() const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000482
Chris Lattner699683c2002-02-04 05:59:25 +0000483 virtual int getInvalidRegNum() const {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000484 return InvalidRegNum;
485 }
486
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000487 // This method inserts the caller saving code for call instructions
488 //
Anand Shukla24787fa2002-07-11 00:16:28 +0000489 void insertCallerSavingCode(std::vector<MachineInstr*>& instrnsBefore,
490 std::vector<MachineInstr*>& instrnsAfter,
Vikram S. Adve6a49a1e2002-07-10 21:42:42 +0000491 MachineInstr *MInst,
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000492 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000493};
494
495
496
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000497
498//---------------------------------------------------------------------------
499// class UltraSparcSchedInfo
500//
501// Purpose:
502// Interface to instruction scheduling information for UltraSPARC.
503// The parameter values above are based on UltraSPARC IIi.
504//---------------------------------------------------------------------------
505
506
507class UltraSparcSchedInfo: public MachineSchedInfo {
508public:
Chris Lattner699683c2002-02-04 05:59:25 +0000509 UltraSparcSchedInfo(const TargetMachine &tgt);
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000510protected:
Chris Lattner699683c2002-02-04 05:59:25 +0000511 virtual void initializeResources();
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000512};
513
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000514
515//---------------------------------------------------------------------------
Vikram S. Advec1521632001-10-22 13:31:53 +0000516// class UltraSparcFrameInfo
517//
518// Purpose:
519// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +0000520// Starting offsets for each area of the stack frame are aligned at
521// a multiple of getStackFrameSizeAlignment().
Vikram S. Advec1521632001-10-22 13:31:53 +0000522//---------------------------------------------------------------------------
523
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000524class UltraSparcFrameInfo: public MachineFrameInfo {
Vikram S. Advec1521632001-10-22 13:31:53 +0000525public:
Chris Lattner699683c2002-02-04 05:59:25 +0000526 UltraSparcFrameInfo(const TargetMachine &tgt) : MachineFrameInfo(tgt) {}
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000527
528public:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000529 int getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;}
530 int getMinStackFrameSize() const { return MinStackFrameSize; }
531 int getNumFixedOutgoingArgs() const { return NumFixedOutgoingArgs; }
532 int getSizeOfEachArgOnStack() const { return SizeOfEachArgOnStack; }
533 bool argsOnStackHaveFixedSize() const { return true; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000534
535 //
536 // These methods compute offsets using the frame contents for a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000537 // particular function. The frame contents are obtained from the
538 // MachineCodeInfoForMethod object for the given function.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000539 //
540 int getFirstIncomingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000541 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000542 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000543 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000544 return FirstIncomingArgOffsetFromFP;
545 }
546 int getFirstOutgoingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000547 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000548 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000549 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000550 return FirstOutgoingArgOffsetFromSP;
551 }
552 int getFirstOptionalOutgoingArgOffset(MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000553 bool& growUp)const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000554 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000555 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000556 return FirstOptionalOutgoingArgOffsetFromSP;
557 }
558
559 int getFirstAutomaticVarOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000560 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000561 int getRegSpillAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000562 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000563 int getTmpAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000564 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000565 int getDynamicAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000566 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000567
568 //
569 // These methods specify the base register used for each stack area
570 // (generally FP or SP)
571 //
572 virtual int getIncomingArgBaseRegNum() const {
573 return (int) target.getRegInfo().getFramePointer();
574 }
575 virtual int getOutgoingArgBaseRegNum() const {
576 return (int) target.getRegInfo().getStackPointer();
577 }
578 virtual int getOptionalOutgoingArgBaseRegNum() const {
579 return (int) target.getRegInfo().getStackPointer();
580 }
581 virtual int getAutomaticVarBaseRegNum() const {
582 return (int) target.getRegInfo().getFramePointer();
583 }
584 virtual int getRegSpillAreaBaseRegNum() const {
585 return (int) target.getRegInfo().getFramePointer();
586 }
587 virtual int getDynamicAreaBaseRegNum() const {
588 return (int) target.getRegInfo().getStackPointer();
589 }
590
591private:
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000592 // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
593 static const int OFFSET = (int) 0x7ff;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000594 static const int StackFrameSizeAlignment = 16;
Vikram S. Advec1521632001-10-22 13:31:53 +0000595 static const int MinStackFrameSize = 176;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000596 static const int NumFixedOutgoingArgs = 6;
597 static const int SizeOfEachArgOnStack = 8;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +0000598 static const int StaticAreaOffsetFromFP = 0 + OFFSET;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000599 static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET;
600 static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET;
601 static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET;
602 static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET;
Vikram S. Advec1521632001-10-22 13:31:53 +0000603};
604
605
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000606//---------------------------------------------------------------------------
607// class UltraSparcCacheInfo
608//
609// Purpose:
610// Interface to cache parameters for the UltraSPARC.
611// Just use defaults for now.
612//---------------------------------------------------------------------------
613
614class UltraSparcCacheInfo: public MachineCacheInfo {
615public:
Chris Lattner7327d7e2002-02-04 00:04:35 +0000616 UltraSparcCacheInfo(const TargetMachine &T) : MachineCacheInfo(T) {}
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000617};
618
Vikram S. Advec1521632001-10-22 13:31:53 +0000619
620//---------------------------------------------------------------------------
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000621// class UltraSparcMachine
622//
623// Purpose:
624// Primary interface to machine description for the UltraSPARC.
625// Primarily just initializes machine-dependent parameters in
626// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +0000627// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000628//---------------------------------------------------------------------------
629
630class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +0000631private:
632 UltraSparcInstrInfo instrInfo;
633 UltraSparcSchedInfo schedInfo;
634 UltraSparcRegInfo regInfo;
Vikram S. Advec1521632001-10-22 13:31:53 +0000635 UltraSparcFrameInfo frameInfo;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000636 UltraSparcCacheInfo cacheInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000637public:
638 UltraSparc();
Vikram S. Adve339084b2001-09-18 13:04:24 +0000639
Chris Lattner32f600a2001-09-19 13:47:12 +0000640 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
641 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
642 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000643 virtual const MachineFrameInfo &getFrameInfo() const { return frameInfo; }
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000644 virtual const MachineCacheInfo &getCacheInfo() const { return cacheInfo; }
Chris Lattner32f600a2001-09-19 13:47:12 +0000645
646 //
Chris Lattner4387e312002-02-03 23:42:19 +0000647 // addPassesToEmitAssembly - Add passes to the specified pass manager to get
648 // assembly langage code emited. For sparc, we have to do ...
Chris Lattner32f600a2001-09-19 13:47:12 +0000649 //
Chris Lattner4387e312002-02-03 23:42:19 +0000650 virtual void addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000651
Chris Lattner4387e312002-02-03 23:42:19 +0000652private:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000653 Pass *getFunctionAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner4387e312002-02-03 23:42:19 +0000654 Pass *getModuleAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner9530a6f2002-02-11 22:35:46 +0000655 Pass *getEmitBytecodeToAsmPass(std::ostream &Out);
Chris Lattner6edfcc52002-02-03 07:51:17 +0000656};
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000657
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000658#endif