29ab1f3b72cb2c00b2f46dd38a295bd7f0c5056c
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9Internals.h
1 //===-- SparcInternals.h ----------------------------------------*- C++ -*-===//
2 // 
3 // This file defines stuff that is to be private to the Sparc backend, but is
4 // shared among different portions of the backend.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef SPARC_INTERNALS_H
9 #define SPARC_INTERNALS_H
10
11 #include "llvm/CodeGen/MachineInstrBuilder.h"
12 #include "llvm/Target/TargetMachine.h"
13 #include "llvm/Target/TargetSchedInfo.h"
14 #include "llvm/Target/TargetFrameInfo.h"
15 #include "llvm/Target/TargetCacheInfo.h"
16 #include "llvm/Target/TargetRegInfo.h"
17 #include "llvm/Type.h"
18 #include "SparcRegClassInfo.h"
19 #include "Config/sys/types.h"
20
21 class LiveRange;
22 class UltraSparc;
23 class Pass;
24
25 enum SparcInstrSchedClass {
26   SPARC_NONE,           /* Instructions with no scheduling restrictions */
27   SPARC_IEUN,           /* Integer class that can use IEU0 or IEU1 */
28   SPARC_IEU0,           /* Integer class IEU0 */
29   SPARC_IEU1,           /* Integer class IEU1 */
30   SPARC_FPM,            /* FP Multiply or Divide instructions */
31   SPARC_FPA,            /* All other FP instructions */ 
32   SPARC_CTI,            /* Control-transfer instructions */
33   SPARC_LD,             /* Load instructions */
34   SPARC_ST,             /* Store instructions */
35   SPARC_SINGLE,         /* Instructions that must issue by themselves */
36   
37   SPARC_INV,            /* This should stay at the end for the next value */
38   SPARC_NUM_SCHED_CLASSES = SPARC_INV
39 };
40
41
42 //---------------------------------------------------------------------------
43 // enum SparcMachineOpCode. 
44 // const TargetInstrDescriptor SparcMachineInstrDesc[]
45 // 
46 // Purpose:
47 //   Description of UltraSparc machine instructions.
48 // 
49 //---------------------------------------------------------------------------
50
51 namespace V9 {
52   enum SparcMachineOpCode {
53 #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
54           NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS)             \
55    ENUM,
56 #include "SparcInstr.def"
57
58     // End-of-array marker
59     INVALID_OPCODE,
60     NUM_REAL_OPCODES = PHI,             // number of valid opcodes
61     NUM_TOTAL_OPCODES = INVALID_OPCODE
62   };
63 }
64
65
66 // Array of machine instruction descriptions...
67 extern const TargetInstrDescriptor SparcMachineInstrDesc[];
68
69
70 //---------------------------------------------------------------------------
71 // class UltraSparcInstrInfo 
72 // 
73 // Purpose:
74 //   Information about individual instructions.
75 //   Most information is stored in the SparcMachineInstrDesc array above.
76 //   Other information is computed on demand, and most such functions
77 //   default to member functions in base class TargetInstrInfo. 
78 //---------------------------------------------------------------------------
79
80 struct UltraSparcInstrInfo : public TargetInstrInfo {
81   UltraSparcInstrInfo();
82
83   //
84   // All immediate constants are in position 1 except the
85   // store instructions and SETxx.
86   // 
87   virtual int getImmedConstantPos(MachineOpCode opCode) const {
88     bool ignore;
89     if (this->maxImmedConstant(opCode, ignore) != 0) {
90       // 1st store opcode
91       assert(! this->isStore((MachineOpCode) V9::STBr - 1));
92       // last store opcode
93       assert(! this->isStore((MachineOpCode) V9::STXFSRi + 1));
94
95       if (opCode == V9::SETSW || opCode == V9::SETUW ||
96           opCode == V9::SETX  || opCode == V9::SETHI)
97         return 0;
98       if (opCode >= V9::STBr && opCode <= V9::STXFSRi)
99         return 2;
100       return 1;
101     }
102     else
103       return -1;
104   }
105
106   /// createNOPinstr - returns the target's implementation of NOP, which is
107   /// usually a pseudo-instruction, implemented by a degenerate version of
108   /// another instruction, e.g. X86: xchg ax, ax; SparcV9: sethi 0, g0
109   ///
110   MachineInstr* createNOPinstr() const {
111     return BuildMI(V9::SETHI, 2).addZImm(0).addReg(SparcIntRegClass::g0);
112   }
113
114   /// isNOPinstr - not having a special NOP opcode, we need to know if a given
115   /// instruction is interpreted as an `official' NOP instr, i.e., there may be
116   /// more than one way to `do nothing' but only one canonical way to slack off.
117   ///
118   bool isNOPinstr(const MachineInstr &MI) const {
119     // Make sure the instruction is EXACTLY `sethi g0, 0'
120     if (MI.getOpcode() == V9::SETHI && MI.getNumOperands() == 2) {
121       const MachineOperand &op0 = MI.getOperand(0), &op1 = MI.getOperand(1);
122       if (op0.isImmediate() && op0.getImmedValue() == 0 &&
123           op1.isMachineRegister() &&
124           op1.getMachineRegNum() == SparcIntRegClass::g0)
125       {
126         return true;
127       }
128     }
129     return false;
130   }
131   
132   virtual bool hasResultInterlock(MachineOpCode opCode) const
133   {
134     // All UltraSPARC instructions have interlocks (note that delay slots
135     // are not considered here).
136     // However, instructions that use the result of an FCMP produce a
137     // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
138     // Force the compiler to insert a software interlock (i.e., gap of
139     // 2 other groups, including NOPs if necessary).
140     return (opCode == V9::FCMPS || opCode == V9::FCMPD || opCode == V9::FCMPQ);
141   }
142
143   //-------------------------------------------------------------------------
144   // Queries about representation of LLVM quantities (e.g., constants)
145   //-------------------------------------------------------------------------
146
147   virtual bool ConstantMayNotFitInImmedField(const Constant* CV,
148                                              const Instruction* I) const;
149
150   //-------------------------------------------------------------------------
151   // Code generation support for creating individual machine instructions
152   //-------------------------------------------------------------------------
153
154   // Get certain common op codes for the current target.  This and all the
155   // Create* methods below should be moved to a machine code generation class
156   // 
157   virtual MachineOpCode getNOPOpCode() const { return V9::NOP; }
158
159   // Get the value of an integral constant in the form that must
160   // be put into the machine register.  The specified constant is interpreted
161   // as (i.e., converted if necessary to) the specified destination type.  The
162   // result is always returned as an uint64_t, since the representation of
163   // int64_t and uint64_t are identical.  The argument can be any known const.
164   // 
165   // isValidConstant is set to true if a valid constant was found.
166   // 
167   virtual uint64_t ConvertConstantToIntType(const TargetMachine &target,
168                                             const Value *V,
169                                             const Type *destType,
170                                             bool  &isValidConstant) const;
171
172   // Create an instruction sequence to put the constant `val' into
173   // the virtual register `dest'.  `val' may be a Constant or a
174   // GlobalValue, viz., the constant address of a global variable or function.
175   // The generated instructions are returned in `mvec'.
176   // Any temp. registers (TmpInstruction) created are recorded in mcfi.
177   // Any stack space required is allocated via mcff.
178   // 
179   virtual void  CreateCodeToLoadConst(const TargetMachine& target,
180                                       Function* F,
181                                       Value* val,
182                                       Instruction* dest,
183                                       std::vector<MachineInstr*>& mvec,
184                                       MachineCodeForInstruction& mcfi) const;
185
186   // Create an instruction sequence to copy an integer value `val'
187   // to a floating point value `dest' by copying to memory and back.
188   // val must be an integral type.  dest must be a Float or Double.
189   // The generated instructions are returned in `mvec'.
190   // Any temp. registers (TmpInstruction) created are recorded in mcfi.
191   // Any stack space required is allocated via mcff.
192   // 
193   virtual void  CreateCodeToCopyIntToFloat(const TargetMachine& target,
194                                        Function* F,
195                                        Value* val,
196                                        Instruction* dest,
197                                        std::vector<MachineInstr*>& mvec,
198                                        MachineCodeForInstruction& mcfi) const;
199
200   // Similarly, create an instruction sequence to copy an FP value
201   // `val' to an integer value `dest' by copying to memory and back.
202   // The generated instructions are returned in `mvec'.
203   // Any temp. registers (TmpInstruction) created are recorded in mcfi.
204   // Any stack space required is allocated via mcff.
205   // 
206   virtual void  CreateCodeToCopyFloatToInt(const TargetMachine& target,
207                                        Function* F,
208                                        Value* val,
209                                        Instruction* dest,
210                                        std::vector<MachineInstr*>& mvec,
211                                        MachineCodeForInstruction& mcfi) const;
212   
213   // Create instruction(s) to copy src to dest, for arbitrary types
214   // The generated instructions are returned in `mvec'.
215   // Any temp. registers (TmpInstruction) created are recorded in mcfi.
216   // Any stack space required is allocated via mcff.
217   // 
218   virtual void CreateCopyInstructionsByType(const TargetMachine& target,
219                                        Function* F,
220                                        Value* src,
221                                        Instruction* dest,
222                                        std::vector<MachineInstr*>& mvec,
223                                        MachineCodeForInstruction& mcfi) const;
224
225   // Create instruction sequence to produce a sign-extended register value
226   // from an arbitrary sized value (sized in bits, not bytes).
227   // The generated instructions are appended to `mvec'.
228   // Any temp. registers (TmpInstruction) created are recorded in mcfi.
229   // Any stack space required is allocated via mcff.
230   // 
231   virtual void CreateSignExtensionInstructions(const TargetMachine& target,
232                                        Function* F,
233                                        Value* srcVal,
234                                        Value* destVal,
235                                        unsigned int numLowBits,
236                                        std::vector<MachineInstr*>& mvec,
237                                        MachineCodeForInstruction& mcfi) const;
238
239   // Create instruction sequence to produce a zero-extended register value
240   // from an arbitrary sized value (sized in bits, not bytes).
241   // The generated instructions are appended to `mvec'.
242   // Any temp. registers (TmpInstruction) created are recorded in mcfi.
243   // Any stack space required is allocated via mcff.
244   // 
245   virtual void CreateZeroExtensionInstructions(const TargetMachine& target,
246                                        Function* F,
247                                        Value* srcVal,
248                                        Value* destVal,
249                                        unsigned int numLowBits,
250                                        std::vector<MachineInstr*>& mvec,
251                                        MachineCodeForInstruction& mcfi) const;
252 };
253
254
255 //----------------------------------------------------------------------------
256 // class UltraSparcRegInfo
257 //
258 // This class implements the virtual class TargetRegInfo for Sparc.
259 //
260 //----------------------------------------------------------------------------
261
262 class UltraSparcRegInfo : public TargetRegInfo {
263
264 private:
265
266   // Number of registers used for passing int args (usually 6: %o0 - %o5)
267   //
268   unsigned const NumOfIntArgRegs;
269
270   // Number of registers used for passing float args (usually 32: %f0 - %f31)
271   //
272   unsigned const NumOfFloatArgRegs;
273
274   // ========================  Private Methods =============================
275
276   // The following methods are used to color special live ranges (e.g.
277   // function args and return values etc.) with specific hardware registers
278   // as required. See SparcRegInfo.cpp for the implementation.
279   //
280   void suggestReg4RetAddr(MachineInstr *RetMI, 
281                           LiveRangeInfo &LRI) const;
282
283   void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI) const;
284   
285   // Helper used by the all the getRegType() functions.
286   int getRegTypeForClassAndType(unsigned regClassID, const Type* type) const;
287
288 public:
289   // Type of registers available in Sparc. There can be several reg types
290   // in the same class. For instace, the float reg class has Single/Double
291   // types
292   //
293   enum RegTypes {
294     IntRegType,
295     FPSingleRegType,
296     FPDoubleRegType,
297     IntCCRegType,
298     FloatCCRegType,
299     SpecialRegType
300   };
301
302   // The actual register classes in the Sparc
303   //
304   // **** WARNING: If this enum order is changed, also modify 
305   // getRegisterClassOfValue method below since it assumes this particular 
306   // order for efficiency.
307   // 
308   enum RegClassIDs { 
309     IntRegClassID,                      // Integer
310     FloatRegClassID,                    // Float (both single/double)
311     IntCCRegClassID,                    // Int Condition Code
312     FloatCCRegClassID,                  // Float Condition code
313     SpecialRegClassID                   // Special (unallocated) registers
314   };
315
316   UltraSparcRegInfo(const UltraSparc &tgt);
317
318   // To find the register class used for a specified Type
319   //
320   unsigned getRegClassIDOfType(const Type *type,
321                                bool isCCReg = false) const;
322
323   // To find the register class to which a specified register belongs
324   //
325   unsigned getRegClassIDOfRegType(int regType) const;
326   
327   // getZeroRegNum - returns the register that contains always zero this is the
328   // unified register number
329   //
330   virtual int getZeroRegNum() const;
331
332   // getCallAddressReg - returns the reg used for pushing the address when a
333   // function is called. This can be used for other purposes between calls
334   //
335   unsigned getCallAddressReg() const;
336
337   // Returns the register containing the return address.
338   // It should be made sure that this  register contains the return 
339   // value when a return instruction is reached.
340   //
341   unsigned getReturnAddressReg() const;
342
343   // Number of registers used for passing int args (usually 6: %o0 - %o5)
344   // and float args (usually 32: %f0 - %f31)
345   //
346   unsigned const getNumOfIntArgRegs() const   { return NumOfIntArgRegs; }
347   unsigned const getNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
348   
349   // Compute which register can be used for an argument, if any
350   // 
351   int regNumForIntArg(bool inCallee, bool isVarArgsCall,
352                       unsigned argNo, unsigned& regClassId) const;
353
354   int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
355                      unsigned argNo, unsigned& regClassId) const;
356   
357   // The following methods are used to color special live ranges (e.g.
358   // function args and return values etc.) with specific hardware registers
359   // as required. See SparcRegInfo.cpp for the implementation for Sparc.
360   //
361   void suggestRegs4MethodArgs(const Function *Meth, 
362                               LiveRangeInfo& LRI) const;
363
364   void suggestRegs4CallArgs(MachineInstr *CallMI, 
365                             LiveRangeInfo& LRI) const; 
366
367   void suggestReg4RetValue(MachineInstr *RetMI, 
368                            LiveRangeInfo& LRI) const;
369   
370   void colorMethodArgs(const Function *Meth,  LiveRangeInfo& LRI,
371                        std::vector<MachineInstr*>& InstrnsBefore,
372                        std::vector<MachineInstr*>& InstrnsAfter) const;
373
374   // method used for printing a register for debugging purposes
375   //
376   void printReg(const LiveRange *LR) const;
377   
378   // returns the # of bytes of stack space allocated for each register
379   // type. For Sparc, currently we allocate 8 bytes on stack for all 
380   // register types. We can optimize this later if necessary to save stack
381   // space (However, should make sure that stack alignment is correct)
382   //
383   inline int getSpilledRegSize(int RegType) const {
384     return 8;
385   }
386
387
388   // To obtain the return value and the indirect call address (if any)
389   // contained in a CALL machine instruction
390   //
391   const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
392   const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
393
394   // The following methods are used to generate "copy" machine instructions
395   // for an architecture.
396   //
397   // The function regTypeNeedsScratchReg() can be used to check whether a
398   // scratch register is needed to copy a register of type `regType' to
399   // or from memory.  If so, such a scratch register can be provided by
400   // the caller (e.g., if it knows which regsiters are free); otherwise
401   // an arbitrary one will be chosen and spilled by the copy instructions.
402   //
403   bool regTypeNeedsScratchReg(int RegType,
404                               int& scratchRegClassId) const;
405
406   void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
407                    unsigned SrcReg, unsigned DestReg,
408                    int RegType) const;
409
410   void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
411                    unsigned SrcReg, unsigned DestPtrReg,
412                    int Offset, int RegType, int scratchReg = -1) const;
413
414   void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
415                    unsigned SrcPtrReg, int Offset, unsigned DestReg,
416                    int RegType, int scratchReg = -1) const;
417
418   void cpValue2Value(Value *Src, Value *Dest,
419                      std::vector<MachineInstr*>& mvec) const;
420
421   // Get the register type for a register identified different ways.
422   // Note that getRegTypeForLR(LR) != getRegTypeForDataType(LR->getType())!
423   // The reg class of a LR depends both on the Value types in it and whether
424   // they are CC registers or not (for example).
425   int getRegTypeForDataType(const Type* type) const;
426   int getRegTypeForLR(const LiveRange *LR) const;
427   int getRegType(int unifiedRegNum) const;
428
429   virtual unsigned getFramePointer() const;
430   virtual unsigned getStackPointer() const;
431 };
432
433
434
435
436 //---------------------------------------------------------------------------
437 // class UltraSparcSchedInfo
438 // 
439 // Purpose:
440 //   Interface to instruction scheduling information for UltraSPARC.
441 //   The parameter values above are based on UltraSPARC IIi.
442 //---------------------------------------------------------------------------
443
444
445 class UltraSparcSchedInfo: public TargetSchedInfo {
446 public:
447   UltraSparcSchedInfo(const TargetMachine &tgt);
448 protected:
449   virtual void initializeResources();
450 };
451
452
453 //---------------------------------------------------------------------------
454 // class UltraSparcFrameInfo 
455 // 
456 // Purpose:
457 //   Interface to stack frame layout info for the UltraSPARC.
458 //   Starting offsets for each area of the stack frame are aligned at
459 //   a multiple of getStackFrameSizeAlignment().
460 //---------------------------------------------------------------------------
461
462 class UltraSparcFrameInfo: public TargetFrameInfo {
463   const TargetMachine &target;
464 public:
465   UltraSparcFrameInfo(const TargetMachine &TM)
466     : TargetFrameInfo(StackGrowsDown, StackFrameSizeAlignment, 0), target(TM) {}
467   
468 public:
469   // These methods provide constant parameters of the frame layout.
470   // 
471   int  getStackFrameSizeAlignment() const { return StackFrameSizeAlignment;}
472   int  getMinStackFrameSize()       const { return MinStackFrameSize; }
473   int  getNumFixedOutgoingArgs()    const { return NumFixedOutgoingArgs; }
474   int  getSizeOfEachArgOnStack()    const { return SizeOfEachArgOnStack; }
475   bool argsOnStackHaveFixedSize()   const { return true; }
476
477   // This method adjusts a stack offset to meet alignment rules of target.
478   // The fixed OFFSET (0x7ff) must be subtracted and the result aligned.
479   virtual int  adjustAlignment                  (int unalignedOffset,
480                                                  bool growUp,
481                                                  unsigned int align) const {
482     return unalignedOffset + (growUp? +1:-1)*((unalignedOffset-OFFSET) % align);
483   }
484
485   // These methods compute offsets using the frame contents for a
486   // particular function.  The frame contents are obtained from the
487   // MachineCodeInfoForMethod object for the given function.
488   // 
489   int getFirstIncomingArgOffset  (MachineFunction& mcInfo,
490                                   bool& growUp) const
491   {
492     growUp = true;                         // arguments area grows upwards
493     return FirstIncomingArgOffsetFromFP;
494   }
495   int getFirstOutgoingArgOffset  (MachineFunction& mcInfo,
496                                   bool& growUp) const
497   {
498     growUp = true;                         // arguments area grows upwards
499     return FirstOutgoingArgOffsetFromSP;
500   }
501   int getFirstOptionalOutgoingArgOffset(MachineFunction& mcInfo,
502                                         bool& growUp)const
503   {
504     growUp = true;                         // arguments area grows upwards
505     return FirstOptionalOutgoingArgOffsetFromSP;
506   }
507   
508   int getFirstAutomaticVarOffset (MachineFunction& mcInfo,
509                                   bool& growUp) const;
510   int getRegSpillAreaOffset      (MachineFunction& mcInfo,
511                                   bool& growUp) const;
512   int getTmpAreaOffset           (MachineFunction& mcInfo,
513                                   bool& growUp) const;
514   int getDynamicAreaOffset       (MachineFunction& mcInfo,
515                                   bool& growUp) const;
516
517   //
518   // These methods specify the base register used for each stack area
519   // (generally FP or SP)
520   // 
521   virtual int getIncomingArgBaseRegNum()               const {
522     return (int) target.getRegInfo().getFramePointer();
523   }
524   virtual int getOutgoingArgBaseRegNum()               const {
525     return (int) target.getRegInfo().getStackPointer();
526   }
527   virtual int getOptionalOutgoingArgBaseRegNum()       const {
528     return (int) target.getRegInfo().getStackPointer();
529   }
530   virtual int getAutomaticVarBaseRegNum()              const {
531     return (int) target.getRegInfo().getFramePointer();
532   }
533   virtual int getRegSpillAreaBaseRegNum()              const {
534     return (int) target.getRegInfo().getFramePointer();
535   }
536   virtual int getDynamicAreaBaseRegNum()               const {
537     return (int) target.getRegInfo().getStackPointer();
538   }
539
540   virtual int getIncomingArgOffset(MachineFunction& mcInfo,
541                                    unsigned argNum) const {
542     assert(argsOnStackHaveFixedSize()); 
543   
544     unsigned relativeOffset = argNum * getSizeOfEachArgOnStack();
545     bool growUp;                          // do args grow up or down
546     int firstArg = getFirstIncomingArgOffset(mcInfo, growUp);
547     return growUp ? firstArg + relativeOffset : firstArg - relativeOffset; 
548   }
549
550   virtual int getOutgoingArgOffset(MachineFunction& mcInfo,
551                                    unsigned argNum) const {
552     assert(argsOnStackHaveFixedSize()); 
553     //assert(((int) argNum - this->getNumFixedOutgoingArgs())
554     //     <= (int) mcInfo.getInfo()->getMaxOptionalNumArgs());
555     
556     unsigned relativeOffset = argNum * getSizeOfEachArgOnStack();
557     bool growUp;                          // do args grow up or down
558     int firstArg = getFirstOutgoingArgOffset(mcInfo, growUp);
559     return growUp ? firstArg + relativeOffset : firstArg - relativeOffset; 
560   }
561   
562 private:
563   /*----------------------------------------------------------------------
564     This diagram shows the stack frame layout used by llc on Sparc V9.
565     Note that only the location of automatic variables, spill area,
566     temporary storage, and dynamically allocated stack area are chosen
567     by us.  The rest conform to the Sparc V9 ABI.
568     All stack addresses are offset by OFFSET = 0x7ff (2047).
569
570     Alignment assumptions and other invariants:
571     (1) %sp+OFFSET and %fp+OFFSET are always aligned on 16-byte boundary
572     (2) Variables in automatic, spill, temporary, or dynamic regions
573         are aligned according to their size as in all memory accesses.
574     (3) Everything below the dynamically allocated stack area is only used
575         during a call to another function, so it is never needed when
576         the current function is active.  This is why space can be allocated
577         dynamically by incrementing %sp any time within the function.
578     
579     STACK FRAME LAYOUT:
580
581        ...
582        %fp+OFFSET+176      Optional extra incoming arguments# 1..N
583        %fp+OFFSET+168      Incoming argument #6
584        ...                 ...
585        %fp+OFFSET+128      Incoming argument #1
586        ...                 ...
587     ---%fp+OFFSET-0--------Bottom of caller's stack frame--------------------
588        %fp+OFFSET-8        Automatic variables <-- ****TOP OF STACK FRAME****
589                            Spill area
590                            Temporary storage
591        ...
592
593        %sp+OFFSET+176+8N   Bottom of dynamically allocated stack area
594        %sp+OFFSET+168+8N   Optional extra outgoing argument# N
595        ...                 ...
596        %sp+OFFSET+176      Optional extra outgoing argument# 1
597        %sp+OFFSET+168      Outgoing argument #6
598        ...                 ...
599        %sp+OFFSET+128      Outgoing argument #1
600        %sp+OFFSET+120      Save area for %i7
601        ...                 ...
602        %sp+OFFSET+0        Save area for %l0 <-- ****BOTTOM OF STACK FRAME****
603
604    *----------------------------------------------------------------------*/
605
606   // All stack addresses must be offset by 0x7ff (2047) on Sparc V9.
607   static const int OFFSET                                  = (int) 0x7ff;
608   static const int StackFrameSizeAlignment                 =  16;
609   static const int MinStackFrameSize                       = 176;
610   static const int NumFixedOutgoingArgs                    =   6;
611   static const int SizeOfEachArgOnStack                    =   8;
612   static const int FirstIncomingArgOffsetFromFP            = 128 + OFFSET;
613   static const int FirstOptionalIncomingArgOffsetFromFP    = 176 + OFFSET;
614   static const int StaticAreaOffsetFromFP                  =   0 + OFFSET;
615   static const int FirstOutgoingArgOffsetFromSP            = 128 + OFFSET;
616   static const int FirstOptionalOutgoingArgOffsetFromSP    = 176 + OFFSET;
617 };
618
619
620 //---------------------------------------------------------------------------
621 // class UltraSparcCacheInfo 
622 // 
623 // Purpose:
624 //   Interface to cache parameters for the UltraSPARC.
625 //   Just use defaults for now.
626 //---------------------------------------------------------------------------
627
628 struct UltraSparcCacheInfo: public TargetCacheInfo {
629   UltraSparcCacheInfo(const TargetMachine &T) : TargetCacheInfo(T) {} 
630 };
631
632
633 /// createStackSlotsPass - External interface to stack-slots pass that enters 2
634 /// empty slots at the top of each function stack
635 Pass *createStackSlotsPass(const TargetMachine &TM);
636
637 // Interface to pre-selection pass that specializes LLVM code for a target
638 // machine.
639 Pass *createPreSelectionPass(TargetMachine &Target);
640
641 // External interface to peephole optimization pass operating on machine code.
642 FunctionPass *createPeepholeOptsPass(TargetMachine &Target);
643
644
645 //---------------------------------------------------------------------------
646 // class UltraSparc 
647 // 
648 // Purpose:
649 //   Primary interface to machine description for the UltraSPARC.
650 //   Primarily just initializes machine-dependent parameters in
651 //   class TargetMachine, and creates machine-dependent subclasses
652 //   for classes such as InstrInfo, SchedInfo and RegInfo. 
653 //---------------------------------------------------------------------------
654
655 class UltraSparc : public TargetMachine {
656   UltraSparcInstrInfo instrInfo;
657   UltraSparcSchedInfo schedInfo;
658   UltraSparcRegInfo   regInfo;
659   UltraSparcFrameInfo frameInfo;
660   UltraSparcCacheInfo cacheInfo;
661 public:
662   UltraSparc();
663
664   virtual const TargetInstrInfo  &getInstrInfo() const { return instrInfo; }
665   virtual const TargetSchedInfo  &getSchedInfo() const { return schedInfo; }
666   virtual const TargetRegInfo    &getRegInfo()   const { return regInfo; }
667   virtual const TargetFrameInfo  &getFrameInfo() const { return frameInfo; }
668   virtual const TargetCacheInfo  &getCacheInfo() const { return cacheInfo; }
669
670   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
671   virtual bool addPassesToJITCompile(FunctionPassManager &PM);
672   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
673                                           MachineCodeEmitter &MCE);
674   virtual void replaceMachineCodeForFunction(void *Old, void *New);
675
676   // getPrologEpilogInsertionPass - Inserts prolog/epilog code.
677   FunctionPass* getPrologEpilogInsertionPass();
678
679   // getFunctionAsmPrinterPass - Writes out machine code for a single function
680   Pass* getFunctionAsmPrinterPass(std::ostream &Out);
681
682   // getModuleAsmPrinterPass - Writes generated machine code to assembly file.
683   Pass* getModuleAsmPrinterPass(std::ostream &Out);
684
685   // getBytecodeAsmPrinterPass - Emits final LLVM bytecode to assembly file.
686   Pass* getBytecodeAsmPrinterPass(std::ostream &Out);
687 };
688
689 #endif