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