blob: 1d9641d013e9198bc627b2ac4016dd0e9b96a4a8 [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).
Vikram S. Advef36f06b2002-09-05 18:34:31 +0000175 // The generated instructions are appended to `mvec'.
176 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000177 // Any stack space required is allocated via mcff.
178 //
179 virtual void CreateSignExtensionInstructions(const TargetMachine& target,
180 Function* F,
Vikram S. Advef36f06b2002-09-05 18:34:31 +0000181 Value* srcVal,
182 unsigned int srcSizeInBits,
183 Value* dest,
184 std::vector<MachineInstr*>& mvec,
185 MachineCodeForInstruction& mcfi) const;
186
187 // Create instruction sequence to produce a zero-extended register value
188 // from an arbitrary sized value (sized in bits, not bytes).
189 // The generated instructions are appended to `mvec'.
190 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
191 // Any stack space required is allocated via mcff.
192 //
193 virtual void CreateZeroExtensionInstructions(const TargetMachine& target,
194 Function* F,
195 Value* srcVal,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000196 unsigned int srcSizeInBits,
197 Value* dest,
198 std::vector<MachineInstr*>& mvec,
199 MachineCodeForInstruction& mcfi) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000200};
201
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000202
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000203//----------------------------------------------------------------------------
204// class UltraSparcRegInfo
205//
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000206// This class implements the virtual class MachineRegInfo for Sparc.
207//
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000208//----------------------------------------------------------------------------
209
Chris Lattner699683c2002-02-04 05:59:25 +0000210class UltraSparcRegInfo : public MachineRegInfo {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000211 // The actual register classes in the Sparc
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000212 //
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000213 enum RegClassIDs {
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000214 IntRegClassID, // Integer
215 FloatRegClassID, // Float (both single/double)
216 IntCCRegClassID, // Int Condition Code
217 FloatCCRegClassID // Float Condition code
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000218 };
219
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000220
221 // Type of registers available in Sparc. There can be several reg types
222 // in the same class. For instace, the float reg class has Single/Double
223 // types
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000224 //
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000225 enum RegTypes {
226 IntRegType,
227 FPSingleRegType,
228 FPDoubleRegType,
229 IntCCRegType,
230 FloatCCRegType
231 };
232
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000233 // **** WARNING: If the above enum order is changed, also modify
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000234 // getRegisterClassOfValue method below since it assumes this particular
235 // order for efficiency.
236
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000237
238 // reverse pointer to get info about the ultra sparc machine
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000239 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000240 const UltraSparc *const UltraSparcInfo;
241
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000242 // Number of registers used for passing int args (usually 6: %o0 - %o5)
243 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000244 unsigned const NumOfIntArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000245
246 // Number of registers used for passing float args (usually 32: %f0 - %f31)
247 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000248 unsigned const NumOfFloatArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000249
250 // An out of bound register number that can be used to initialize register
251 // numbers. Useful for error detection.
252 //
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000253 int const InvalidRegNum;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000254
255
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000256 // ======================== Private Methods =============================
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000257
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000258 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000259 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000260 // as required. See SparcRegInfo.cpp for the implementation.
261 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000262 void suggestReg4RetAddr(MachineInstr *RetMI,
Chris Lattner699683c2002-02-04 05:59:25 +0000263 LiveRangeInfo &LRI) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000264
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000265 void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner697954c2002-01-20 22:54:45 +0000266 std::vector<RegClass *> RCList) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000267
268 void InitializeOutgoingArg(MachineInstr* CallMI, AddedInstrns *CallAI,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000269 PhyRegAlloc &PRA, LiveRange* LR,
270 unsigned regType, unsigned RegClassID,
271 int UniArgReg, unsigned int argNo,
272 std::vector<MachineInstr *>& AddedInstrnsBefore)
273 const;
274
275 // The following 4 methods are used to find the RegType (see enum above)
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000276 // for a reg class and a given primitive type, a LiveRange, a Value,
277 // or a particular machine register.
278 // The fifth function gives the reg class of the given RegType.
279 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000280 int getRegType(unsigned regClassID, const Type* type) const;
Chris Lattner699683c2002-02-04 05:59:25 +0000281 int getRegType(const LiveRange *LR) const;
282 int getRegType(const Value *Val) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000283 int getRegType(int unifiedRegNum) const;
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000284
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000285 // Used to generate a copy instruction based on the register class of
286 // value.
287 //
Chris Lattner699683c2002-02-04 05:59:25 +0000288 MachineInstr *cpValue2RegMI(Value *Val, unsigned DestReg,
289 int RegType) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000290
291
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000292 // The following 2 methods are used to order the instructions addeed by
Chris Lattnerf57b8452002-04-27 06:56:12 +0000293 // the register allocator in association with function calling. See
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000294 // SparcRegInfo.cpp for more details
295 //
Chris Lattner697954c2002-01-20 22:54:45 +0000296 void moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec,
297 MachineInstr *UnordInst,
298 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000299
Chris Lattner697954c2002-01-20 22:54:45 +0000300 void OrderAddedInstrns(std::vector<MachineInstr *> &UnordVec,
301 std::vector<MachineInstr *> &OrdVec,
302 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000303
304
Vikram S. Adve6d783112002-04-25 04:40:24 +0000305 // Compute which register can be used for an argument, if any
306 //
307 int regNumForIntArg(bool inCallee, bool isVarArgsCall,
308 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
309 unsigned& regClassId) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000310
Vikram S. Adve6d783112002-04-25 04:40:24 +0000311 int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
312 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
313 unsigned& regClassId) const;
314
Chris Lattner699683c2002-02-04 05:59:25 +0000315public:
316 UltraSparcRegInfo(const UltraSparc &tgt);
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000317
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000318 // To get complete machine information structure using the machine register
319 // information
320 //
Chris Lattner699683c2002-02-04 05:59:25 +0000321 inline const UltraSparc &getUltraSparcInfo() const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000322 return *UltraSparcInfo;
323 }
324
Vikram S. Advedd558992002-03-18 03:02:42 +0000325 // To find the register class used for a specified Type
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000326 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000327 unsigned getRegClassIDOfType(const Type *type,
328 bool isCCReg = false) const;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000329
Vikram S. Advedd558992002-03-18 03:02:42 +0000330 // To find the register class of a Value
331 //
332 inline unsigned getRegClassIDOfValue(const Value *Val,
333 bool isCCReg = false) const {
334 return getRegClassIDOfType(Val->getType(), isCCReg);
335 }
336
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000337 // To find the register class to which a specified register belongs
338 //
339 unsigned getRegClassIDOfReg(int unifiedRegNum) const;
340 unsigned getRegClassIDOfRegType(int regType) const;
Vikram S. Advedd558992002-03-18 03:02:42 +0000341
Chris Lattner699683c2002-02-04 05:59:25 +0000342 // getZeroRegNum - returns the register that contains always zero this is the
343 // unified register number
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000344 //
Chris Lattner699683c2002-02-04 05:59:25 +0000345 virtual int getZeroRegNum() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000346
Chris Lattner699683c2002-02-04 05:59:25 +0000347 // getCallAddressReg - returns the reg used for pushing the address when a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000348 // function is called. This can be used for other purposes between calls
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000349 //
Chris Lattner699683c2002-02-04 05:59:25 +0000350 unsigned getCallAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000351
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000352 // Returns the register containing the return address.
353 // It should be made sure that this register contains the return
354 // value when a return instruction is reached.
355 //
Chris Lattner699683c2002-02-04 05:59:25 +0000356 unsigned getReturnAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000357
Vikram S. Adve242a8082002-05-19 15:25:51 +0000358 // Number of registers used for passing int args (usually 6: %o0 - %o5)
359 // and float args (usually 32: %f0 - %f31)
360 //
361 unsigned const GetNumOfIntArgRegs() const { return NumOfIntArgRegs; }
362 unsigned const GetNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
363
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000364 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000365 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000366 // as required. See SparcRegInfo.cpp for the implementation for Sparc.
367 //
Chris Lattnerb7653df2002-04-08 22:03:57 +0000368 void suggestRegs4MethodArgs(const Function *Meth,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000369 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000370
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000371 void suggestRegs4CallArgs(MachineInstr *CallMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000372 LiveRangeInfo& LRI,
373 std::vector<RegClass *> RCL) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000374
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000375 void suggestReg4RetValue(MachineInstr *RetMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000376 LiveRangeInfo& LRI) const;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000377
Chris Lattnerb7653df2002-04-08 22:03:57 +0000378 void colorMethodArgs(const Function *Meth, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000379 AddedInstrns *FirstAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000380
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000381 void colorCallArgs(MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000382 AddedInstrns *CallAI, PhyRegAlloc &PRA,
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000383 const BasicBlock *BB) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000384
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000385 void colorRetValue(MachineInstr *RetI, LiveRangeInfo& LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000386 AddedInstrns *RetAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000387
388
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000389 // method used for printing a register for debugging purposes
390 //
Chris Lattner699683c2002-02-04 05:59:25 +0000391 static void printReg(const LiveRange *LR);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000392
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000393 // Each register class has a seperate space for register IDs. To convert
394 // a regId in a register class to a common Id, or vice versa,
395 // we use the folloing methods.
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000396 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000397 // This method provides a unique number for each register
398 inline int getUnifiedRegNum(unsigned regClassID, int reg) const {
399
400 if (regClassID == IntRegClassID) {
401 assert(reg < 32 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000402 return reg;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000403 }
404 else if (regClassID == FloatRegClassID) {
405 assert(reg < 64 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000406 return reg + 32; // we have 32 int regs
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000407 }
408 else if (regClassID == FloatCCRegClassID) {
409 assert(reg < 4 && "Invalid reg. number");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000410 return reg + 32 + 64; // 32 int, 64 float
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000411 }
412 else if (regClassID == IntCCRegClassID ) {
413 assert(reg == 0 && "Invalid reg. number");
414 return reg + 4+ 32 + 64; // only one int CC reg
415 }
416 else if (reg==InvalidRegNum) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000417 return InvalidRegNum;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000418 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000419 else
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000420 assert(0 && "Invalid register class");
Chris Lattner6dad5062001-11-07 13:49:12 +0000421 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000422 }
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000423
424 // This method converts the unified number to the number in its class,
425 // and returns the class ID in regClassID.
426 inline int getClassRegNum(int ureg, unsigned& regClassID) const {
427 if (ureg < 32) { regClassID = IntRegClassID; return ureg; }
428 else if (ureg < 32+64) { regClassID = FloatRegClassID; return ureg-32; }
429 else if (ureg < 4 +96) { regClassID = FloatCCRegClassID; return ureg-96; }
430 else if (ureg < 1 +100) { regClassID = IntCCRegClassID; return ureg-100;}
431 else if (ureg == InvalidRegNum) { return InvalidRegNum; }
432 else { assert(0 && "Invalid unified register number"); }
Chris Lattnerb82d97e2002-07-25 06:08:32 +0000433 return 0;
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000434 }
435
436 // Returns the assembly-language name of the specified machine register.
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000437 //
Chris Lattner95685682002-08-12 21:25:05 +0000438 virtual const char * const getUnifiedRegName(int reg) const;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000439
440
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000441 // returns the # of bytes of stack space allocated for each register
442 // type. For Sparc, currently we allocate 8 bytes on stack for all
443 // register types. We can optimize this later if necessary to save stack
444 // space (However, should make sure that stack alignment is correct)
445 //
Chris Lattner699683c2002-02-04 05:59:25 +0000446 inline int getSpilledRegSize(int RegType) const {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000447 return 8;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000448 }
449
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000450
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000451 // To obtain the return value and the indirect call address (if any)
452 // contained in a CALL machine instruction
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000453 //
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000454 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000455 const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000456
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000457 // The following methods are used to generate "copy" machine instructions
458 // for an architecture.
459 //
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000460 // The function regTypeNeedsScratchReg() can be used to check whether a
461 // scratch register is needed to copy a register of type `regType' to
462 // or from memory. If so, such a scratch register can be provided by
463 // the caller (e.g., if it knows which regsiters are free); otherwise
464 // an arbitrary one will be chosen and spilled by the copy instructions.
465 //
466 bool regTypeNeedsScratchReg(int RegType,
467 int& scratchRegClassId) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000468
Vikram S. Advefe09fb22002-07-08 23:34:10 +0000469 void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
470 unsigned SrcReg, unsigned DestReg,
471 int RegType) const;
472
473 void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
474 unsigned SrcReg, unsigned DestPtrReg,
475 int Offset, int RegType, int scratchReg = -1) const;
476
477 void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
478 unsigned SrcPtrReg, int Offset, unsigned DestReg,
479 int RegType, int scratchReg = -1) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000480
Vikram S. Adve242a8082002-05-19 15:25:51 +0000481 void cpValue2Value(Value *Src, Value *Dest,
Anand Shuklacfb22d32002-06-25 20:55:50 +0000482 std::vector<MachineInstr*>& mvec) const;
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000483
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000484 // To see whether a register is a volatile (i.e., whehter it must be
485 // preserved acorss calls)
486 //
Chris Lattner699683c2002-02-04 05:59:25 +0000487 inline bool isRegVolatile(int RegClassID, int Reg) const {
488 return MachineRegClassArr[RegClassID]->isRegVolatile(Reg);
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000489 }
490
491
Chris Lattner699683c2002-02-04 05:59:25 +0000492 virtual unsigned getFramePointer() const;
493 virtual unsigned getStackPointer() const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000494
Chris Lattner699683c2002-02-04 05:59:25 +0000495 virtual int getInvalidRegNum() const {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000496 return InvalidRegNum;
497 }
498
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000499 // This method inserts the caller saving code for call instructions
500 //
Anand Shukla24787fa2002-07-11 00:16:28 +0000501 void insertCallerSavingCode(std::vector<MachineInstr*>& instrnsBefore,
502 std::vector<MachineInstr*>& instrnsAfter,
Vikram S. Adve6a49a1e2002-07-10 21:42:42 +0000503 MachineInstr *MInst,
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000504 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000505};
506
507
508
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000509
510//---------------------------------------------------------------------------
511// class UltraSparcSchedInfo
512//
513// Purpose:
514// Interface to instruction scheduling information for UltraSPARC.
515// The parameter values above are based on UltraSPARC IIi.
516//---------------------------------------------------------------------------
517
518
519class UltraSparcSchedInfo: public MachineSchedInfo {
520public:
Chris Lattner699683c2002-02-04 05:59:25 +0000521 UltraSparcSchedInfo(const TargetMachine &tgt);
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000522protected:
Chris Lattner699683c2002-02-04 05:59:25 +0000523 virtual void initializeResources();
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000524};
525
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000526
527//---------------------------------------------------------------------------
Vikram S. Advec1521632001-10-22 13:31:53 +0000528// class UltraSparcFrameInfo
529//
530// Purpose:
531// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +0000532// Starting offsets for each area of the stack frame are aligned at
533// a multiple of getStackFrameSizeAlignment().
Vikram S. Advec1521632001-10-22 13:31:53 +0000534//---------------------------------------------------------------------------
535
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000536class UltraSparcFrameInfo: public MachineFrameInfo {
Vikram S. Advec1521632001-10-22 13:31:53 +0000537public:
Chris Lattner699683c2002-02-04 05:59:25 +0000538 UltraSparcFrameInfo(const TargetMachine &tgt) : MachineFrameInfo(tgt) {}
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000539
540public:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000541 int getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;}
542 int getMinStackFrameSize() const { return MinStackFrameSize; }
543 int getNumFixedOutgoingArgs() const { return NumFixedOutgoingArgs; }
544 int getSizeOfEachArgOnStack() const { return SizeOfEachArgOnStack; }
545 bool argsOnStackHaveFixedSize() const { return true; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000546
547 //
548 // These methods compute offsets using the frame contents for a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000549 // particular function. The frame contents are obtained from the
550 // MachineCodeInfoForMethod object for the given function.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000551 //
552 int getFirstIncomingArgOffset (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 FirstIncomingArgOffsetFromFP;
557 }
558 int getFirstOutgoingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000559 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000560 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000561 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000562 return FirstOutgoingArgOffsetFromSP;
563 }
564 int getFirstOptionalOutgoingArgOffset(MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000565 bool& growUp)const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000566 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000567 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000568 return FirstOptionalOutgoingArgOffsetFromSP;
569 }
570
571 int getFirstAutomaticVarOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000572 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000573 int getRegSpillAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000574 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000575 int getTmpAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000576 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000577 int getDynamicAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000578 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000579
580 //
581 // These methods specify the base register used for each stack area
582 // (generally FP or SP)
583 //
584 virtual int getIncomingArgBaseRegNum() const {
585 return (int) target.getRegInfo().getFramePointer();
586 }
587 virtual int getOutgoingArgBaseRegNum() const {
588 return (int) target.getRegInfo().getStackPointer();
589 }
590 virtual int getOptionalOutgoingArgBaseRegNum() const {
591 return (int) target.getRegInfo().getStackPointer();
592 }
593 virtual int getAutomaticVarBaseRegNum() const {
594 return (int) target.getRegInfo().getFramePointer();
595 }
596 virtual int getRegSpillAreaBaseRegNum() const {
597 return (int) target.getRegInfo().getFramePointer();
598 }
599 virtual int getDynamicAreaBaseRegNum() const {
600 return (int) target.getRegInfo().getStackPointer();
601 }
602
603private:
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000604 // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
605 static const int OFFSET = (int) 0x7ff;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000606 static const int StackFrameSizeAlignment = 16;
Vikram S. Advec1521632001-10-22 13:31:53 +0000607 static const int MinStackFrameSize = 176;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000608 static const int NumFixedOutgoingArgs = 6;
609 static const int SizeOfEachArgOnStack = 8;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +0000610 static const int StaticAreaOffsetFromFP = 0 + OFFSET;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000611 static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET;
612 static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET;
613 static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET;
614 static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET;
Vikram S. Advec1521632001-10-22 13:31:53 +0000615};
616
617
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000618//---------------------------------------------------------------------------
619// class UltraSparcCacheInfo
620//
621// Purpose:
622// Interface to cache parameters for the UltraSPARC.
623// Just use defaults for now.
624//---------------------------------------------------------------------------
625
626class UltraSparcCacheInfo: public MachineCacheInfo {
627public:
Chris Lattner7327d7e2002-02-04 00:04:35 +0000628 UltraSparcCacheInfo(const TargetMachine &T) : MachineCacheInfo(T) {}
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000629};
630
Vikram S. Advec1521632001-10-22 13:31:53 +0000631
632//---------------------------------------------------------------------------
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000633// class UltraSparcMachine
634//
635// Purpose:
636// Primary interface to machine description for the UltraSPARC.
637// Primarily just initializes machine-dependent parameters in
638// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +0000639// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000640//---------------------------------------------------------------------------
641
642class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +0000643private:
644 UltraSparcInstrInfo instrInfo;
645 UltraSparcSchedInfo schedInfo;
646 UltraSparcRegInfo regInfo;
Vikram S. Advec1521632001-10-22 13:31:53 +0000647 UltraSparcFrameInfo frameInfo;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000648 UltraSparcCacheInfo cacheInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000649public:
650 UltraSparc();
Vikram S. Adve339084b2001-09-18 13:04:24 +0000651
Chris Lattner32f600a2001-09-19 13:47:12 +0000652 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
653 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
654 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000655 virtual const MachineFrameInfo &getFrameInfo() const { return frameInfo; }
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000656 virtual const MachineCacheInfo &getCacheInfo() const { return cacheInfo; }
Chris Lattner32f600a2001-09-19 13:47:12 +0000657
658 //
Chris Lattner4387e312002-02-03 23:42:19 +0000659 // addPassesToEmitAssembly - Add passes to the specified pass manager to get
660 // assembly langage code emited. For sparc, we have to do ...
Chris Lattner32f600a2001-09-19 13:47:12 +0000661 //
Chris Lattner4387e312002-02-03 23:42:19 +0000662 virtual void addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000663
Chris Lattner4387e312002-02-03 23:42:19 +0000664private:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000665 Pass *getFunctionAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner4387e312002-02-03 23:42:19 +0000666 Pass *getModuleAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner9530a6f2002-02-11 22:35:46 +0000667 Pass *getEmitBytecodeToAsmPass(std::ostream &Out);
Chris Lattner6edfcc52002-02-03 07:51:17 +0000668};
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000669
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000670#endif