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