Support multiple ValueTypes per RegisterClass, needed for upcoming vector
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9FrameInfo.h
1 //===-- SparcV9FrameInfo.h - Define TargetFrameInfo for SparcV9 -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Interface to stack frame layout info for the UltraSPARC.
11 //
12 //----------------------------------------------------------------------------
13
14 #ifndef SPARC_FRAMEINFO_H
15 #define SPARC_FRAMEINFO_H
16
17 #include "llvm/Target/TargetFrameInfo.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "SparcV9RegInfo.h"
20
21 namespace llvm {
22
23 class SparcV9FrameInfo: public TargetFrameInfo {
24   const TargetMachine ⌖
25 public:
26   SparcV9FrameInfo(const TargetMachine &TM)
27     : TargetFrameInfo(StackGrowsDown, StackFrameSizeAlignment, 0), target(TM) {}
28
29   // This method adjusts a stack offset to meet alignment rules of target.
30   // The fixed OFFSET (0x7ff) must be subtracted and the result aligned.
31   virtual int  adjustAlignment(int unalignedOffset, bool growUp,
32                                unsigned int align) const {
33     return unalignedOffset + (growUp? +1:-1)*((unalignedOffset-OFFSET) % align);
34   }
35
36   // These methods compute offsets using the frame contents for a
37   // particular function.  The frame contents are obtained from the
38   // MachineCodeInfoForMethod object for the given function.
39   //
40   int getFirstAutomaticVarOffset(MachineFunction& mcInfo, bool& growUp) const {
41     growUp = false;
42     return StaticAreaOffsetFromFP;
43   }
44   int getRegSpillAreaOffset(MachineFunction& mcInfo, bool& growUp) const;
45   int getTmpAreaOffset(MachineFunction& mcInfo, bool& growUp) const;
46   int getDynamicAreaOffset(MachineFunction& mcInfo, bool& growUp) const;
47
48   virtual int getIncomingArgOffset(MachineFunction& mcInfo,
49                                    unsigned argNum) const {
50     unsigned relativeOffset = argNum * SizeOfEachArgOnStack;
51     int firstArg = FirstIncomingArgOffsetFromFP;
52     return firstArg + relativeOffset;
53   }
54
55   virtual int getOutgoingArgOffset(MachineFunction& mcInfo,
56                                    unsigned argNum) const {
57     return FirstOutgoingArgOffsetFromSP + argNum * SizeOfEachArgOnStack;
58   }
59
60   /*----------------------------------------------------------------------
61     This diagram shows the stack frame layout used by llc on SparcV9 V9.
62     Note that only the location of automatic variables, spill area,
63     temporary storage, and dynamically allocated stack area are chosen
64     by us.  The rest conform to the SparcV9 V9 ABI.
65     All stack addresses are offset by OFFSET = 0x7ff (2047).
66
67     Alignment assumptions and other invariants:
68     (1) %sp+OFFSET and %fp+OFFSET are always aligned on 16-byte boundary
69     (2) Variables in automatic, spill, temporary, or dynamic regions
70         are aligned according to their size as in all memory accesses.
71     (3) Everything below the dynamically allocated stack area is only used
72         during a call to another function, so it is never needed when
73         the current function is active.  This is why space can be allocated
74         dynamically by incrementing %sp any time within the function.
75
76     STACK FRAME LAYOUT:
77
78        ...
79        %fp+OFFSET+176      Optional extra incoming arguments# 1..N
80        %fp+OFFSET+168      Incoming argument #6
81        ...                 ...
82        %fp+OFFSET+128      Incoming argument #1
83        ...                 ...
84     ---%fp+OFFSET-0--------Bottom of caller's stack frame--------------------
85        %fp+OFFSET-8        Automatic variables <-- ****TOP OF STACK FRAME****
86                            Spill area
87                            Temporary storage
88        ...
89
90        %sp+OFFSET+176+8N   Bottom of dynamically allocated stack area
91        %sp+OFFSET+168+8N   Optional extra outgoing argument# N
92        ...                 ...
93        %sp+OFFSET+176      Optional extra outgoing argument# 1
94        %sp+OFFSET+168      Outgoing argument #6
95        ...                 ...
96        %sp+OFFSET+128      Outgoing argument #1
97        %sp+OFFSET+120      Save area for %i7
98        ...                 ...
99        %sp+OFFSET+0        Save area for %l0 <-- ****BOTTOM OF STACK FRAME****
100
101    *----------------------------------------------------------------------*/
102
103   // All stack addresses must be offset by 0x7ff (2047) on SparcV9 V9.
104   static const int OFFSET                                  = (int) 0x7ff;
105   static const int StackFrameSizeAlignment                 =  16;
106   static const int MinStackFrameSize                       = 176;
107   static const int SizeOfEachArgOnStack                    =   8;
108   static const int FirstIncomingArgOffsetFromFP            = 128 + OFFSET;
109   static const int FirstOptionalIncomingArgOffsetFromFP    = 176 + OFFSET;
110   static const int StaticAreaOffsetFromFP                  =   0 + OFFSET;
111   static const int FirstOutgoingArgOffsetFromSP            = 128 + OFFSET;
112   static const int FirstOptionalOutgoingArgOffsetFromSP    = 176 + OFFSET;
113 };
114
115 } // End llvm namespace
116
117 #endif