blob: 172ae2d334aea2958105c4b37b969c26cba6e489 [file] [log] [blame]
Chris Lattnerc6495ee2001-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 Sasanka89fb46b2001-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. Adve339084b2001-09-18 13:04:24 +000016#include "llvm/Target/MachineSchedInfo.h"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000017#include "llvm/Type.h"
Vikram S. Adve339084b2001-09-18 13:04:24 +000018
Chris Lattner46cbff62001-09-14 16:56:32 +000019#include <sys/types.h>
Chris Lattnerc6495ee2001-09-14 03:56:45 +000020
Chris Lattnerf6e0e282001-09-14 04:32:55 +000021class UltraSparc;
22
Chris Lattnerc6495ee2001-09-14 03:56:45 +000023// OpCodeMask definitions for the Sparc V9
24//
25const OpCodeMask Immed = 0x00002000; // immed or reg operand?
26const OpCodeMask Annul = 0x20000000; // annul delay instr?
27const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
28
29
30enum SparcInstrSchedClass {
31 SPARC_NONE, /* Instructions with no scheduling restrictions */
32 SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */
33 SPARC_IEU0, /* Integer class IEU0 */
34 SPARC_IEU1, /* Integer class IEU1 */
35 SPARC_FPM, /* FP Multiply or Divide instructions */
36 SPARC_FPA, /* All other FP instructions */
37 SPARC_CTI, /* Control-transfer instructions */
38 SPARC_LD, /* Load instructions */
39 SPARC_ST, /* Store instructions */
40 SPARC_SINGLE, /* Instructions that must issue by themselves */
41
42 SPARC_INV, /* This should stay at the end for the next value */
43 SPARC_NUM_SCHED_CLASSES = SPARC_INV
44};
45
Chris Lattnerc6495ee2001-09-14 03:56:45 +000046
47//---------------------------------------------------------------------------
48// enum SparcMachineOpCode.
49// const MachineInstrDescriptor SparcMachineInstrDesc[]
50//
51// Purpose:
52// Description of UltraSparc machine instructions.
53//
54//---------------------------------------------------------------------------
55
Chris Lattnerc6495ee2001-09-14 03:56:45 +000056enum SparcMachineOpCode {
Chris Lattner9a3d63b2001-09-19 15:56:23 +000057#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
58 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
59 ENUM,
60#include "SparcInstr.def"
Chris Lattnerc6495ee2001-09-14 03:56:45 +000061
Chris Lattnerc6495ee2001-09-14 03:56:45 +000062 // End-of-array marker
63 INVALID_OPCODE,
64 NUM_REAL_OPCODES = RETURN+1, // number of valid opcodes
65 NUM_TOTAL_OPCODES = INVALID_OPCODE
66};
67
Chris Lattnerc6495ee2001-09-14 03:56:45 +000068
Chris Lattner9a3d63b2001-09-19 15:56:23 +000069// Array of machine instruction descriptions...
70extern const MachineInstrDescriptor SparcMachineInstrDesc[];
Chris Lattnerc6495ee2001-09-14 03:56:45 +000071
72
73//---------------------------------------------------------------------------
74// class UltraSparcInstrInfo
75//
76// Purpose:
77// Information about individual instructions.
78// Most information is stored in the SparcMachineInstrDesc array above.
79// Other information is computed on demand, and most such functions
80// default to member functions in base class MachineInstrInfo.
81//---------------------------------------------------------------------------
82
83class UltraSparcInstrInfo : public MachineInstrInfo {
84public:
85 /*ctor*/ UltraSparcInstrInfo();
86
87 virtual bool hasResultInterlock (MachineOpCode opCode)
88 {
89 // All UltraSPARC instructions have interlocks (note that delay slots
90 // are not considered here).
91 // However, instructions that use the result of an FCMP produce a
92 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
93 // Force the compiler to insert a software interlock (i.e., gap of
94 // 2 other groups, including NOPs if necessary).
95 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
96 }
97
98};
99
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000100
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000101
102class LiveRange;
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000103class UltraSparc;
104
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000105
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000106
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000107class UltraSparcRegInfo : public MachineRegInfo
108{
109
110 private:
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000111
112 enum RegClassIDs {
113 IntRegClassID,
114 FloatRegClassID,
115 IntCCRegClassID,
116 FloatCCRegClassID
117 };
118
119 // WARNING: If the above enum order must be changed, also modify
120 // getRegisterClassOfValue method below since it assumes this particular
121 // order for efficiency.
122
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000123
124 // reverse pointer to get info about the ultra sparc machine
125 const UltraSparc *const UltraSparcInfo;
126
127 // Int arguments can be passed in 6 int regs - %o0 to %o5 (cannot be changed)
128 unsigned const NumOfIntArgRegs;
129
130 // Float arguments can be passed in this many regs - can be canged if needed
131 // %f0 - %f5 are used (can hold 6 floats or 3 doubles)
132 unsigned const NumOfFloatArgRegs;
133
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000134 //void setCallArgColor(LiveRange *const LR, const unsigned RegNo) const;
135
136 void setCallOrRetArgCol(LiveRange *const LR, const unsigned RegNo,
137 const MachineInstr *MI,AddedInstrMapType &AIMap)const;
138
139 MachineInstr * getCopy2RegMI(const Value *SrcVal, const unsigned Reg,
140 unsigned RegClassID) const ;
141
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000142 public:
143
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000144
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000145 UltraSparcRegInfo(const UltraSparc *const USI ) : UltraSparcInfo(USI),
146 NumOfIntArgRegs(6),
147 NumOfFloatArgRegs(6)
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000148 {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000149 MachineRegClassArr.push_back( new SparcIntRegClass(IntRegClassID) );
150 MachineRegClassArr.push_back( new SparcFloatRegClass(FloatRegClassID) );
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000151 MachineRegClassArr.push_back( new SparcIntCCRegClass(IntCCRegClassID) );
152 MachineRegClassArr.push_back( new SparcFloatCCRegClass(FloatCCRegClassID));
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000153
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000154 assert( SparcFloatRegOrder::StartOfNonVolatileRegs == 6 &&
155 "6 Float regs are used for float arg passing");
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000156 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000157
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000158 // ***** TODO Delete
159 ~UltraSparcRegInfo(void) { } // empty destructor
160
161
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000162 inline const UltraSparc & getUltraSparcInfo() const {
163 return *UltraSparcInfo;
164 }
165
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000166
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000167
168 inline unsigned getRegClassIDOfValue (const Value *const Val,
169 bool isCCReg = false) const {
170
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000171 Type::PrimitiveID ty = (Val->getType())->getPrimitiveID();
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000172
173 unsigned res;
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000174
175 if( ty && ty <= Type::LongTyID || (ty == Type::PointerTyID) )
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000176 res = IntRegClassID; // sparc int reg (ty=0: void)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000177 else if( ty <= Type::DoubleTyID)
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000178 res = FloatRegClassID; // sparc float reg class
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000179 else {
180 cout << "TypeID: " << ty << endl;
181 assert(0 && "Cannot resolve register class for type");
182
183 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000184
185 if(isCCReg)
186 return res + 2; // corresponidng condition code regiser
187
188 else
189 return res;
190
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000191 }
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000192
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000193 // returns the register tha contains always zero
194 inline int getZeroRegNum() const { return SparcIntRegOrder::g0; }
195
196 // returns the reg used for pushing the address when a method is called.
197 // This can be used for other purposes between calls
198 unsigned getCallAddressReg() const { return SparcIntRegOrder::o7; }
199
200
201 // and when we return from a method. It should be made sure that this
202 // register contains the return value when a return instruction is reached.
203 unsigned getReturnAddressReg() const { return SparcIntRegOrder::i7; }
204
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000205 void colorArgs(const Method *const Meth, LiveRangeInfo& LRI) const;
206
207 static void printReg(const LiveRange *const LR) ;
208
209 void colorCallArgs(vector<const Instruction *> & CallInstrList,
210 LiveRangeInfo& LRI,
211 AddedInstrMapType& AddedInstrMap ) const;
212
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000213 void colorRetArg(vector<const Instruction *> &
214 RetInstrList, LiveRangeInfo& LRI,
215 AddedInstrMapType &AddedInstrMap) const;
216
217
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000218 // this method provides a unique number for each register
219 inline int getUnifiedRegNum(int RegClassID, int reg) const {
220
221 if( RegClassID == IntRegClassID && reg < 32 )
222 return reg;
223 else if ( RegClassID == FloatRegClassID && reg < 64)
224 return reg + 32; // we have 32 int regs
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000225 else if( RegClassID == FloatCCRegClassID && reg < 4)
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000226 return reg + 32 + 64; // 32 int, 64 float
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000227 else if( RegClassID == IntCCRegClassID )
228 return 4+ 32 + 64; // only int cc reg
229 else
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000230 assert(0 && "Invalid register class or reg number");
231
232 }
233
234 // given the unified register number, this gives the name
235 inline const string getUnifiedRegName(int reg) const {
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000236 if( reg < 32 )
237 return SparcIntRegOrder::getRegName(reg);
238 else if ( reg < (64 + 32) )
239 return SparcFloatRegOrder::getRegName( reg - 32);
240 else if( reg < (64+32+4) )
Ruchira Sasankae38bd5332001-09-15 00:30:44 +0000241 return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
242 else if ( reg == 64+32+4)
243 return "xcc"; // only integer cc reg
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000244 else
245 assert(0 && "Invalid register number");
246 }
247
248
249};
250
251
252
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000253/*---------------------------------------------------------------------------
254Scheduling guidelines for SPARC IIi:
255
256I-Cache alignment rules (pg 326)
257-- Align a branch target instruction so that it's entire group is within
258 the same cache line (may be 1-4 instructions).
259** Don't let a branch that is predicted taken be the last instruction
260 on an I-cache line: delay slot will need an entire line to be fetched
261-- Make a FP instruction or a branch be the 4th instruction in a group.
262 For branches, there are tradeoffs in reordering to make this happen
263 (see pg. 327).
264** Don't put a branch in a group that crosses a 32-byte boundary!
265 An artificial branch is inserted after every 32 bytes, and having
266 another branch will force the group to be broken into 2 groups.
267
268iTLB rules:
269-- Don't let a loop span two memory pages, if possible
270
271Branch prediction performance:
272-- Don't make the branch in a delay slot the target of a branch
273-- Try not to have 2 predicted branches within a group of 4 instructions
274 (because each such group has a single branch target field).
275-- Try to align branches in slots 0, 2, 4 or 6 of a cache line (to avoid
276 the wrong prediction bits being used in some cases).
277
278D-Cache timing constraints:
279-- Signed int loads of less than 64 bits have 3 cycle latency, not 2
280-- All other loads that hit in D-Cache have 2 cycle latency
281-- All loads are returned IN ORDER, so a D-Cache miss will delay a later hit
282-- Mis-aligned loads or stores cause a trap. In particular, replace
283 mis-aligned FP double precision l/s with 2 single-precision l/s.
284-- Simulations of integer codes show increase in avg. group size of
285 33% when code (including esp. non-faulting loads) is moved across
286 one branch, and 50% across 2 branches.
287
288E-Cache timing constraints:
289-- Scheduling for E-cache (D-Cache misses) is effective (due to load buffering)
290
291Store buffer timing constraints:
292-- Stores can be executed in same cycle as instruction producing the value
293-- Stores are buffered and have lower priority for E-cache until
294 highwater mark is reached in the store buffer (5 stores)
295
296Pipeline constraints:
297-- Shifts can only use IEU0.
298-- CC setting instructions can only use IEU1.
299-- Several other instructions must only use IEU1:
300 EDGE(?), ARRAY(?), CALL, JMPL, BPr, PST, and FCMP.
301-- Two instructions cannot store to the same register file in a single cycle
302 (single write port per file).
303
304Issue and grouping constraints:
305-- FP and branch instructions must use slot 4.
306-- Shift instructions cannot be grouped with other IEU0-specific instructions.
307-- CC setting instructions cannot be grouped with other IEU1-specific instrs.
308-- Several instructions must be issued in a single-instruction group:
309 MOVcc or MOVr, MULs/x and DIVs/x, SAVE/RESTORE, many others
310-- A CALL or JMPL breaks a group, ie, is not combined with subsequent instrs.
311--
312--
313
314Branch delay slot scheduling rules:
315-- A CTI couple (two back-to-back CTI instructions in the dynamic stream)
316 has a 9-instruction penalty: the entire pipeline is flushed when the
317 second instruction reaches stage 9 (W-Writeback).
318-- Avoid putting multicycle instructions, and instructions that may cause
319 load misses, in the delay slot of an annulling branch.
320-- Avoid putting WR, SAVE..., RESTORE and RETURN instructions in the
321 delay slot of an annulling branch.
322
323 *--------------------------------------------------------------------------- */
324
325//---------------------------------------------------------------------------
326// List of CPUResources for UltraSPARC IIi.
327//---------------------------------------------------------------------------
328
329const CPUResource AllIssueSlots( "All Instr Slots", 4);
330const CPUResource IntIssueSlots( "Int Instr Slots", 3);
331const CPUResource First3IssueSlots("Instr Slots 0-3", 3);
332const CPUResource LSIssueSlots( "Load-Store Instr Slot", 1);
333const CPUResource CTIIssueSlots( "Ctrl Transfer Instr Slot", 1);
334const CPUResource FPAIssueSlots( "Int Instr Slot 1", 1);
335const CPUResource FPMIssueSlots( "Int Instr Slot 1", 1);
336
337// IEUN instructions can use either Alu and should use IAluN.
338// IEU0 instructions must use Alu 1 and should use both IAluN and IAlu0.
339// IEU1 instructions must use Alu 2 and should use both IAluN and IAlu1.
340const CPUResource IAluN("Int ALU 1or2", 2);
341const CPUResource IAlu0("Int ALU 1", 1);
342const CPUResource IAlu1("Int ALU 2", 1);
343
344const CPUResource LSAluC1("Load/Store Unit Addr Cycle", 1);
345const CPUResource LSAluC2("Load/Store Unit Issue Cycle", 1);
346const CPUResource LdReturn("Load Return Unit", 1);
347
348const CPUResource FPMAluC1("FP Mul/Div Alu Cycle 1", 1);
349const CPUResource FPMAluC2("FP Mul/Div Alu Cycle 2", 1);
350const CPUResource FPMAluC3("FP Mul/Div Alu Cycle 3", 1);
351
352const CPUResource FPAAluC1("FP Other Alu Cycle 1", 1);
353const CPUResource FPAAluC2("FP Other Alu Cycle 2", 1);
354const CPUResource FPAAluC3("FP Other Alu Cycle 3", 1);
355
356const CPUResource IRegReadPorts("Int Reg ReadPorts", INT_MAX); // CHECK
357const CPUResource IRegWritePorts("Int Reg WritePorts", 2); // CHECK
358const CPUResource FPRegReadPorts("FP Reg Read Ports", INT_MAX); // CHECK
359const CPUResource FPRegWritePorts("FP Reg Write Ports", 1); // CHECK
360
361const CPUResource CTIDelayCycle( "CTI delay cycle", 1);
362const CPUResource FCMPDelayCycle("FCMP delay cycle", 1);
363
364
365//---------------------------------------------------------------------------
366// const InstrClassRUsage SparcRUsageDesc[]
367//
368// Purpose:
369// Resource usage information for instruction in each scheduling class.
370// The InstrRUsage Objects for individual classes are specified first.
371// Note that fetch and decode are decoupled from the execution pipelines
372// via an instr buffer, so they are not included in the cycles below.
373//---------------------------------------------------------------------------
374
375const InstrClassRUsage NoneClassRUsage = {
376 SPARC_NONE,
377 /*totCycles*/ 7,
378
379 /* maxIssueNum */ 4,
380 /* isSingleIssue */ false,
381 /* breaksGroup */ false,
382 /* numBubbles */ 0,
383
384 /*numSlots*/ 4,
385 /* feasibleSlots[] */ { 0, 1, 2, 3 },
386
387 /*numEntries*/ 0,
388 /* V[] */ {
389 /*Cycle G */
390 /*Cycle E */
391 /*Cycle C */
392 /*Cycle N1*/
393 /*Cycle N1*/
394 /*Cycle N1*/
395 /*Cycle W */
396 }
397};
398
399const InstrClassRUsage IEUNClassRUsage = {
400 SPARC_IEUN,
401 /*totCycles*/ 7,
402
403 /* maxIssueNum */ 3,
404 /* isSingleIssue */ false,
405 /* breaksGroup */ false,
406 /* numBubbles */ 0,
407
408 /*numSlots*/ 3,
409 /* feasibleSlots[] */ { 0, 1, 2 },
410
411 /*numEntries*/ 4,
412 /* V[] */ {
413 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
414 { IntIssueSlots.rid, 0, 1 },
415 /*Cycle E */ { IAluN.rid, 1, 1 },
416 /*Cycle C */
417 /*Cycle N1*/
418 /*Cycle N1*/
419 /*Cycle N1*/
420 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
421 }
422};
423
424const InstrClassRUsage IEU0ClassRUsage = {
425 SPARC_IEU0,
426 /*totCycles*/ 7,
427
428 /* maxIssueNum */ 1,
429 /* isSingleIssue */ false,
430 /* breaksGroup */ false,
431 /* numBubbles */ 0,
432
433 /*numSlots*/ 3,
434 /* feasibleSlots[] */ { 0, 1, 2 },
435
436 /*numEntries*/ 5,
437 /* V[] */ {
438 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
439 { IntIssueSlots.rid, 0, 1 },
440 /*Cycle E */ { IAluN.rid, 1, 1 },
441 { IAlu0.rid, 1, 1 },
442 /*Cycle C */
443 /*Cycle N1*/
444 /*Cycle N1*/
445 /*Cycle N1*/
446 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
447 }
448};
449
450const InstrClassRUsage IEU1ClassRUsage = {
451 SPARC_IEU1,
452 /*totCycles*/ 7,
453
454 /* maxIssueNum */ 1,
455 /* isSingleIssue */ false,
456 /* breaksGroup */ false,
457 /* numBubbles */ 0,
458
459 /*numSlots*/ 3,
460 /* feasibleSlots[] */ { 0, 1, 2 },
461
462 /*numEntries*/ 5,
463 /* V[] */ {
464 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
465 { IntIssueSlots.rid, 0, 1 },
466 /*Cycle E */ { IAluN.rid, 1, 1 },
467 { IAlu1.rid, 1, 1 },
468 /*Cycle C */
469 /*Cycle N1*/
470 /*Cycle N1*/
471 /*Cycle N1*/
472 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
473 }
474};
475
476const InstrClassRUsage FPMClassRUsage = {
477 SPARC_FPM,
478 /*totCycles*/ 7,
479
480 /* maxIssueNum */ 1,
481 /* isSingleIssue */ false,
482 /* breaksGroup */ false,
483 /* numBubbles */ 0,
484
485 /*numSlots*/ 4,
486 /* feasibleSlots[] */ { 0, 1, 2, 3 },
487
488 /*numEntries*/ 7,
489 /* V[] */ {
490 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
491 { FPMIssueSlots.rid, 0, 1 },
492 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
493 /*Cycle C */ { FPMAluC1.rid, 2, 1 },
494 /*Cycle N1*/ { FPMAluC2.rid, 3, 1 },
495 /*Cycle N1*/ { FPMAluC3.rid, 4, 1 },
496 /*Cycle N1*/
497 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
498 }
499};
500
501const InstrClassRUsage FPAClassRUsage = {
502 SPARC_FPA,
503 /*totCycles*/ 7,
504
505 /* maxIssueNum */ 1,
506 /* isSingleIssue */ false,
507 /* breaksGroup */ false,
508 /* numBubbles */ 0,
509
510 /*numSlots*/ 4,
511 /* feasibleSlots[] */ { 0, 1, 2, 3 },
512
513 /*numEntries*/ 7,
514 /* V[] */ {
515 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
516 { FPAIssueSlots.rid, 0, 1 },
517 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
518 /*Cycle C */ { FPAAluC1.rid, 2, 1 },
519 /*Cycle N1*/ { FPAAluC2.rid, 3, 1 },
520 /*Cycle N1*/ { FPAAluC3.rid, 4, 1 },
521 /*Cycle N1*/
522 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
523 }
524};
525
526const InstrClassRUsage LDClassRUsage = {
527 SPARC_LD,
528 /*totCycles*/ 7,
529
530 /* maxIssueNum */ 1,
531 /* isSingleIssue */ false,
532 /* breaksGroup */ false,
533 /* numBubbles */ 0,
534
535 /*numSlots*/ 3,
536 /* feasibleSlots[] */ { 0, 1, 2, },
537
538 /*numEntries*/ 6,
539 /* V[] */ {
540 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
541 { First3IssueSlots.rid, 0, 1 },
542 { LSIssueSlots.rid, 0, 1 },
543 /*Cycle E */ { LSAluC1.rid, 1, 1 },
544 /*Cycle C */ { LSAluC2.rid, 2, 1 },
545 { LdReturn.rid, 2, 1 },
546 /*Cycle N1*/
547 /*Cycle N1*/
548 /*Cycle N1*/
549 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
550 }
551};
552
553const InstrClassRUsage STClassRUsage = {
554 SPARC_ST,
555 /*totCycles*/ 7,
556
557 /* maxIssueNum */ 1,
558 /* isSingleIssue */ false,
559 /* breaksGroup */ false,
560 /* numBubbles */ 0,
561
562 /*numSlots*/ 3,
563 /* feasibleSlots[] */ { 0, 1, 2 },
564
565 /*numEntries*/ 4,
566 /* V[] */ {
567 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
568 { First3IssueSlots.rid, 0, 1 },
569 { LSIssueSlots.rid, 0, 1 },
570 /*Cycle E */ { LSAluC1.rid, 1, 1 },
571 /*Cycle C */ { LSAluC2.rid, 2, 1 }
572 /*Cycle N1*/
573 /*Cycle N1*/
574 /*Cycle N1*/
575 /*Cycle W */
576 }
577};
578
579const InstrClassRUsage CTIClassRUsage = {
580 SPARC_CTI,
581 /*totCycles*/ 7,
582
583 /* maxIssueNum */ 1,
584 /* isSingleIssue */ false,
585 /* breaksGroup */ false,
586 /* numBubbles */ 0,
587
588 /*numSlots*/ 4,
589 /* feasibleSlots[] */ { 0, 1, 2, 3 },
590
591 /*numEntries*/ 4,
592 /* V[] */ {
593 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
594 { CTIIssueSlots.rid, 0, 1 },
595 /*Cycle E */ { IAlu0.rid, 1, 1 },
596 /*Cycles E-C */ { CTIDelayCycle.rid, 1, 2 }
597 /*Cycle C */
598 /*Cycle N1*/
599 /*Cycle N1*/
600 /*Cycle N1*/
601 /*Cycle W */
602 }
603};
604
605const InstrClassRUsage SingleClassRUsage = {
606 SPARC_SINGLE,
607 /*totCycles*/ 7,
608
609 /* maxIssueNum */ 1,
610 /* isSingleIssue */ true,
611 /* breaksGroup */ false,
612 /* numBubbles */ 0,
613
614 /*numSlots*/ 1,
615 /* feasibleSlots[] */ { 0 },
616
617 /*numEntries*/ 5,
618 /* V[] */ {
619 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
620 { AllIssueSlots.rid, 0, 1 },
621 { AllIssueSlots.rid, 0, 1 },
622 { AllIssueSlots.rid, 0, 1 },
623 /*Cycle E */ { IAlu0.rid, 1, 1 }
624 /*Cycle C */
625 /*Cycle N1*/
626 /*Cycle N1*/
627 /*Cycle N1*/
628 /*Cycle W */
629 }
630};
631
632
633const InstrClassRUsage SparcRUsageDesc[] = {
634 NoneClassRUsage,
635 IEUNClassRUsage,
636 IEU0ClassRUsage,
637 IEU1ClassRUsage,
638 FPMClassRUsage,
639 FPAClassRUsage,
640 CTIClassRUsage,
641 LDClassRUsage,
642 STClassRUsage,
643 SingleClassRUsage
644};
645
646
647//---------------------------------------------------------------------------
648// const InstrIssueDelta SparcInstrIssueDeltas[]
649//
650// Purpose:
651// Changes to issue restrictions information in InstrClassRUsage for
652// instructions that differ from other instructions in their class.
653//---------------------------------------------------------------------------
654
655const InstrIssueDelta SparcInstrIssueDeltas[] = {
656
657 // opCode, isSingleIssue, breaksGroup, numBubbles
658
659 // Special cases for single-issue only
660 // Other single issue cases are below.
661//{ LDDA, true, true, 0 },
662//{ STDA, true, true, 0 },
663//{ LDDF, true, true, 0 },
664//{ LDDFA, true, true, 0 },
665 { ADDC, true, true, 0 },
666 { ADDCcc, true, true, 0 },
667 { SUBC, true, true, 0 },
668 { SUBCcc, true, true, 0 },
669//{ SAVE, true, true, 0 },
670//{ RESTORE, true, true, 0 },
671//{ LDSTUB, true, true, 0 },
672//{ SWAP, true, true, 0 },
673//{ SWAPA, true, true, 0 },
674//{ CAS, true, true, 0 },
675//{ CASA, true, true, 0 },
676//{ CASX, true, true, 0 },
677//{ CASXA, true, true, 0 },
678//{ LDFSR, true, true, 0 },
679//{ LDFSRA, true, true, 0 },
680//{ LDXFSR, true, true, 0 },
681//{ LDXFSRA, true, true, 0 },
682//{ STFSR, true, true, 0 },
683//{ STFSRA, true, true, 0 },
684//{ STXFSR, true, true, 0 },
685//{ STXFSRA, true, true, 0 },
686//{ SAVED, true, true, 0 },
687//{ RESTORED, true, true, 0 },
688//{ FLUSH, true, true, 9 },
689//{ FLUSHW, true, true, 9 },
690//{ ALIGNADDR, true, true, 0 },
691 { RETURN, true, true, 0 },
692//{ DONE, true, true, 0 },
693//{ RETRY, true, true, 0 },
694//{ WR, true, true, 0 },
695//{ WRPR, true, true, 4 },
696//{ RD, true, true, 0 },
697//{ RDPR, true, true, 0 },
698//{ TCC, true, true, 0 },
699//{ SHUTDOWN, true, true, 0 },
700
701 // Special cases for breaking group *before*
702 // CURRENTLY NOT SUPPORTED!
703 { CALL, false, false, 0 },
704 { JMPL, false, false, 0 },
705
706 // Special cases for breaking the group *after*
707 { MULX, true, true, (4+34)/2 },
708 { FDIVS, false, true, 0 },
709 { FDIVD, false, true, 0 },
710 { FDIVQ, false, true, 0 },
711 { FSQRTS, false, true, 0 },
712 { FSQRTD, false, true, 0 },
713 { FSQRTQ, false, true, 0 },
714//{ FCMP{LE,GT,NE,EQ}, false, true, 0 },
715
716 // Instructions that introduce bubbles
717//{ MULScc, true, true, 2 },
718//{ SMULcc, true, true, (4+18)/2 },
719//{ UMULcc, true, true, (4+19)/2 },
720 { SDIVX, true, true, 68 },
721 { UDIVX, true, true, 68 },
722//{ SDIVcc, true, true, 36 },
723//{ UDIVcc, true, true, 37 },
724//{ WR, false, false, 4 },
725//{ WRPR, false, false, 4 },
726};
727
728
729//---------------------------------------------------------------------------
730// const InstrRUsageDelta SparcInstrUsageDeltas[]
731//
732// Purpose:
733// Changes to resource usage information in InstrClassRUsage for
734// instructions that differ from other instructions in their class.
735//---------------------------------------------------------------------------
736
737const InstrRUsageDelta SparcInstrUsageDeltas[] = {
738
739 // MachineOpCode, Resource, Start cycle, Num cycles
740
741 //
742 // JMPL counts as a load/store instruction for issue!
743 //
744 { JMPL, LSIssueSlots.rid, 0, 1 },
745
746 //
747 // Many instructions cannot issue for the next 2 cycles after an FCMP
748 // We model that with a fake resource FCMPDelayCycle.
749 //
750 { FCMPS, FCMPDelayCycle.rid, 1, 3 },
751 { FCMPD, FCMPDelayCycle.rid, 1, 3 },
752 { FCMPQ, FCMPDelayCycle.rid, 1, 3 },
753
754 { MULX, FCMPDelayCycle.rid, 1, 1 },
755 { SDIVX, FCMPDelayCycle.rid, 1, 1 },
756 { UDIVX, FCMPDelayCycle.rid, 1, 1 },
757//{ SMULcc, FCMPDelayCycle.rid, 1, 1 },
758//{ UMULcc, FCMPDelayCycle.rid, 1, 1 },
759//{ SDIVcc, FCMPDelayCycle.rid, 1, 1 },
760//{ UDIVcc, FCMPDelayCycle.rid, 1, 1 },
761 { STD, FCMPDelayCycle.rid, 1, 1 },
762 { FMOVRSZ, FCMPDelayCycle.rid, 1, 1 },
763 { FMOVRSLEZ,FCMPDelayCycle.rid, 1, 1 },
764 { FMOVRSLZ, FCMPDelayCycle.rid, 1, 1 },
765 { FMOVRSNZ, FCMPDelayCycle.rid, 1, 1 },
766 { FMOVRSGZ, FCMPDelayCycle.rid, 1, 1 },
767 { FMOVRSGEZ,FCMPDelayCycle.rid, 1, 1 },
768
769 //
770 // Some instructions are stalled in the GROUP stage if a CTI is in
771 // the E or C stage
772 //
773 { LDD, CTIDelayCycle.rid, 1, 1 },
774//{ LDDA, CTIDelayCycle.rid, 1, 1 },
775//{ LDDSTUB, CTIDelayCycle.rid, 1, 1 },
776//{ LDDSTUBA, CTIDelayCycle.rid, 1, 1 },
777//{ SWAP, CTIDelayCycle.rid, 1, 1 },
778//{ SWAPA, CTIDelayCycle.rid, 1, 1 },
779//{ CAS, CTIDelayCycle.rid, 1, 1 },
780//{ CASA, CTIDelayCycle.rid, 1, 1 },
781//{ CASX, CTIDelayCycle.rid, 1, 1 },
782//{ CASXA, CTIDelayCycle.rid, 1, 1 },
783
784 //
785 // Signed int loads of less than dword size return data in cycle N1 (not C)
786 // and put all loads in consecutive cycles into delayed load return mode.
787 //
788 { LDSB, LdReturn.rid, 2, -1 },
789 { LDSB, LdReturn.rid, 3, 1 },
790
791 { LDSH, LdReturn.rid, 2, -1 },
792 { LDSH, LdReturn.rid, 3, 1 },
793
794 { LDSW, LdReturn.rid, 2, -1 },
795 { LDSW, LdReturn.rid, 3, 1 },
796
797
798#undef EXPLICIT_BUBBLES_NEEDED
799#ifdef EXPLICIT_BUBBLES_NEEDED
800 //
801 // MULScc inserts one bubble.
802 // This means it breaks the current group (captured in UltraSparcSchedInfo)
803 // *and occupies all issue slots for the next cycle
804 //
805//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
806//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
807//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
808//{ MULScc, AllIssueSlots.rid, 2, 2-1 },
809
810 //
811 // SMULcc inserts between 4 and 18 bubbles, depending on #leading 0s in rs1.
812 // We just model this with a simple average.
813 //
814//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
815//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
816//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
817//{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
818
819 // SMULcc inserts between 4 and 19 bubbles, depending on #leading 0s in rs1.
820//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
821//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
822//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
823//{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
824
825 //
826 // MULX inserts between 4 and 34 bubbles, depending on #leading 0s in rs1.
827 //
828 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
829 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
830 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
831 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
832
833 //
834 // SDIVcc inserts 36 bubbles.
835 //
836//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
837//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
838//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
839//{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
840
841 // UDIVcc inserts 37 bubbles.
842//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
843//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
844//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
845//{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
846
847 //
848 // SDIVX inserts 68 bubbles.
849 //
850 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
851 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
852 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
853 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
854
855 //
856 // UDIVX inserts 68 bubbles.
857 //
858 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
859 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
860 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
861 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
862
863 //
864 // WR inserts 4 bubbles.
865 //
866//{ WR, AllIssueSlots.rid, 2, 68-1 },
867//{ WR, AllIssueSlots.rid, 2, 68-1 },
868//{ WR, AllIssueSlots.rid, 2, 68-1 },
869//{ WR, AllIssueSlots.rid, 2, 68-1 },
870
871 //
872 // WRPR inserts 4 bubbles.
873 //
874//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
875//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
876//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
877//{ WRPR, AllIssueSlots.rid, 2, 68-1 },
878
879 //
880 // DONE inserts 9 bubbles.
881 //
882//{ DONE, AllIssueSlots.rid, 2, 9-1 },
883//{ DONE, AllIssueSlots.rid, 2, 9-1 },
884//{ DONE, AllIssueSlots.rid, 2, 9-1 },
885//{ DONE, AllIssueSlots.rid, 2, 9-1 },
886
887 //
888 // RETRY inserts 9 bubbles.
889 //
890//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
891//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
892//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
893//{ RETRY, AllIssueSlots.rid, 2, 9-1 },
894
895#endif EXPLICIT_BUBBLES_NEEDED
896};
897
898
899
900// Additional delays to be captured in code:
901// 1. RDPR from several state registers (page 349)
902// 2. RD from *any* register (page 349)
903// 3. Writes to TICK, PSTATE, TL registers and FLUSH{W} instr (page 349)
904// 4. Integer store can be in same group as instr producing value to store.
905// 5. BICC and BPICC can be in the same group as instr producing CC (pg 350)
906// 6. FMOVr cannot be in the same or next group as an IEU instr (pg 351).
907// 7. The second instr. of a CTI group inserts 9 bubbles (pg 351)
908// 8. WR{PR}, SVAE, SAVED, RESTORE, RESTORED, RETURN, RETRY, and DONE that
909// follow an annulling branch cannot be issued in the same group or in
910// the 3 groups following the branch.
911// 9. A predicted annulled load does not stall dependent instructions.
912// Other annulled delay slot instructions *do* stall dependents, so
913// nothing special needs to be done for them during scheduling.
914//10. Do not put a load use that may be annulled in the same group as the
915// branch. The group will stall until the load returns.
916//11. Single-prec. FP loads lock 2 registers, for dependency checking.
917//
918//
919// Additional delays we cannot or will not capture:
920// 1. If DCTI is last word of cache line, it is delayed until next line can be
921// fetched. Also, other DCTI alignment-related delays (pg 352)
922// 2. Load-after-store is delayed by 7 extra cycles if load hits in D-Cache.
923// Also, several other store-load and load-store conflicts (pg 358)
924// 3. MEMBAR, LD{X}FSR, LDD{A} and a bunch of other load stalls (pg 358)
925// 4. There can be at most 8 outstanding buffered store instructions
926// (including some others like MEMBAR, LDSTUB, CAS{AX}, and FLUSH)
927
928
929
930//---------------------------------------------------------------------------
931// class UltraSparcSchedInfo
932//
933// Purpose:
934// Interface to instruction scheduling information for UltraSPARC.
935// The parameter values above are based on UltraSPARC IIi.
936//---------------------------------------------------------------------------
937
938
939class UltraSparcSchedInfo: public MachineSchedInfo {
940public:
941 /*ctor*/ UltraSparcSchedInfo (const MachineInstrInfo* mii);
942 /*dtor*/ virtual ~UltraSparcSchedInfo () {}
943protected:
944 virtual void initializeResources ();
945};
946
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000947
948//---------------------------------------------------------------------------
949// class UltraSparcMachine
950//
951// Purpose:
952// Primary interface to machine description for the UltraSPARC.
953// Primarily just initializes machine-dependent parameters in
954// class TargetMachine, and creates machine-dependent subclasses
Vikram S. Adve339084b2001-09-18 13:04:24 +0000955// for classes such as InstrInfo, SchedInfo and RegInfo.
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000956//---------------------------------------------------------------------------
957
958class UltraSparc : public TargetMachine {
Vikram S. Adve339084b2001-09-18 13:04:24 +0000959private:
960 UltraSparcInstrInfo instrInfo;
961 UltraSparcSchedInfo schedInfo;
962 UltraSparcRegInfo regInfo;
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000963public:
964 UltraSparc();
965 virtual ~UltraSparc() {}
Vikram S. Adve339084b2001-09-18 13:04:24 +0000966
Chris Lattner32f600a2001-09-19 13:47:12 +0000967 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
968 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
969 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
Vikram S. Adve339084b2001-09-18 13:04:24 +0000970
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000971 // compileMethod - For the sparc, we do instruction selection, followed by
972 // delay slot scheduling, then register allocation.
973 //
974 virtual bool compileMethod(Method *M);
Chris Lattner32f600a2001-09-19 13:47:12 +0000975
976 //
977 // emitAssembly - Output assembly language code (a .s file) for the specified
978 // module. The specified module must have been compiled before this may be
979 // used.
980 //
981 virtual void emitAssembly(const Module *M, ostream &OutStr);
Chris Lattnerf6e0e282001-09-14 04:32:55 +0000982};
983
984
Chris Lattnerc6495ee2001-09-14 03:56:45 +0000985#endif