blob: 9b8fe177ef2753ca32638582630994477dbb5e65 [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);
Chris Lattnerc6495ee2001-09-14 03:56:45 +000092
Vikram S. Adve5684c4e2001-10-18 00:02:06 +000093 virtual bool hasResultInterlock (MachineOpCode opCode) const
Chris Lattnerc6495ee2001-09-14 03:56:45 +000094 {
95 // All UltraSPARC instructions have interlocks (note that delay slots
96 // are not considered here).
97 // However, instructions that use the result of an FCMP produce a
98 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
99 // Force the compiler to insert a software interlock (i.e., gap of
100 // 2 other groups, including NOPs if necessary).
101 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
102 }
103
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000104 //-------------------------------------------------------------------------
105 // Code generation support for creating individual machine instructions
106 //-------------------------------------------------------------------------
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000107
Vikram S. Adve5684c4e2001-10-18 00:02:06 +0000108 // Create an instruction sequence to put the constant `val' into
109 // the virtual register `dest'. The generated instructions are
110 // returned in `minstrVec'. Any temporary registers (TmpInstruction)
111 // created are returned in `tempVec'.
112 //
113 virtual void CreateCodeToLoadConst(Value* val,
114 Instruction* dest,
115 vector<MachineInstr*>& minstrVec,
116 vector<TmpInstruction*>& tempVec) const;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000117
118
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000119 // Create an instruction sequence to copy an integer value `val'
120 // to a floating point value `dest' by copying to memory and back.
121 // val must be an integral type. dest must be a Float or Double.
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000122 // The generated instructions are returned in `minstrVec'.
123 // Any temp. registers (TmpInstruction) created are returned in `tempVec'.
124 //
125 virtual void CreateCodeToCopyIntToFloat(Method* method,
126 Value* val,
127 Instruction* dest,
128 vector<MachineInstr*>& minstrVec,
129 vector<TmpInstruction*>& tempVec,
130 TargetMachine& target) const;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +0000131
132 // Similarly, create an instruction sequence to copy an FP value
133 // `val' to an integer value `dest' by copying to memory and back.
134 // See the previous function for information about return values.
135 //
136 virtual void CreateCodeToCopyFloatToInt(Method* method,
137 Value* val,
138 Instruction* dest,
139 vector<MachineInstr*>& minstrVec,
140 vector<TmpInstruction*>& tempVec,
141 TargetMachine& target) const;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +0000142
143 // create copy instruction(s)
144 virtual void
145 CreateCopyInstructionsByType(const TargetMachine& target,
146 Value* src,
147 Instruction* dest,
148 vector<MachineInstr*>& minstrVec) const;
149
150
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000151};
152
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000153
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000154//----------------------------------------------------------------------------
155// class UltraSparcRegInfo
156//
157//----------------------------------------------------------------------------
158
159
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000160class LiveRange;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000161class UltraSparc;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000162class PhyRegAlloc;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000163
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000164
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000165class UltraSparcRegInfo : public MachineRegInfo
166{
167
168 private:
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000169
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000170 // The actual register classes in the Sparc
171
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000172 enum RegClassIDs {
173 IntRegClassID,
174 FloatRegClassID,
175 IntCCRegClassID,
176 FloatCCRegClassID
177 };
178
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000179
180 // Type of registers available in Sparc. There can be several reg types
181 // in the same class. For instace, the float reg class has Single/Double
182 // types
183 enum RegTypes {
184 IntRegType,
185 FPSingleRegType,
186 FPDoubleRegType,
187 IntCCRegType,
188 FloatCCRegType
189 };
190
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000191 // the size of a value (int, float, etc..) stored in the stack frame
192
193
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000194
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000195 // WARNING: If the above enum order must be changed, also modify
196 // getRegisterClassOfValue method below since it assumes this particular
197 // order for efficiency.
198
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000199
200 // reverse pointer to get info about the ultra sparc machine
201 const UltraSparc *const UltraSparcInfo;
202
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000203 // Both int and float rguments can be passed in 6 int regs -
204 // %o0 to %o5 (cannot be changed)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000205 unsigned const NumOfIntArgRegs;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000206 unsigned const NumOfFloatArgRegs;
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000207 int const InvalidRegNum;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000208 int SizeOfOperandOnStack;
209
210
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000211
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000212 //void setCallArgColor(LiveRange *const LR, const unsigned RegNo) const;
213
214 void setCallOrRetArgCol(LiveRange *const LR, const unsigned RegNo,
215 const MachineInstr *MI,AddedInstrMapType &AIMap)const;
216
217 MachineInstr * getCopy2RegMI(const Value *SrcVal, const unsigned Reg,
218 unsigned RegClassID) const ;
219
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000220
221 void suggestReg4RetAddr(const MachineInstr * RetMI,
222 LiveRangeInfo& LRI) const;
223
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000224 void suggestReg4CallAddr(const MachineInstr * CallMI, LiveRangeInfo& LRI,
225 vector<RegClass *> RCList) const;
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000226
227
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000228 Value *getValue4ReturnAddr( const MachineInstr * MInst ) const ;
229
230 int getRegType(const LiveRange *const LR) const {
231
232 unsigned Typ;
233
234 switch( (LR->getRegClass())->getID() ) {
235
236 case IntRegClassID: return IntRegType;
237
238 case FloatRegClassID:
239 Typ = LR->getTypeID();
240 if( Typ == Type::FloatTyID )
241 return FPSingleRegType;
242 else if( Typ == Type::DoubleTyID )
243 return FPDoubleRegType;
244 else assert(0 && "Unknown type in FloatRegClass");
245
246 case IntCCRegClassID: return IntCCRegType;
247
248 case FloatCCRegClassID: return FloatCCRegType ;
249
250 default: assert( 0 && "Unknown reg class ID");
Chris Lattner6dad5062001-11-07 13:49:12 +0000251 return 0;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000252 }
253
254 }
255
256 int getRegType(const Value *const Val) const {
257
258 unsigned Typ;
259
260 switch( getRegClassIDOfValue(Val) ) {
261
262 case IntRegClassID: return IntRegType;
263
264 case FloatRegClassID:
265 Typ = (Val->getType())->getPrimitiveID();
266 if( Typ == Type::FloatTyID )
267 return FPSingleRegType;
268 else if( Typ == Type::DoubleTyID )
269 return FPDoubleRegType;
270 else assert(0 && "Unknown type in FloatRegClass");
271
272 case IntCCRegClassID: return IntCCRegType;
273
274 case FloatCCRegClassID: return FloatCCRegType ;
275
276 default: assert( 0 && "Unknown reg class ID");
Chris Lattner6dad5062001-11-07 13:49:12 +0000277 return 0;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000278 }
279
280 }
281
282
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000283 int getRegType(int reg) const {
284 if( reg < 32 )
285 return IntRegType;
286 else if ( reg < (32 + 32) )
287 return FPSingleRegType;
288 else if ( reg < (64 + 32) )
289 return FPDoubleRegType;
290 else if( reg < (64+32+4) )
291 return FloatCCRegType;
292 else if( reg < (64+32+4+2) )
293 return IntCCRegType;
294 else
295 assert(0 && "Invalid register number in getRegType");
296 }
297
298
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000299
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000300 // ***TODO: See this method is necessary
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000301
302 MachineInstr * cpValue2RegMI(Value * Val, const unsigned DestReg,
303 const int RegType) const;
304
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000305 const Value *getCallInstRetAddr(const MachineInstr *CallMI) const;
306 const unsigned getCallInstNumArgs(const MachineInstr *CallMI) const;
307
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000308
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000309 MachineInstr * cpCCR2IntMI(const unsigned IntReg) const;
310 MachineInstr * cpInt2CCRMI(const unsigned IntReg) const;
311
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000312
313
314 void moveInst2OrdVec(vector<MachineInstr *> &OrdVec, MachineInstr *UnordInst,
315 PhyRegAlloc &PRA ) const;
316
Ruchira Sasanka868cf822001-11-09 23:49:14 +0000317 void OrderAddedInstrns( vector<MachineInstr *> &UnordVec,
Ruchira Sasankaae4bcd72001-11-10 21:20:43 +0000318 vector<MachineInstr *> &OrdVec,
319 PhyRegAlloc &PRA) const;
320
321
322
323
324
Ruchira Sasanka868cf822001-11-09 23:49:14 +0000325
326
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000327 public:
328
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000329
Vikram S. Adve7f37fe52001-11-08 04:55:13 +0000330 UltraSparcRegInfo(const TargetMachine& tgt ) : MachineRegInfo(tgt),
331 UltraSparcInfo(& (const UltraSparc&) tgt),
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000332 NumOfIntArgRegs(6),
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000333 NumOfFloatArgRegs(32),
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000334 InvalidRegNum(1000),
335 SizeOfOperandOnStack(8)
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000336 {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000337 MachineRegClassArr.push_back( new SparcIntRegClass(IntRegClassID) );
338 MachineRegClassArr.push_back( new SparcFloatRegClass(FloatRegClassID) );
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000339 MachineRegClassArr.push_back( new SparcIntCCRegClass(IntCCRegClassID) );
340 MachineRegClassArr.push_back( new SparcFloatCCRegClass(FloatCCRegClassID));
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000341
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000342 assert( SparcFloatRegOrder::StartOfNonVolatileRegs == 32 &&
343 "32 Float regs are used for float arg passing");
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000344
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000345 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000346
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000347 // ***** TODO Delete
348 ~UltraSparcRegInfo(void) { } // empty destructor
349
350
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000351 inline const UltraSparc & getUltraSparcInfo() const {
352 return *UltraSparcInfo;
353 }
354
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000355
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000356
357 inline unsigned getRegClassIDOfValue (const Value *const Val,
358 bool isCCReg = false) const {
359
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000360 Type::PrimitiveID ty = (Val->getType())->getPrimitiveID();
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000361
362 unsigned res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000363
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000364 if( (ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
365 (ty == Type::MethodTyID) || (ty == Type::PointerTyID) )
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000366 res = IntRegClassID; // sparc int reg (ty=0: void)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000367 else if( ty <= Type::DoubleTyID)
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000368 res = FloatRegClassID; // sparc float reg class
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000369 else {
Chris Lattner1e23ed72001-10-15 18:15:27 +0000370 cerr << "TypeID: " << ty << endl;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000371 assert(0 && "Cannot resolve register class for type");
Chris Lattner8e5c0b42001-11-07 14:01:59 +0000372 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000373 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000374
375 if(isCCReg)
376 return res + 2; // corresponidng condition code regiser
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000377 else
378 return res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000379 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000380
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000381 // returns the register tha contains always zero
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000382 // this is the unified register number
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000383 inline int getZeroRegNum() const { return SparcIntRegOrder::g0; }
384
385 // returns the reg used for pushing the address when a method is called.
386 // This can be used for other purposes between calls
387 unsigned getCallAddressReg() const { return SparcIntRegOrder::o7; }
388
389
390 // and when we return from a method. It should be made sure that this
391 // register contains the return value when a return instruction is reached.
392 unsigned getReturnAddressReg() const { return SparcIntRegOrder::i7; }
393
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000394 void suggestRegs4MethodArgs(const Method *const Meth,
395 LiveRangeInfo& LRI) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000396
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000397 void suggestRegs4CallArgs(const MachineInstr *const CallMI,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000398 LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000399
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000400 void suggestReg4RetValue(const MachineInstr *const RetMI,
401 LiveRangeInfo& LRI ) const;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000402
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000403
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000404 void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
405 AddedInstrns *const FirstAI) const;
406
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000407 void colorCallArgs(const MachineInstr *const CallMI, LiveRangeInfo& LRI,
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000408 AddedInstrns *const CallAI, PhyRegAlloc &PRA) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000409
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000410 void colorRetValue(const MachineInstr *const RetI, LiveRangeInfo& LRI,
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000411 AddedInstrns *const RetAI) const;
412
413
Ruchira Sasankacc3ccac2001-10-15 16:25:28 +0000414 // bool handleSpecialMInstr(const MachineInstr * MInst,
415 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000416
417
418 static void printReg(const LiveRange *const LR) ;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000419
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000420 // this method provides a unique number for each register
421 inline int getUnifiedRegNum(int RegClassID, int reg) const {
422
423 if( RegClassID == IntRegClassID && reg < 32 )
424 return reg;
425 else if ( RegClassID == FloatRegClassID && reg < 64)
426 return reg + 32; // we have 32 int regs
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000427 else if( RegClassID == FloatCCRegClassID && reg < 4)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000428 return reg + 32 + 64; // 32 int, 64 float
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000429 else if( RegClassID == IntCCRegClassID )
430 return 4+ 32 + 64; // only int cc reg
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000431 else if (reg==InvalidRegNum)
432 return InvalidRegNum;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000433 else
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000434 assert(0 && "Invalid register class or reg number");
Chris Lattner6dad5062001-11-07 13:49:12 +0000435 return 0;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000436 }
437
438 // given the unified register number, this gives the name
439 inline const string getUnifiedRegName(int reg) const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000440 if( reg < 32 )
441 return SparcIntRegOrder::getRegName(reg);
442 else if ( reg < (64 + 32) )
443 return SparcFloatRegOrder::getRegName( reg - 32);
444 else if( reg < (64+32+4) )
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000445 return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
Ruchira Sasanka3839e6e2001-11-03 19:59:59 +0000446 else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr
447 return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4);
Vikram S. Advec1521632001-10-22 13:31:53 +0000448 else if (reg== InvalidRegNum) //****** TODO: Remove */
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000449 return "<*NoReg*>";
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000450 else
451 assert(0 && "Invalid register number");
Chris Lattner6dad5062001-11-07 13:49:12 +0000452 return "";
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000453 }
454
Vikram S. Advec1521632001-10-22 13:31:53 +0000455 inline unsigned int getRegNumInCallersWindow(int reg) {
456 if (reg == InvalidRegNum || reg >= 32)
457 return reg;
458 return SparcIntRegOrder::getRegNumInCallersWindow(reg);
459 }
460
461 inline bool mustBeRemappedInCallersWindow(int reg) {
462 return (reg != InvalidRegNum && reg < 32);
463 }
464
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000465 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
466
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000467 MachineInstr * cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
468 const int RegType) const;
469
470 MachineInstr * cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
471 const int Offset, const int RegType) const;
472
473 MachineInstr * cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
474 const unsigned DestReg, const int RegType) const;
475
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000476 MachineInstr* cpValue2Value(Value *Src, Value *Dest) const;
477
478
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000479 inline bool isRegVolatile(const int RegClassID, const int Reg) const {
480 return (MachineRegClassArr[RegClassID])->isRegVolatile(Reg);
481 }
482
483
484 inline unsigned getFramePointer() const {
485 return SparcIntRegOrder::i6;
486 }
487
488 inline unsigned getStackPointer() const {
489 return SparcIntRegOrder::o6;
490 }
491
492 inline int getInvalidRegNum() const {
493 return InvalidRegNum;
494 }
495
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000496
497 void insertCallerSavingCode(const MachineInstr *MInst,
498 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
499
500
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000501};
502
503
504
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000505/*---------------------------------------------------------------------------
506Scheduling guidelines for SPARC IIi:
507
508I-Cache alignment rules (pg 326)
509-- Align a branch target instruction so that it's entire group is within
510 the same cache line (may be 1-4 instructions).
511** Don't let a branch that is predicted taken be the last instruction
512 on an I-cache line: delay slot will need an entire line to be fetched
513-- Make a FP instruction or a branch be the 4th instruction in a group.
514 For branches, there are tradeoffs in reordering to make this happen
515 (see pg. 327).
516** Don't put a branch in a group that crosses a 32-byte boundary!
517 An artificial branch is inserted after every 32 bytes, and having
518 another branch will force the group to be broken into 2 groups.
519
520iTLB rules:
521-- Don't let a loop span two memory pages, if possible
522
523Branch prediction performance:
524-- Don't make the branch in a delay slot the target of a branch
525-- Try not to have 2 predicted branches within a group of 4 instructions
526 (because each such group has a single branch target field).
527-- Try to align branches in slots 0, 2, 4 or 6 of a cache line (to avoid
528 the wrong prediction bits being used in some cases).
529
530D-Cache timing constraints:
531-- Signed int loads of less than 64 bits have 3 cycle latency, not 2
532-- All other loads that hit in D-Cache have 2 cycle latency
533-- All loads are returned IN ORDER, so a D-Cache miss will delay a later hit
534-- Mis-aligned loads or stores cause a trap. In particular, replace
535 mis-aligned FP double precision l/s with 2 single-precision l/s.
536-- Simulations of integer codes show increase in avg. group size of
537 33% when code (including esp. non-faulting loads) is moved across
538 one branch, and 50% across 2 branches.
539
540E-Cache timing constraints:
541-- Scheduling for E-cache (D-Cache misses) is effective (due to load buffering)
542
543Store buffer timing constraints:
544-- Stores can be executed in same cycle as instruction producing the value
545-- Stores are buffered and have lower priority for E-cache until
546 highwater mark is reached in the store buffer (5 stores)
547
548Pipeline constraints:
549-- Shifts can only use IEU0.
550-- CC setting instructions can only use IEU1.
551-- Several other instructions must only use IEU1:
552 EDGE(?), ARRAY(?), CALL, JMPL, BPr, PST, and FCMP.
553-- Two instructions cannot store to the same register file in a single cycle
554 (single write port per file).
555
556Issue and grouping constraints:
557-- FP and branch instructions must use slot 4.
558-- Shift instructions cannot be grouped with other IEU0-specific instructions.
559-- CC setting instructions cannot be grouped with other IEU1-specific instrs.
560-- Several instructions must be issued in a single-instruction group:
561 MOVcc or MOVr, MULs/x and DIVs/x, SAVE/RESTORE, many others
562-- A CALL or JMPL breaks a group, ie, is not combined with subsequent instrs.
563--
564--
565
566Branch delay slot scheduling rules:
567-- A CTI couple (two back-to-back CTI instructions in the dynamic stream)
568 has a 9-instruction penalty: the entire pipeline is flushed when the
569 second instruction reaches stage 9 (W-Writeback).
570-- Avoid putting multicycle instructions, and instructions that may cause
571 load misses, in the delay slot of an annulling branch.
572-- Avoid putting WR, SAVE..., RESTORE and RETURN instructions in the
573 delay slot of an annulling branch.
574
575 *--------------------------------------------------------------------------- */
576
577//---------------------------------------------------------------------------
578// List of CPUResources for UltraSPARC IIi.
579//---------------------------------------------------------------------------
580
581const CPUResource AllIssueSlots( "All Instr Slots", 4);
582const CPUResource IntIssueSlots( "Int Instr Slots", 3);
583const CPUResource First3IssueSlots("Instr Slots 0-3", 3);
584const CPUResource LSIssueSlots( "Load-Store Instr Slot", 1);
585const CPUResource CTIIssueSlots( "Ctrl Transfer Instr Slot", 1);
586const CPUResource FPAIssueSlots( "Int Instr Slot 1", 1);
587const CPUResource FPMIssueSlots( "Int Instr Slot 1", 1);
588
589// IEUN instructions can use either Alu and should use IAluN.
590// IEU0 instructions must use Alu 1 and should use both IAluN and IAlu0.
591// IEU1 instructions must use Alu 2 and should use both IAluN and IAlu1.
592const CPUResource IAluN("Int ALU 1or2", 2);
593const CPUResource IAlu0("Int ALU 1", 1);
594const CPUResource IAlu1("Int ALU 2", 1);
595
596const CPUResource LSAluC1("Load/Store Unit Addr Cycle", 1);
597const CPUResource LSAluC2("Load/Store Unit Issue Cycle", 1);
598const CPUResource LdReturn("Load Return Unit", 1);
599
600const CPUResource FPMAluC1("FP Mul/Div Alu Cycle 1", 1);
601const CPUResource FPMAluC2("FP Mul/Div Alu Cycle 2", 1);
602const CPUResource FPMAluC3("FP Mul/Div Alu Cycle 3", 1);
603
604const CPUResource FPAAluC1("FP Other Alu Cycle 1", 1);
605const CPUResource FPAAluC2("FP Other Alu Cycle 2", 1);
606const CPUResource FPAAluC3("FP Other Alu Cycle 3", 1);
607
608const CPUResource IRegReadPorts("Int Reg ReadPorts", INT_MAX); // CHECK
609const CPUResource IRegWritePorts("Int Reg WritePorts", 2); // CHECK
610const CPUResource FPRegReadPorts("FP Reg Read Ports", INT_MAX); // CHECK
611const CPUResource FPRegWritePorts("FP Reg Write Ports", 1); // CHECK
612
613const CPUResource CTIDelayCycle( "CTI delay cycle", 1);
614const CPUResource FCMPDelayCycle("FCMP delay cycle", 1);
615
616
617//---------------------------------------------------------------------------
618// const InstrClassRUsage SparcRUsageDesc[]
619//
620// Purpose:
621// Resource usage information for instruction in each scheduling class.
622// The InstrRUsage Objects for individual classes are specified first.
623// Note that fetch and decode are decoupled from the execution pipelines
624// via an instr buffer, so they are not included in the cycles below.
625//---------------------------------------------------------------------------
626
627const InstrClassRUsage NoneClassRUsage = {
628 SPARC_NONE,
629 /*totCycles*/ 7,
630
631 /* maxIssueNum */ 4,
632 /* isSingleIssue */ false,
633 /* breaksGroup */ false,
634 /* numBubbles */ 0,
635
636 /*numSlots*/ 4,
637 /* feasibleSlots[] */ { 0, 1, 2, 3 },
638
639 /*numEntries*/ 0,
640 /* V[] */ {
641 /*Cycle G */
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000642 /*Ccle E */
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000643 /*Cycle C */
644 /*Cycle N1*/
645 /*Cycle N1*/
646 /*Cycle N1*/
647 /*Cycle W */
648 }
649};
650
651const InstrClassRUsage IEUNClassRUsage = {
652 SPARC_IEUN,
653 /*totCycles*/ 7,
654
655 /* maxIssueNum */ 3,
656 /* isSingleIssue */ false,
657 /* breaksGroup */ false,
658 /* numBubbles */ 0,
659
660 /*numSlots*/ 3,
661 /* feasibleSlots[] */ { 0, 1, 2 },
662
663 /*numEntries*/ 4,
664 /* V[] */ {
665 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
666 { IntIssueSlots.rid, 0, 1 },
667 /*Cycle E */ { IAluN.rid, 1, 1 },
668 /*Cycle C */
669 /*Cycle N1*/
670 /*Cycle N1*/
671 /*Cycle N1*/
672 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
673 }
674};
675
676const InstrClassRUsage IEU0ClassRUsage = {
677 SPARC_IEU0,
678 /*totCycles*/ 7,
679
680 /* maxIssueNum */ 1,
681 /* isSingleIssue */ false,
682 /* breaksGroup */ false,
683 /* numBubbles */ 0,
684
685 /*numSlots*/ 3,
686 /* feasibleSlots[] */ { 0, 1, 2 },
687
688 /*numEntries*/ 5,
689 /* V[] */ {
690 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
691 { IntIssueSlots.rid, 0, 1 },
692 /*Cycle E */ { IAluN.rid, 1, 1 },
693 { IAlu0.rid, 1, 1 },
694 /*Cycle C */
695 /*Cycle N1*/
696 /*Cycle N1*/
697 /*Cycle N1*/
698 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
699 }
700};
701
702const InstrClassRUsage IEU1ClassRUsage = {
703 SPARC_IEU1,
704 /*totCycles*/ 7,
705
706 /* maxIssueNum */ 1,
707 /* isSingleIssue */ false,
708 /* breaksGroup */ false,
709 /* numBubbles */ 0,
710
711 /*numSlots*/ 3,
712 /* feasibleSlots[] */ { 0, 1, 2 },
713
714 /*numEntries*/ 5,
715 /* V[] */ {
716 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
717 { IntIssueSlots.rid, 0, 1 },
718 /*Cycle E */ { IAluN.rid, 1, 1 },
719 { IAlu1.rid, 1, 1 },
720 /*Cycle C */
721 /*Cycle N1*/
722 /*Cycle N1*/
723 /*Cycle N1*/
724 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
725 }
726};
727
728const InstrClassRUsage FPMClassRUsage = {
729 SPARC_FPM,
730 /*totCycles*/ 7,
731
732 /* maxIssueNum */ 1,
733 /* isSingleIssue */ false,
734 /* breaksGroup */ false,
735 /* numBubbles */ 0,
736
737 /*numSlots*/ 4,
738 /* feasibleSlots[] */ { 0, 1, 2, 3 },
739
740 /*numEntries*/ 7,
741 /* V[] */ {
742 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
743 { FPMIssueSlots.rid, 0, 1 },
744 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
745 /*Cycle C */ { FPMAluC1.rid, 2, 1 },
746 /*Cycle N1*/ { FPMAluC2.rid, 3, 1 },
747 /*Cycle N1*/ { FPMAluC3.rid, 4, 1 },
748 /*Cycle N1*/
749 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
750 }
751};
752
753const InstrClassRUsage FPAClassRUsage = {
754 SPARC_FPA,
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 { FPAIssueSlots.rid, 0, 1 },
769 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
770 /*Cycle C */ { FPAAluC1.rid, 2, 1 },
771 /*Cycle N1*/ { FPAAluC2.rid, 3, 1 },
772 /*Cycle N1*/ { FPAAluC3.rid, 4, 1 },
773 /*Cycle N1*/
774 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
775 }
776};
777
778const InstrClassRUsage LDClassRUsage = {
779 SPARC_LD,
780 /*totCycles*/ 7,
781
782 /* maxIssueNum */ 1,
783 /* isSingleIssue */ false,
784 /* breaksGroup */ false,
785 /* numBubbles */ 0,
786
787 /*numSlots*/ 3,
788 /* feasibleSlots[] */ { 0, 1, 2, },
789
790 /*numEntries*/ 6,
791 /* V[] */ {
792 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
793 { First3IssueSlots.rid, 0, 1 },
794 { LSIssueSlots.rid, 0, 1 },
795 /*Cycle E */ { LSAluC1.rid, 1, 1 },
796 /*Cycle C */ { LSAluC2.rid, 2, 1 },
797 { LdReturn.rid, 2, 1 },
798 /*Cycle N1*/
799 /*Cycle N1*/
800 /*Cycle N1*/
801 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
802 }
803};
804
805const InstrClassRUsage STClassRUsage = {
806 SPARC_ST,
807 /*totCycles*/ 7,
808
809 /* maxIssueNum */ 1,
810 /* isSingleIssue */ false,
811 /* breaksGroup */ false,
812 /* numBubbles */ 0,
813
814 /*numSlots*/ 3,
815 /* feasibleSlots[] */ { 0, 1, 2 },
816
817 /*numEntries*/ 4,
818 /* V[] */ {
819 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
820 { First3IssueSlots.rid, 0, 1 },
821 { LSIssueSlots.rid, 0, 1 },
822 /*Cycle E */ { LSAluC1.rid, 1, 1 },
823 /*Cycle C */ { LSAluC2.rid, 2, 1 }
824 /*Cycle N1*/
825 /*Cycle N1*/
826 /*Cycle N1*/
827 /*Cycle W */
828 }
829};
830
831const InstrClassRUsage CTIClassRUsage = {
832 SPARC_CTI,
833 /*totCycles*/ 7,
834
835 /* maxIssueNum */ 1,
836 /* isSingleIssue */ false,
837 /* breaksGroup */ false,
838 /* numBubbles */ 0,
839
840 /*numSlots*/ 4,
841 /* feasibleSlots[] */ { 0, 1, 2, 3 },
842
843 /*numEntries*/ 4,
844 /* V[] */ {
845 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
846 { CTIIssueSlots.rid, 0, 1 },
847 /*Cycle E */ { IAlu0.rid, 1, 1 },
848 /*Cycles E-C */ { CTIDelayCycle.rid, 1, 2 }
849 /*Cycle C */
850 /*Cycle N1*/
851 /*Cycle N1*/
852 /*Cycle N1*/
853 /*Cycle W */
854 }
855};
856
857const InstrClassRUsage SingleClassRUsage = {
858 SPARC_SINGLE,
859 /*totCycles*/ 7,
860
861 /* maxIssueNum */ 1,
862 /* isSingleIssue */ true,
863 /* breaksGroup */ false,
864 /* numBubbles */ 0,
865
866 /*numSlots*/ 1,
867 /* feasibleSlots[] */ { 0 },
868
869 /*numEntries*/ 5,
870 /* V[] */ {
871 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
872 { AllIssueSlots.rid, 0, 1 },
873 { AllIssueSlots.rid, 0, 1 },
874 { AllIssueSlots.rid, 0, 1 },
875 /*Cycle E */ { IAlu0.rid, 1, 1 }
876 /*Cycle C */
877 /*Cycle N1*/
878 /*Cycle N1*/
879 /*Cycle N1*/
880 /*Cycle W */
881 }
882};
883
884
885const InstrClassRUsage SparcRUsageDesc[] = {
886 NoneClassRUsage,
887 IEUNClassRUsage,
888 IEU0ClassRUsage,
889 IEU1ClassRUsage,
890 FPMClassRUsage,
891 FPAClassRUsage,
892 CTIClassRUsage,
893 LDClassRUsage,
894 STClassRUsage,
895 SingleClassRUsage
896};
897
898
899//---------------------------------------------------------------------------
900// const InstrIssueDelta SparcInstrIssueDeltas[]
901//
902// Purpose:
903// Changes to issue restrictions information in InstrClassRUsage for
904// instructions that differ from other instructions in their class.
905//---------------------------------------------------------------------------
906
907const InstrIssueDelta SparcInstrIssueDeltas[] = {
908
909 // opCode, isSingleIssue, breaksGroup, numBubbles
910
911 // Special cases for single-issue only
912 // Other single issue cases are below.
913//{ LDDA, true, true, 0 },
914//{ STDA, true, true, 0 },
915//{ LDDF, true, true, 0 },
916//{ LDDFA, true, true, 0 },
917 { ADDC, true, true, 0 },
918 { ADDCcc, true, true, 0 },
919 { SUBC, true, true, 0 },
920 { SUBCcc, true, true, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000921//{ LDSTUB, true, true, 0 },
922//{ SWAP, true, true, 0 },
923//{ SWAPA, true, true, 0 },
924//{ CAS, true, true, 0 },
925//{ CASA, true, true, 0 },
926//{ CASX, true, true, 0 },
927//{ CASXA, true, true, 0 },
928//{ LDFSR, true, true, 0 },
929//{ LDFSRA, true, true, 0 },
930//{ LDXFSR, true, true, 0 },
931//{ LDXFSRA, true, true, 0 },
932//{ STFSR, true, true, 0 },
933//{ STFSRA, true, true, 0 },
934//{ STXFSR, true, true, 0 },
935//{ STXFSRA, true, true, 0 },
936//{ SAVED, true, true, 0 },
937//{ RESTORED, true, true, 0 },
938//{ FLUSH, true, true, 9 },
939//{ FLUSHW, true, true, 9 },
940//{ ALIGNADDR, true, true, 0 },
941 { RETURN, true, true, 0 },
942//{ DONE, true, true, 0 },
943//{ RETRY, true, true, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000944//{ TCC, true, true, 0 },
945//{ SHUTDOWN, true, true, 0 },
946
947 // Special cases for breaking group *before*
948 // CURRENTLY NOT SUPPORTED!
949 { CALL, false, false, 0 },
Vikram S. Advec1521632001-10-22 13:31:53 +0000950 { JMPLCALL, false, false, 0 },
951 { JMPLRET, false, false, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000952
953 // Special cases for breaking the group *after*
954 { MULX, true, true, (4+34)/2 },
955 { FDIVS, false, true, 0 },
956 { FDIVD, false, true, 0 },
957 { FDIVQ, false, true, 0 },
958 { FSQRTS, false, true, 0 },
959 { FSQRTD, false, true, 0 },
960 { FSQRTQ, false, true, 0 },
961//{ FCMP{LE,GT,NE,EQ}, false, true, 0 },
962
963 // Instructions that introduce bubbles
964//{ MULScc, true, true, 2 },
965//{ SMULcc, true, true, (4+18)/2 },
966//{ UMULcc, true, true, (4+19)/2 },
967 { SDIVX, true, true, 68 },
968 { UDIVX, true, true, 68 },
969//{ SDIVcc, true, true, 36 },
970//{ UDIVcc, true, true, 37 },
Vikram S. Adveb7f06f42001-11-04 19:34:49 +0000971 { WRCCR, true, true, 4 },
972//{ WRPR, true, true, 4 },
973//{ RDCCR, true, true, 0 }, // no bubbles after, but see below
974//{ RDPR, true, true, 0 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000975};
976
977
978//---------------------------------------------------------------------------
979// const InstrRUsageDelta SparcInstrUsageDeltas[]
980//
981// Purpose:
982// Changes to resource usage information in InstrClassRUsage for
983// instructions that differ from other instructions in their class.
984//---------------------------------------------------------------------------
985
986const InstrRUsageDelta SparcInstrUsageDeltas[] = {
987
988 // MachineOpCode, Resource, Start cycle, Num cycles
989
990 //
991 // JMPL counts as a load/store instruction for issue!
992 //
Vikram S. Advec1521632001-10-22 13:31:53 +0000993 { JMPLCALL, LSIssueSlots.rid, 0, 1 },
994 { JMPLRET, LSIssueSlots.rid, 0, 1 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000995
996 //
997 // Many instructions cannot issue for the next 2 cycles after an FCMP
998 // We model that with a fake resource FCMPDelayCycle.
999 //
1000 { FCMPS, FCMPDelayCycle.rid, 1, 3 },
1001 { FCMPD, FCMPDelayCycle.rid, 1, 3 },
1002 { FCMPQ, FCMPDelayCycle.rid, 1, 3 },
1003
1004 { MULX, FCMPDelayCycle.rid, 1, 1 },
1005 { SDIVX, FCMPDelayCycle.rid, 1, 1 },
1006 { UDIVX, FCMPDelayCycle.rid, 1, 1 },
1007//{ SMULcc, FCMPDelayCycle.rid, 1, 1 },
1008//{ UMULcc, FCMPDelayCycle.rid, 1, 1 },
1009//{ SDIVcc, FCMPDelayCycle.rid, 1, 1 },
1010//{ UDIVcc, FCMPDelayCycle.rid, 1, 1 },
1011 { STD, FCMPDelayCycle.rid, 1, 1 },
1012 { FMOVRSZ, FCMPDelayCycle.rid, 1, 1 },
1013 { FMOVRSLEZ,FCMPDelayCycle.rid, 1, 1 },
1014 { FMOVRSLZ, FCMPDelayCycle.rid, 1, 1 },
1015 { FMOVRSNZ, FCMPDelayCycle.rid, 1, 1 },
1016 { FMOVRSGZ, FCMPDelayCycle.rid, 1, 1 },
1017 { FMOVRSGEZ,FCMPDelayCycle.rid, 1, 1 },
1018
1019 //
1020 // Some instructions are stalled in the GROUP stage if a CTI is in
Vikram S. Adveb7f06f42001-11-04 19:34:49 +00001021 // the E or C stage. We model that with a fake resource CTIDelayCycle.
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001022 //
1023 { LDD, CTIDelayCycle.rid, 1, 1 },
1024//{ LDDA, CTIDelayCycle.rid, 1, 1 },
1025//{ LDDSTUB, CTIDelayCycle.rid, 1, 1 },
1026//{ LDDSTUBA, CTIDelayCycle.rid, 1, 1 },
1027//{ SWAP, CTIDelayCycle.rid, 1, 1 },
1028//{ SWAPA, CTIDelayCycle.rid, 1, 1 },
1029//{ CAS, CTIDelayCycle.rid, 1, 1 },
1030//{ CASA, CTIDelayCycle.rid, 1, 1 },
1031//{ CASX, CTIDelayCycle.rid, 1, 1 },
1032//{ CASXA, CTIDelayCycle.rid, 1, 1 },
1033
1034 //
1035 // Signed int loads of less than dword size return data in cycle N1 (not C)
1036 // and put all loads in consecutive cycles into delayed load return mode.
1037 //
1038 { LDSB, LdReturn.rid, 2, -1 },
1039 { LDSB, LdReturn.rid, 3, 1 },
1040
1041 { LDSH, LdReturn.rid, 2, -1 },
1042 { LDSH, LdReturn.rid, 3, 1 },
1043
1044 { LDSW, LdReturn.rid, 2, -1 },
1045 { LDSW, LdReturn.rid, 3, 1 },
1046
Vikram S. Adveb7f06f42001-11-04 19:34:49 +00001047 //
1048 // RDPR from certain registers and RD from any register are not dispatchable
1049 // until four clocks after they reach the head of the instr. buffer.
1050 // Together with their single-issue requirement, this means all four issue
1051 // slots are effectively blocked for those cycles, plus the issue cycle.
1052 // This does not increase the latency of the instruction itself.
1053 //
1054 { RDCCR, AllIssueSlots.rid, 0, 5 },
1055 { RDCCR, AllIssueSlots.rid, 0, 5 },
1056 { RDCCR, AllIssueSlots.rid, 0, 5 },
1057 { RDCCR, AllIssueSlots.rid, 0, 5 },
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001058
1059#undef EXPLICIT_BUBBLES_NEEDED
1060#ifdef EXPLICIT_BUBBLES_NEEDED
1061 //
1062 // MULScc inserts one bubble.
1063 // This means it breaks the current group (captured in UltraSparcSchedInfo)
1064 // *and occupies all issue slots for the next cycle
1065 //
1066//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1067//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1068//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1069//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1070
1071 //
1072 // SMULcc inserts between 4 and 18 bubbles, depending on #leading 0s in rs1.
1073 // We just model this with a simple average.
1074 //
1075//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1076//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1077//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1078//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1079
1080 // SMULcc inserts between 4 and 19 bubbles, depending on #leading 0s in rs1.
1081//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1082//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1083//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1084//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1085
1086 //
1087 // MULX inserts between 4 and 34 bubbles, depending on #leading 0s in rs1.
1088 //
1089 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1090 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1091 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1092 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1093
1094 //
1095 // SDIVcc inserts 36 bubbles.
1096 //
1097//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1098//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1099//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1100//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1101
1102 // UDIVcc inserts 37 bubbles.
1103//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1104//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1105//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1106//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1107
1108 //
1109 // SDIVX inserts 68 bubbles.
1110 //
1111 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1112 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1113 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1114 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1115
1116 //
1117 // UDIVX inserts 68 bubbles.
1118 //
1119 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1120 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1121 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1122 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1123
1124 //
1125 // WR inserts 4 bubbles.
1126 //
1127//{ WR, AllIssueSlots.rid, 2, 68-1 },
1128//{ WR, AllIssueSlots.rid, 2, 68-1 },
1129//{ WR, AllIssueSlots.rid, 2, 68-1 },
1130//{ WR, AllIssueSlots.rid, 2, 68-1 },
1131
1132 //
1133 // WRPR inserts 4 bubbles.
1134 //
1135//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1136//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1137//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1138//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1139
1140 //
1141 // DONE inserts 9 bubbles.
1142 //
1143//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1144//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1145//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1146//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1147
1148 //
1149 // RETRY inserts 9 bubbles.
1150 //
1151//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1152//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1153//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1154//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1155
Chris Lattnere369fcb2001-10-13 06:54:54 +00001156#endif /*EXPLICIT_BUBBLES_NEEDED */
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001157};
1158
1159
1160
1161// Additional delays to be captured in code:
1162// 1. RDPR from several state registers (page 349)
1163// 2. RD from *any* register (page 349)
1164// 3. Writes to TICK, PSTATE, TL registers and FLUSH{W} instr (page 349)
1165// 4. Integer store can be in same group as instr producing value to store.
1166// 5. BICC and BPICC can be in the same group as instr producing CC (pg 350)
1167// 6. FMOVr cannot be in the same or next group as an IEU instr (pg 351).
1168// 7. The second instr. of a CTI group inserts 9 bubbles (pg 351)
1169// 8. WR{PR}, SVAE, SAVED, RESTORE, RESTORED, RETURN, RETRY, and DONE that
1170// follow an annulling branch cannot be issued in the same group or in
1171// the 3 groups following the branch.
1172// 9. A predicted annulled load does not stall dependent instructions.
1173// Other annulled delay slot instructions *do* stall dependents, so
1174// nothing special needs to be done for them during scheduling.
1175//10. Do not put a load use that may be annulled in the same group as the
1176// branch. The group will stall until the load returns.
1177//11. Single-prec. FP loads lock 2 registers, for dependency checking.
1178//
1179//
1180// Additional delays we cannot or will not capture:
1181// 1. If DCTI is last word of cache line, it is delayed until next line can be
1182// fetched. Also, other DCTI alignment-related delays (pg 352)
1183// 2. Load-after-store is delayed by 7 extra cycles if load hits in D-Cache.
1184// Also, several other store-load and load-store conflicts (pg 358)
1185// 3. MEMBAR, LD{X}FSR, LDD{A} and a bunch of other load stalls (pg 358)
1186// 4. There can be at most 8 outstanding buffered store instructions
1187// (including some others like MEMBAR, LDSTUB, CAS{AX}, and FLUSH)
1188
1189
1190
1191//---------------------------------------------------------------------------
1192// class UltraSparcSchedInfo
1193//
1194// Purpose:
1195// Interface to instruction scheduling information for UltraSPARC.
1196// The parameter values above are based on UltraSPARC IIi.
1197//---------------------------------------------------------------------------
1198
1199
1200class UltraSparcSchedInfo: public MachineSchedInfo {
1201public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001202 /*ctor*/ UltraSparcSchedInfo (const TargetMachine& tgt);
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001203 /*dtor*/ virtual ~UltraSparcSchedInfo () {}
1204protected:
1205 virtual void initializeResources ();
1206};
1207
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001208
1209//---------------------------------------------------------------------------
Vikram S. Advec1521632001-10-22 13:31:53 +00001210// class UltraSparcFrameInfo
1211//
1212// Purpose:
1213// Interface to stack frame layout info for the UltraSPARC.
Vikram S. Advec1521632001-10-22 13:31:53 +00001214//---------------------------------------------------------------------------
1215
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001216class UltraSparcFrameInfo: public MachineFrameInfo {
Vikram S. Advec1521632001-10-22 13:31:53 +00001217public:
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001218 /*ctor*/ UltraSparcFrameInfo(const TargetMachine& tgt) : MachineFrameInfo(tgt) {}
1219
1220public:
1221 int getStackFrameSizeAlignment () const { return StackFrameSizeAlignment;}
1222 int getMinStackFrameSize () const { return MinStackFrameSize; }
1223 int getNumFixedOutgoingArgs () const { return NumFixedOutgoingArgs; }
1224 int getSizeOfEachArgOnStack () const { return SizeOfEachArgOnStack; }
1225 bool argsOnStackHaveFixedSize () const { return true; }
1226
1227 //
1228 // These methods compute offsets using the frame contents for a
1229 // particular method. The frame contents are obtained from the
1230 // MachineCodeInfoForMethod object for the given method.
1231 //
1232 int getFirstIncomingArgOffset (MachineCodeForMethod& mcInfo,
1233 bool& pos) const
1234 {
1235 pos = true; // arguments area grows upwards
1236 return FirstIncomingArgOffsetFromFP;
1237 }
1238 int getFirstOutgoingArgOffset (MachineCodeForMethod& mcInfo,
1239 bool& pos) const
1240 {
1241 pos = true; // arguments area grows upwards
1242 return FirstOutgoingArgOffsetFromSP;
1243 }
1244 int getFirstOptionalOutgoingArgOffset(MachineCodeForMethod& mcInfo,
1245 bool& pos)const
1246 {
1247 pos = true; // arguments area grows upwards
1248 return FirstOptionalOutgoingArgOffsetFromSP;
1249 }
1250
1251 int getFirstAutomaticVarOffset (MachineCodeForMethod& mcInfo,
1252 bool& pos) const;
1253 int getRegSpillAreaOffset (MachineCodeForMethod& mcInfo,
1254 bool& pos) const;
1255 int getTmpAreaOffset (MachineCodeForMethod& mcInfo,
1256 bool& pos) const;
1257 int getDynamicAreaOffset (MachineCodeForMethod& mcInfo,
1258 bool& pos) const;
1259
1260 //
1261 // These methods specify the base register used for each stack area
1262 // (generally FP or SP)
1263 //
1264 virtual int getIncomingArgBaseRegNum() const {
1265 return (int) target.getRegInfo().getFramePointer();
1266 }
1267 virtual int getOutgoingArgBaseRegNum() const {
1268 return (int) target.getRegInfo().getStackPointer();
1269 }
1270 virtual int getOptionalOutgoingArgBaseRegNum() const {
1271 return (int) target.getRegInfo().getStackPointer();
1272 }
1273 virtual int getAutomaticVarBaseRegNum() const {
1274 return (int) target.getRegInfo().getFramePointer();
1275 }
1276 virtual int getRegSpillAreaBaseRegNum() const {
1277 return (int) target.getRegInfo().getFramePointer();
1278 }
1279 virtual int getDynamicAreaBaseRegNum() const {
1280 return (int) target.getRegInfo().getStackPointer();
1281 }
1282
1283private:
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001284 // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
1285 static const int OFFSET = (int) 0x7ff;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001286 static const int StackFrameSizeAlignment = 16;
Vikram S. Advec1521632001-10-22 13:31:53 +00001287 static const int MinStackFrameSize = 176;
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001288 static const int NumFixedOutgoingArgs = 6;
1289 static const int SizeOfEachArgOnStack = 8;
Ruchira Sasanka67a463a2001-11-12 14:45:33 +00001290 static const int StaticAreaOffsetFromFP = 0 + OFFSET;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001291 static const int FirstIncomingArgOffsetFromFP = 128 + OFFSET;
1292 static const int FirstOptionalIncomingArgOffsetFromFP = 176 + OFFSET;
1293 static const int FirstOutgoingArgOffsetFromSP = 128 + OFFSET;
1294 static const int FirstOptionalOutgoingArgOffsetFromSP = 176 + OFFSET;
Vikram S. Advec1521632001-10-22 13:31:53 +00001295};
1296
1297
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001298//---------------------------------------------------------------------------
1299// class UltraSparcCacheInfo
1300//
1301// Purpose:
1302// Interface to cache parameters for the UltraSPARC.
1303// Just use defaults for now.
1304//---------------------------------------------------------------------------
1305
1306class UltraSparcCacheInfo: public MachineCacheInfo {
1307public:
1308 /*ctor*/ UltraSparcCacheInfo (const TargetMachine& target) :
1309 MachineCacheInfo(target) {}
1310};
1311
Vikram S. Advec1521632001-10-22 13:31:53 +00001312
1313//---------------------------------------------------------------------------
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001314// class UltraSparcMachine
1315//
1316// Purpose:
1317// Primary interface to machine description for the UltraSPARC.
1318// Primarily just initializes machine-dependent parameters in
1319// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +00001320// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001321//---------------------------------------------------------------------------
1322
1323class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +00001324private:
1325 UltraSparcInstrInfo instrInfo;
1326 UltraSparcSchedInfo schedInfo;
1327 UltraSparcRegInfo regInfo;
Vikram S. Advec1521632001-10-22 13:31:53 +00001328 UltraSparcFrameInfo frameInfo;
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001329 UltraSparcCacheInfo cacheInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001330public:
1331 UltraSparc();
1332 virtual ~UltraSparc() {}
Vikram S. Adve339084b2001-09-18 13:04:24 +00001333
Chris Lattner32f600a2001-09-19 13:47:12 +00001334 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
1335 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
1336 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7f37fe52001-11-08 04:55:13 +00001337 virtual const MachineFrameInfo &getFrameInfo() const { return frameInfo; }
Vikram S. Adve5afff3b2001-11-09 02:15:52 +00001338 virtual const MachineCacheInfo &getCacheInfo() const { return cacheInfo; }
Vikram S. Adve339084b2001-09-18 13:04:24 +00001339
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001340 // compileMethod - For the sparc, we do instruction selection, followed by
1341 // delay slot scheduling, then register allocation.
1342 //
1343 virtual bool compileMethod(Method *M);
Chris Lattner32f600a2001-09-19 13:47:12 +00001344
1345 //
1346 // emitAssembly - Output assembly language code (a .s file) for the specified
1347 // module. The specified module must have been compiled before this may be
1348 // used.
1349 //
Chris Lattnerec0a95f2001-10-15 15:54:43 +00001350 virtual void emitAssembly(const Module *M, ostream &OutStr) const;
Chris Lattnerf6e0e282001-09-14 04:32:55 +00001351};
1352
1353
Chris Lattnerc6495ee2001-09-14 03:56:45 +00001354#endif