blob: d715d792a31dbbf9677bbef08afda5932f4607d2 [file] [log] [blame]
Chris Lattner5fae0de2001-09-14 03:56:45 +00001//===-- SparcInternals.h - Header file for Sparc backend ---------*- C++ -*--=//
2//
3// This file defines stuff that is to be private to the Sparc backend, but is
4// shared among different portions of the backend.
5//
6//===----------------------------------------------------------------------===//
7
8#ifndef SPARC_INTERNALS_H
9#define SPARC_INTERNALS_H
10
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000011
12#include "SparcRegClassInfo.h"
13#include "llvm/Target/TargetMachine.h"
14#include "llvm/Target/MachineInstrInfo.h"
15
Vikram S. Adve514180e2001-09-18 13:04:24 +000016#include "llvm/Target/MachineSchedInfo.h"
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000017#include "llvm/CodeGen/RegClass.h"
Chris Lattner5fae0de2001-09-14 03:56:45 +000018#include "llvm/Type.h"
Vikram S. Adve514180e2001-09-18 13:04:24 +000019
Chris Lattner8d44b992001-09-14 16:56:32 +000020#include <sys/types.h>
Chris Lattner5fae0de2001-09-14 03:56:45 +000021
Chris Lattnerf8464e42001-09-14 04:32:55 +000022class UltraSparc;
23
Chris Lattner5fae0de2001-09-14 03:56:45 +000024// OpCodeMask definitions for the Sparc V9
25//
26const OpCodeMask Immed = 0x00002000; // immed or reg operand?
27const OpCodeMask Annul = 0x20000000; // annul delay instr?
28const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
29
30
31enum SparcInstrSchedClass {
32 SPARC_NONE, /* Instructions with no scheduling restrictions */
33 SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */
34 SPARC_IEU0, /* Integer class IEU0 */
35 SPARC_IEU1, /* Integer class IEU1 */
36 SPARC_FPM, /* FP Multiply or Divide instructions */
37 SPARC_FPA, /* All other FP instructions */
38 SPARC_CTI, /* Control-transfer instructions */
39 SPARC_LD, /* Load instructions */
40 SPARC_ST, /* Store instructions */
41 SPARC_SINGLE, /* Instructions that must issue by themselves */
42
43 SPARC_INV, /* This should stay at the end for the next value */
44 SPARC_NUM_SCHED_CLASSES = SPARC_INV
45};
46
Chris Lattner5fae0de2001-09-14 03:56:45 +000047
48//---------------------------------------------------------------------------
49// enum SparcMachineOpCode.
50// const MachineInstrDescriptor SparcMachineInstrDesc[]
51//
52// Purpose:
53// Description of UltraSparc machine instructions.
54//
55//---------------------------------------------------------------------------
56
Chris Lattner5fae0de2001-09-14 03:56:45 +000057enum SparcMachineOpCode {
Chris Lattnere86a0232001-09-19 15:56:23 +000058#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
59 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
60 ENUM,
61#include "SparcInstr.def"
Chris Lattner5fae0de2001-09-14 03:56:45 +000062
Chris Lattner5fae0de2001-09-14 03:56:45 +000063 // End-of-array marker
64 INVALID_OPCODE,
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +000065 NUM_REAL_OPCODES = PHI, // number of valid opcodes
Chris Lattner5fae0de2001-09-14 03:56:45 +000066 NUM_TOTAL_OPCODES = INVALID_OPCODE
67};
68
Chris Lattner5fae0de2001-09-14 03:56:45 +000069
Chris Lattnere86a0232001-09-19 15:56:23 +000070// Array of machine instruction descriptions...
71extern const MachineInstrDescriptor SparcMachineInstrDesc[];
Chris Lattner5fae0de2001-09-14 03:56:45 +000072
73
74//---------------------------------------------------------------------------
75// class UltraSparcInstrInfo
76//
77// Purpose:
78// Information about individual instructions.
79// Most information is stored in the SparcMachineInstrDesc array above.
80// Other information is computed on demand, and most such functions
81// default to member functions in base class MachineInstrInfo.
82//---------------------------------------------------------------------------
83
84class UltraSparcInstrInfo : public MachineInstrInfo {
85public:
86 /*ctor*/ UltraSparcInstrInfo();
87
Vikram S. Adve505130c2001-10-18 00:02:06 +000088 virtual bool hasResultInterlock (MachineOpCode opCode) const
Chris Lattner5fae0de2001-09-14 03:56:45 +000089 {
90 // All UltraSPARC instructions have interlocks (note that delay slots
91 // are not considered here).
92 // However, instructions that use the result of an FCMP produce a
93 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
94 // Force the compiler to insert a software interlock (i.e., gap of
95 // 2 other groups, including NOPs if necessary).
96 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
97 }
98
Vikram S. Adve505130c2001-10-18 00:02:06 +000099 //-------------------------------------------------------------------------
100 // Code generation support for creating individual machine instructions
101 //-------------------------------------------------------------------------
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000102
Vikram S. Adve505130c2001-10-18 00:02:06 +0000103 // Create an instruction sequence to put the constant `val' into
104 // the virtual register `dest'. The generated instructions are
105 // returned in `minstrVec'. Any temporary registers (TmpInstruction)
106 // created are returned in `tempVec'.
107 //
108 virtual void CreateCodeToLoadConst(Value* val,
109 Instruction* dest,
110 vector<MachineInstr*>& minstrVec,
111 vector<TmpInstruction*>& tempVec) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000112};
113
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000114
Chris Lattner5fae0de2001-09-14 03:56:45 +0000115
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000116
117
118//----------------------------------------------------------------------------
119// class UltraSparcRegInfo
120//
121//----------------------------------------------------------------------------
122
123
Chris Lattner5fae0de2001-09-14 03:56:45 +0000124class LiveRange;
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000125class UltraSparc;
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000126class PhyRegAlloc;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000127
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000128
Chris Lattner5fae0de2001-09-14 03:56:45 +0000129class UltraSparcRegInfo : public MachineRegInfo
130{
131
132 private:
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000133
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000134 // The actual register classes in the Sparc
135
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000136 enum RegClassIDs {
137 IntRegClassID,
138 FloatRegClassID,
139 IntCCRegClassID,
140 FloatCCRegClassID
141 };
142
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000143
144 // Type of registers available in Sparc. There can be several reg types
145 // in the same class. For instace, the float reg class has Single/Double
146 // types
147 enum RegTypes {
148 IntRegType,
149 FPSingleRegType,
150 FPDoubleRegType,
151 IntCCRegType,
152 FloatCCRegType
153 };
154
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000155 // the size of a value (int, float, etc..) stored in the stack frame
156
157
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000158
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000159 // WARNING: If the above enum order must be changed, also modify
160 // getRegisterClassOfValue method below since it assumes this particular
161 // order for efficiency.
162
Chris Lattner5fae0de2001-09-14 03:56:45 +0000163
164 // reverse pointer to get info about the ultra sparc machine
165 const UltraSparc *const UltraSparcInfo;
166
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000167 // Both int and float rguments can be passed in 6 int regs -
168 // %o0 to %o5 (cannot be changed)
Chris Lattner5fae0de2001-09-14 03:56:45 +0000169 unsigned const NumOfIntArgRegs;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000170 unsigned const NumOfFloatArgRegs;
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000171 int const InvalidRegNum;
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000172 int SizeOfOperandOnStack;
173
174
Chris Lattner5fae0de2001-09-14 03:56:45 +0000175
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000176 //void setCallArgColor(LiveRange *const LR, const unsigned RegNo) const;
177
178 void setCallOrRetArgCol(LiveRange *const LR, const unsigned RegNo,
179 const MachineInstr *MI,AddedInstrMapType &AIMap)const;
180
181 MachineInstr * getCopy2RegMI(const Value *SrcVal, const unsigned Reg,
182 unsigned RegClassID) const ;
183
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000184
185 void suggestReg4RetAddr(const MachineInstr * RetMI,
186 LiveRangeInfo& LRI) const;
187
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000188 void suggestReg4CallAddr(const MachineInstr * CallMI, LiveRangeInfo& LRI,
189 vector<RegClass *> RCList) const;
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000190
191
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000192 Value *getValue4ReturnAddr( const MachineInstr * MInst ) const ;
193
194 int getRegType(const LiveRange *const LR) const {
195
196 unsigned Typ;
197
198 switch( (LR->getRegClass())->getID() ) {
199
200 case IntRegClassID: return IntRegType;
201
202 case FloatRegClassID:
203 Typ = LR->getTypeID();
204 if( Typ == Type::FloatTyID )
205 return FPSingleRegType;
206 else if( Typ == Type::DoubleTyID )
207 return FPDoubleRegType;
208 else assert(0 && "Unknown type in FloatRegClass");
209
210 case IntCCRegClassID: return IntCCRegType;
211
212 case FloatCCRegClassID: return FloatCCRegType ;
213
214 default: assert( 0 && "Unknown reg class ID");
Chris Lattner5e030832001-11-07 13:49:12 +0000215 return 0;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000216 }
217
218 }
219
220 int getRegType(const Value *const Val) const {
221
222 unsigned Typ;
223
224 switch( getRegClassIDOfValue(Val) ) {
225
226 case IntRegClassID: return IntRegType;
227
228 case FloatRegClassID:
229 Typ = (Val->getType())->getPrimitiveID();
230 if( Typ == Type::FloatTyID )
231 return FPSingleRegType;
232 else if( Typ == Type::DoubleTyID )
233 return FPDoubleRegType;
234 else assert(0 && "Unknown type in FloatRegClass");
235
236 case IntCCRegClassID: return IntCCRegType;
237
238 case FloatCCRegClassID: return FloatCCRegType ;
239
240 default: assert( 0 && "Unknown reg class ID");
Chris Lattner5e030832001-11-07 13:49:12 +0000241 return 0;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000242 }
243
244 }
245
246
247
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000248 // ***TODO: See this method is necessary
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000249
250 MachineInstr * cpValue2RegMI(Value * Val, const unsigned DestReg,
251 const int RegType) const;
252
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000253 const Value *getCallInstRetAddr(const MachineInstr *CallMI) const;
254 const unsigned getCallInstNumArgs(const MachineInstr *CallMI) const;
255
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000256
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000257 MachineInstr * cpCCR2IntMI(const unsigned IntReg) const;
258 MachineInstr * cpInt2CCRMI(const unsigned IntReg) const;
259
Chris Lattner5fae0de2001-09-14 03:56:45 +0000260 public:
261
Chris Lattner5fae0de2001-09-14 03:56:45 +0000262
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000263 UltraSparcRegInfo(const UltraSparc *const USI ) : UltraSparcInfo(USI),
264 NumOfIntArgRegs(6),
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000265 NumOfFloatArgRegs(32),
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000266 InvalidRegNum(1000),
267 SizeOfOperandOnStack(8)
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000268 {
Chris Lattner5fae0de2001-09-14 03:56:45 +0000269 MachineRegClassArr.push_back( new SparcIntRegClass(IntRegClassID) );
270 MachineRegClassArr.push_back( new SparcFloatRegClass(FloatRegClassID) );
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000271 MachineRegClassArr.push_back( new SparcIntCCRegClass(IntCCRegClassID) );
272 MachineRegClassArr.push_back( new SparcFloatCCRegClass(FloatCCRegClassID));
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000273
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000274 assert( SparcFloatRegOrder::StartOfNonVolatileRegs == 32 &&
275 "32 Float regs are used for float arg passing");
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000276
Chris Lattner5fae0de2001-09-14 03:56:45 +0000277 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000278
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000279 // ***** TODO Delete
280 ~UltraSparcRegInfo(void) { } // empty destructor
281
282
Chris Lattner5fae0de2001-09-14 03:56:45 +0000283 inline const UltraSparc & getUltraSparcInfo() const {
284 return *UltraSparcInfo;
285 }
286
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000287
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000288
289 inline unsigned getRegClassIDOfValue (const Value *const Val,
290 bool isCCReg = false) const {
291
Chris Lattner5fae0de2001-09-14 03:56:45 +0000292 Type::PrimitiveID ty = (Val->getType())->getPrimitiveID();
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000293
294 unsigned res;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000295
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000296 if( (ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
297 (ty == Type::MethodTyID) || (ty == Type::PointerTyID) )
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000298 res = IntRegClassID; // sparc int reg (ty=0: void)
Chris Lattner5fae0de2001-09-14 03:56:45 +0000299 else if( ty <= Type::DoubleTyID)
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000300 res = FloatRegClassID; // sparc float reg class
Chris Lattner5fae0de2001-09-14 03:56:45 +0000301 else {
Chris Lattnerf3f1e452001-10-15 18:15:27 +0000302 cerr << "TypeID: " << ty << endl;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000303 assert(0 && "Cannot resolve register class for type");
Chris Lattnere147d062001-11-07 14:01:59 +0000304 return 0;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000305 }
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000306
307 if(isCCReg)
308 return res + 2; // corresponidng condition code regiser
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000309 else
310 return res;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000311 }
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000312
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000313 // returns the register tha contains always zero
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000314 // this is the unified register number
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000315 inline int getZeroRegNum() const { return SparcIntRegOrder::g0; }
316
317 // returns the reg used for pushing the address when a method is called.
318 // This can be used for other purposes between calls
319 unsigned getCallAddressReg() const { return SparcIntRegOrder::o7; }
320
321
322 // and when we return from a method. It should be made sure that this
323 // register contains the return value when a return instruction is reached.
324 unsigned getReturnAddressReg() const { return SparcIntRegOrder::i7; }
325
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000326 void suggestRegs4MethodArgs(const Method *const Meth,
327 LiveRangeInfo& LRI) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000328
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000329 void suggestRegs4CallArgs(const MachineInstr *const CallMI,
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000330 LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000331
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000332 void suggestReg4RetValue(const MachineInstr *const RetMI,
333 LiveRangeInfo& LRI ) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000334
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000335
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000336 void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
337 AddedInstrns *const FirstAI) const;
338
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000339 void colorCallArgs(const MachineInstr *const CallMI, LiveRangeInfo& LRI,
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000340 AddedInstrns *const CallAI, PhyRegAlloc &PRA) const;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000341
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000342 void colorRetValue(const MachineInstr *const RetI, LiveRangeInfo& LRI,
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000343 AddedInstrns *const RetAI) const;
344
345
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000346 // bool handleSpecialMInstr(const MachineInstr * MInst,
347 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000348
349
350 static void printReg(const LiveRange *const LR) ;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000351
Chris Lattner5fae0de2001-09-14 03:56:45 +0000352 // this method provides a unique number for each register
353 inline int getUnifiedRegNum(int RegClassID, int reg) const {
354
355 if( RegClassID == IntRegClassID && reg < 32 )
356 return reg;
357 else if ( RegClassID == FloatRegClassID && reg < 64)
358 return reg + 32; // we have 32 int regs
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000359 else if( RegClassID == FloatCCRegClassID && reg < 4)
Chris Lattner5fae0de2001-09-14 03:56:45 +0000360 return reg + 32 + 64; // 32 int, 64 float
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000361 else if( RegClassID == IntCCRegClassID )
362 return 4+ 32 + 64; // only int cc reg
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000363 else if (reg==InvalidRegNum)
364 return InvalidRegNum;
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000365 else
Chris Lattner5fae0de2001-09-14 03:56:45 +0000366 assert(0 && "Invalid register class or reg number");
Chris Lattner5e030832001-11-07 13:49:12 +0000367 return 0;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000368 }
369
370 // given the unified register number, this gives the name
371 inline const string getUnifiedRegName(int reg) const {
Chris Lattner5fae0de2001-09-14 03:56:45 +0000372 if( reg < 32 )
373 return SparcIntRegOrder::getRegName(reg);
374 else if ( reg < (64 + 32) )
375 return SparcFloatRegOrder::getRegName( reg - 32);
376 else if( reg < (64+32+4) )
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000377 return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000378 else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr
379 return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4);
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000380 else if (reg== InvalidRegNum) //****** TODO: Remove */
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000381 return "<*NoReg*>";
Chris Lattner5fae0de2001-09-14 03:56:45 +0000382 else
383 assert(0 && "Invalid register number");
Chris Lattner5e030832001-11-07 13:49:12 +0000384 return "";
Chris Lattner5fae0de2001-09-14 03:56:45 +0000385 }
386
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000387 inline unsigned int getRegNumInCallersWindow(int reg) {
388 if (reg == InvalidRegNum || reg >= 32)
389 return reg;
390 return SparcIntRegOrder::getRegNumInCallersWindow(reg);
391 }
392
393 inline bool mustBeRemappedInCallersWindow(int reg) {
394 return (reg != InvalidRegNum && reg < 32);
395 }
396
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000397 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
398
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000399 MachineInstr * cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
400 const int RegType) const;
401
402 MachineInstr * cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
403 const int Offset, const int RegType) const;
404
405 MachineInstr * cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
406 const unsigned DestReg, const int RegType) const;
407
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000408 MachineInstr* cpValue2Value(Value *Src, Value *Dest) const;
409
410
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000411 inline bool isRegVolatile(const int RegClassID, const int Reg) const {
412 return (MachineRegClassArr[RegClassID])->isRegVolatile(Reg);
413 }
414
415
416 inline unsigned getFramePointer() const {
417 return SparcIntRegOrder::i6;
418 }
419
420 inline unsigned getStackPointer() const {
421 return SparcIntRegOrder::o6;
422 }
423
424 inline int getInvalidRegNum() const {
425 return InvalidRegNum;
426 }
427
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000428
429 void insertCallerSavingCode(const MachineInstr *MInst,
430 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
431
432
Chris Lattner5fae0de2001-09-14 03:56:45 +0000433};
434
435
436
Chris Lattner5fae0de2001-09-14 03:56:45 +0000437/*---------------------------------------------------------------------------
438Scheduling guidelines for SPARC IIi:
439
440I-Cache alignment rules (pg 326)
441-- Align a branch target instruction so that it's entire group is within
442 the same cache line (may be 1-4 instructions).
443** Don't let a branch that is predicted taken be the last instruction
444 on an I-cache line: delay slot will need an entire line to be fetched
445-- Make a FP instruction or a branch be the 4th instruction in a group.
446 For branches, there are tradeoffs in reordering to make this happen
447 (see pg. 327).
448** Don't put a branch in a group that crosses a 32-byte boundary!
449 An artificial branch is inserted after every 32 bytes, and having
450 another branch will force the group to be broken into 2 groups.
451
452iTLB rules:
453-- Don't let a loop span two memory pages, if possible
454
455Branch prediction performance:
456-- Don't make the branch in a delay slot the target of a branch
457-- Try not to have 2 predicted branches within a group of 4 instructions
458 (because each such group has a single branch target field).
459-- Try to align branches in slots 0, 2, 4 or 6 of a cache line (to avoid
460 the wrong prediction bits being used in some cases).
461
462D-Cache timing constraints:
463-- Signed int loads of less than 64 bits have 3 cycle latency, not 2
464-- All other loads that hit in D-Cache have 2 cycle latency
465-- All loads are returned IN ORDER, so a D-Cache miss will delay a later hit
466-- Mis-aligned loads or stores cause a trap. In particular, replace
467 mis-aligned FP double precision l/s with 2 single-precision l/s.
468-- Simulations of integer codes show increase in avg. group size of
469 33% when code (including esp. non-faulting loads) is moved across
470 one branch, and 50% across 2 branches.
471
472E-Cache timing constraints:
473-- Scheduling for E-cache (D-Cache misses) is effective (due to load buffering)
474
475Store buffer timing constraints:
476-- Stores can be executed in same cycle as instruction producing the value
477-- Stores are buffered and have lower priority for E-cache until
478 highwater mark is reached in the store buffer (5 stores)
479
480Pipeline constraints:
481-- Shifts can only use IEU0.
482-- CC setting instructions can only use IEU1.
483-- Several other instructions must only use IEU1:
484 EDGE(?), ARRAY(?), CALL, JMPL, BPr, PST, and FCMP.
485-- Two instructions cannot store to the same register file in a single cycle
486 (single write port per file).
487
488Issue and grouping constraints:
489-- FP and branch instructions must use slot 4.
490-- Shift instructions cannot be grouped with other IEU0-specific instructions.
491-- CC setting instructions cannot be grouped with other IEU1-specific instrs.
492-- Several instructions must be issued in a single-instruction group:
493 MOVcc or MOVr, MULs/x and DIVs/x, SAVE/RESTORE, many others
494-- A CALL or JMPL breaks a group, ie, is not combined with subsequent instrs.
495--
496--
497
498Branch delay slot scheduling rules:
499-- A CTI couple (two back-to-back CTI instructions in the dynamic stream)
500 has a 9-instruction penalty: the entire pipeline is flushed when the
501 second instruction reaches stage 9 (W-Writeback).
502-- Avoid putting multicycle instructions, and instructions that may cause
503 load misses, in the delay slot of an annulling branch.
504-- Avoid putting WR, SAVE..., RESTORE and RETURN instructions in the
505 delay slot of an annulling branch.
506
507 *--------------------------------------------------------------------------- */
508
509//---------------------------------------------------------------------------
510// List of CPUResources for UltraSPARC IIi.
511//---------------------------------------------------------------------------
512
513const CPUResource AllIssueSlots( "All Instr Slots", 4);
514const CPUResource IntIssueSlots( "Int Instr Slots", 3);
515const CPUResource First3IssueSlots("Instr Slots 0-3", 3);
516const CPUResource LSIssueSlots( "Load-Store Instr Slot", 1);
517const CPUResource CTIIssueSlots( "Ctrl Transfer Instr Slot", 1);
518const CPUResource FPAIssueSlots( "Int Instr Slot 1", 1);
519const CPUResource FPMIssueSlots( "Int Instr Slot 1", 1);
520
521// IEUN instructions can use either Alu and should use IAluN.
522// IEU0 instructions must use Alu 1 and should use both IAluN and IAlu0.
523// IEU1 instructions must use Alu 2 and should use both IAluN and IAlu1.
524const CPUResource IAluN("Int ALU 1or2", 2);
525const CPUResource IAlu0("Int ALU 1", 1);
526const CPUResource IAlu1("Int ALU 2", 1);
527
528const CPUResource LSAluC1("Load/Store Unit Addr Cycle", 1);
529const CPUResource LSAluC2("Load/Store Unit Issue Cycle", 1);
530const CPUResource LdReturn("Load Return Unit", 1);
531
532const CPUResource FPMAluC1("FP Mul/Div Alu Cycle 1", 1);
533const CPUResource FPMAluC2("FP Mul/Div Alu Cycle 2", 1);
534const CPUResource FPMAluC3("FP Mul/Div Alu Cycle 3", 1);
535
536const CPUResource FPAAluC1("FP Other Alu Cycle 1", 1);
537const CPUResource FPAAluC2("FP Other Alu Cycle 2", 1);
538const CPUResource FPAAluC3("FP Other Alu Cycle 3", 1);
539
540const CPUResource IRegReadPorts("Int Reg ReadPorts", INT_MAX); // CHECK
541const CPUResource IRegWritePorts("Int Reg WritePorts", 2); // CHECK
542const CPUResource FPRegReadPorts("FP Reg Read Ports", INT_MAX); // CHECK
543const CPUResource FPRegWritePorts("FP Reg Write Ports", 1); // CHECK
544
545const CPUResource CTIDelayCycle( "CTI delay cycle", 1);
546const CPUResource FCMPDelayCycle("FCMP delay cycle", 1);
547
548
549//---------------------------------------------------------------------------
550// const InstrClassRUsage SparcRUsageDesc[]
551//
552// Purpose:
553// Resource usage information for instruction in each scheduling class.
554// The InstrRUsage Objects for individual classes are specified first.
555// Note that fetch and decode are decoupled from the execution pipelines
556// via an instr buffer, so they are not included in the cycles below.
557//---------------------------------------------------------------------------
558
559const InstrClassRUsage NoneClassRUsage = {
560 SPARC_NONE,
561 /*totCycles*/ 7,
562
563 /* maxIssueNum */ 4,
564 /* isSingleIssue */ false,
565 /* breaksGroup */ false,
566 /* numBubbles */ 0,
567
568 /*numSlots*/ 4,
569 /* feasibleSlots[] */ { 0, 1, 2, 3 },
570
571 /*numEntries*/ 0,
572 /* V[] */ {
573 /*Cycle G */
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000574 /*Ccle E */
Chris Lattner5fae0de2001-09-14 03:56:45 +0000575 /*Cycle C */
576 /*Cycle N1*/
577 /*Cycle N1*/
578 /*Cycle N1*/
579 /*Cycle W */
580 }
581};
582
583const InstrClassRUsage IEUNClassRUsage = {
584 SPARC_IEUN,
585 /*totCycles*/ 7,
586
587 /* maxIssueNum */ 3,
588 /* isSingleIssue */ false,
589 /* breaksGroup */ false,
590 /* numBubbles */ 0,
591
592 /*numSlots*/ 3,
593 /* feasibleSlots[] */ { 0, 1, 2 },
594
595 /*numEntries*/ 4,
596 /* V[] */ {
597 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
598 { IntIssueSlots.rid, 0, 1 },
599 /*Cycle E */ { IAluN.rid, 1, 1 },
600 /*Cycle C */
601 /*Cycle N1*/
602 /*Cycle N1*/
603 /*Cycle N1*/
604 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
605 }
606};
607
608const InstrClassRUsage IEU0ClassRUsage = {
609 SPARC_IEU0,
610 /*totCycles*/ 7,
611
612 /* maxIssueNum */ 1,
613 /* isSingleIssue */ false,
614 /* breaksGroup */ false,
615 /* numBubbles */ 0,
616
617 /*numSlots*/ 3,
618 /* feasibleSlots[] */ { 0, 1, 2 },
619
620 /*numEntries*/ 5,
621 /* V[] */ {
622 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
623 { IntIssueSlots.rid, 0, 1 },
624 /*Cycle E */ { IAluN.rid, 1, 1 },
625 { IAlu0.rid, 1, 1 },
626 /*Cycle C */
627 /*Cycle N1*/
628 /*Cycle N1*/
629 /*Cycle N1*/
630 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
631 }
632};
633
634const InstrClassRUsage IEU1ClassRUsage = {
635 SPARC_IEU1,
636 /*totCycles*/ 7,
637
638 /* maxIssueNum */ 1,
639 /* isSingleIssue */ false,
640 /* breaksGroup */ false,
641 /* numBubbles */ 0,
642
643 /*numSlots*/ 3,
644 /* feasibleSlots[] */ { 0, 1, 2 },
645
646 /*numEntries*/ 5,
647 /* V[] */ {
648 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
649 { IntIssueSlots.rid, 0, 1 },
650 /*Cycle E */ { IAluN.rid, 1, 1 },
651 { IAlu1.rid, 1, 1 },
652 /*Cycle C */
653 /*Cycle N1*/
654 /*Cycle N1*/
655 /*Cycle N1*/
656 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
657 }
658};
659
660const InstrClassRUsage FPMClassRUsage = {
661 SPARC_FPM,
662 /*totCycles*/ 7,
663
664 /* maxIssueNum */ 1,
665 /* isSingleIssue */ false,
666 /* breaksGroup */ false,
667 /* numBubbles */ 0,
668
669 /*numSlots*/ 4,
670 /* feasibleSlots[] */ { 0, 1, 2, 3 },
671
672 /*numEntries*/ 7,
673 /* V[] */ {
674 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
675 { FPMIssueSlots.rid, 0, 1 },
676 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
677 /*Cycle C */ { FPMAluC1.rid, 2, 1 },
678 /*Cycle N1*/ { FPMAluC2.rid, 3, 1 },
679 /*Cycle N1*/ { FPMAluC3.rid, 4, 1 },
680 /*Cycle N1*/
681 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
682 }
683};
684
685const InstrClassRUsage FPAClassRUsage = {
686 SPARC_FPA,
687 /*totCycles*/ 7,
688
689 /* maxIssueNum */ 1,
690 /* isSingleIssue */ false,
691 /* breaksGroup */ false,
692 /* numBubbles */ 0,
693
694 /*numSlots*/ 4,
695 /* feasibleSlots[] */ { 0, 1, 2, 3 },
696
697 /*numEntries*/ 7,
698 /* V[] */ {
699 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
700 { FPAIssueSlots.rid, 0, 1 },
701 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
702 /*Cycle C */ { FPAAluC1.rid, 2, 1 },
703 /*Cycle N1*/ { FPAAluC2.rid, 3, 1 },
704 /*Cycle N1*/ { FPAAluC3.rid, 4, 1 },
705 /*Cycle N1*/
706 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
707 }
708};
709
710const InstrClassRUsage LDClassRUsage = {
711 SPARC_LD,
712 /*totCycles*/ 7,
713
714 /* maxIssueNum */ 1,
715 /* isSingleIssue */ false,
716 /* breaksGroup */ false,
717 /* numBubbles */ 0,
718
719 /*numSlots*/ 3,
720 /* feasibleSlots[] */ { 0, 1, 2, },
721
722 /*numEntries*/ 6,
723 /* V[] */ {
724 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
725 { First3IssueSlots.rid, 0, 1 },
726 { LSIssueSlots.rid, 0, 1 },
727 /*Cycle E */ { LSAluC1.rid, 1, 1 },
728 /*Cycle C */ { LSAluC2.rid, 2, 1 },
729 { LdReturn.rid, 2, 1 },
730 /*Cycle N1*/
731 /*Cycle N1*/
732 /*Cycle N1*/
733 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
734 }
735};
736
737const InstrClassRUsage STClassRUsage = {
738 SPARC_ST,
739 /*totCycles*/ 7,
740
741 /* maxIssueNum */ 1,
742 /* isSingleIssue */ false,
743 /* breaksGroup */ false,
744 /* numBubbles */ 0,
745
746 /*numSlots*/ 3,
747 /* feasibleSlots[] */ { 0, 1, 2 },
748
749 /*numEntries*/ 4,
750 /* V[] */ {
751 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
752 { First3IssueSlots.rid, 0, 1 },
753 { LSIssueSlots.rid, 0, 1 },
754 /*Cycle E */ { LSAluC1.rid, 1, 1 },
755 /*Cycle C */ { LSAluC2.rid, 2, 1 }
756 /*Cycle N1*/
757 /*Cycle N1*/
758 /*Cycle N1*/
759 /*Cycle W */
760 }
761};
762
763const InstrClassRUsage CTIClassRUsage = {
764 SPARC_CTI,
765 /*totCycles*/ 7,
766
767 /* maxIssueNum */ 1,
768 /* isSingleIssue */ false,
769 /* breaksGroup */ false,
770 /* numBubbles */ 0,
771
772 /*numSlots*/ 4,
773 /* feasibleSlots[] */ { 0, 1, 2, 3 },
774
775 /*numEntries*/ 4,
776 /* V[] */ {
777 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
778 { CTIIssueSlots.rid, 0, 1 },
779 /*Cycle E */ { IAlu0.rid, 1, 1 },
780 /*Cycles E-C */ { CTIDelayCycle.rid, 1, 2 }
781 /*Cycle C */
782 /*Cycle N1*/
783 /*Cycle N1*/
784 /*Cycle N1*/
785 /*Cycle W */
786 }
787};
788
789const InstrClassRUsage SingleClassRUsage = {
790 SPARC_SINGLE,
791 /*totCycles*/ 7,
792
793 /* maxIssueNum */ 1,
794 /* isSingleIssue */ true,
795 /* breaksGroup */ false,
796 /* numBubbles */ 0,
797
798 /*numSlots*/ 1,
799 /* feasibleSlots[] */ { 0 },
800
801 /*numEntries*/ 5,
802 /* V[] */ {
803 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
804 { AllIssueSlots.rid, 0, 1 },
805 { AllIssueSlots.rid, 0, 1 },
806 { AllIssueSlots.rid, 0, 1 },
807 /*Cycle E */ { IAlu0.rid, 1, 1 }
808 /*Cycle C */
809 /*Cycle N1*/
810 /*Cycle N1*/
811 /*Cycle N1*/
812 /*Cycle W */
813 }
814};
815
816
817const InstrClassRUsage SparcRUsageDesc[] = {
818 NoneClassRUsage,
819 IEUNClassRUsage,
820 IEU0ClassRUsage,
821 IEU1ClassRUsage,
822 FPMClassRUsage,
823 FPAClassRUsage,
824 CTIClassRUsage,
825 LDClassRUsage,
826 STClassRUsage,
827 SingleClassRUsage
828};
829
830
831//---------------------------------------------------------------------------
832// const InstrIssueDelta SparcInstrIssueDeltas[]
833//
834// Purpose:
835// Changes to issue restrictions information in InstrClassRUsage for
836// instructions that differ from other instructions in their class.
837//---------------------------------------------------------------------------
838
839const InstrIssueDelta SparcInstrIssueDeltas[] = {
840
841 // opCode, isSingleIssue, breaksGroup, numBubbles
842
843 // Special cases for single-issue only
844 // Other single issue cases are below.
845//{ LDDA, true, true, 0 },
846//{ STDA, true, true, 0 },
847//{ LDDF, true, true, 0 },
848//{ LDDFA, true, true, 0 },
849 { ADDC, true, true, 0 },
850 { ADDCcc, true, true, 0 },
851 { SUBC, true, true, 0 },
852 { SUBCcc, true, true, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000853//{ LDSTUB, true, true, 0 },
854//{ SWAP, true, true, 0 },
855//{ SWAPA, true, true, 0 },
856//{ CAS, true, true, 0 },
857//{ CASA, true, true, 0 },
858//{ CASX, true, true, 0 },
859//{ CASXA, true, true, 0 },
860//{ LDFSR, true, true, 0 },
861//{ LDFSRA, true, true, 0 },
862//{ LDXFSR, true, true, 0 },
863//{ LDXFSRA, true, true, 0 },
864//{ STFSR, true, true, 0 },
865//{ STFSRA, true, true, 0 },
866//{ STXFSR, true, true, 0 },
867//{ STXFSRA, true, true, 0 },
868//{ SAVED, true, true, 0 },
869//{ RESTORED, true, true, 0 },
870//{ FLUSH, true, true, 9 },
871//{ FLUSHW, true, true, 9 },
872//{ ALIGNADDR, true, true, 0 },
873 { RETURN, true, true, 0 },
874//{ DONE, true, true, 0 },
875//{ RETRY, true, true, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000876//{ TCC, true, true, 0 },
877//{ SHUTDOWN, true, true, 0 },
878
879 // Special cases for breaking group *before*
880 // CURRENTLY NOT SUPPORTED!
881 { CALL, false, false, 0 },
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000882 { JMPLCALL, false, false, 0 },
883 { JMPLRET, false, false, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000884
885 // Special cases for breaking the group *after*
886 { MULX, true, true, (4+34)/2 },
887 { FDIVS, false, true, 0 },
888 { FDIVD, false, true, 0 },
889 { FDIVQ, false, true, 0 },
890 { FSQRTS, false, true, 0 },
891 { FSQRTD, false, true, 0 },
892 { FSQRTQ, false, true, 0 },
893//{ FCMP{LE,GT,NE,EQ}, false, true, 0 },
894
895 // Instructions that introduce bubbles
896//{ MULScc, true, true, 2 },
897//{ SMULcc, true, true, (4+18)/2 },
898//{ UMULcc, true, true, (4+19)/2 },
899 { SDIVX, true, true, 68 },
900 { UDIVX, true, true, 68 },
901//{ SDIVcc, true, true, 36 },
902//{ UDIVcc, true, true, 37 },
Vikram S. Adveea5d1f52001-11-04 19:34:49 +0000903 { WRCCR, true, true, 4 },
904//{ WRPR, true, true, 4 },
905//{ RDCCR, true, true, 0 }, // no bubbles after, but see below
906//{ RDPR, true, true, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000907};
908
909
910//---------------------------------------------------------------------------
911// const InstrRUsageDelta SparcInstrUsageDeltas[]
912//
913// Purpose:
914// Changes to resource usage information in InstrClassRUsage for
915// instructions that differ from other instructions in their class.
916//---------------------------------------------------------------------------
917
918const InstrRUsageDelta SparcInstrUsageDeltas[] = {
919
920 // MachineOpCode, Resource, Start cycle, Num cycles
921
922 //
923 // JMPL counts as a load/store instruction for issue!
924 //
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000925 { JMPLCALL, LSIssueSlots.rid, 0, 1 },
926 { JMPLRET, LSIssueSlots.rid, 0, 1 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000927
928 //
929 // Many instructions cannot issue for the next 2 cycles after an FCMP
930 // We model that with a fake resource FCMPDelayCycle.
931 //
932 { FCMPS, FCMPDelayCycle.rid, 1, 3 },
933 { FCMPD, FCMPDelayCycle.rid, 1, 3 },
934 { FCMPQ, FCMPDelayCycle.rid, 1, 3 },
935
936 { MULX, FCMPDelayCycle.rid, 1, 1 },
937 { SDIVX, FCMPDelayCycle.rid, 1, 1 },
938 { UDIVX, FCMPDelayCycle.rid, 1, 1 },
939//{ SMULcc, FCMPDelayCycle.rid, 1, 1 },
940//{ UMULcc, FCMPDelayCycle.rid, 1, 1 },
941//{ SDIVcc, FCMPDelayCycle.rid, 1, 1 },
942//{ UDIVcc, FCMPDelayCycle.rid, 1, 1 },
943 { STD, FCMPDelayCycle.rid, 1, 1 },
944 { FMOVRSZ, FCMPDelayCycle.rid, 1, 1 },
945 { FMOVRSLEZ,FCMPDelayCycle.rid, 1, 1 },
946 { FMOVRSLZ, FCMPDelayCycle.rid, 1, 1 },
947 { FMOVRSNZ, FCMPDelayCycle.rid, 1, 1 },
948 { FMOVRSGZ, FCMPDelayCycle.rid, 1, 1 },
949 { FMOVRSGEZ,FCMPDelayCycle.rid, 1, 1 },
950
951 //
952 // Some instructions are stalled in the GROUP stage if a CTI is in
Vikram S. Adveea5d1f52001-11-04 19:34:49 +0000953 // the E or C stage. We model that with a fake resource CTIDelayCycle.
Chris Lattner5fae0de2001-09-14 03:56:45 +0000954 //
955 { LDD, CTIDelayCycle.rid, 1, 1 },
956//{ LDDA, CTIDelayCycle.rid, 1, 1 },
957//{ LDDSTUB, CTIDelayCycle.rid, 1, 1 },
958//{ LDDSTUBA, CTIDelayCycle.rid, 1, 1 },
959//{ SWAP, CTIDelayCycle.rid, 1, 1 },
960//{ SWAPA, CTIDelayCycle.rid, 1, 1 },
961//{ CAS, CTIDelayCycle.rid, 1, 1 },
962//{ CASA, CTIDelayCycle.rid, 1, 1 },
963//{ CASX, CTIDelayCycle.rid, 1, 1 },
964//{ CASXA, CTIDelayCycle.rid, 1, 1 },
965
966 //
967 // Signed int loads of less than dword size return data in cycle N1 (not C)
968 // and put all loads in consecutive cycles into delayed load return mode.
969 //
970 { LDSB, LdReturn.rid, 2, -1 },
971 { LDSB, LdReturn.rid, 3, 1 },
972
973 { LDSH, LdReturn.rid, 2, -1 },
974 { LDSH, LdReturn.rid, 3, 1 },
975
976 { LDSW, LdReturn.rid, 2, -1 },
977 { LDSW, LdReturn.rid, 3, 1 },
978
Vikram S. Adveea5d1f52001-11-04 19:34:49 +0000979 //
980 // RDPR from certain registers and RD from any register are not dispatchable
981 // until four clocks after they reach the head of the instr. buffer.
982 // Together with their single-issue requirement, this means all four issue
983 // slots are effectively blocked for those cycles, plus the issue cycle.
984 // This does not increase the latency of the instruction itself.
985 //
986 { RDCCR, AllIssueSlots.rid, 0, 5 },
987 { RDCCR, AllIssueSlots.rid, 0, 5 },
988 { RDCCR, AllIssueSlots.rid, 0, 5 },
989 { RDCCR, AllIssueSlots.rid, 0, 5 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000990
991#undef EXPLICIT_BUBBLES_NEEDED
992#ifdef EXPLICIT_BUBBLES_NEEDED
993 //
994 // MULScc inserts one bubble.
995 // This means it breaks the current group (captured in UltraSparcSchedInfo)
996 // *and occupies all issue slots for the next cycle
997 //
998//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
999//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1000//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1001//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1002
1003 //
1004 // SMULcc inserts between 4 and 18 bubbles, depending on #leading 0s in rs1.
1005 // We just model this with a simple average.
1006 //
1007//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1008//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1009//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1010//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1011
1012 // SMULcc inserts between 4 and 19 bubbles, depending on #leading 0s in rs1.
1013//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1014//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1015//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1016//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1017
1018 //
1019 // MULX inserts between 4 and 34 bubbles, depending on #leading 0s in rs1.
1020 //
1021 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1022 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1023 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1024 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1025
1026 //
1027 // SDIVcc inserts 36 bubbles.
1028 //
1029//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1030//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1031//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1032//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1033
1034 // UDIVcc inserts 37 bubbles.
1035//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1036//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1037//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1038//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1039
1040 //
1041 // SDIVX inserts 68 bubbles.
1042 //
1043 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1044 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1045 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1046 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1047
1048 //
1049 // UDIVX inserts 68 bubbles.
1050 //
1051 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1052 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1053 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1054 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1055
1056 //
1057 // WR inserts 4 bubbles.
1058 //
1059//{ WR, AllIssueSlots.rid, 2, 68-1 },
1060//{ WR, AllIssueSlots.rid, 2, 68-1 },
1061//{ WR, AllIssueSlots.rid, 2, 68-1 },
1062//{ WR, AllIssueSlots.rid, 2, 68-1 },
1063
1064 //
1065 // WRPR inserts 4 bubbles.
1066 //
1067//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1068//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1069//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1070//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1071
1072 //
1073 // DONE inserts 9 bubbles.
1074 //
1075//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1076//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1077//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1078//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1079
1080 //
1081 // RETRY inserts 9 bubbles.
1082 //
1083//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1084//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1085//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1086//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1087
Chris Lattner8deb9e52001-10-13 06:54:54 +00001088#endif /*EXPLICIT_BUBBLES_NEEDED */
Chris Lattner5fae0de2001-09-14 03:56:45 +00001089};
1090
1091
1092
1093// Additional delays to be captured in code:
1094// 1. RDPR from several state registers (page 349)
1095// 2. RD from *any* register (page 349)
1096// 3. Writes to TICK, PSTATE, TL registers and FLUSH{W} instr (page 349)
1097// 4. Integer store can be in same group as instr producing value to store.
1098// 5. BICC and BPICC can be in the same group as instr producing CC (pg 350)
1099// 6. FMOVr cannot be in the same or next group as an IEU instr (pg 351).
1100// 7. The second instr. of a CTI group inserts 9 bubbles (pg 351)
1101// 8. WR{PR}, SVAE, SAVED, RESTORE, RESTORED, RETURN, RETRY, and DONE that
1102// follow an annulling branch cannot be issued in the same group or in
1103// the 3 groups following the branch.
1104// 9. A predicted annulled load does not stall dependent instructions.
1105// Other annulled delay slot instructions *do* stall dependents, so
1106// nothing special needs to be done for them during scheduling.
1107//10. Do not put a load use that may be annulled in the same group as the
1108// branch. The group will stall until the load returns.
1109//11. Single-prec. FP loads lock 2 registers, for dependency checking.
1110//
1111//
1112// Additional delays we cannot or will not capture:
1113// 1. If DCTI is last word of cache line, it is delayed until next line can be
1114// fetched. Also, other DCTI alignment-related delays (pg 352)
1115// 2. Load-after-store is delayed by 7 extra cycles if load hits in D-Cache.
1116// Also, several other store-load and load-store conflicts (pg 358)
1117// 3. MEMBAR, LD{X}FSR, LDD{A} and a bunch of other load stalls (pg 358)
1118// 4. There can be at most 8 outstanding buffered store instructions
1119// (including some others like MEMBAR, LDSTUB, CAS{AX}, and FLUSH)
1120
1121
1122
1123//---------------------------------------------------------------------------
1124// class UltraSparcSchedInfo
1125//
1126// Purpose:
1127// Interface to instruction scheduling information for UltraSPARC.
1128// The parameter values above are based on UltraSPARC IIi.
1129//---------------------------------------------------------------------------
1130
1131
1132class UltraSparcSchedInfo: public MachineSchedInfo {
1133public:
1134 /*ctor*/ UltraSparcSchedInfo (const MachineInstrInfo* mii);
1135 /*dtor*/ virtual ~UltraSparcSchedInfo () {}
1136protected:
1137 virtual void initializeResources ();
1138};
1139
Chris Lattnerf8464e42001-09-14 04:32:55 +00001140
1141//---------------------------------------------------------------------------
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001142// class UltraSparcFrameInfo
1143//
1144// Purpose:
1145// Interface to stack frame layout info for the UltraSPARC.
1146// Note that there is no machine-independent interface to this information
1147//---------------------------------------------------------------------------
1148
1149class UltraSparcFrameInfo: public NonCopyable {
1150public:
1151 static const int MinStackFrameSize = 176;
1152 static const int FirstOutgoingArgOffsetFromSP = 128;
1153 static const int FirstOptionalOutgoingArgOffsetFromSP = 176;
1154 static const int StaticStackAreaOffsetFromFP = -1;
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +00001155
1156 static const int FirstIncomingArgOffsetFromFP = 126;
1157
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001158 static int getFirstAutomaticVarOffsetFromFP (const Method* method);
1159 static int getRegSpillAreaOffsetFromFP (const Method* method);
1160 static int getFrameSizeBelowDynamicArea (const Method* method);
1161};
1162
1163
1164
1165//---------------------------------------------------------------------------
Chris Lattnerf8464e42001-09-14 04:32:55 +00001166// class UltraSparcMachine
1167//
1168// Purpose:
1169// Primary interface to machine description for the UltraSPARC.
1170// Primarily just initializes machine-dependent parameters in
1171// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve514180e2001-09-18 13:04:24 +00001172// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf8464e42001-09-14 04:32:55 +00001173//---------------------------------------------------------------------------
1174
1175class UltraSparc : public TargetMachine {
Vikram S. Adve514180e2001-09-18 13:04:24 +00001176private:
1177 UltraSparcInstrInfo instrInfo;
1178 UltraSparcSchedInfo schedInfo;
1179 UltraSparcRegInfo regInfo;
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001180 UltraSparcFrameInfo frameInfo;
Chris Lattnerf8464e42001-09-14 04:32:55 +00001181public:
1182 UltraSparc();
1183 virtual ~UltraSparc() {}
Vikram S. Adve514180e2001-09-18 13:04:24 +00001184
Chris Lattner518da4f2001-09-19 13:47:12 +00001185 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
1186 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
1187 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001188 const UltraSparcFrameInfo &getFrameInfo() const { return frameInfo; }
1189
Vikram S. Adve514180e2001-09-18 13:04:24 +00001190
Chris Lattnerf8464e42001-09-14 04:32:55 +00001191 // compileMethod - For the sparc, we do instruction selection, followed by
1192 // delay slot scheduling, then register allocation.
1193 //
1194 virtual bool compileMethod(Method *M);
Chris Lattner518da4f2001-09-19 13:47:12 +00001195
1196 //
1197 // emitAssembly - Output assembly language code (a .s file) for the specified
1198 // module. The specified module must have been compiled before this may be
1199 // used.
1200 //
Chris Lattner02b67132001-10-15 15:54:43 +00001201 virtual void emitAssembly(const Module *M, ostream &OutStr) const;
Chris Lattnerf8464e42001-09-14 04:32:55 +00001202};
1203
1204
Chris Lattner5fae0de2001-09-14 03:56:45 +00001205#endif