blob: e7caf1399d40dc9f5bb5833987439770fd1174f8 [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 Lattner5fae0de2001-09-14 03:56:45 +0000304 }
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000305
306 if(isCCReg)
307 return res + 2; // corresponidng condition code regiser
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000308 else
309 return res;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000310 }
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000311
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000312 // returns the register tha contains always zero
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000313 // this is the unified register number
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000314 inline int getZeroRegNum() const { return SparcIntRegOrder::g0; }
315
316 // returns the reg used for pushing the address when a method is called.
317 // This can be used for other purposes between calls
318 unsigned getCallAddressReg() const { return SparcIntRegOrder::o7; }
319
320
321 // and when we return from a method. It should be made sure that this
322 // register contains the return value when a return instruction is reached.
323 unsigned getReturnAddressReg() const { return SparcIntRegOrder::i7; }
324
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000325 void suggestRegs4MethodArgs(const Method *const Meth,
326 LiveRangeInfo& LRI) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000327
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000328 void suggestRegs4CallArgs(const MachineInstr *const CallMI,
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000329 LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000330
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000331 void suggestReg4RetValue(const MachineInstr *const RetMI,
332 LiveRangeInfo& LRI ) const;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000333
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000334
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000335 void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
336 AddedInstrns *const FirstAI) const;
337
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000338 void colorCallArgs(const MachineInstr *const CallMI, LiveRangeInfo& LRI,
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000339 AddedInstrns *const CallAI, PhyRegAlloc &PRA) const;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000340
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000341 void colorRetValue(const MachineInstr *const RetI, LiveRangeInfo& LRI,
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000342 AddedInstrns *const RetAI) const;
343
344
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000345 // bool handleSpecialMInstr(const MachineInstr * MInst,
346 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000347
348
349 static void printReg(const LiveRange *const LR) ;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000350
Chris Lattner5fae0de2001-09-14 03:56:45 +0000351 // this method provides a unique number for each register
352 inline int getUnifiedRegNum(int RegClassID, int reg) const {
353
354 if( RegClassID == IntRegClassID && reg < 32 )
355 return reg;
356 else if ( RegClassID == FloatRegClassID && reg < 64)
357 return reg + 32; // we have 32 int regs
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000358 else if( RegClassID == FloatCCRegClassID && reg < 4)
Chris Lattner5fae0de2001-09-14 03:56:45 +0000359 return reg + 32 + 64; // 32 int, 64 float
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000360 else if( RegClassID == IntCCRegClassID )
361 return 4+ 32 + 64; // only int cc reg
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000362 else if (reg==InvalidRegNum)
363 return InvalidRegNum;
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000364 else
Chris Lattner5fae0de2001-09-14 03:56:45 +0000365 assert(0 && "Invalid register class or reg number");
Chris Lattner5e030832001-11-07 13:49:12 +0000366 return 0;
Chris Lattner5fae0de2001-09-14 03:56:45 +0000367 }
368
369 // given the unified register number, this gives the name
370 inline const string getUnifiedRegName(int reg) const {
Chris Lattner5fae0de2001-09-14 03:56:45 +0000371 if( reg < 32 )
372 return SparcIntRegOrder::getRegName(reg);
373 else if ( reg < (64 + 32) )
374 return SparcFloatRegOrder::getRegName( reg - 32);
375 else if( reg < (64+32+4) )
Ruchira Sasanka7d144a82001-09-15 00:30:44 +0000376 return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000377 else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr
378 return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4);
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000379 else if (reg== InvalidRegNum) //****** TODO: Remove */
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +0000380 return "<*NoReg*>";
Chris Lattner5fae0de2001-09-14 03:56:45 +0000381 else
382 assert(0 && "Invalid register number");
Chris Lattner5e030832001-11-07 13:49:12 +0000383 return "";
Chris Lattner5fae0de2001-09-14 03:56:45 +0000384 }
385
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000386 inline unsigned int getRegNumInCallersWindow(int reg) {
387 if (reg == InvalidRegNum || reg >= 32)
388 return reg;
389 return SparcIntRegOrder::getRegNumInCallersWindow(reg);
390 }
391
392 inline bool mustBeRemappedInCallersWindow(int reg) {
393 return (reg != InvalidRegNum && reg < 32);
394 }
395
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000396 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
397
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000398 MachineInstr * cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
399 const int RegType) const;
400
401 MachineInstr * cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
402 const int Offset, const int RegType) const;
403
404 MachineInstr * cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
405 const unsigned DestReg, const int RegType) const;
406
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000407 MachineInstr* cpValue2Value(Value *Src, Value *Dest) const;
408
409
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000410 inline bool isRegVolatile(const int RegClassID, const int Reg) const {
411 return (MachineRegClassArr[RegClassID])->isRegVolatile(Reg);
412 }
413
414
415 inline unsigned getFramePointer() const {
416 return SparcIntRegOrder::i6;
417 }
418
419 inline unsigned getStackPointer() const {
420 return SparcIntRegOrder::o6;
421 }
422
423 inline int getInvalidRegNum() const {
424 return InvalidRegNum;
425 }
426
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000427
428 void insertCallerSavingCode(const MachineInstr *MInst,
429 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
430
431
Chris Lattner5fae0de2001-09-14 03:56:45 +0000432};
433
434
435
Chris Lattner5fae0de2001-09-14 03:56:45 +0000436/*---------------------------------------------------------------------------
437Scheduling guidelines for SPARC IIi:
438
439I-Cache alignment rules (pg 326)
440-- Align a branch target instruction so that it's entire group is within
441 the same cache line (may be 1-4 instructions).
442** Don't let a branch that is predicted taken be the last instruction
443 on an I-cache line: delay slot will need an entire line to be fetched
444-- Make a FP instruction or a branch be the 4th instruction in a group.
445 For branches, there are tradeoffs in reordering to make this happen
446 (see pg. 327).
447** Don't put a branch in a group that crosses a 32-byte boundary!
448 An artificial branch is inserted after every 32 bytes, and having
449 another branch will force the group to be broken into 2 groups.
450
451iTLB rules:
452-- Don't let a loop span two memory pages, if possible
453
454Branch prediction performance:
455-- Don't make the branch in a delay slot the target of a branch
456-- Try not to have 2 predicted branches within a group of 4 instructions
457 (because each such group has a single branch target field).
458-- Try to align branches in slots 0, 2, 4 or 6 of a cache line (to avoid
459 the wrong prediction bits being used in some cases).
460
461D-Cache timing constraints:
462-- Signed int loads of less than 64 bits have 3 cycle latency, not 2
463-- All other loads that hit in D-Cache have 2 cycle latency
464-- All loads are returned IN ORDER, so a D-Cache miss will delay a later hit
465-- Mis-aligned loads or stores cause a trap. In particular, replace
466 mis-aligned FP double precision l/s with 2 single-precision l/s.
467-- Simulations of integer codes show increase in avg. group size of
468 33% when code (including esp. non-faulting loads) is moved across
469 one branch, and 50% across 2 branches.
470
471E-Cache timing constraints:
472-- Scheduling for E-cache (D-Cache misses) is effective (due to load buffering)
473
474Store buffer timing constraints:
475-- Stores can be executed in same cycle as instruction producing the value
476-- Stores are buffered and have lower priority for E-cache until
477 highwater mark is reached in the store buffer (5 stores)
478
479Pipeline constraints:
480-- Shifts can only use IEU0.
481-- CC setting instructions can only use IEU1.
482-- Several other instructions must only use IEU1:
483 EDGE(?), ARRAY(?), CALL, JMPL, BPr, PST, and FCMP.
484-- Two instructions cannot store to the same register file in a single cycle
485 (single write port per file).
486
487Issue and grouping constraints:
488-- FP and branch instructions must use slot 4.
489-- Shift instructions cannot be grouped with other IEU0-specific instructions.
490-- CC setting instructions cannot be grouped with other IEU1-specific instrs.
491-- Several instructions must be issued in a single-instruction group:
492 MOVcc or MOVr, MULs/x and DIVs/x, SAVE/RESTORE, many others
493-- A CALL or JMPL breaks a group, ie, is not combined with subsequent instrs.
494--
495--
496
497Branch delay slot scheduling rules:
498-- A CTI couple (two back-to-back CTI instructions in the dynamic stream)
499 has a 9-instruction penalty: the entire pipeline is flushed when the
500 second instruction reaches stage 9 (W-Writeback).
501-- Avoid putting multicycle instructions, and instructions that may cause
502 load misses, in the delay slot of an annulling branch.
503-- Avoid putting WR, SAVE..., RESTORE and RETURN instructions in the
504 delay slot of an annulling branch.
505
506 *--------------------------------------------------------------------------- */
507
508//---------------------------------------------------------------------------
509// List of CPUResources for UltraSPARC IIi.
510//---------------------------------------------------------------------------
511
512const CPUResource AllIssueSlots( "All Instr Slots", 4);
513const CPUResource IntIssueSlots( "Int Instr Slots", 3);
514const CPUResource First3IssueSlots("Instr Slots 0-3", 3);
515const CPUResource LSIssueSlots( "Load-Store Instr Slot", 1);
516const CPUResource CTIIssueSlots( "Ctrl Transfer Instr Slot", 1);
517const CPUResource FPAIssueSlots( "Int Instr Slot 1", 1);
518const CPUResource FPMIssueSlots( "Int Instr Slot 1", 1);
519
520// IEUN instructions can use either Alu and should use IAluN.
521// IEU0 instructions must use Alu 1 and should use both IAluN and IAlu0.
522// IEU1 instructions must use Alu 2 and should use both IAluN and IAlu1.
523const CPUResource IAluN("Int ALU 1or2", 2);
524const CPUResource IAlu0("Int ALU 1", 1);
525const CPUResource IAlu1("Int ALU 2", 1);
526
527const CPUResource LSAluC1("Load/Store Unit Addr Cycle", 1);
528const CPUResource LSAluC2("Load/Store Unit Issue Cycle", 1);
529const CPUResource LdReturn("Load Return Unit", 1);
530
531const CPUResource FPMAluC1("FP Mul/Div Alu Cycle 1", 1);
532const CPUResource FPMAluC2("FP Mul/Div Alu Cycle 2", 1);
533const CPUResource FPMAluC3("FP Mul/Div Alu Cycle 3", 1);
534
535const CPUResource FPAAluC1("FP Other Alu Cycle 1", 1);
536const CPUResource FPAAluC2("FP Other Alu Cycle 2", 1);
537const CPUResource FPAAluC3("FP Other Alu Cycle 3", 1);
538
539const CPUResource IRegReadPorts("Int Reg ReadPorts", INT_MAX); // CHECK
540const CPUResource IRegWritePorts("Int Reg WritePorts", 2); // CHECK
541const CPUResource FPRegReadPorts("FP Reg Read Ports", INT_MAX); // CHECK
542const CPUResource FPRegWritePorts("FP Reg Write Ports", 1); // CHECK
543
544const CPUResource CTIDelayCycle( "CTI delay cycle", 1);
545const CPUResource FCMPDelayCycle("FCMP delay cycle", 1);
546
547
548//---------------------------------------------------------------------------
549// const InstrClassRUsage SparcRUsageDesc[]
550//
551// Purpose:
552// Resource usage information for instruction in each scheduling class.
553// The InstrRUsage Objects for individual classes are specified first.
554// Note that fetch and decode are decoupled from the execution pipelines
555// via an instr buffer, so they are not included in the cycles below.
556//---------------------------------------------------------------------------
557
558const InstrClassRUsage NoneClassRUsage = {
559 SPARC_NONE,
560 /*totCycles*/ 7,
561
562 /* maxIssueNum */ 4,
563 /* isSingleIssue */ false,
564 /* breaksGroup */ false,
565 /* numBubbles */ 0,
566
567 /*numSlots*/ 4,
568 /* feasibleSlots[] */ { 0, 1, 2, 3 },
569
570 /*numEntries*/ 0,
571 /* V[] */ {
572 /*Cycle G */
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000573 /*Ccle E */
Chris Lattner5fae0de2001-09-14 03:56:45 +0000574 /*Cycle C */
575 /*Cycle N1*/
576 /*Cycle N1*/
577 /*Cycle N1*/
578 /*Cycle W */
579 }
580};
581
582const InstrClassRUsage IEUNClassRUsage = {
583 SPARC_IEUN,
584 /*totCycles*/ 7,
585
586 /* maxIssueNum */ 3,
587 /* isSingleIssue */ false,
588 /* breaksGroup */ false,
589 /* numBubbles */ 0,
590
591 /*numSlots*/ 3,
592 /* feasibleSlots[] */ { 0, 1, 2 },
593
594 /*numEntries*/ 4,
595 /* V[] */ {
596 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
597 { IntIssueSlots.rid, 0, 1 },
598 /*Cycle E */ { IAluN.rid, 1, 1 },
599 /*Cycle C */
600 /*Cycle N1*/
601 /*Cycle N1*/
602 /*Cycle N1*/
603 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
604 }
605};
606
607const InstrClassRUsage IEU0ClassRUsage = {
608 SPARC_IEU0,
609 /*totCycles*/ 7,
610
611 /* maxIssueNum */ 1,
612 /* isSingleIssue */ false,
613 /* breaksGroup */ false,
614 /* numBubbles */ 0,
615
616 /*numSlots*/ 3,
617 /* feasibleSlots[] */ { 0, 1, 2 },
618
619 /*numEntries*/ 5,
620 /* V[] */ {
621 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
622 { IntIssueSlots.rid, 0, 1 },
623 /*Cycle E */ { IAluN.rid, 1, 1 },
624 { IAlu0.rid, 1, 1 },
625 /*Cycle C */
626 /*Cycle N1*/
627 /*Cycle N1*/
628 /*Cycle N1*/
629 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
630 }
631};
632
633const InstrClassRUsage IEU1ClassRUsage = {
634 SPARC_IEU1,
635 /*totCycles*/ 7,
636
637 /* maxIssueNum */ 1,
638 /* isSingleIssue */ false,
639 /* breaksGroup */ false,
640 /* numBubbles */ 0,
641
642 /*numSlots*/ 3,
643 /* feasibleSlots[] */ { 0, 1, 2 },
644
645 /*numEntries*/ 5,
646 /* V[] */ {
647 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
648 { IntIssueSlots.rid, 0, 1 },
649 /*Cycle E */ { IAluN.rid, 1, 1 },
650 { IAlu1.rid, 1, 1 },
651 /*Cycle C */
652 /*Cycle N1*/
653 /*Cycle N1*/
654 /*Cycle N1*/
655 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
656 }
657};
658
659const InstrClassRUsage FPMClassRUsage = {
660 SPARC_FPM,
661 /*totCycles*/ 7,
662
663 /* maxIssueNum */ 1,
664 /* isSingleIssue */ false,
665 /* breaksGroup */ false,
666 /* numBubbles */ 0,
667
668 /*numSlots*/ 4,
669 /* feasibleSlots[] */ { 0, 1, 2, 3 },
670
671 /*numEntries*/ 7,
672 /* V[] */ {
673 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
674 { FPMIssueSlots.rid, 0, 1 },
675 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
676 /*Cycle C */ { FPMAluC1.rid, 2, 1 },
677 /*Cycle N1*/ { FPMAluC2.rid, 3, 1 },
678 /*Cycle N1*/ { FPMAluC3.rid, 4, 1 },
679 /*Cycle N1*/
680 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
681 }
682};
683
684const InstrClassRUsage FPAClassRUsage = {
685 SPARC_FPA,
686 /*totCycles*/ 7,
687
688 /* maxIssueNum */ 1,
689 /* isSingleIssue */ false,
690 /* breaksGroup */ false,
691 /* numBubbles */ 0,
692
693 /*numSlots*/ 4,
694 /* feasibleSlots[] */ { 0, 1, 2, 3 },
695
696 /*numEntries*/ 7,
697 /* V[] */ {
698 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
699 { FPAIssueSlots.rid, 0, 1 },
700 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
701 /*Cycle C */ { FPAAluC1.rid, 2, 1 },
702 /*Cycle N1*/ { FPAAluC2.rid, 3, 1 },
703 /*Cycle N1*/ { FPAAluC3.rid, 4, 1 },
704 /*Cycle N1*/
705 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
706 }
707};
708
709const InstrClassRUsage LDClassRUsage = {
710 SPARC_LD,
711 /*totCycles*/ 7,
712
713 /* maxIssueNum */ 1,
714 /* isSingleIssue */ false,
715 /* breaksGroup */ false,
716 /* numBubbles */ 0,
717
718 /*numSlots*/ 3,
719 /* feasibleSlots[] */ { 0, 1, 2, },
720
721 /*numEntries*/ 6,
722 /* V[] */ {
723 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
724 { First3IssueSlots.rid, 0, 1 },
725 { LSIssueSlots.rid, 0, 1 },
726 /*Cycle E */ { LSAluC1.rid, 1, 1 },
727 /*Cycle C */ { LSAluC2.rid, 2, 1 },
728 { LdReturn.rid, 2, 1 },
729 /*Cycle N1*/
730 /*Cycle N1*/
731 /*Cycle N1*/
732 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
733 }
734};
735
736const InstrClassRUsage STClassRUsage = {
737 SPARC_ST,
738 /*totCycles*/ 7,
739
740 /* maxIssueNum */ 1,
741 /* isSingleIssue */ false,
742 /* breaksGroup */ false,
743 /* numBubbles */ 0,
744
745 /*numSlots*/ 3,
746 /* feasibleSlots[] */ { 0, 1, 2 },
747
748 /*numEntries*/ 4,
749 /* V[] */ {
750 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
751 { First3IssueSlots.rid, 0, 1 },
752 { LSIssueSlots.rid, 0, 1 },
753 /*Cycle E */ { LSAluC1.rid, 1, 1 },
754 /*Cycle C */ { LSAluC2.rid, 2, 1 }
755 /*Cycle N1*/
756 /*Cycle N1*/
757 /*Cycle N1*/
758 /*Cycle W */
759 }
760};
761
762const InstrClassRUsage CTIClassRUsage = {
763 SPARC_CTI,
764 /*totCycles*/ 7,
765
766 /* maxIssueNum */ 1,
767 /* isSingleIssue */ false,
768 /* breaksGroup */ false,
769 /* numBubbles */ 0,
770
771 /*numSlots*/ 4,
772 /* feasibleSlots[] */ { 0, 1, 2, 3 },
773
774 /*numEntries*/ 4,
775 /* V[] */ {
776 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
777 { CTIIssueSlots.rid, 0, 1 },
778 /*Cycle E */ { IAlu0.rid, 1, 1 },
779 /*Cycles E-C */ { CTIDelayCycle.rid, 1, 2 }
780 /*Cycle C */
781 /*Cycle N1*/
782 /*Cycle N1*/
783 /*Cycle N1*/
784 /*Cycle W */
785 }
786};
787
788const InstrClassRUsage SingleClassRUsage = {
789 SPARC_SINGLE,
790 /*totCycles*/ 7,
791
792 /* maxIssueNum */ 1,
793 /* isSingleIssue */ true,
794 /* breaksGroup */ false,
795 /* numBubbles */ 0,
796
797 /*numSlots*/ 1,
798 /* feasibleSlots[] */ { 0 },
799
800 /*numEntries*/ 5,
801 /* V[] */ {
802 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
803 { AllIssueSlots.rid, 0, 1 },
804 { AllIssueSlots.rid, 0, 1 },
805 { AllIssueSlots.rid, 0, 1 },
806 /*Cycle E */ { IAlu0.rid, 1, 1 }
807 /*Cycle C */
808 /*Cycle N1*/
809 /*Cycle N1*/
810 /*Cycle N1*/
811 /*Cycle W */
812 }
813};
814
815
816const InstrClassRUsage SparcRUsageDesc[] = {
817 NoneClassRUsage,
818 IEUNClassRUsage,
819 IEU0ClassRUsage,
820 IEU1ClassRUsage,
821 FPMClassRUsage,
822 FPAClassRUsage,
823 CTIClassRUsage,
824 LDClassRUsage,
825 STClassRUsage,
826 SingleClassRUsage
827};
828
829
830//---------------------------------------------------------------------------
831// const InstrIssueDelta SparcInstrIssueDeltas[]
832//
833// Purpose:
834// Changes to issue restrictions information in InstrClassRUsage for
835// instructions that differ from other instructions in their class.
836//---------------------------------------------------------------------------
837
838const InstrIssueDelta SparcInstrIssueDeltas[] = {
839
840 // opCode, isSingleIssue, breaksGroup, numBubbles
841
842 // Special cases for single-issue only
843 // Other single issue cases are below.
844//{ LDDA, true, true, 0 },
845//{ STDA, true, true, 0 },
846//{ LDDF, true, true, 0 },
847//{ LDDFA, true, true, 0 },
848 { ADDC, true, true, 0 },
849 { ADDCcc, true, true, 0 },
850 { SUBC, true, true, 0 },
851 { SUBCcc, true, true, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000852//{ LDSTUB, true, true, 0 },
853//{ SWAP, true, true, 0 },
854//{ SWAPA, true, true, 0 },
855//{ CAS, true, true, 0 },
856//{ CASA, true, true, 0 },
857//{ CASX, true, true, 0 },
858//{ CASXA, true, true, 0 },
859//{ LDFSR, true, true, 0 },
860//{ LDFSRA, true, true, 0 },
861//{ LDXFSR, true, true, 0 },
862//{ LDXFSRA, true, true, 0 },
863//{ STFSR, true, true, 0 },
864//{ STFSRA, true, true, 0 },
865//{ STXFSR, true, true, 0 },
866//{ STXFSRA, true, true, 0 },
867//{ SAVED, true, true, 0 },
868//{ RESTORED, true, true, 0 },
869//{ FLUSH, true, true, 9 },
870//{ FLUSHW, true, true, 9 },
871//{ ALIGNADDR, true, true, 0 },
872 { RETURN, true, true, 0 },
873//{ DONE, true, true, 0 },
874//{ RETRY, true, true, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000875//{ TCC, true, true, 0 },
876//{ SHUTDOWN, true, true, 0 },
877
878 // Special cases for breaking group *before*
879 // CURRENTLY NOT SUPPORTED!
880 { CALL, false, false, 0 },
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000881 { JMPLCALL, false, false, 0 },
882 { JMPLRET, false, false, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000883
884 // Special cases for breaking the group *after*
885 { MULX, true, true, (4+34)/2 },
886 { FDIVS, false, true, 0 },
887 { FDIVD, false, true, 0 },
888 { FDIVQ, false, true, 0 },
889 { FSQRTS, false, true, 0 },
890 { FSQRTD, false, true, 0 },
891 { FSQRTQ, false, true, 0 },
892//{ FCMP{LE,GT,NE,EQ}, false, true, 0 },
893
894 // Instructions that introduce bubbles
895//{ MULScc, true, true, 2 },
896//{ SMULcc, true, true, (4+18)/2 },
897//{ UMULcc, true, true, (4+19)/2 },
898 { SDIVX, true, true, 68 },
899 { UDIVX, true, true, 68 },
900//{ SDIVcc, true, true, 36 },
901//{ UDIVcc, true, true, 37 },
Vikram S. Adveea5d1f52001-11-04 19:34:49 +0000902 { WRCCR, true, true, 4 },
903//{ WRPR, true, true, 4 },
904//{ RDCCR, true, true, 0 }, // no bubbles after, but see below
905//{ RDPR, true, true, 0 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000906};
907
908
909//---------------------------------------------------------------------------
910// const InstrRUsageDelta SparcInstrUsageDeltas[]
911//
912// Purpose:
913// Changes to resource usage information in InstrClassRUsage for
914// instructions that differ from other instructions in their class.
915//---------------------------------------------------------------------------
916
917const InstrRUsageDelta SparcInstrUsageDeltas[] = {
918
919 // MachineOpCode, Resource, Start cycle, Num cycles
920
921 //
922 // JMPL counts as a load/store instruction for issue!
923 //
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +0000924 { JMPLCALL, LSIssueSlots.rid, 0, 1 },
925 { JMPLRET, LSIssueSlots.rid, 0, 1 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000926
927 //
928 // Many instructions cannot issue for the next 2 cycles after an FCMP
929 // We model that with a fake resource FCMPDelayCycle.
930 //
931 { FCMPS, FCMPDelayCycle.rid, 1, 3 },
932 { FCMPD, FCMPDelayCycle.rid, 1, 3 },
933 { FCMPQ, FCMPDelayCycle.rid, 1, 3 },
934
935 { MULX, FCMPDelayCycle.rid, 1, 1 },
936 { SDIVX, FCMPDelayCycle.rid, 1, 1 },
937 { UDIVX, FCMPDelayCycle.rid, 1, 1 },
938//{ SMULcc, FCMPDelayCycle.rid, 1, 1 },
939//{ UMULcc, FCMPDelayCycle.rid, 1, 1 },
940//{ SDIVcc, FCMPDelayCycle.rid, 1, 1 },
941//{ UDIVcc, FCMPDelayCycle.rid, 1, 1 },
942 { STD, FCMPDelayCycle.rid, 1, 1 },
943 { FMOVRSZ, FCMPDelayCycle.rid, 1, 1 },
944 { FMOVRSLEZ,FCMPDelayCycle.rid, 1, 1 },
945 { FMOVRSLZ, FCMPDelayCycle.rid, 1, 1 },
946 { FMOVRSNZ, FCMPDelayCycle.rid, 1, 1 },
947 { FMOVRSGZ, FCMPDelayCycle.rid, 1, 1 },
948 { FMOVRSGEZ,FCMPDelayCycle.rid, 1, 1 },
949
950 //
951 // Some instructions are stalled in the GROUP stage if a CTI is in
Vikram S. Adveea5d1f52001-11-04 19:34:49 +0000952 // the E or C stage. We model that with a fake resource CTIDelayCycle.
Chris Lattner5fae0de2001-09-14 03:56:45 +0000953 //
954 { LDD, CTIDelayCycle.rid, 1, 1 },
955//{ LDDA, CTIDelayCycle.rid, 1, 1 },
956//{ LDDSTUB, CTIDelayCycle.rid, 1, 1 },
957//{ LDDSTUBA, CTIDelayCycle.rid, 1, 1 },
958//{ SWAP, CTIDelayCycle.rid, 1, 1 },
959//{ SWAPA, CTIDelayCycle.rid, 1, 1 },
960//{ CAS, CTIDelayCycle.rid, 1, 1 },
961//{ CASA, CTIDelayCycle.rid, 1, 1 },
962//{ CASX, CTIDelayCycle.rid, 1, 1 },
963//{ CASXA, CTIDelayCycle.rid, 1, 1 },
964
965 //
966 // Signed int loads of less than dword size return data in cycle N1 (not C)
967 // and put all loads in consecutive cycles into delayed load return mode.
968 //
969 { LDSB, LdReturn.rid, 2, -1 },
970 { LDSB, LdReturn.rid, 3, 1 },
971
972 { LDSH, LdReturn.rid, 2, -1 },
973 { LDSH, LdReturn.rid, 3, 1 },
974
975 { LDSW, LdReturn.rid, 2, -1 },
976 { LDSW, LdReturn.rid, 3, 1 },
977
Vikram S. Adveea5d1f52001-11-04 19:34:49 +0000978 //
979 // RDPR from certain registers and RD from any register are not dispatchable
980 // until four clocks after they reach the head of the instr. buffer.
981 // Together with their single-issue requirement, this means all four issue
982 // slots are effectively blocked for those cycles, plus the issue cycle.
983 // This does not increase the latency of the instruction itself.
984 //
985 { RDCCR, AllIssueSlots.rid, 0, 5 },
986 { RDCCR, AllIssueSlots.rid, 0, 5 },
987 { RDCCR, AllIssueSlots.rid, 0, 5 },
988 { RDCCR, AllIssueSlots.rid, 0, 5 },
Chris Lattner5fae0de2001-09-14 03:56:45 +0000989
990#undef EXPLICIT_BUBBLES_NEEDED
991#ifdef EXPLICIT_BUBBLES_NEEDED
992 //
993 // MULScc inserts one bubble.
994 // This means it breaks the current group (captured in UltraSparcSchedInfo)
995 // *and occupies all issue slots for the next cycle
996 //
997//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
998//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
999//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1000//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
1001
1002 //
1003 // SMULcc inserts between 4 and 18 bubbles, depending on #leading 0s in rs1.
1004 // We just model this with a simple average.
1005 //
1006//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
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
1011 // SMULcc inserts between 4 and 19 bubbles, depending on #leading 0s in rs1.
1012//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
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
1017 //
1018 // MULX inserts between 4 and 34 bubbles, depending on #leading 0s in rs1.
1019 //
1020 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
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
1025 //
1026 // SDIVcc inserts 36 bubbles.
1027 //
1028//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1029//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1030//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1031//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1032
1033 // UDIVcc inserts 37 bubbles.
1034//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1035//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1036//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1037//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1038
1039 //
1040 // SDIVX inserts 68 bubbles.
1041 //
1042 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1043 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1044 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1045 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1046
1047 //
1048 // UDIVX inserts 68 bubbles.
1049 //
1050 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1051 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1052 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1053 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1054
1055 //
1056 // WR inserts 4 bubbles.
1057 //
1058//{ WR, AllIssueSlots.rid, 2, 68-1 },
1059//{ WR, AllIssueSlots.rid, 2, 68-1 },
1060//{ WR, AllIssueSlots.rid, 2, 68-1 },
1061//{ WR, AllIssueSlots.rid, 2, 68-1 },
1062
1063 //
1064 // WRPR inserts 4 bubbles.
1065 //
1066//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1067//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1068//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1069//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1070
1071 //
1072 // DONE inserts 9 bubbles.
1073 //
1074//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1075//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1076//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1077//{ DONE, AllIssueSlots.rid, 2, 9-1 },
1078
1079 //
1080 // RETRY inserts 9 bubbles.
1081 //
1082//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1083//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1084//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1085//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1086
Chris Lattner8deb9e52001-10-13 06:54:54 +00001087#endif /*EXPLICIT_BUBBLES_NEEDED */
Chris Lattner5fae0de2001-09-14 03:56:45 +00001088};
1089
1090
1091
1092// Additional delays to be captured in code:
1093// 1. RDPR from several state registers (page 349)
1094// 2. RD from *any* register (page 349)
1095// 3. Writes to TICK, PSTATE, TL registers and FLUSH{W} instr (page 349)
1096// 4. Integer store can be in same group as instr producing value to store.
1097// 5. BICC and BPICC can be in the same group as instr producing CC (pg 350)
1098// 6. FMOVr cannot be in the same or next group as an IEU instr (pg 351).
1099// 7. The second instr. of a CTI group inserts 9 bubbles (pg 351)
1100// 8. WR{PR}, SVAE, SAVED, RESTORE, RESTORED, RETURN, RETRY, and DONE that
1101// follow an annulling branch cannot be issued in the same group or in
1102// the 3 groups following the branch.
1103// 9. A predicted annulled load does not stall dependent instructions.
1104// Other annulled delay slot instructions *do* stall dependents, so
1105// nothing special needs to be done for them during scheduling.
1106//10. Do not put a load use that may be annulled in the same group as the
1107// branch. The group will stall until the load returns.
1108//11. Single-prec. FP loads lock 2 registers, for dependency checking.
1109//
1110//
1111// Additional delays we cannot or will not capture:
1112// 1. If DCTI is last word of cache line, it is delayed until next line can be
1113// fetched. Also, other DCTI alignment-related delays (pg 352)
1114// 2. Load-after-store is delayed by 7 extra cycles if load hits in D-Cache.
1115// Also, several other store-load and load-store conflicts (pg 358)
1116// 3. MEMBAR, LD{X}FSR, LDD{A} and a bunch of other load stalls (pg 358)
1117// 4. There can be at most 8 outstanding buffered store instructions
1118// (including some others like MEMBAR, LDSTUB, CAS{AX}, and FLUSH)
1119
1120
1121
1122//---------------------------------------------------------------------------
1123// class UltraSparcSchedInfo
1124//
1125// Purpose:
1126// Interface to instruction scheduling information for UltraSPARC.
1127// The parameter values above are based on UltraSPARC IIi.
1128//---------------------------------------------------------------------------
1129
1130
1131class UltraSparcSchedInfo: public MachineSchedInfo {
1132public:
1133 /*ctor*/ UltraSparcSchedInfo (const MachineInstrInfo* mii);
1134 /*dtor*/ virtual ~UltraSparcSchedInfo () {}
1135protected:
1136 virtual void initializeResources ();
1137};
1138
Chris Lattnerf8464e42001-09-14 04:32:55 +00001139
1140//---------------------------------------------------------------------------
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001141// class UltraSparcFrameInfo
1142//
1143// Purpose:
1144// Interface to stack frame layout info for the UltraSPARC.
1145// Note that there is no machine-independent interface to this information
1146//---------------------------------------------------------------------------
1147
1148class UltraSparcFrameInfo: public NonCopyable {
1149public:
1150 static const int MinStackFrameSize = 176;
1151 static const int FirstOutgoingArgOffsetFromSP = 128;
1152 static const int FirstOptionalOutgoingArgOffsetFromSP = 176;
1153 static const int StaticStackAreaOffsetFromFP = -1;
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +00001154
1155 static const int FirstIncomingArgOffsetFromFP = 126;
1156
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001157 static int getFirstAutomaticVarOffsetFromFP (const Method* method);
1158 static int getRegSpillAreaOffsetFromFP (const Method* method);
1159 static int getFrameSizeBelowDynamicArea (const Method* method);
1160};
1161
1162
1163
1164//---------------------------------------------------------------------------
Chris Lattnerf8464e42001-09-14 04:32:55 +00001165// class UltraSparcMachine
1166//
1167// Purpose:
1168// Primary interface to machine description for the UltraSPARC.
1169// Primarily just initializes machine-dependent parameters in
1170// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve514180e2001-09-18 13:04:24 +00001171// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf8464e42001-09-14 04:32:55 +00001172//---------------------------------------------------------------------------
1173
1174class UltraSparc : public TargetMachine {
Vikram S. Adve514180e2001-09-18 13:04:24 +00001175private:
1176 UltraSparcInstrInfo instrInfo;
1177 UltraSparcSchedInfo schedInfo;
1178 UltraSparcRegInfo regInfo;
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001179 UltraSparcFrameInfo frameInfo;
Chris Lattnerf8464e42001-09-14 04:32:55 +00001180public:
1181 UltraSparc();
1182 virtual ~UltraSparc() {}
Vikram S. Adve514180e2001-09-18 13:04:24 +00001183
Chris Lattner518da4f2001-09-19 13:47:12 +00001184 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
1185 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
1186 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve7c1a8d62001-10-22 13:31:53 +00001187 const UltraSparcFrameInfo &getFrameInfo() const { return frameInfo; }
1188
Vikram S. Adve514180e2001-09-18 13:04:24 +00001189
Chris Lattnerf8464e42001-09-14 04:32:55 +00001190 // compileMethod - For the sparc, we do instruction selection, followed by
1191 // delay slot scheduling, then register allocation.
1192 //
1193 virtual bool compileMethod(Method *M);
Chris Lattner518da4f2001-09-19 13:47:12 +00001194
1195 //
1196 // emitAssembly - Output assembly language code (a .s file) for the specified
1197 // module. The specified module must have been compiled before this may be
1198 // used.
1199 //
Chris Lattner02b67132001-10-15 15:54:43 +00001200 virtual void emitAssembly(const Module *M, ostream &OutStr) const;
Chris Lattnerf8464e42001-09-14 04:32:55 +00001201};
1202
1203
Chris Lattner5fae0de2001-09-14 03:56:45 +00001204#endif