blob: b85b58f39becc8541044108ec4d5bc72bba6b01f [file] [log] [blame]
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001// $Id$ -*- C++ -*--
2//***************************************************************************
3// File:
4// SparcInternals.h
5//
6// Purpose:
7// This file defines stuff that is to be private to the Sparc
8// backend, but is shared among different portions of the backend.
9//**************************************************************************/
10
Chris Lattnerc6495ee2001-09-14 03:56:45 +000011
12#ifndef SPARC_INTERNALS_H
13#define SPARC_INTERNALS_H
14
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000015#include "llvm/Target/TargetMachine.h"
Vikram S. Adve339084b2001-09-18 13:04:24 +000016#include "llvm/Target/MachineSchedInfo.h"
Vikram S. Adve5afff3b2001-11-09 02:15:52 +000017#include "llvm/Target/MachineFrameInfo.h"
18#include "llvm/Target/MachineCacheInfo.h"
Chris Lattner699683c2002-02-04 05:59:25 +000019#include "llvm/Target/MachineRegInfo.h"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000020#include "llvm/Type.h"
Chris Lattner46cbff62001-09-14 16:56:32 +000021#include <sys/types.h>
Chris Lattnerc6495ee2001-09-14 03:56:45 +000022
Chris Lattner4387e312002-02-03 23:42:19 +000023class LiveRange;
Chris Lattnerf6e0e282001-09-14 04:32:55 +000024class UltraSparc;
Chris Lattner4387e312002-02-03 23:42:19 +000025class PhyRegAlloc;
Chris Lattner9aa697b2002-04-09 05:16:36 +000026class Pass;
Chris Lattner4387e312002-02-03 23:42:19 +000027
Chris Lattner9aa697b2002-04-09 05:16:36 +000028Pass *createPrologEpilogCodeInserter(TargetMachine &TM);
Chris Lattnerf6e0e282001-09-14 04:32:55 +000029
Chris Lattnerc6495ee2001-09-14 03:56:45 +000030// OpCodeMask definitions for the Sparc V9
31//
32const OpCodeMask Immed = 0x00002000; // immed or reg operand?
33const OpCodeMask Annul = 0x20000000; // annul delay instr?
34const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
35
36
37enum SparcInstrSchedClass {
38 SPARC_NONE, /* Instructions with no scheduling restrictions */
39 SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */
40 SPARC_IEU0, /* Integer class IEU0 */
41 SPARC_IEU1, /* Integer class IEU1 */
42 SPARC_FPM, /* FP Multiply or Divide instructions */
43 SPARC_FPA, /* All other FP instructions */
44 SPARC_CTI, /* Control-transfer instructions */
45 SPARC_LD, /* Load instructions */
46 SPARC_ST, /* Store instructions */
47 SPARC_SINGLE, /* Instructions that must issue by themselves */
48
49 SPARC_INV, /* This should stay at the end for the next value */
50 SPARC_NUM_SCHED_CLASSES = SPARC_INV
51};
52
Chris Lattnerc6495ee2001-09-14 03:56:45 +000053
54//---------------------------------------------------------------------------
55// enum SparcMachineOpCode.
56// const MachineInstrDescriptor SparcMachineInstrDesc[]
57//
58// Purpose:
59// Description of UltraSparc machine instructions.
60//
61//---------------------------------------------------------------------------
62
Chris Lattnerc6495ee2001-09-14 03:56:45 +000063enum SparcMachineOpCode {
Chris Lattner9a3d63b2001-09-19 15:56:23 +000064#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
65 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
66 ENUM,
67#include "SparcInstr.def"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000068
Chris Lattnerc6495ee2001-09-14 03:56:45 +000069 // End-of-array marker
70 INVALID_OPCODE,
Vikram S. Advec1521632001-10-22 13:31:53 +000071 NUM_REAL_OPCODES = PHI, // number of valid opcodes
Chris Lattnerc6495ee2001-09-14 03:56:45 +000072 NUM_TOTAL_OPCODES = INVALID_OPCODE
73};
74
Chris Lattnerc6495ee2001-09-14 03:56:45 +000075
Chris Lattner9a3d63b2001-09-19 15:56:23 +000076// Array of machine instruction descriptions...
77extern const MachineInstrDescriptor SparcMachineInstrDesc[];
Chris Lattnerc6495ee2001-09-14 03:56:45 +000078
79
80//---------------------------------------------------------------------------
81// class UltraSparcInstrInfo
82//
83// Purpose:
84// Information about individual instructions.
85// Most information is stored in the SparcMachineInstrDesc array above.
86// Other information is computed on demand, and most such functions
87// default to member functions in base class MachineInstrInfo.
88//---------------------------------------------------------------------------
89
90class UltraSparcInstrInfo : public MachineInstrInfo {
91public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000092 /*ctor*/ UltraSparcInstrInfo(const TargetMachine& tgt);
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000093
94 //
Vikram S. Advedd558992002-03-18 03:02:42 +000095 // All immediate constants are in position 1 except the
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000096 // store instructions.
97 //
Vikram S. Advedd558992002-03-18 03:02:42 +000098 virtual int getImmedConstantPos(MachineOpCode opCode) const {
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000099 bool ignore;
100 if (this->maxImmedConstant(opCode, ignore) != 0)
101 {
102 assert(! this->isStore((MachineOpCode) STB - 1)); // first store is STB
103 assert(! this->isStore((MachineOpCode) STD + 1)); // last store is STD
Vikram S. Advedd558992002-03-18 03:02:42 +0000104 return (opCode >= STB && opCode <= STD)? 2 : 1;
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +0000105 }
106 else
107 return -1;
108 }
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000109
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000110 virtual bool hasResultInterlock (MachineOpCode opCode) const
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000111 {
112 // All UltraSPARC instructions have interlocks (note that delay slots
113 // are not considered here).
114 // However, instructions that use the result of an FCMP produce a
115 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
116 // Force the compiler to insert a software interlock (i.e., gap of
117 // 2 other groups, including NOPs if necessary).
118 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
119 }
120
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000121 //-------------------------------------------------------------------------
122 // Code generation support for creating individual machine instructions
123 //-------------------------------------------------------------------------
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000124
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000125 // Create an instruction sequence to put the constant `val' into
Vikram S. Adve242a8082002-05-19 15:25:51 +0000126 // the virtual register `dest'. `val' may be a Constant or a
127 // GlobalValue, viz., the constant address of a global variable or function.
128 // The generated instructions are returned in `mvec'.
129 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
130 // Any stack space required is allocated via mcff.
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000131 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000132 virtual void CreateCodeToLoadConst(const TargetMachine& target,
133 Function* F,
Vikram S. Advedd558992002-03-18 03:02:42 +0000134 Value* val,
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000135 Instruction* dest,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000136 std::vector<MachineInstr*>& mvec,
137 MachineCodeForInstruction& mcfi) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000138
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000139 // Create an instruction sequence to copy an integer value `val'
140 // to a floating point value `dest' by copying to memory and back.
141 // val must be an integral type. dest must be a Float or Double.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000142 // The generated instructions are returned in `mvec'.
143 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
144 // Any stack space required is allocated via mcff.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000145 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000146 virtual void CreateCodeToCopyIntToFloat(const TargetMachine& target,
147 Function* F,
148 Value* val,
149 Instruction* dest,
150 std::vector<MachineInstr*>& mvec,
151 MachineCodeForInstruction& mcfi) const;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000152
153 // Similarly, create an instruction sequence to copy an FP value
154 // `val' to an integer value `dest' by copying to memory and back.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000155 // The generated instructions are returned in `mvec'.
156 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
157 // Any stack space required is allocated via mcff.
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000158 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000159 virtual void CreateCodeToCopyFloatToInt(const TargetMachine& target,
160 Function* F,
161 Value* val,
162 Instruction* dest,
163 std::vector<MachineInstr*>& mvec,
164 MachineCodeForInstruction& mcfi) const;
165
166 // Create instruction(s) to copy src to dest, for arbitrary types
167 // The generated instructions are returned in `mvec'.
168 // Any temp. registers (TmpInstruction) created are recorded in mcfi.
169 // Any stack space required is allocated via mcff.
170 //
Vikram S. Advedd558992002-03-18 03:02:42 +0000171 virtual void CreateCopyInstructionsByType(const TargetMachine& target,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000172 Function* F,
173 Value* src,
174 Instruction* dest,
175 std::vector<MachineInstr*>& mvec,
176 MachineCodeForInstruction& mcfi) const;
177
178 // Create instruction sequence to produce a sign-extended register value
179 // from an arbitrary sized value (sized in bits, not bytes).
180 // Any stack space required is allocated via mcff.
181 //
182 virtual void CreateSignExtensionInstructions(const TargetMachine& target,
183 Function* F,
184 Value* unsignedSrcVal,
185 unsigned int srcSizeInBits,
186 Value* dest,
187 std::vector<MachineInstr*>& mvec,
188 MachineCodeForInstruction& mcfi) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000189};
190
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000191
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000192//----------------------------------------------------------------------------
193// class UltraSparcRegInfo
194//
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000195// This class implements the virtual class MachineRegInfo for Sparc.
196//
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000197//----------------------------------------------------------------------------
198
Chris Lattner699683c2002-02-04 05:59:25 +0000199class UltraSparcRegInfo : public MachineRegInfo {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000200 // The actual register classes in the Sparc
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000201 //
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000202 enum RegClassIDs {
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000203 IntRegClassID, // Integer
204 FloatRegClassID, // Float (both single/double)
205 IntCCRegClassID, // Int Condition Code
206 FloatCCRegClassID // Float Condition code
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000207 };
208
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000209
210 // Type of registers available in Sparc. There can be several reg types
211 // in the same class. For instace, the float reg class has Single/Double
212 // types
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000213 //
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000214 enum RegTypes {
215 IntRegType,
216 FPSingleRegType,
217 FPDoubleRegType,
218 IntCCRegType,
219 FloatCCRegType
220 };
221
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000222 // **** WARNING: If the above enum order is changed, also modify
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000223 // getRegisterClassOfValue method below since it assumes this particular
224 // order for efficiency.
225
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000226
227 // reverse pointer to get info about the ultra sparc machine
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000228 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000229 const UltraSparc *const UltraSparcInfo;
230
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000231 // Number of registers used for passing int args (usually 6: %o0 - %o5)
232 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000233 unsigned const NumOfIntArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000234
235 // Number of registers used for passing float args (usually 32: %f0 - %f31)
236 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000237 unsigned const NumOfFloatArgRegs;
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000238
239 // An out of bound register number that can be used to initialize register
240 // numbers. Useful for error detection.
241 //
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000242 int const InvalidRegNum;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000243
244
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000245 // ======================== Private Methods =============================
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000246
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000247 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000248 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000249 // as required. See SparcRegInfo.cpp for the implementation.
250 //
Chris Lattner699683c2002-02-04 05:59:25 +0000251 void setCallOrRetArgCol(LiveRange *LR, unsigned RegNo,
252 const MachineInstr *MI,
253 std::hash_map<const MachineInstr *,
254 AddedInstrns *> &AIMap) const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000255
Chris Lattner699683c2002-02-04 05:59:25 +0000256 MachineInstr *getCopy2RegMI(const Value *SrcVal, unsigned Reg,
257 unsigned RegClassID) const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000258
Chris Lattner699683c2002-02-04 05:59:25 +0000259 void suggestReg4RetAddr(const MachineInstr *RetMI,
260 LiveRangeInfo &LRI) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000261
Chris Lattner699683c2002-02-04 05:59:25 +0000262 void suggestReg4CallAddr(const MachineInstr *CallMI, LiveRangeInfo &LRI,
Chris Lattner697954c2002-01-20 22:54:45 +0000263 std::vector<RegClass *> RCList) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000264
Vikram S. Adve242a8082002-05-19 15:25:51 +0000265 void InitializeOutgoingArg(const MachineInstr* CallMI, AddedInstrns *CallAI,
266 PhyRegAlloc &PRA, LiveRange* LR,
267 unsigned regType, unsigned RegClassID,
268 int UniArgReg, unsigned int argNo,
269 std::vector<MachineInstr *>& AddedInstrnsBefore)
270 const;
271
272 // The following 4 methods are used to find the RegType (see enum above)
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000273 // of a LiveRange, Value and using the unified RegClassID
Vikram S. Adve242a8082002-05-19 15:25:51 +0000274 int getRegType(unsigned regClassID, const Type* type) const;
Chris Lattner699683c2002-02-04 05:59:25 +0000275 int getRegType(const LiveRange *LR) const;
276 int getRegType(const Value *Val) const;
277 int getRegType(int reg) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000278
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000279
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000280 // The following methods are used to generate copy instructions to move
281 // data between condition code registers
282 //
Chris Lattner699683c2002-02-04 05:59:25 +0000283 MachineInstr *cpCCR2IntMI(unsigned IntReg) const;
284 MachineInstr *cpInt2CCRMI(unsigned IntReg) const;
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000285
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000286 // Used to generate a copy instruction based on the register class of
287 // value.
288 //
Chris Lattner699683c2002-02-04 05:59:25 +0000289 MachineInstr *cpValue2RegMI(Value *Val, unsigned DestReg,
290 int RegType) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000291
292
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000293 // The following 2 methods are used to order the instructions addeed by
Chris Lattnerf57b8452002-04-27 06:56:12 +0000294 // the register allocator in association with function calling. See
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000295 // SparcRegInfo.cpp for more details
296 //
Chris Lattner697954c2002-01-20 22:54:45 +0000297 void moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec,
298 MachineInstr *UnordInst,
299 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000300
Chris Lattner697954c2002-01-20 22:54:45 +0000301 void OrderAddedInstrns(std::vector<MachineInstr *> &UnordVec,
302 std::vector<MachineInstr *> &OrdVec,
303 PhyRegAlloc &PRA) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000304
305
Vikram S. Adve6d783112002-04-25 04:40:24 +0000306 // Compute which register can be used for an argument, if any
307 //
308 int regNumForIntArg(bool inCallee, bool isVarArgsCall,
309 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
310 unsigned& regClassId) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000311
Vikram S. Adve6d783112002-04-25 04:40:24 +0000312 int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
313 unsigned argNo, unsigned intArgNo, unsigned fpArgNo,
314 unsigned& regClassId) const;
315
Chris Lattner699683c2002-02-04 05:59:25 +0000316public:
317 UltraSparcRegInfo(const UltraSparc &tgt);
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000318
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000319 // To get complete machine information structure using the machine register
320 // information
321 //
Chris Lattner699683c2002-02-04 05:59:25 +0000322 inline const UltraSparc &getUltraSparcInfo() const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000323 return *UltraSparcInfo;
324 }
325
Vikram S. Advedd558992002-03-18 03:02:42 +0000326 // To find the register class used for a specified Type
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000327 //
Vikram S. Advedd558992002-03-18 03:02:42 +0000328 inline unsigned getRegClassIDOfType(const Type *type,
329 bool isCCReg = false) const {
330 Type::PrimitiveID ty = type->getPrimitiveID();
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000331 unsigned res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000332
Chris Lattnerc9aa7df2002-03-29 03:51:11 +0000333 // FIXME: Comparing types like this isn't very safe...
Chris Lattner699683c2002-02-04 05:59:25 +0000334 if ((ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
Chris Lattnerc9aa7df2002-03-29 03:51:11 +0000335 (ty == Type::FunctionTyID) || (ty == Type::PointerTyID) )
Chris Lattner699683c2002-02-04 05:59:25 +0000336 res = IntRegClassID; // sparc int reg (ty=0: void)
337 else if (ty <= Type::DoubleTyID)
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000338 res = FloatRegClassID; // sparc float reg class
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000339 else {
Chris Lattner49b8a9c2002-02-24 23:02:40 +0000340 //std::cerr << "TypeID: " << ty << "\n";
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000341 assert(0 && "Cannot resolve register class for type");
Chris Lattner8e5c0b42001-11-07 14:01:59 +0000342 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000343 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000344
345 if(isCCReg)
346 return res + 2; // corresponidng condition code regiser
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000347 else
348 return res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000349 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000350
Vikram S. Advedd558992002-03-18 03:02:42 +0000351 // To find the register class of a Value
352 //
353 inline unsigned getRegClassIDOfValue(const Value *Val,
354 bool isCCReg = false) const {
355 return getRegClassIDOfType(Val->getType(), isCCReg);
356 }
357
358
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000359
Chris Lattner699683c2002-02-04 05:59:25 +0000360 // getZeroRegNum - returns the register that contains always zero this is the
361 // unified register number
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000362 //
Chris Lattner699683c2002-02-04 05:59:25 +0000363 virtual int getZeroRegNum() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000364
Chris Lattner699683c2002-02-04 05:59:25 +0000365 // getCallAddressReg - returns the reg used for pushing the address when a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000366 // function is called. This can be used for other purposes between calls
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000367 //
Chris Lattner699683c2002-02-04 05:59:25 +0000368 unsigned getCallAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000369
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000370 // Returns the register containing the return address.
371 // It should be made sure that this register contains the return
372 // value when a return instruction is reached.
373 //
Chris Lattner699683c2002-02-04 05:59:25 +0000374 unsigned getReturnAddressReg() const;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000375
Vikram S. Adve242a8082002-05-19 15:25:51 +0000376 // Number of registers used for passing int args (usually 6: %o0 - %o5)
377 // and float args (usually 32: %f0 - %f31)
378 //
379 unsigned const GetNumOfIntArgRegs() const { return NumOfIntArgRegs; }
380 unsigned const GetNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
381
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000382 // The following methods are used to color special live ranges (e.g.
Chris Lattnerf57b8452002-04-27 06:56:12 +0000383 // function args and return values etc.) with specific hardware registers
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000384 // as required. See SparcRegInfo.cpp for the implementation for Sparc.
385 //
Chris Lattnerb7653df2002-04-08 22:03:57 +0000386 void suggestRegs4MethodArgs(const Function *Meth,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000387 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000388
Chris Lattner699683c2002-02-04 05:59:25 +0000389 void suggestRegs4CallArgs(const MachineInstr *CallMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000390 LiveRangeInfo& LRI,
391 std::vector<RegClass *> RCL) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000392
Chris Lattner699683c2002-02-04 05:59:25 +0000393 void suggestReg4RetValue(const MachineInstr *RetMI,
Chris Lattner697954c2002-01-20 22:54:45 +0000394 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000395
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000396
Chris Lattnerb7653df2002-04-08 22:03:57 +0000397 void colorMethodArgs(const Function *Meth, LiveRangeInfo &LRI,
Chris Lattner699683c2002-02-04 05:59:25 +0000398 AddedInstrns *FirstAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000399
Chris Lattner699683c2002-02-04 05:59:25 +0000400 void colorCallArgs(const MachineInstr *CallMI, LiveRangeInfo &LRI,
401 AddedInstrns *CallAI, PhyRegAlloc &PRA,
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000402 const BasicBlock *BB) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000403
Chris Lattner699683c2002-02-04 05:59:25 +0000404 void colorRetValue(const MachineInstr *RetI, LiveRangeInfo& LRI,
405 AddedInstrns *RetAI) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000406
407
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000408
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000409 // method used for printing a register for debugging purposes
410 //
Chris Lattner699683c2002-02-04 05:59:25 +0000411 static void printReg(const LiveRange *LR);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000412
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000413 // this method provides a unique number for each register
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000414 //
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000415 inline int getUnifiedRegNum(int RegClassID, int reg) const {
416
417 if( RegClassID == IntRegClassID && reg < 32 )
418 return reg;
419 else if ( RegClassID == FloatRegClassID && reg < 64)
420 return reg + 32; // we have 32 int regs
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000421 else if( RegClassID == FloatCCRegClassID && reg < 4)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000422 return reg + 32 + 64; // 32 int, 64 float
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000423 else if( RegClassID == IntCCRegClassID )
Vikram S. Advedd558992002-03-18 03:02:42 +0000424 return reg + 4+ 32 + 64; // only int cc reg
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000425 else if (reg==InvalidRegNum)
426 return InvalidRegNum;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000427 else
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000428 assert(0 && "Invalid register class or reg number");
Chris Lattner6dad5062001-11-07 13:49:12 +0000429 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000430 }
431
432 // given the unified register number, this gives the name
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000433 // for generating assembly code or debugging.
434 //
Chris Lattner699683c2002-02-04 05:59:25 +0000435 virtual const std::string getUnifiedRegName(int reg) const;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000436
437
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000438 // returns the # of bytes of stack space allocated for each register
439 // type. For Sparc, currently we allocate 8 bytes on stack for all
440 // register types. We can optimize this later if necessary to save stack
441 // space (However, should make sure that stack alignment is correct)
442 //
Chris Lattner699683c2002-02-04 05:59:25 +0000443 inline int getSpilledRegSize(int RegType) const {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000444 return 8;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000445 }
446
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000447
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000448 // To obtain the return value and the indirect call address (if any)
449 // contained in a CALL machine instruction
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000450 //
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000451 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
Vikram S. Advea44c6c02002-03-31 19:04:50 +0000452 const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000453
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000454 // The following methods are used to generate "copy" machine instructions
455 // for an architecture.
456 //
Vikram S. Adve242a8082002-05-19 15:25:51 +0000457 void cpReg2RegMI(unsigned SrcReg, unsigned DestReg,
458 int RegType, vector<MachineInstr*>& mvec) const;
Vikram S. Adve6d783112002-04-25 04:40:24 +0000459
Vikram S. Adve242a8082002-05-19 15:25:51 +0000460 void cpReg2MemMI(unsigned SrcReg, unsigned DestPtrReg,
461 int Offset, int RegType, vector<MachineInstr*>& mvec) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000462
Vikram S. Adve242a8082002-05-19 15:25:51 +0000463 void cpMem2RegMI(unsigned SrcPtrReg, int Offset, unsigned DestReg,
464 int RegType, vector<MachineInstr*>& mvec) const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000465
Vikram S. Adve242a8082002-05-19 15:25:51 +0000466 void cpValue2Value(Value *Src, Value *Dest,
467 vector<MachineInstr*>& mvec) const;
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000468
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000469 // To see whether a register is a volatile (i.e., whehter it must be
470 // preserved acorss calls)
471 //
Chris Lattner699683c2002-02-04 05:59:25 +0000472 inline bool isRegVolatile(int RegClassID, int Reg) const {
473 return MachineRegClassArr[RegClassID]->isRegVolatile(Reg);
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000474 }
475
476
Chris Lattner699683c2002-02-04 05:59:25 +0000477 virtual unsigned getFramePointer() const;
478 virtual unsigned getStackPointer() const;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000479
Chris Lattner699683c2002-02-04 05:59:25 +0000480 virtual int getInvalidRegNum() const {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000481 return InvalidRegNum;
482 }
483
Ruchira Sasanka2563a982002-01-07 20:28:49 +0000484 // This method inserts the caller saving code for call instructions
485 //
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000486 void insertCallerSavingCode(const MachineInstr *MInst,
487 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000488};
489
490
491
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000492
493//---------------------------------------------------------------------------
494// class UltraSparcSchedInfo
495//
496// Purpose:
497// Interface to instruction scheduling information for UltraSPARC.
498// The parameter values above are based on UltraSPARC IIi.
499//---------------------------------------------------------------------------
500
501
502class UltraSparcSchedInfo: public MachineSchedInfo {
503public:
Chris Lattner699683c2002-02-04 05:59:25 +0000504 UltraSparcSchedInfo(const TargetMachine &tgt);
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000505protected:
Chris Lattner699683c2002-02-04 05:59:25 +0000506 virtual void initializeResources();
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000507};
508
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000509
510//---------------------------------------------------------------------------
Vikram S. Advec1521632001-10-22 13:31:53 +0000511// class UltraSparcFrameInfo
512//
513// Purpose:
514// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +0000515// Starting offsets for each area of the stack frame are aligned at
516// a multiple of getStackFrameSizeAlignment().
Vikram S. Advec1521632001-10-22 13:31:53 +0000517//---------------------------------------------------------------------------
518
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000519class UltraSparcFrameInfo: public MachineFrameInfo {
Vikram S. Advec1521632001-10-22 13:31:53 +0000520public:
Chris Lattner699683c2002-02-04 05:59:25 +0000521 UltraSparcFrameInfo(const TargetMachine &tgt) : MachineFrameInfo(tgt) {}
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000522
523public:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000524 int getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;}
525 int getMinStackFrameSize() const { return MinStackFrameSize; }
526 int getNumFixedOutgoingArgs() const { return NumFixedOutgoingArgs; }
527 int getSizeOfEachArgOnStack() const { return SizeOfEachArgOnStack; }
528 bool argsOnStackHaveFixedSize() const { return true; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000529
530 //
531 // These methods compute offsets using the frame contents for a
Chris Lattnerf57b8452002-04-27 06:56:12 +0000532 // particular function. The frame contents are obtained from the
533 // MachineCodeInfoForMethod object for the given function.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000534 //
535 int getFirstIncomingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000536 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000537 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000538 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000539 return FirstIncomingArgOffsetFromFP;
540 }
541 int getFirstOutgoingArgOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000542 bool& growUp) const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000543 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000544 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000545 return FirstOutgoingArgOffsetFromSP;
546 }
547 int getFirstOptionalOutgoingArgOffset(MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000548 bool& growUp)const
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000549 {
Vikram S. Adve6d783112002-04-25 04:40:24 +0000550 growUp = true; // arguments area grows upwards
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000551 return FirstOptionalOutgoingArgOffsetFromSP;
552 }
553
554 int getFirstAutomaticVarOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000555 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000556 int getRegSpillAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000557 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000558 int getTmpAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000559 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000560 int getDynamicAreaOffset (MachineCodeForMethod& mcInfo,
Vikram S. Adve6d783112002-04-25 04:40:24 +0000561 bool& growUp) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000562
563 //
564 // These methods specify the base register used for each stack area
565 // (generally FP or SP)
566 //
567 virtual int getIncomingArgBaseRegNum() const {
568 return (int) target.getRegInfo().getFramePointer();
569 }
570 virtual int getOutgoingArgBaseRegNum() const {
571 return (int) target.getRegInfo().getStackPointer();
572 }
573 virtual int getOptionalOutgoingArgBaseRegNum() const {
574 return (int) target.getRegInfo().getStackPointer();
575 }
576 virtual int getAutomaticVarBaseRegNum() const {
577 return (int) target.getRegInfo().getFramePointer();
578 }
579 virtual int getRegSpillAreaBaseRegNum() const {
580 return (int) target.getRegInfo().getFramePointer();
581 }
582 virtual int getDynamicAreaBaseRegNum() const {
583 return (int) target.getRegInfo().getStackPointer();
584 }
585
586private:
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000587 // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
588 static const int OFFSET = (int) 0x7ff;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000589 static const int StackFrameSizeAlignment = 16;
Vikram S. Advec1521632001-10-22 13:31:53 +0000590 static const int MinStackFrameSize = 176;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000591 static const int NumFixedOutgoingArgs = 6;
592 static const int SizeOfEachArgOnStack = 8;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +0000593 static const int StaticAreaOffsetFromFP = 0 + OFFSET;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000594 static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET;
595 static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET;
596 static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET;
597 static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET;
Vikram S. Advec1521632001-10-22 13:31:53 +0000598};
599
600
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000601//---------------------------------------------------------------------------
602// class UltraSparcCacheInfo
603//
604// Purpose:
605// Interface to cache parameters for the UltraSPARC.
606// Just use defaults for now.
607//---------------------------------------------------------------------------
608
609class UltraSparcCacheInfo: public MachineCacheInfo {
610public:
Chris Lattner7327d7e2002-02-04 00:04:35 +0000611 UltraSparcCacheInfo(const TargetMachine &T) : MachineCacheInfo(T) {}
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000612};
613
Vikram S. Advec1521632001-10-22 13:31:53 +0000614
615//---------------------------------------------------------------------------
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000616// class UltraSparcMachine
617//
618// Purpose:
619// Primary interface to machine description for the UltraSPARC.
620// Primarily just initializes machine-dependent parameters in
621// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +0000622// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000623//---------------------------------------------------------------------------
624
625class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +0000626private:
627 UltraSparcInstrInfo instrInfo;
628 UltraSparcSchedInfo schedInfo;
629 UltraSparcRegInfo regInfo;
Vikram S. Advec1521632001-10-22 13:31:53 +0000630 UltraSparcFrameInfo frameInfo;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000631 UltraSparcCacheInfo cacheInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000632public:
633 UltraSparc();
Vikram S. Adve339084b2001-09-18 13:04:24 +0000634
Chris Lattner32f600a2001-09-19 13:47:12 +0000635 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
636 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
637 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000638 virtual const MachineFrameInfo &getFrameInfo() const { return frameInfo; }
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000639 virtual const MachineCacheInfo &getCacheInfo() const { return cacheInfo; }
Chris Lattner32f600a2001-09-19 13:47:12 +0000640
641 //
Chris Lattner4387e312002-02-03 23:42:19 +0000642 // addPassesToEmitAssembly - Add passes to the specified pass manager to get
643 // assembly langage code emited. For sparc, we have to do ...
Chris Lattner32f600a2001-09-19 13:47:12 +0000644 //
Chris Lattner4387e312002-02-03 23:42:19 +0000645 virtual void addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000646
Chris Lattner4387e312002-02-03 23:42:19 +0000647private:
Chris Lattnerf57b8452002-04-27 06:56:12 +0000648 Pass *getFunctionAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner4387e312002-02-03 23:42:19 +0000649 Pass *getModuleAsmPrinterPass(PassManager &PM, std::ostream &Out);
Chris Lattner9530a6f2002-02-11 22:35:46 +0000650 Pass *getEmitBytecodeToAsmPass(std::ostream &Out);
Chris Lattner6edfcc52002-02-03 07:51:17 +0000651};
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000652
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000653#endif