blob: 45aa029e877418a9c041dc088ed8af1cb6da7c26 [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
16#include "SparcRegClassInfo.h"
17#include "llvm/Target/TargetMachine.h"
18#include "llvm/Target/MachineInstrInfo.h"
Vikram S. Adve339084b2001-09-18 13:04:24 +000019#include "llvm/Target/MachineSchedInfo.h"
Vikram S. Adve5afff3b2001-11-09 02:15:52 +000020#include "llvm/Target/MachineFrameInfo.h"
21#include "llvm/Target/MachineCacheInfo.h"
Ruchira Sasankaab304c42001-09-30 23:19:57 +000022#include "llvm/CodeGen/RegClass.h"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000023#include "llvm/Type.h"
Vikram S. Adve339084b2001-09-18 13:04:24 +000024
Chris Lattner46cbff62001-09-14 16:56:32 +000025#include <sys/types.h>
Chris Lattnerc6495ee2001-09-14 03:56:45 +000026
Chris Lattnerf6e0e282001-09-14 04:32:55 +000027class UltraSparc;
28
Chris Lattnerc6495ee2001-09-14 03:56:45 +000029// OpCodeMask definitions for the Sparc V9
30//
31const OpCodeMask Immed = 0x00002000; // immed or reg operand?
32const OpCodeMask Annul = 0x20000000; // annul delay instr?
33const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
34
35
36enum SparcInstrSchedClass {
37 SPARC_NONE, /* Instructions with no scheduling restrictions */
38 SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */
39 SPARC_IEU0, /* Integer class IEU0 */
40 SPARC_IEU1, /* Integer class IEU1 */
41 SPARC_FPM, /* FP Multiply or Divide instructions */
42 SPARC_FPA, /* All other FP instructions */
43 SPARC_CTI, /* Control-transfer instructions */
44 SPARC_LD, /* Load instructions */
45 SPARC_ST, /* Store instructions */
46 SPARC_SINGLE, /* Instructions that must issue by themselves */
47
48 SPARC_INV, /* This should stay at the end for the next value */
49 SPARC_NUM_SCHED_CLASSES = SPARC_INV
50};
51
Chris Lattnerc6495ee2001-09-14 03:56:45 +000052
53//---------------------------------------------------------------------------
54// enum SparcMachineOpCode.
55// const MachineInstrDescriptor SparcMachineInstrDesc[]
56//
57// Purpose:
58// Description of UltraSparc machine instructions.
59//
60//---------------------------------------------------------------------------
61
Chris Lattnerc6495ee2001-09-14 03:56:45 +000062enum SparcMachineOpCode {
Chris Lattner9a3d63b2001-09-19 15:56:23 +000063#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
64 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
65 ENUM,
66#include "SparcInstr.def"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000067
Chris Lattnerc6495ee2001-09-14 03:56:45 +000068 // End-of-array marker
69 INVALID_OPCODE,
Vikram S. Advec1521632001-10-22 13:31:53 +000070 NUM_REAL_OPCODES = PHI, // number of valid opcodes
Chris Lattnerc6495ee2001-09-14 03:56:45 +000071 NUM_TOTAL_OPCODES = INVALID_OPCODE
72};
73
Chris Lattnerc6495ee2001-09-14 03:56:45 +000074
Chris Lattner9a3d63b2001-09-19 15:56:23 +000075// Array of machine instruction descriptions...
76extern const MachineInstrDescriptor SparcMachineInstrDesc[];
Chris Lattnerc6495ee2001-09-14 03:56:45 +000077
78
79//---------------------------------------------------------------------------
80// class UltraSparcInstrInfo
81//
82// Purpose:
83// Information about individual instructions.
84// Most information is stored in the SparcMachineInstrDesc array above.
85// Other information is computed on demand, and most such functions
86// default to member functions in base class MachineInstrInfo.
87//---------------------------------------------------------------------------
88
89class UltraSparcInstrInfo : public MachineInstrInfo {
90public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +000091 /*ctor*/ UltraSparcInstrInfo(const TargetMachine& tgt);
Vikram S. Adve4c5fe2d2001-11-14 18:48:36 +000092
93 //
94 // All immediate constants are in position 0 except the
95 // store instructions.
96 //
97 virtual int getImmmedConstantPos(MachineOpCode opCode) const {
98 bool ignore;
99 if (this->maxImmedConstant(opCode, ignore) != 0)
100 {
101 assert(! this->isStore((MachineOpCode) STB - 1)); // first store is STB
102 assert(! this->isStore((MachineOpCode) STD + 1)); // last store is STD
103 return (opCode >= STB || opCode <= STD)? 2 : 1;
104 }
105 else
106 return -1;
107 }
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000108
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000109 virtual bool hasResultInterlock (MachineOpCode opCode) const
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000110 {
111 // All UltraSPARC instructions have interlocks (note that delay slots
112 // are not considered here).
113 // However, instructions that use the result of an FCMP produce a
114 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
115 // Force the compiler to insert a software interlock (i.e., gap of
116 // 2 other groups, including NOPs if necessary).
117 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
118 }
119
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000120 //-------------------------------------------------------------------------
121 // Code generation support for creating individual machine instructions
122 //-------------------------------------------------------------------------
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000123
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000124 // Create an instruction sequence to put the constant `val' into
125 // the virtual register `dest'. The generated instructions are
126 // returned in `minstrVec'. Any temporary registers (TmpInstruction)
127 // created are returned in `tempVec'.
128 //
129 virtual void CreateCodeToLoadConst(Value* val,
130 Instruction* dest,
131 vector<MachineInstr*>& minstrVec,
132 vector<TmpInstruction*>& tempVec) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000133
134
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000135 // Create an instruction sequence to copy an integer value `val'
136 // to a floating point value `dest' by copying to memory and back.
137 // val must be an integral type. dest must be a Float or Double.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000138 // The generated instructions are returned in `minstrVec'.
139 // Any temp. registers (TmpInstruction) created are returned in `tempVec'.
140 //
141 virtual void CreateCodeToCopyIntToFloat(Method* method,
142 Value* val,
143 Instruction* dest,
144 vector<MachineInstr*>& minstrVec,
145 vector<TmpInstruction*>& tempVec,
146 TargetMachine& target) 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.
150 // See the previous function for information about return values.
151 //
152 virtual void CreateCodeToCopyFloatToInt(Method* method,
153 Value* val,
154 Instruction* dest,
155 vector<MachineInstr*>& minstrVec,
156 vector<TmpInstruction*>& tempVec,
157 TargetMachine& target) const;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +0000158
159 // create copy instruction(s)
160 virtual void
161 CreateCopyInstructionsByType(const TargetMachine& target,
162 Value* src,
163 Instruction* dest,
164 vector<MachineInstr*>& minstrVec) const;
165
166
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000167};
168
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000169
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000170//----------------------------------------------------------------------------
171// class UltraSparcRegInfo
172//
173//----------------------------------------------------------------------------
174
175
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000176class LiveRange;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000177class UltraSparc;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000178class PhyRegAlloc;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000179
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000180
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000181class UltraSparcRegInfo : public MachineRegInfo
182{
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000183 private:
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000184
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000185 // The actual register classes in the Sparc
186
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000187 enum RegClassIDs {
188 IntRegClassID,
189 FloatRegClassID,
190 IntCCRegClassID,
191 FloatCCRegClassID
192 };
193
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000194
195 // Type of registers available in Sparc. There can be several reg types
196 // in the same class. For instace, the float reg class has Single/Double
197 // types
198 enum RegTypes {
199 IntRegType,
200 FPSingleRegType,
201 FPDoubleRegType,
202 IntCCRegType,
203 FloatCCRegType
204 };
205
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000206 // the size of a value (int, float, etc..) stored in the stack frame
207
208
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000209
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000210 // WARNING: If the above enum order must be changed, also modify
211 // getRegisterClassOfValue method below since it assumes this particular
212 // order for efficiency.
213
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000214
215 // reverse pointer to get info about the ultra sparc machine
216 const UltraSparc *const UltraSparcInfo;
217
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000218 // Both int and float rguments can be passed in 6 int regs -
219 // %o0 to %o5 (cannot be changed)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000220 unsigned const NumOfIntArgRegs;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000221 unsigned const NumOfFloatArgRegs;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000222 int const InvalidRegNum;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000223 int SizeOfOperandOnStack;
224
225
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000226
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000227 //void setCallArgColor(LiveRange *const LR, const unsigned RegNo) const;
228
229 void setCallOrRetArgCol(LiveRange *const LR, const unsigned RegNo,
230 const MachineInstr *MI,AddedInstrMapType &AIMap)const;
231
232 MachineInstr * getCopy2RegMI(const Value *SrcVal, const unsigned Reg,
233 unsigned RegClassID) const ;
234
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000235
236 void suggestReg4RetAddr(const MachineInstr * RetMI,
237 LiveRangeInfo& LRI) const;
238
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000239 void suggestReg4CallAddr(const MachineInstr * CallMI, LiveRangeInfo& LRI,
240 vector<RegClass *> RCList) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000241
242
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000243 Value *getValue4ReturnAddr( const MachineInstr * MInst ) const ;
244
245 int getRegType(const LiveRange *const LR) const {
246
247 unsigned Typ;
248
249 switch( (LR->getRegClass())->getID() ) {
250
251 case IntRegClassID: return IntRegType;
252
253 case FloatRegClassID:
254 Typ = LR->getTypeID();
255 if( Typ == Type::FloatTyID )
256 return FPSingleRegType;
257 else if( Typ == Type::DoubleTyID )
258 return FPDoubleRegType;
259 else assert(0 && "Unknown type in FloatRegClass");
260
261 case IntCCRegClassID: return IntCCRegType;
262
263 case FloatCCRegClassID: return FloatCCRegType ;
264
265 default: assert( 0 && "Unknown reg class ID");
Chris Lattner6dad5062001-11-07 13:49:12 +0000266 return 0;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000267 }
268
269 }
270
271 int getRegType(const Value *const Val) const {
272
273 unsigned Typ;
274
275 switch( getRegClassIDOfValue(Val) ) {
276
277 case IntRegClassID: return IntRegType;
278
279 case FloatRegClassID:
280 Typ = (Val->getType())->getPrimitiveID();
281 if( Typ == Type::FloatTyID )
282 return FPSingleRegType;
283 else if( Typ == Type::DoubleTyID )
284 return FPDoubleRegType;
285 else assert(0 && "Unknown type in FloatRegClass");
286
287 case IntCCRegClassID: return IntCCRegType;
288
289 case FloatCCRegClassID: return FloatCCRegType ;
290
291 default: assert( 0 && "Unknown reg class ID");
Chris Lattner6dad5062001-11-07 13:49:12 +0000292 return 0;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000293 }
294
295 }
296
297
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000298 int getRegType(int reg) const {
299 if( reg < 32 )
300 return IntRegType;
301 else if ( reg < (32 + 32) )
302 return FPSingleRegType;
303 else if ( reg < (64 + 32) )
304 return FPDoubleRegType;
305 else if( reg < (64+32+4) )
306 return FloatCCRegType;
307 else if( reg < (64+32+4+2) )
308 return IntCCRegType;
309 else
310 assert(0 && "Invalid register number in getRegType");
311 }
312
313
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000314
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000315 // ***TODO: See this method is necessary
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000316
317 MachineInstr * cpValue2RegMI(Value * Val, const unsigned DestReg,
318 const int RegType) const;
319
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000320 const Value *getCallInstRetAddr(const MachineInstr *CallMI) const;
321 const unsigned getCallInstNumArgs(const MachineInstr *CallMI) const;
322
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000323
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000324 MachineInstr * cpCCR2IntMI(const unsigned IntReg) const;
325 MachineInstr * cpInt2CCRMI(const unsigned IntReg) const;
326
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000327
328
329 void moveInst2OrdVec(vector<MachineInstr *> &OrdVec, MachineInstr *UnordInst,
330 PhyRegAlloc &PRA ) const;
331
Ruchira Sasanka868cf822001-11-09 23:49:14 +0000332 void OrderAddedInstrns( vector<MachineInstr *> &UnordVec,
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000333 vector<MachineInstr *> &OrdVec,
334 PhyRegAlloc &PRA) const;
335
336
337
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000338 bool isVarArgCall(const MachineInstr *CallMI) const;
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000339
Ruchira Sasanka868cf822001-11-09 23:49:14 +0000340
341
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000342 public:
343
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000344
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000345 UltraSparcRegInfo(const TargetMachine& tgt ) :
346 MachineRegInfo(tgt),
347 UltraSparcInfo(& (const UltraSparc&) tgt),
348 NumOfIntArgRegs(6),
349 NumOfFloatArgRegs(32),
350 InvalidRegNum(1000),
351 SizeOfOperandOnStack(8) {
352
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000353 MachineRegClassArr.push_back( new SparcIntRegClass(IntRegClassID) );
354 MachineRegClassArr.push_back( new SparcFloatRegClass(FloatRegClassID) );
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000355 MachineRegClassArr.push_back( new SparcIntCCRegClass(IntCCRegClassID) );
356 MachineRegClassArr.push_back( new SparcFloatCCRegClass(FloatCCRegClassID));
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000357
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000358 assert( SparcFloatRegOrder::StartOfNonVolatileRegs == 32 &&
359 "32 Float regs are used for float arg passing");
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000360
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000361 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000362
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000363 // ***** TODO Delete
364 ~UltraSparcRegInfo(void) { } // empty destructor
365
366
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000367 inline const UltraSparc & getUltraSparcInfo() const {
368 return *UltraSparcInfo;
369 }
370
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000371
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000372
373 inline unsigned getRegClassIDOfValue (const Value *const Val,
374 bool isCCReg = false) const {
375
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000376 Type::PrimitiveID ty = (Val->getType())->getPrimitiveID();
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000377
378 unsigned res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000379
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000380 if( (ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
381 (ty == Type::MethodTyID) || (ty == Type::PointerTyID) )
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000382 res = IntRegClassID; // sparc int reg (ty=0: void)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000383 else if( ty <= Type::DoubleTyID)
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000384 res = FloatRegClassID; // sparc float reg class
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000385 else {
Chris Lattner1e23ed72001-10-15 18:15:27 +0000386 cerr << "TypeID: " << ty << endl;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000387 assert(0 && "Cannot resolve register class for type");
Chris Lattner8e5c0b42001-11-07 14:01:59 +0000388 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000389 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000390
391 if(isCCReg)
392 return res + 2; // corresponidng condition code regiser
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000393 else
394 return res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000395 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000396
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000397 // returns the register tha contains always zero
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000398 // this is the unified register number
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000399 inline int getZeroRegNum() const { return SparcIntRegOrder::g0; }
400
401 // returns the reg used for pushing the address when a method is called.
402 // This can be used for other purposes between calls
403 unsigned getCallAddressReg() const { return SparcIntRegOrder::o7; }
404
405
406 // and when we return from a method. It should be made sure that this
407 // register contains the return value when a return instruction is reached.
408 unsigned getReturnAddressReg() const { return SparcIntRegOrder::i7; }
409
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000410 void suggestRegs4MethodArgs(const Method *const Meth,
411 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000412
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000413 void suggestRegs4CallArgs(const MachineInstr *const CallMI,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000414 LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000415
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000416 void suggestReg4RetValue(const MachineInstr *const RetMI,
417 LiveRangeInfo& LRI ) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000418
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000419
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000420 void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
421 AddedInstrns *const FirstAI) const;
422
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000423 void colorCallArgs(const MachineInstr *const CallMI, LiveRangeInfo& LRI,
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000424 AddedInstrns *const CallAI, PhyRegAlloc &PRA,
425 const BasicBlock *BB) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000426
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000427 void colorRetValue(const MachineInstr *const RetI, LiveRangeInfo& LRI,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000428 AddedInstrns *const RetAI) const;
429
430
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000431 // bool handleSpecialMInstr(const MachineInstr * MInst,
432 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000433
434
435 static void printReg(const LiveRange *const LR) ;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000436
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000437 // this method provides a unique number for each register
438 inline int getUnifiedRegNum(int RegClassID, int reg) const {
439
440 if( RegClassID == IntRegClassID && reg < 32 )
441 return reg;
442 else if ( RegClassID == FloatRegClassID && reg < 64)
443 return reg + 32; // we have 32 int regs
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000444 else if( RegClassID == FloatCCRegClassID && reg < 4)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000445 return reg + 32 + 64; // 32 int, 64 float
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000446 else if( RegClassID == IntCCRegClassID )
447 return 4+ 32 + 64; // only int cc reg
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000448 else if (reg==InvalidRegNum)
449 return InvalidRegNum;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000450 else
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000451 assert(0 && "Invalid register class or reg number");
Chris Lattner6dad5062001-11-07 13:49:12 +0000452 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000453 }
454
455 // given the unified register number, this gives the name
456 inline const string getUnifiedRegName(int reg) const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000457 if( reg < 32 )
458 return SparcIntRegOrder::getRegName(reg);
459 else if ( reg < (64 + 32) )
460 return SparcFloatRegOrder::getRegName( reg - 32);
461 else if( reg < (64+32+4) )
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000462 return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000463 else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr
464 return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4);
Vikram S. Advec1521632001-10-22 13:31:53 +0000465 else if (reg== InvalidRegNum) //****** TODO: Remove */
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000466 return "<*NoReg*>";
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000467 else
468 assert(0 && "Invalid register number");
Chris Lattner6dad5062001-11-07 13:49:12 +0000469 return "";
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000470 }
471
Vikram S. Advec1521632001-10-22 13:31:53 +0000472 inline unsigned int getRegNumInCallersWindow(int reg) {
473 if (reg == InvalidRegNum || reg >= 32)
474 return reg;
475 return SparcIntRegOrder::getRegNumInCallersWindow(reg);
476 }
477
478 inline bool mustBeRemappedInCallersWindow(int reg) {
479 return (reg != InvalidRegNum && reg < 32);
480 }
481
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000482
483
484 inline int getSpilledRegSize(const int RegType) const {
485 return 8;
486 //
487 // for Sparc, we allocate 8 bytes on stack for all register types
488 }
489
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000490 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
491
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000492 MachineInstr * cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
493 const int RegType) const;
494
495 MachineInstr * cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
496 const int Offset, const int RegType) const;
497
498 MachineInstr * cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
499 const unsigned DestReg, const int RegType) const;
500
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000501 MachineInstr* cpValue2Value(Value *Src, Value *Dest) const;
502
503
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000504 inline bool isRegVolatile(const int RegClassID, const int Reg) const {
505 return (MachineRegClassArr[RegClassID])->isRegVolatile(Reg);
506 }
507
508
509 inline unsigned getFramePointer() const {
510 return SparcIntRegOrder::i6;
511 }
512
513 inline unsigned getStackPointer() const {
514 return SparcIntRegOrder::o6;
515 }
516
517 inline int getInvalidRegNum() const {
518 return InvalidRegNum;
519 }
520
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000521
522 void insertCallerSavingCode(const MachineInstr *MInst,
523 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
524
525
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000526};
527
528
529
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000530/*---------------------------------------------------------------------------
531Scheduling guidelines for SPARC IIi:
532
533I-Cache alignment rules (pg 326)
534-- Align a branch target instruction so that it's entire group is within
535 the same cache line (may be 1-4 instructions).
536** Don't let a branch that is predicted taken be the last instruction
537 on an I-cache line: delay slot will need an entire line to be fetched
538-- Make a FP instruction or a branch be the 4th instruction in a group.
539 For branches, there are tradeoffs in reordering to make this happen
540 (see pg. 327).
541** Don't put a branch in a group that crosses a 32-byte boundary!
542 An artificial branch is inserted after every 32 bytes, and having
543 another branch will force the group to be broken into 2 groups.
544
545iTLB rules:
546-- Don't let a loop span two memory pages, if possible
547
548Branch prediction performance:
549-- Don't make the branch in a delay slot the target of a branch
550-- Try not to have 2 predicted branches within a group of 4 instructions
551 (because each such group has a single branch target field).
552-- Try to align branches in slots 0, 2, 4 or 6 of a cache line (to avoid
553 the wrong prediction bits being used in some cases).
554
555D-Cache timing constraints:
556-- Signed int loads of less than 64 bits have 3 cycle latency, not 2
557-- All other loads that hit in D-Cache have 2 cycle latency
558-- All loads are returned IN ORDER, so a D-Cache miss will delay a later hit
559-- Mis-aligned loads or stores cause a trap. In particular, replace
560 mis-aligned FP double precision l/s with 2 single-precision l/s.
561-- Simulations of integer codes show increase in avg. group size of
562 33% when code (including esp. non-faulting loads) is moved across
563 one branch, and 50% across 2 branches.
564
565E-Cache timing constraints:
566-- Scheduling for E-cache (D-Cache misses) is effective (due to load buffering)
567
568Store buffer timing constraints:
569-- Stores can be executed in same cycle as instruction producing the value
570-- Stores are buffered and have lower priority for E-cache until
571 highwater mark is reached in the store buffer (5 stores)
572
573Pipeline constraints:
574-- Shifts can only use IEU0.
575-- CC setting instructions can only use IEU1.
576-- Several other instructions must only use IEU1:
577 EDGE(?), ARRAY(?), CALL, JMPL, BPr, PST, and FCMP.
578-- Two instructions cannot store to the same register file in a single cycle
579 (single write port per file).
580
581Issue and grouping constraints:
582-- FP and branch instructions must use slot 4.
583-- Shift instructions cannot be grouped with other IEU0-specific instructions.
584-- CC setting instructions cannot be grouped with other IEU1-specific instrs.
585-- Several instructions must be issued in a single-instruction group:
586 MOVcc or MOVr, MULs/x and DIVs/x, SAVE/RESTORE, many others
587-- A CALL or JMPL breaks a group, ie, is not combined with subsequent instrs.
588--
589--
590
591Branch delay slot scheduling rules:
592-- A CTI couple (two back-to-back CTI instructions in the dynamic stream)
593 has a 9-instruction penalty: the entire pipeline is flushed when the
594 second instruction reaches stage 9 (W-Writeback).
595-- Avoid putting multicycle instructions, and instructions that may cause
596 load misses, in the delay slot of an annulling branch.
597-- Avoid putting WR, SAVE..., RESTORE and RETURN instructions in the
598 delay slot of an annulling branch.
599
600 *--------------------------------------------------------------------------- */
601
602//---------------------------------------------------------------------------
603// List of CPUResources for UltraSPARC IIi.
604//---------------------------------------------------------------------------
605
606const CPUResource AllIssueSlots( "All Instr Slots", 4);
607const CPUResource IntIssueSlots( "Int Instr Slots", 3);
608const CPUResource First3IssueSlots("Instr Slots 0-3", 3);
609const CPUResource LSIssueSlots( "Load-Store Instr Slot", 1);
610const CPUResource CTIIssueSlots( "Ctrl Transfer Instr Slot", 1);
611const CPUResource FPAIssueSlots( "Int Instr Slot 1", 1);
612const CPUResource FPMIssueSlots( "Int Instr Slot 1", 1);
613
614// IEUN instructions can use either Alu and should use IAluN.
615// IEU0 instructions must use Alu 1 and should use both IAluN and IAlu0.
616// IEU1 instructions must use Alu 2 and should use both IAluN and IAlu1.
617const CPUResource IAluN("Int ALU 1or2", 2);
618const CPUResource IAlu0("Int ALU 1", 1);
619const CPUResource IAlu1("Int ALU 2", 1);
620
621const CPUResource LSAluC1("Load/Store Unit Addr Cycle", 1);
622const CPUResource LSAluC2("Load/Store Unit Issue Cycle", 1);
623const CPUResource LdReturn("Load Return Unit", 1);
624
625const CPUResource FPMAluC1("FP Mul/Div Alu Cycle 1", 1);
626const CPUResource FPMAluC2("FP Mul/Div Alu Cycle 2", 1);
627const CPUResource FPMAluC3("FP Mul/Div Alu Cycle 3", 1);
628
629const CPUResource FPAAluC1("FP Other Alu Cycle 1", 1);
630const CPUResource FPAAluC2("FP Other Alu Cycle 2", 1);
631const CPUResource FPAAluC3("FP Other Alu Cycle 3", 1);
632
633const CPUResource IRegReadPorts("Int Reg ReadPorts", INT_MAX); // CHECK
634const CPUResource IRegWritePorts("Int Reg WritePorts", 2); // CHECK
635const CPUResource FPRegReadPorts("FP Reg Read Ports", INT_MAX); // CHECK
636const CPUResource FPRegWritePorts("FP Reg Write Ports", 1); // CHECK
637
638const CPUResource CTIDelayCycle( "CTI delay cycle", 1);
639const CPUResource FCMPDelayCycle("FCMP delay cycle", 1);
640
641
642//---------------------------------------------------------------------------
643// const InstrClassRUsage SparcRUsageDesc[]
644//
645// Purpose:
646// Resource usage information for instruction in each scheduling class.
647// The InstrRUsage Objects for individual classes are specified first.
648// Note that fetch and decode are decoupled from the execution pipelines
649// via an instr buffer, so they are not included in the cycles below.
650//---------------------------------------------------------------------------
651
652const InstrClassRUsage NoneClassRUsage = {
653 SPARC_NONE,
654 /*totCycles*/ 7,
655
656 /* maxIssueNum */ 4,
657 /* isSingleIssue */ false,
658 /* breaksGroup */ false,
659 /* numBubbles */ 0,
660
661 /*numSlots*/ 4,
662 /* feasibleSlots[] */ { 0, 1, 2, 3 },
663
664 /*numEntries*/ 0,
665 /* V[] */ {
666 /*Cycle G */
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000667 /*Ccle E */
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000668 /*Cycle C */
669 /*Cycle N1*/
670 /*Cycle N1*/
671 /*Cycle N1*/
672 /*Cycle W */
673 }
674};
675
676const InstrClassRUsage IEUNClassRUsage = {
677 SPARC_IEUN,
678 /*totCycles*/ 7,
679
680 /* maxIssueNum */ 3,
681 /* isSingleIssue */ false,
682 /* breaksGroup */ false,
683 /* numBubbles */ 0,
684
685 /*numSlots*/ 3,
686 /* feasibleSlots[] */ { 0, 1, 2 },
687
688 /*numEntries*/ 4,
689 /* V[] */ {
690 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
691 { IntIssueSlots.rid, 0, 1 },
692 /*Cycle E */ { IAluN.rid, 1, 1 },
693 /*Cycle C */
694 /*Cycle N1*/
695 /*Cycle N1*/
696 /*Cycle N1*/
697 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
698 }
699};
700
701const InstrClassRUsage IEU0ClassRUsage = {
702 SPARC_IEU0,
703 /*totCycles*/ 7,
704
705 /* maxIssueNum */ 1,
706 /* isSingleIssue */ false,
707 /* breaksGroup */ false,
708 /* numBubbles */ 0,
709
710 /*numSlots*/ 3,
711 /* feasibleSlots[] */ { 0, 1, 2 },
712
713 /*numEntries*/ 5,
714 /* V[] */ {
715 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
716 { IntIssueSlots.rid, 0, 1 },
717 /*Cycle E */ { IAluN.rid, 1, 1 },
718 { IAlu0.rid, 1, 1 },
719 /*Cycle C */
720 /*Cycle N1*/
721 /*Cycle N1*/
722 /*Cycle N1*/
723 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
724 }
725};
726
727const InstrClassRUsage IEU1ClassRUsage = {
728 SPARC_IEU1,
729 /*totCycles*/ 7,
730
731 /* maxIssueNum */ 1,
732 /* isSingleIssue */ false,
733 /* breaksGroup */ false,
734 /* numBubbles */ 0,
735
736 /*numSlots*/ 3,
737 /* feasibleSlots[] */ { 0, 1, 2 },
738
739 /*numEntries*/ 5,
740 /* V[] */ {
741 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
742 { IntIssueSlots.rid, 0, 1 },
743 /*Cycle E */ { IAluN.rid, 1, 1 },
744 { IAlu1.rid, 1, 1 },
745 /*Cycle C */
746 /*Cycle N1*/
747 /*Cycle N1*/
748 /*Cycle N1*/
749 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
750 }
751};
752
753const InstrClassRUsage FPMClassRUsage = {
754 SPARC_FPM,
755 /*totCycles*/ 7,
756
757 /* maxIssueNum */ 1,
758 /* isSingleIssue */ false,
759 /* breaksGroup */ false,
760 /* numBubbles */ 0,
761
762 /*numSlots*/ 4,
763 /* feasibleSlots[] */ { 0, 1, 2, 3 },
764
765 /*numEntries*/ 7,
766 /* V[] */ {
767 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
768 { FPMIssueSlots.rid, 0, 1 },
769 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
770 /*Cycle C */ { FPMAluC1.rid, 2, 1 },
771 /*Cycle N1*/ { FPMAluC2.rid, 3, 1 },
772 /*Cycle N1*/ { FPMAluC3.rid, 4, 1 },
773 /*Cycle N1*/
774 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
775 }
776};
777
778const InstrClassRUsage FPAClassRUsage = {
779 SPARC_FPA,
780 /*totCycles*/ 7,
781
782 /* maxIssueNum */ 1,
783 /* isSingleIssue */ false,
784 /* breaksGroup */ false,
785 /* numBubbles */ 0,
786
787 /*numSlots*/ 4,
788 /* feasibleSlots[] */ { 0, 1, 2, 3 },
789
790 /*numEntries*/ 7,
791 /* V[] */ {
792 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
793 { FPAIssueSlots.rid, 0, 1 },
794 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
795 /*Cycle C */ { FPAAluC1.rid, 2, 1 },
796 /*Cycle N1*/ { FPAAluC2.rid, 3, 1 },
797 /*Cycle N1*/ { FPAAluC3.rid, 4, 1 },
798 /*Cycle N1*/
799 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
800 }
801};
802
803const InstrClassRUsage LDClassRUsage = {
804 SPARC_LD,
805 /*totCycles*/ 7,
806
807 /* maxIssueNum */ 1,
808 /* isSingleIssue */ false,
809 /* breaksGroup */ false,
810 /* numBubbles */ 0,
811
812 /*numSlots*/ 3,
813 /* feasibleSlots[] */ { 0, 1, 2, },
814
815 /*numEntries*/ 6,
816 /* V[] */ {
817 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
818 { First3IssueSlots.rid, 0, 1 },
819 { LSIssueSlots.rid, 0, 1 },
820 /*Cycle E */ { LSAluC1.rid, 1, 1 },
821 /*Cycle C */ { LSAluC2.rid, 2, 1 },
822 { LdReturn.rid, 2, 1 },
823 /*Cycle N1*/
824 /*Cycle N1*/
825 /*Cycle N1*/
826 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
827 }
828};
829
830const InstrClassRUsage STClassRUsage = {
831 SPARC_ST,
832 /*totCycles*/ 7,
833
834 /* maxIssueNum */ 1,
835 /* isSingleIssue */ false,
836 /* breaksGroup */ false,
837 /* numBubbles */ 0,
838
839 /*numSlots*/ 3,
840 /* feasibleSlots[] */ { 0, 1, 2 },
841
842 /*numEntries*/ 4,
843 /* V[] */ {
844 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
845 { First3IssueSlots.rid, 0, 1 },
846 { LSIssueSlots.rid, 0, 1 },
847 /*Cycle E */ { LSAluC1.rid, 1, 1 },
848 /*Cycle C */ { LSAluC2.rid, 2, 1 }
849 /*Cycle N1*/
850 /*Cycle N1*/
851 /*Cycle N1*/
852 /*Cycle W */
853 }
854};
855
856const InstrClassRUsage CTIClassRUsage = {
857 SPARC_CTI,
858 /*totCycles*/ 7,
859
860 /* maxIssueNum */ 1,
861 /* isSingleIssue */ false,
862 /* breaksGroup */ false,
863 /* numBubbles */ 0,
864
865 /*numSlots*/ 4,
866 /* feasibleSlots[] */ { 0, 1, 2, 3 },
867
868 /*numEntries*/ 4,
869 /* V[] */ {
870 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
871 { CTIIssueSlots.rid, 0, 1 },
872 /*Cycle E */ { IAlu0.rid, 1, 1 },
873 /*Cycles E-C */ { CTIDelayCycle.rid, 1, 2 }
874 /*Cycle C */
875 /*Cycle N1*/
876 /*Cycle N1*/
877 /*Cycle N1*/
878 /*Cycle W */
879 }
880};
881
882const InstrClassRUsage SingleClassRUsage = {
883 SPARC_SINGLE,
884 /*totCycles*/ 7,
885
886 /* maxIssueNum */ 1,
887 /* isSingleIssue */ true,
888 /* breaksGroup */ false,
889 /* numBubbles */ 0,
890
891 /*numSlots*/ 1,
892 /* feasibleSlots[] */ { 0 },
893
894 /*numEntries*/ 5,
895 /* V[] */ {
896 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
897 { AllIssueSlots.rid, 0, 1 },
898 { AllIssueSlots.rid, 0, 1 },
899 { AllIssueSlots.rid, 0, 1 },
900 /*Cycle E */ { IAlu0.rid, 1, 1 }
901 /*Cycle C */
902 /*Cycle N1*/
903 /*Cycle N1*/
904 /*Cycle N1*/
905 /*Cycle W */
906 }
907};
908
909
910const InstrClassRUsage SparcRUsageDesc[] = {
911 NoneClassRUsage,
912 IEUNClassRUsage,
913 IEU0ClassRUsage,
914 IEU1ClassRUsage,
915 FPMClassRUsage,
916 FPAClassRUsage,
917 CTIClassRUsage,
918 LDClassRUsage,
919 STClassRUsage,
920 SingleClassRUsage
921};
922
923
924//---------------------------------------------------------------------------
925// const InstrIssueDelta SparcInstrIssueDeltas[]
926//
927// Purpose:
928// Changes to issue restrictions information in InstrClassRUsage for
929// instructions that differ from other instructions in their class.
930//---------------------------------------------------------------------------
931
932const InstrIssueDelta SparcInstrIssueDeltas[] = {
933
934 // opCode, isSingleIssue, breaksGroup, numBubbles
935
936 // Special cases for single-issue only
937 // Other single issue cases are below.
938//{ LDDA, true, true, 0 },
939//{ STDA, true, true, 0 },
940//{ LDDF, true, true, 0 },
941//{ LDDFA, true, true, 0 },
942 { ADDC, true, true, 0 },
943 { ADDCcc, true, true, 0 },
944 { SUBC, true, true, 0 },
945 { SUBCcc, true, true, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000946//{ LDSTUB, true, true, 0 },
947//{ SWAP, true, true, 0 },
948//{ SWAPA, true, true, 0 },
949//{ CAS, true, true, 0 },
950//{ CASA, true, true, 0 },
951//{ CASX, true, true, 0 },
952//{ CASXA, true, true, 0 },
953//{ LDFSR, true, true, 0 },
954//{ LDFSRA, true, true, 0 },
955//{ LDXFSR, true, true, 0 },
956//{ LDXFSRA, true, true, 0 },
957//{ STFSR, true, true, 0 },
958//{ STFSRA, true, true, 0 },
959//{ STXFSR, true, true, 0 },
960//{ STXFSRA, true, true, 0 },
961//{ SAVED, true, true, 0 },
962//{ RESTORED, true, true, 0 },
963//{ FLUSH, true, true, 9 },
964//{ FLUSHW, true, true, 9 },
965//{ ALIGNADDR, true, true, 0 },
966 { RETURN, true, true, 0 },
967//{ DONE, true, true, 0 },
968//{ RETRY, true, true, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000969//{ TCC, true, true, 0 },
970//{ SHUTDOWN, true, true, 0 },
971
972 // Special cases for breaking group *before*
973 // CURRENTLY NOT SUPPORTED!
974 { CALL, false, false, 0 },
Vikram S. Advec1521632001-10-22 13:31:53 +0000975 { JMPLCALL, false, false, 0 },
976 { JMPLRET, false, false, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000977
978 // Special cases for breaking the group *after*
979 { MULX, true, true, (4+34)/2 },
980 { FDIVS, false, true, 0 },
981 { FDIVD, false, true, 0 },
982 { FDIVQ, false, true, 0 },
983 { FSQRTS, false, true, 0 },
984 { FSQRTD, false, true, 0 },
985 { FSQRTQ, false, true, 0 },
986//{ FCMP{LE,GT,NE,EQ}, false, true, 0 },
987
988 // Instructions that introduce bubbles
989//{ MULScc, true, true, 2 },
990//{ SMULcc, true, true, (4+18)/2 },
991//{ UMULcc, true, true, (4+19)/2 },
992 { SDIVX, true, true, 68 },
993 { UDIVX, true, true, 68 },
994//{ SDIVcc, true, true, 36 },
995//{ UDIVcc, true, true, 37 },
Vikram S. Adveb7f06f42001-11-04 19:34:49 +0000996 { WRCCR, true, true, 4 },
997//{ WRPR, true, true, 4 },
998//{ RDCCR, true, true, 0 }, // no bubbles after, but see below
999//{ RDPR, true, true, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001000};
1001
1002
1003//---------------------------------------------------------------------------
1004// const InstrRUsageDelta SparcInstrUsageDeltas[]
1005//
1006// Purpose:
1007// Changes to resource usage information in InstrClassRUsage for
1008// instructions that differ from other instructions in their class.
1009//---------------------------------------------------------------------------
1010
1011const InstrRUsageDelta SparcInstrUsageDeltas[] = {
1012
1013 // MachineOpCode, Resource, Start cycle, Num cycles
1014
1015 //
1016 // JMPL counts as a load/store instruction for issue!
1017 //
Vikram S. Advec1521632001-10-22 13:31:53 +00001018 { JMPLCALL, LSIssueSlots.rid, 0, 1 },
1019 { JMPLRET, LSIssueSlots.rid, 0, 1 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001020
1021 //
1022 // Many instructions cannot issue for the next 2 cycles after an FCMP
1023 // We model that with a fake resource FCMPDelayCycle.
1024 //
1025 { FCMPS, FCMPDelayCycle.rid, 1, 3 },
1026 { FCMPD, FCMPDelayCycle.rid, 1, 3 },
1027 { FCMPQ, FCMPDelayCycle.rid, 1, 3 },
1028
1029 { MULX, FCMPDelayCycle.rid, 1, 1 },
1030 { SDIVX, FCMPDelayCycle.rid, 1, 1 },
1031 { UDIVX, FCMPDelayCycle.rid, 1, 1 },
1032//{ SMULcc, FCMPDelayCycle.rid, 1, 1 },
1033//{ UMULcc, FCMPDelayCycle.rid, 1, 1 },
1034//{ SDIVcc, FCMPDelayCycle.rid, 1, 1 },
1035//{ UDIVcc, FCMPDelayCycle.rid, 1, 1 },
1036 { STD, FCMPDelayCycle.rid, 1, 1 },
1037 { FMOVRSZ, FCMPDelayCycle.rid, 1, 1 },
1038 { FMOVRSLEZ,FCMPDelayCycle.rid, 1, 1 },
1039 { FMOVRSLZ, FCMPDelayCycle.rid, 1, 1 },
1040 { FMOVRSNZ, FCMPDelayCycle.rid, 1, 1 },
1041 { FMOVRSGZ, FCMPDelayCycle.rid, 1, 1 },
1042 { FMOVRSGEZ,FCMPDelayCycle.rid, 1, 1 },
1043
1044 //
1045 // Some instructions are stalled in the GROUP stage if a CTI is in
Vikram S. Adveb7f06f42001-11-04 19:34:49 +00001046 // the E or C stage. We model that with a fake resource CTIDelayCycle.
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001047 //
1048 { LDD, CTIDelayCycle.rid, 1, 1 },
1049//{ LDDA, CTIDelayCycle.rid, 1, 1 },
1050//{ LDDSTUB, CTIDelayCycle.rid, 1, 1 },
1051//{ LDDSTUBA, CTIDelayCycle.rid, 1, 1 },
1052//{ SWAP, CTIDelayCycle.rid, 1, 1 },
1053//{ SWAPA, CTIDelayCycle.rid, 1, 1 },
1054//{ CAS, CTIDelayCycle.rid, 1, 1 },
1055//{ CASA, CTIDelayCycle.rid, 1, 1 },
1056//{ CASX, CTIDelayCycle.rid, 1, 1 },
1057//{ CASXA, CTIDelayCycle.rid, 1, 1 },
1058
1059 //
1060 // Signed int loads of less than dword size return data in cycle N1 (not C)
1061 // and put all loads in consecutive cycles into delayed load return mode.
1062 //
1063 { LDSB, LdReturn.rid, 2, -1 },
1064 { LDSB, LdReturn.rid, 3, 1 },
1065
1066 { LDSH, LdReturn.rid, 2, -1 },
1067 { LDSH, LdReturn.rid, 3, 1 },
1068
1069 { LDSW, LdReturn.rid, 2, -1 },
1070 { LDSW, LdReturn.rid, 3, 1 },
1071
Vikram S. Adveb7f06f42001-11-04 19:34:49 +00001072 //
1073 // RDPR from certain registers and RD from any register are not dispatchable
1074 // until four clocks after they reach the head of the instr. buffer.
1075 // Together with their single-issue requirement, this means all four issue
1076 // slots are effectively blocked for those cycles, plus the issue cycle.
1077 // This does not increase the latency of the instruction itself.
1078 //
1079 { RDCCR, AllIssueSlots.rid, 0, 5 },
1080 { RDCCR, AllIssueSlots.rid, 0, 5 },
1081 { RDCCR, AllIssueSlots.rid, 0, 5 },
1082 { RDCCR, AllIssueSlots.rid, 0, 5 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001083
1084#undef EXPLICIT_BUBBLES_NEEDED
1085#ifdef EXPLICIT_BUBBLES_NEEDED
1086 //
1087 // MULScc inserts one bubble.
1088 // This means it breaks the current group (captured in UltraSparcSchedInfo)
1089 // *and occupies all issue slots for the next cycle
1090 //
1091//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1092//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1093//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1094//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1095
1096 //
1097 // SMULcc inserts between 4 and 18 bubbles, depending on #leading 0s in rs1.
1098 // We just model this with a simple average.
1099 //
1100//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1101//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1102//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1103//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1104
1105 // SMULcc inserts between 4 and 19 bubbles, depending on #leading 0s in rs1.
1106//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1107//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1108//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1109//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1110
1111 //
1112 // MULX inserts between 4 and 34 bubbles, depending on #leading 0s in rs1.
1113 //
1114 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1115 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1116 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1117 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1118
1119 //
1120 // SDIVcc inserts 36 bubbles.
1121 //
1122//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1123//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1124//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1125//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1126
1127 // UDIVcc inserts 37 bubbles.
1128//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1129//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1130//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1131//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1132
1133 //
1134 // SDIVX inserts 68 bubbles.
1135 //
1136 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1137 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1138 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1139 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1140
1141 //
1142 // UDIVX inserts 68 bubbles.
1143 //
1144 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1145 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1146 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1147 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1148
1149 //
1150 // WR inserts 4 bubbles.
1151 //
1152//{ WR, AllIssueSlots.rid, 2, 68-1 },
1153//{ WR, AllIssueSlots.rid, 2, 68-1 },
1154//{ WR, AllIssueSlots.rid, 2, 68-1 },
1155//{ WR, AllIssueSlots.rid, 2, 68-1 },
1156
1157 //
1158 // WRPR inserts 4 bubbles.
1159 //
1160//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1161//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1162//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1163//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1164
1165 //
1166 // DONE inserts 9 bubbles.
1167 //
1168//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1169//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1170//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1171//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1172
1173 //
1174 // RETRY inserts 9 bubbles.
1175 //
1176//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1177//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1178//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1179//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1180
Chris Lattnere369fcb2001-10-13 06:54:54 +00001181#endif /*EXPLICIT_BUBBLES_NEEDED */
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001182};
1183
1184
1185
1186// Additional delays to be captured in code:
1187// 1. RDPR from several state registers (page 349)
1188// 2. RD from *any* register (page 349)
1189// 3. Writes to TICK, PSTATE, TL registers and FLUSH{W} instr (page 349)
1190// 4. Integer store can be in same group as instr producing value to store.
1191// 5. BICC and BPICC can be in the same group as instr producing CC (pg 350)
1192// 6. FMOVr cannot be in the same or next group as an IEU instr (pg 351).
1193// 7. The second instr. of a CTI group inserts 9 bubbles (pg 351)
1194// 8. WR{PR}, SVAE, SAVED, RESTORE, RESTORED, RETURN, RETRY, and DONE that
1195// follow an annulling branch cannot be issued in the same group or in
1196// the 3 groups following the branch.
1197// 9. A predicted annulled load does not stall dependent instructions.
1198// Other annulled delay slot instructions *do* stall dependents, so
1199// nothing special needs to be done for them during scheduling.
1200//10. Do not put a load use that may be annulled in the same group as the
1201// branch. The group will stall until the load returns.
1202//11. Single-prec. FP loads lock 2 registers, for dependency checking.
1203//
1204//
1205// Additional delays we cannot or will not capture:
1206// 1. If DCTI is last word of cache line, it is delayed until next line can be
1207// fetched. Also, other DCTI alignment-related delays (pg 352)
1208// 2. Load-after-store is delayed by 7 extra cycles if load hits in D-Cache.
1209// Also, several other store-load and load-store conflicts (pg 358)
1210// 3. MEMBAR, LD{X}FSR, LDD{A} and a bunch of other load stalls (pg 358)
1211// 4. There can be at most 8 outstanding buffered store instructions
1212// (including some others like MEMBAR, LDSTUB, CAS{AX}, and FLUSH)
1213
1214
1215
1216//---------------------------------------------------------------------------
1217// class UltraSparcSchedInfo
1218//
1219// Purpose:
1220// Interface to instruction scheduling information for UltraSPARC.
1221// The parameter values above are based on UltraSPARC IIi.
1222//---------------------------------------------------------------------------
1223
1224
1225class UltraSparcSchedInfo: public MachineSchedInfo {
1226public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001227 /*ctor*/ UltraSparcSchedInfo (const TargetMachine& tgt);
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001228 /*dtor*/ virtual ~UltraSparcSchedInfo () {}
1229protected:
1230 virtual void initializeResources ();
1231};
1232
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001233
1234//---------------------------------------------------------------------------
Vikram S. Advec1521632001-10-22 13:31:53 +00001235// class UltraSparcFrameInfo
1236//
1237// Purpose:
1238// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Adve00521d72001-11-12 23:26:35 +00001239// Starting offsets for each area of the stack frame are aligned at
1240// a multiple of getStackFrameSizeAlignment().
Vikram S. Advec1521632001-10-22 13:31:53 +00001241//---------------------------------------------------------------------------
1242
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001243class UltraSparcFrameInfo: public MachineFrameInfo {
Vikram S. Advec1521632001-10-22 13:31:53 +00001244public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001245 /*ctor*/ UltraSparcFrameInfo(const TargetMachine& tgt) : MachineFrameInfo(tgt) {}
1246
1247public:
1248 int getStackFrameSizeAlignment () const { return StackFrameSizeAlignment;}
1249 int getMinStackFrameSize () const { return MinStackFrameSize; }
1250 int getNumFixedOutgoingArgs () const { return NumFixedOutgoingArgs; }
1251 int getSizeOfEachArgOnStack () const { return SizeOfEachArgOnStack; }
1252 bool argsOnStackHaveFixedSize () const { return true; }
1253
1254 //
1255 // These methods compute offsets using the frame contents for a
1256 // particular method. The frame contents are obtained from the
1257 // MachineCodeInfoForMethod object for the given method.
1258 //
1259 int getFirstIncomingArgOffset (MachineCodeForMethod& mcInfo,
1260 bool& pos) const
1261 {
1262 pos = true; // arguments area grows upwards
1263 return FirstIncomingArgOffsetFromFP;
1264 }
1265 int getFirstOutgoingArgOffset (MachineCodeForMethod& mcInfo,
1266 bool& pos) const
1267 {
1268 pos = true; // arguments area grows upwards
1269 return FirstOutgoingArgOffsetFromSP;
1270 }
1271 int getFirstOptionalOutgoingArgOffset(MachineCodeForMethod& mcInfo,
1272 bool& pos)const
1273 {
1274 pos = true; // arguments area grows upwards
1275 return FirstOptionalOutgoingArgOffsetFromSP;
1276 }
1277
1278 int getFirstAutomaticVarOffset (MachineCodeForMethod& mcInfo,
1279 bool& pos) const;
1280 int getRegSpillAreaOffset (MachineCodeForMethod& mcInfo,
1281 bool& pos) const;
1282 int getTmpAreaOffset (MachineCodeForMethod& mcInfo,
1283 bool& pos) const;
1284 int getDynamicAreaOffset (MachineCodeForMethod& mcInfo,
1285 bool& pos) const;
1286
1287 //
1288 // These methods specify the base register used for each stack area
1289 // (generally FP or SP)
1290 //
1291 virtual int getIncomingArgBaseRegNum() const {
1292 return (int) target.getRegInfo().getFramePointer();
1293 }
1294 virtual int getOutgoingArgBaseRegNum() const {
1295 return (int) target.getRegInfo().getStackPointer();
1296 }
1297 virtual int getOptionalOutgoingArgBaseRegNum() const {
1298 return (int) target.getRegInfo().getStackPointer();
1299 }
1300 virtual int getAutomaticVarBaseRegNum() const {
1301 return (int) target.getRegInfo().getFramePointer();
1302 }
1303 virtual int getRegSpillAreaBaseRegNum() const {
1304 return (int) target.getRegInfo().getFramePointer();
1305 }
1306 virtual int getDynamicAreaBaseRegNum() const {
1307 return (int) target.getRegInfo().getStackPointer();
1308 }
1309
1310private:
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001311 // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
1312 static const int OFFSET = (int) 0x7ff;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001313 static const int StackFrameSizeAlignment = 16;
Vikram S. Advec1521632001-10-22 13:31:53 +00001314 static const int MinStackFrameSize = 176;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001315 static const int NumFixedOutgoingArgs = 6;
1316 static const int SizeOfEachArgOnStack = 8;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +00001317 static const int StaticAreaOffsetFromFP = 0 + OFFSET;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001318 static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET;
1319 static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET;
1320 static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET;
1321 static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET;
Vikram S. Advec1521632001-10-22 13:31:53 +00001322};
1323
1324
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001325//---------------------------------------------------------------------------
1326// class UltraSparcCacheInfo
1327//
1328// Purpose:
1329// Interface to cache parameters for the UltraSPARC.
1330// Just use defaults for now.
1331//---------------------------------------------------------------------------
1332
1333class UltraSparcCacheInfo: public MachineCacheInfo {
1334public:
1335 /*ctor*/ UltraSparcCacheInfo (const TargetMachine& target) :
1336 MachineCacheInfo(target) {}
1337};
1338
Vikram S. Advec1521632001-10-22 13:31:53 +00001339
1340//---------------------------------------------------------------------------
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001341// class UltraSparcMachine
1342//
1343// Purpose:
1344// Primary interface to machine description for the UltraSPARC.
1345// Primarily just initializes machine-dependent parameters in
1346// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +00001347// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001348//---------------------------------------------------------------------------
1349
1350class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +00001351private:
1352 UltraSparcInstrInfo instrInfo;
1353 UltraSparcSchedInfo schedInfo;
1354 UltraSparcRegInfo regInfo;
Vikram S. Advec1521632001-10-22 13:31:53 +00001355 UltraSparcFrameInfo frameInfo;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001356 UltraSparcCacheInfo cacheInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001357public:
1358 UltraSparc();
1359 virtual ~UltraSparc() {}
Vikram S. Adve339084b2001-09-18 13:04:24 +00001360
Chris Lattner32f600a2001-09-19 13:47:12 +00001361 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
1362 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
1363 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001364 virtual const MachineFrameInfo &getFrameInfo() const { return frameInfo; }
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001365 virtual const MachineCacheInfo &getCacheInfo() const { return cacheInfo; }
Vikram S. Adve339084b2001-09-18 13:04:24 +00001366
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001367 // compileMethod - For the sparc, we do instruction selection, followed by
1368 // delay slot scheduling, then register allocation.
1369 //
1370 virtual bool compileMethod(Method *M);
Chris Lattner32f600a2001-09-19 13:47:12 +00001371
1372 //
1373 // emitAssembly - Output assembly language code (a .s file) for the specified
1374 // module. The specified module must have been compiled before this may be
1375 // used.
1376 //
Chris Lattnerec0a95f2001-10-15 15:54:43 +00001377 virtual void emitAssembly(const Module *M, ostream &OutStr) const;
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001378};
1379
1380
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001381#endif