blob: 157004a104f78696615880ed1654a30cd0ebeb14 [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- SparcInternals.h ----------------------------------------*- C++ -*-===//
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00002//
Chris Lattner035dfbe2002-08-09 20:08:06 +00003// This file defines stuff that is to be private to the Sparc backend, but is
4// shared among different portions of the backend.
5//
6//===----------------------------------------------------------------------===//
Chris Lattnerc6495ee2001-09-14 03:56:45 +00007
8#ifndef SPARC_INTERNALS_H
9#define SPARC_INTERNALS_H
10
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000011#include "llvm/Target/TargetMachine.h"
Vikram S. Adve339084b2001-09-18 13:04:24 +000012#include "llvm/Target/MachineSchedInfo.h"
Vikram S. Adve5afff3b2001-11-09 02:15:52 +000013#include "llvm/Target/MachineFrameInfo.h"
14#include "llvm/Target/MachineCacheInfo.h"
Chris Lattner699683c2002-02-04 05:59:25 +000015#include "llvm/Target/MachineRegInfo.h"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000016#include "llvm/Type.h"
Chris Lattner46cbff62001-09-14 16:56:32 +000017#include <sys/types.h>
Chris Lattnerc6495ee2001-09-14 03:56:45 +000018
Chris Lattner4387e312002-02-03 23:42:19 +000019class LiveRange;
Chris Lattnerf6e0e282001-09-14 04:32:55 +000020class UltraSparc;
Chris Lattner4387e312002-02-03 23:42:19 +000021class PhyRegAlloc;
Chris Lattner9aa697b2002-04-09 05:16:36 +000022class Pass;
Chris Lattner4387e312002-02-03 23:42:19 +000023
Chris Lattner9aa697b2002-04-09 05:16:36 +000024Pass *createPrologEpilogCodeInserter(TargetMachine &TM);
Chris Lattnerf6e0e282001-09-14 04:32:55 +000025
Chris Lattnerc6495ee2001-09-14 03:56:45 +000026// OpCodeMask definitions for the Sparc V9
27//
28const OpCodeMask Immed = 0x00002000; // immed or reg operand?
29const OpCodeMask Annul = 0x20000000; // annul delay instr?
30const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
31
32
33enum SparcInstrSchedClass {
34 SPARC_NONE, /* Instructions with no scheduling restrictions */
35 SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */
36 SPARC_IEU0, /* Integer class IEU0 */
37 SPARC_IEU1, /* Integer class IEU1 */
38 SPARC_FPM, /* FP Multiply or Divide instructions */
39 SPARC_FPA, /* All other FP instructions */
40 SPARC_CTI, /* Control-transfer instructions */
41 SPARC_LD, /* Load instructions */
42 SPARC_ST, /* Store instructions */
43 SPARC_SINGLE, /* Instructions that must issue by themselves */
44
45 SPARC_INV, /* This should stay at the end for the next value */
46 SPARC_NUM_SCHED_CLASSES = SPARC_INV
47};
48
Chris Lattnerc6495ee2001-09-14 03:56:45 +000049
50//---------------------------------------------------------------------------
51// enum SparcMachineOpCode.
52// const MachineInstrDescriptor SparcMachineInstrDesc[]
53//
54// Purpose:
55// Description of UltraSparc machine instructions.
56//
57//---------------------------------------------------------------------------
58
Chris Lattnerc6495ee2001-09-14 03:56:45 +000059enum SparcMachineOpCode {
Chris Lattner9a3d63b2001-09-19 15:56:23 +000060#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
61 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
62 ENUM,
63#include "SparcInstr.def"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000064
Chris Lattnerc6495ee2001-09-14 03:56:45 +000065 // End-of-array marker
66 INVALID_OPCODE,
Vikram S. Advec1521632001-10-22 13:31:53 +000067 NUM_REAL_OPCODES = PHI, // number of valid opcodes
Chris Lattnerc6495ee2001-09-14 03:56:45 +000068 NUM_TOTAL_OPCODES = INVALID_OPCODE
69};
70
Chris Lattnerc6495ee2001-09-14 03:56:45 +000071
Chris Lattner9a3d63b2001-09-19 15:56:23 +000072// Array of machine instruction descriptions...
73extern const MachineInstrDescriptor SparcMachineInstrDesc[];
Chris Lattnerc6495ee2001-09-14 03:56:45 +000074
75
76//---------------------------------------------------------------------------
77// class UltraSparcInstrInfo
78//
79// Purpose:
80// Information about individual instructions.
81// Most information is stored in the SparcMachineInstrDesc array above.
82// Other information is computed on demand, and most such functions
83// default to member functions in base class MachineInstrInfo.
84//---------------------------------------------------------------------------
85
Chris Lattner035dfbe2002-08-09 20:08:06 +000086struct UltraSparcInstrInfo : public MachineInstrInfo {
87 UltraSparcInstrInfo(const TargetMachine& tgt);
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000088
89 //
Vikram S. Advedd558992002-03-18 03:02:42 +000090 // All immediate constants are in position 1 except the
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000091 // store instructions.
92 //
Vikram S. Advedd558992002-03-18 03:02:42 +000093 virtual int getImmedConstantPos(MachineOpCode opCode) const {
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000094 bool ignore;
95 if (this->maxImmedConstant(opCode, ignore) != 0)
96 {
Vikram S. Advefe09fb22002-07-08 23:34:10 +000097 assert(! this->isStore((MachineOpCode) STB - 1)); // 1st store opcode
98 assert(! this->isStore((MachineOpCode) STXFSR+1));// last store opcode
99 return (opCode >= STB && opCode <= STXFSR)? 2 : 1;
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +0000100 }
101 else
102 return -1;
103 }
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000104
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000105 virtual bool hasResultInterlock (MachineOpCode opCode) const
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000106 {
107 // All UltraSPARC instructions have interlocks (note that delay slots
108 // are not considered here).
109 // However, instructions that use the result of an FCMP produce a
110 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
111 // Force the compiler to insert a software interlock (i.e., gap of
112 // 2 other groups, including NOPs if necessary).
113 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
114 }
115
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000116 //-------------------------------------------------------------------------
117 // Code generation support for creating individual machine instructions
118 //-------------------------------------------------------------------------
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000119
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000120 // Create an instruction sequence to put the constant `val' into
Vikram S. Adve242a8082002-05-19 15:25:51 +0000121 // the virtual register `dest'. `val' may be a Constant or a
122 // GlobalValue, viz., the constant address of a global variable or function.
123 // The generated instructions are returned in `mvec'.
124 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
125 // Any stack space required is allocated via mcff.
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000126 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000127 virtual void CreateCodeToLoadConst(const TargetMachine& target,
128 Function* F,
Vikram S. Advedd558992002-03-18 03:02:42 +0000129 Value* val,
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000130 Instruction* dest,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000131 std::vector<MachineInstr*>& mvec,
132 MachineCodeForInstruction& mcfi) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000133
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000134 // Create an instruction sequence to copy an integer value `val'
135 // to a floating point value `dest' by copying to memory and back.
136 // val must be an integral type. dest must be a Float or Double.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000137 // The generated instructions are returned in `mvec'.
138 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
139 // Any stack space required is allocated via mcff.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000140 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000141 virtual void CreateCodeToCopyIntToFloat(const TargetMachine& target,
142 Function* F,
143 Value* val,
144 Instruction* dest,
145 std::vector<MachineInstr*>& mvec,
146 MachineCodeForInstruction& mcfi) const;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000147
148 // Similarly, create an instruction sequence to copy an FP value
149 // `val' to an integer value `dest' by copying to memory and back.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000150 // The generated instructions are returned in `mvec'.
151 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
152 // Any stack space required is allocated via mcff.
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000153 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000154 virtual void CreateCodeToCopyFloatToInt(const TargetMachine& target,
155 Function* F,
156 Value* val,
157 Instruction* dest,
158 std::vector<MachineInstr*>& mvec,
159 MachineCodeForInstruction& mcfi) const;
160
161 // Create instruction(s) to copy src to dest, for arbitrary types
162 // The generated instructions are returned in `mvec'.
163 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
164 // Any stack space required is allocated via mcff.
165 //
Vikram S. Advedd558992002-03-18 03:02:42 +0000166 virtual void CreateCopyInstructionsByType(const TargetMachine& target,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000167 Function* F,
168 Value* src,
169 Instruction* dest,
170 std::vector<MachineInstr*>& mvec,
171 MachineCodeForInstruction& mcfi) const;
172
173 // Create instruction sequence to produce a sign-extended register value
174 // from an arbitrary sized value (sized in bits, not bytes).
175 // Any stack space required is allocated via mcff.
176 //
177 virtual void CreateSignExtensionInstructions(const TargetMachine& target,
178 Function* F,
179 Value* unsignedSrcVal,
180 unsigned int srcSizeInBits,
181 Value* dest,
182 std::vector<MachineInstr*>& mvec,
183 MachineCodeForInstruction& mcfi) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000184};
185
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000186
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000187//----------------------------------------------------------------------------
188// class UltraSparcRegInfo
189//
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000190// This class implements the virtual class MachineRegInfo for Sparc.
191//
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000192//----------------------------------------------------------------------------
193
Chris Lattner699683c2002-02-04 05:59:25 +0000194class UltraSparcRegInfo : public MachineRegInfo {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000195 // The actual register classes in the Sparc
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000196 //
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000197 enum RegClassIDs {
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000198 IntRegClassID, // Integer
199 FloatRegClassID, // Float (both single/double)
200 IntCCRegClassID, // Int Condition Code
201 FloatCCRegClassID // Float Condition code
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000202 };
203
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000204
205 // Type of registers available in Sparc. There can be several reg types
206 // in the same class. For instace, the float reg class has Single/Double
207 // types
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000208 //
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000209 enum RegTypes {
210 IntRegType,
211 FPSingleRegType,
212 FPDoubleRegType,
213 IntCCRegType,
214 FloatCCRegType
215 };
216
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000217 // **** WARNING: If the above enum order is changed, also modify
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000218 // getRegisterClassOfValue method below since it assumes this particular
219 // order for efficiency.
220
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000221
222 // reverse pointer to get info about the ultra sparc machine
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000223 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000224 const UltraSparc *const UltraSparcInfo;
225
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000226 // Number of registers used for passing int args (usually 6: %o0 - %o5)
227 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000228 unsigned const NumOfIntArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000229
230 // Number of registers used for passing float args (usually 32: %f0 - %f31)
231 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000232 unsigned const NumOfFloatArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000233
234 // An out of bound register number that can be used to initialize register
235 // numbers. Useful for error detection.
236 //
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000237 int const InvalidRegNum;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000238
239
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000240 // ======================== Private Methods =============================
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000241
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000242 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000243 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000244 // as required. See SparcRegInfo.cpp for the implementation.
245 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000246 void suggestReg4RetAddr(MachineInstr *RetMI,
Chris Lattner699683c2002-02-04 05:59:25 +0000247 LiveRangeInfo &LRI) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000248
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000249 void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner697954c2002-01-20 22:54:45 +0000250 std::vector<RegClass *> RCList) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000251
252 void InitializeOutgoingArg(MachineInstr* CallMI, AddedInstrns *CallAI,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000253 PhyRegAlloc &PRA, LiveRange* LR,
254 unsigned regType, unsigned RegClassID,
255 int UniArgReg, unsigned int argNo,
256 std::vector<MachineInstr *>& AddedInstrnsBefore)
257 const;
258
259 // The following 4 methods are used to find the RegType (see enum above)
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000260 // for a reg class and a given primitive type, a LiveRange, a Value,
261 // or a particular machine register.
262 // The fifth function gives the reg class of the given RegType.
263 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000264 int getRegType(unsigned regClassID, const Type* type) const;
Chris Lattner699683c2002-02-04 05:59:25 +0000265 int getRegType(const LiveRange *LR) const;
266 int getRegType(const Value *Val) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000267 int getRegType(int unifiedRegNum) const;
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000268
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000269 // Used to generate a copy instruction based on the register class of
270 // value.
271 //
Chris Lattner699683c2002-02-04 05:59:25 +0000272 MachineInstr *cpValue2RegMI(Value *Val, unsigned DestReg,
273 int RegType) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000274
275
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000276 // The following 2 methods are used to order the instructions addeed by
Chris Lattnerf57b8452002-04-27 06:56:12 +0000277 // the register allocator in association with function calling. See
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000278 // SparcRegInfo.cpp for more details
279 //
Chris Lattner697954c2002-01-20 22:54:45 +0000280 void moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec,
281 MachineInstr *UnordInst,
282 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000283
Chris Lattner697954c2002-01-20 22:54:45 +0000284 void OrderAddedInstrns(std::vector<MachineInstr *> &UnordVec,
285 std::vector<MachineInstr *> &OrdVec,
286 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000287
288
Vikram S. Adve6d783112002-04-25 04:40:24 +0000289 // Compute which register can be used for an argument, if any
290 //
291 int regNumForIntArg(bool inCallee, bool isVarArgsCall,
292 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
293 unsigned& regClassId) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000294
Vikram S. Adve6d783112002-04-25 04:40:24 +0000295 int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
296 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
297 unsigned& regClassId) const;
298
Chris Lattner699683c2002-02-04 05:59:25 +0000299public:
300 UltraSparcRegInfo(const UltraSparc &tgt);
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000301
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000302 // To get complete machine information structure using the machine register
303 // information
304 //
Chris Lattner699683c2002-02-04 05:59:25 +0000305 inline const UltraSparc &getUltraSparcInfo() const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000306 return *UltraSparcInfo;
307 }
308
Vikram S. Advedd558992002-03-18 03:02:42 +0000309 // To find the register class used for a specified Type
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000310 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000311 unsigned getRegClassIDOfType(const Type *type,
312 bool isCCReg = false) const;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000313
Vikram S. Advedd558992002-03-18 03:02:42 +0000314 // To find the register class of a Value
315 //
316 inline unsigned getRegClassIDOfValue(const Value *Val,
317 bool isCCReg = false) const {
318 return getRegClassIDOfType(Val->getType(), isCCReg);
319 }
320
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000321 // To find the register class to which a specified register belongs
322 //
323 unsigned getRegClassIDOfReg(int unifiedRegNum) const;
324 unsigned getRegClassIDOfRegType(int regType) const;
Vikram S. Advedd558992002-03-18 03:02:42 +0000325
Chris Lattner699683c2002-02-04 05:59:25 +0000326 // getZeroRegNum - returns the register that contains always zero this is the
327 // unified register number
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000328 //
Chris Lattner699683c2002-02-04 05:59:25 +0000329 virtual int getZeroRegNum() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000330
Chris Lattner699683c2002-02-04 05:59:25 +0000331 // getCallAddressReg - returns the reg used for pushing the address when a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000332 // function is called. This can be used for other purposes between calls
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000333 //
Chris Lattner699683c2002-02-04 05:59:25 +0000334 unsigned getCallAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000335
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000336 // Returns the register containing the return address.
337 // It should be made sure that this register contains the return
338 // value when a return instruction is reached.
339 //
Chris Lattner699683c2002-02-04 05:59:25 +0000340 unsigned getReturnAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000341
Vikram S. Adve242a8082002-05-19 15:25:51 +0000342 // Number of registers used for passing int args (usually 6: %o0 - %o5)
343 // and float args (usually 32: %f0 - %f31)
344 //
345 unsigned const GetNumOfIntArgRegs() const { return NumOfIntArgRegs; }
346 unsigned const GetNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
347
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000348 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000349 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000350 // as required. See SparcRegInfo.cpp for the implementation for Sparc.
351 //
Chris Lattnerb7653df2002-04-08 22:03:57 +0000352 void suggestRegs4MethodArgs(const Function *Meth,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000353 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000354
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000355 void suggestRegs4CallArgs(MachineInstr *CallMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000356 LiveRangeInfo& LRI,
357 std::vector<RegClass *> RCL) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000358
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000359 void suggestReg4RetValue(MachineInstr *RetMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000360 LiveRangeInfo& LRI) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000361
Chris Lattnerb7653df2002-04-08 22:03:57 +0000362 void colorMethodArgs(const Function *Meth, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000363 AddedInstrns *FirstAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000364
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000365 void colorCallArgs(MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000366 AddedInstrns *CallAI, PhyRegAlloc &PRA,
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000367 const BasicBlock *BB) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000368
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000369 void colorRetValue(MachineInstr *RetI, LiveRangeInfo& LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000370 AddedInstrns *RetAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000371
372
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000373 // method used for printing a register for debugging purposes
374 //
Chris Lattner699683c2002-02-04 05:59:25 +0000375 static void printReg(const LiveRange *LR);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000376
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000377 // Each register class has a seperate space for register IDs. To convert
378 // a regId in a register class to a common Id, or vice versa,
379 // we use the folloing methods.
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000380 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000381 // This method provides a unique number for each register
382 inline int getUnifiedRegNum(unsigned regClassID, int reg) const {
383
384 if (regClassID == IntRegClassID) {
385 assert(reg < 32 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000386 return reg;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000387 }
388 else if (regClassID == FloatRegClassID) {
389 assert(reg < 64 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000390 return reg + 32; // we have 32 int regs
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000391 }
392 else if (regClassID == FloatCCRegClassID) {
393 assert(reg < 4 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000394 return reg + 32 + 64; // 32 int, 64 float
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000395 }
396 else if (regClassID == IntCCRegClassID ) {
397 assert(reg == 0 && "Invalid reg. number");
398 return reg + 4+ 32 + 64; // only one int CC reg
399 }
400 else if (reg==InvalidRegNum) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000401 return InvalidRegNum;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000402 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000403 else
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000404 assert(0 && "Invalid register class");
Chris Lattner6dad5062001-11-07 13:49:12 +0000405 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000406 }
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000407
408 // This method converts the unified number to the number in its class,
409 // and returns the class ID in regClassID.
410 inline int getClassRegNum(int ureg, unsigned& regClassID) const {
411 if (ureg < 32) { regClassID = IntRegClassID; return ureg; }
412 else if (ureg < 32+64) { regClassID = FloatRegClassID; return ureg-32; }
413 else if (ureg < 4 +96) { regClassID = FloatCCRegClassID; return ureg-96; }
414 else if (ureg < 1 +100) { regClassID = IntCCRegClassID; return ureg-100;}
415 else if (ureg == InvalidRegNum) { return InvalidRegNum; }
416 else { assert(0 && "Invalid unified register number"); }
Chris Lattnerb82d97e2002-07-25 06:08:32 +0000417 return 0;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000418 }
419
420 // Returns the assembly-language name of the specified machine register.
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000421 //
Chris Lattner699683c2002-02-04 05:59:25 +0000422 virtual const std::string getUnifiedRegName(int reg) const;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000423
424
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000425 // returns the # of bytes of stack space allocated for each register
426 // type. For Sparc, currently we allocate 8 bytes on stack for all
427 // register types. We can optimize this later if necessary to save stack
428 // space (However, should make sure that stack alignment is correct)
429 //
Chris Lattner699683c2002-02-04 05:59:25 +0000430 inline int getSpilledRegSize(int RegType) const {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000431 return 8;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000432 }
433
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000434
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000435 // To obtain the return value and the indirect call address (if any)
436 // contained in a CALL machine instruction
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000437 //
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000438 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000439 const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000440
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000441 // The following methods are used to generate "copy" machine instructions
442 // for an architecture.
443 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000444 // The function regTypeNeedsScratchReg() can be used to check whether a
445 // scratch register is needed to copy a register of type `regType' to
446 // or from memory. If so, such a scratch register can be provided by
447 // the caller (e.g., if it knows which regsiters are free); otherwise
448 // an arbitrary one will be chosen and spilled by the copy instructions.
449 //
450 bool regTypeNeedsScratchReg(int RegType,
451 int& scratchRegClassId) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000452
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000453 void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
454 unsigned SrcReg, unsigned DestReg,
455 int RegType) const;
456
457 void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
458 unsigned SrcReg, unsigned DestPtrReg,
459 int Offset, int RegType, int scratchReg = -1) const;
460
461 void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
462 unsigned SrcPtrReg, int Offset, unsigned DestReg,
463 int RegType, int scratchReg = -1) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000464
Vikram S. Adve242a8082002-05-19 15:25:51 +0000465 void cpValue2Value(Value *Src, Value *Dest,
Anand Shuklacfb22d32002-06-25 20:55:50 +0000466 std::vector<MachineInstr*>& mvec) const;
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000467
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000468 // To see whether a register is a volatile (i.e., whehter it must be
469 // preserved acorss calls)
470 //
Chris Lattner699683c2002-02-04 05:59:25 +0000471 inline bool isRegVolatile(int RegClassID, int Reg) const {
472 return MachineRegClassArr[RegClassID]->isRegVolatile(Reg);
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000473 }
474
475
Chris Lattner699683c2002-02-04 05:59:25 +0000476 virtual unsigned getFramePointer() const;
477 virtual unsigned getStackPointer() const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000478
Chris Lattner699683c2002-02-04 05:59:25 +0000479 virtual int getInvalidRegNum() const {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000480 return InvalidRegNum;
481 }
482
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000483 // This method inserts the caller saving code for call instructions
484 //
Anand Shukla24787fa2002-07-11 00:16:28 +0000485 void insertCallerSavingCode(std::vector<MachineInstr*>& instrnsBefore,
486 std::vector<MachineInstr*>& instrnsAfter,
Vikram S. Adve6a49a1e2002-07-10 21:42:42 +0000487 MachineInstr *MInst,
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000488 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000489};
490
491
492
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000493
494//---------------------------------------------------------------------------
495// class UltraSparcSchedInfo
496//
497// Purpose:
498// Interface to instruction scheduling information for UltraSPARC.
499// The parameter values above are based on UltraSPARC IIi.
500//---------------------------------------------------------------------------
501
502
503class UltraSparcSchedInfo: public MachineSchedInfo {
504public:
Chris Lattner699683c2002-02-04 05:59:25 +0000505 UltraSparcSchedInfo(const TargetMachine &tgt);
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000506protected:
Chris Lattner699683c2002-02-04 05:59:25 +0000507 virtual void initializeResources();
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000508};
509
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000510
511//---------------------------------------------------------------------------
Vikram S. Advec1521632001-10-22 13:31:53 +0000512// class UltraSparcFrameInfo
513//
514// Purpose:
515// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +0000516// Starting offsets for each area of the stack frame are aligned at
517// a multiple of getStackFrameSizeAlignment().
Vikram S. Advec1521632001-10-22 13:31:53 +0000518//---------------------------------------------------------------------------
519
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000520class UltraSparcFrameInfo: public MachineFrameInfo {
Vikram S. Advec1521632001-10-22 13:31:53 +0000521public:
Chris Lattner699683c2002-02-04 05:59:25 +0000522 UltraSparcFrameInfo(const TargetMachine &tgt) : MachineFrameInfo(tgt) {}
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000523
524public:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000525 int getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;}
526 int getMinStackFrameSize() const { return MinStackFrameSize; }
527 int getNumFixedOutgoingArgs() const { return NumFixedOutgoingArgs; }
528 int getSizeOfEachArgOnStack() const { return SizeOfEachArgOnStack; }
529 bool argsOnStackHaveFixedSize() const { return true; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000530
531 //
532 // These methods compute offsets using the frame contents for a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000533 // particular function. The frame contents are obtained from the
534 // MachineCodeInfoForMethod object for the given function.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000535 //
536 int getFirstIncomingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000537 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000538 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000539 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000540 return FirstIncomingArgOffsetFromFP;
541 }
542 int getFirstOutgoingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000543 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000544 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000545 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000546 return FirstOutgoingArgOffsetFromSP;
547 }
548 int getFirstOptionalOutgoingArgOffset(MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000549 bool& growUp)const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000550 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000551 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000552 return FirstOptionalOutgoingArgOffsetFromSP;
553 }
554
555 int getFirstAutomaticVarOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000556 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000557 int getRegSpillAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000558 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000559 int getTmpAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000560 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000561 int getDynamicAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000562 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000563
564 //
565 // These methods specify the base register used for each stack area
566 // (generally FP or SP)
567 //
568 virtual int getIncomingArgBaseRegNum() const {
569 return (int) target.getRegInfo().getFramePointer();
570 }
571 virtual int getOutgoingArgBaseRegNum() const {
572 return (int) target.getRegInfo().getStackPointer();
573 }
574 virtual int getOptionalOutgoingArgBaseRegNum() const {
575 return (int) target.getRegInfo().getStackPointer();
576 }
577 virtual int getAutomaticVarBaseRegNum() const {
578 return (int) target.getRegInfo().getFramePointer();
579 }
580 virtual int getRegSpillAreaBaseRegNum() const {
581 return (int) target.getRegInfo().getFramePointer();
582 }
583 virtual int getDynamicAreaBaseRegNum() const {
584 return (int) target.getRegInfo().getStackPointer();
585 }
586
587private:
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000588 // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
589 static const int OFFSET = (int) 0x7ff;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000590 static const int StackFrameSizeAlignment = 16;
Vikram S. Advec1521632001-10-22 13:31:53 +0000591 static const int MinStackFrameSize = 176;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000592 static const int NumFixedOutgoingArgs = 6;
593 static const int SizeOfEachArgOnStack = 8;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +0000594 static const int StaticAreaOffsetFromFP = 0 + OFFSET;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000595 static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET;
596 static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET;
597 static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET;
598 static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET;
Vikram S. Advec1521632001-10-22 13:31:53 +0000599};
600
601
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000602//---------------------------------------------------------------------------
603// class UltraSparcCacheInfo
604//
605// Purpose:
606// Interface to cache parameters for the UltraSPARC.
607// Just use defaults for now.
608//---------------------------------------------------------------------------
609
610class UltraSparcCacheInfo: public MachineCacheInfo {
611public:
Chris Lattner7327d7e2002-02-04 00:04:35 +0000612 UltraSparcCacheInfo(const TargetMachine &T) : MachineCacheInfo(T) {}
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000613};
614
Vikram S. Advec1521632001-10-22 13:31:53 +0000615
616//---------------------------------------------------------------------------
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000617// class UltraSparcMachine
618//
619// Purpose:
620// Primary interface to machine description for the UltraSPARC.
621// Primarily just initializes machine-dependent parameters in
622// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +0000623// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000624//---------------------------------------------------------------------------
625
626class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +0000627private:
628 UltraSparcInstrInfo instrInfo;
629 UltraSparcSchedInfo schedInfo;
630 UltraSparcRegInfo regInfo;
Vikram S. Advec1521632001-10-22 13:31:53 +0000631 UltraSparcFrameInfo frameInfo;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000632 UltraSparcCacheInfo cacheInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000633public:
634 UltraSparc();
Vikram S. Adve339084b2001-09-18 13:04:24 +0000635
Chris Lattner32f600a2001-09-19 13:47:12 +0000636 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
637 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
638 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000639 virtual const MachineFrameInfo &getFrameInfo() const { return frameInfo; }
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000640 virtual const MachineCacheInfo &getCacheInfo() const { return cacheInfo; }
Chris Lattner32f600a2001-09-19 13:47:12 +0000641
642 //
Chris Lattner4387e312002-02-03 23:42:19 +0000643 // addPassesToEmitAssembly - Add passes to the specified pass manager to get
644 // assembly langage code emited. For sparc, we have to do ...
Chris Lattner32f600a2001-09-19 13:47:12 +0000645 //
Chris Lattner4387e312002-02-03 23:42:19 +0000646 virtual void addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000647
Chris Lattner4387e312002-02-03 23:42:19 +0000648private:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000649 Pass *getFunctionAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner4387e312002-02-03 23:42:19 +0000650 Pass *getModuleAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner9530a6f2002-02-11 22:35:46 +0000651 Pass *getEmitBytecodeToAsmPass(std::ostream &Out);
Chris Lattner6edfcc52002-02-03 07:51:17 +0000652};
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000653
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000654#endif