Move some more hooks to TargetFrameInfo
[oota-llvm.git] / include / llvm / Target / TargetFrameInfo.h
1 //===-- llvm/Target/TargetFrameInfo.h ---------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Interface to describe the layout of a stack frame on the target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETFRAMEINFO_H
15 #define LLVM_TARGET_TARGETFRAMEINFO_H
16
17 #include <utility>
18 #include <vector>
19
20 namespace llvm {
21   class MachineFunction;
22   class MachineBasicBlock;
23   class MachineMove;
24
25 /// Information about stack frame layout on the target.  It holds the direction
26 /// of stack growth, the known stack alignment on entry to each function, and
27 /// the offset to the locals area.
28 ///
29 /// The offset to the local area is the offset from the stack pointer on
30 /// function entry to the first location where function data (local variables,
31 /// spill locations) can be stored.
32 class TargetFrameInfo {
33 public:
34   enum StackDirection {
35     StackGrowsUp,        // Adding to the stack increases the stack address
36     StackGrowsDown       // Adding to the stack decreases the stack address
37   };
38
39   // Maps a callee saved register to a stack slot with a fixed offset.
40   struct SpillSlot {
41     unsigned Reg;
42     int Offset; // Offset relative to stack pointer on function entry.
43   };
44 private:
45   StackDirection StackDir;
46   unsigned StackAlignment;
47   unsigned TransientStackAlignment;
48   int LocalAreaOffset;
49 public:
50   TargetFrameInfo(StackDirection D, unsigned StackAl, int LAO,
51                   unsigned TransAl = 1)
52     : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
53       LocalAreaOffset(LAO) {}
54
55   virtual ~TargetFrameInfo();
56
57   // These methods return information that describes the abstract stack layout
58   // of the target machine.
59
60   /// getStackGrowthDirection - Return the direction the stack grows
61   ///
62   StackDirection getStackGrowthDirection() const { return StackDir; }
63
64   /// getStackAlignment - This method returns the number of bytes to which the
65   /// stack pointer must be aligned on entry to a function.  Typically, this
66   /// is the largest alignment for any data object in the target.
67   ///
68   unsigned getStackAlignment() const { return StackAlignment; }
69
70   /// getTransientStackAlignment - This method returns the number of bytes to
71   /// which the stack pointer must be aligned at all times, even between
72   /// calls.
73   ///
74   unsigned getTransientStackAlignment() const {
75     return TransientStackAlignment;
76   }
77
78   /// getOffsetOfLocalArea - This method returns the offset of the local area
79   /// from the stack pointer on entrance to a function.
80   ///
81   int getOffsetOfLocalArea() const { return LocalAreaOffset; }
82
83   /// getCalleeSavedSpillSlots - This method returns a pointer to an array of
84   /// pairs, that contains an entry for each callee saved register that must be
85   /// spilled to a particular stack location if it is spilled.
86   ///
87   /// Each entry in this array contains a <register,offset> pair, indicating the
88   /// fixed offset from the incoming stack pointer that each register should be
89   /// spilled at. If a register is not listed here, the code generator is
90   /// allowed to spill it anywhere it chooses.
91   ///
92   virtual const SpillSlot *
93   getCalleeSavedSpillSlots(unsigned &NumEntries) const {
94     NumEntries = 0;
95     return 0;
96   }
97
98   /// targetHandlesStackFrameRounding - Returns true if the target is
99   /// responsible for rounding up the stack frame (probably at emitPrologue
100   /// time).
101   virtual bool targetHandlesStackFrameRounding() const {
102     return false;
103   }
104
105   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
106   /// the function.
107   virtual void emitPrologue(MachineFunction &MF) const = 0;
108   virtual void emitEpilogue(MachineFunction &MF,
109                             MachineBasicBlock &MBB) const = 0;
110
111   /// hasFP - Return true if the specified function should have a dedicated
112   /// frame pointer register. For most targets this is true only if the function
113   /// has variable sized allocas or if frame pointer elimination is disabled.
114   virtual bool hasFP(const MachineFunction &MF) const = 0;
115
116   /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
117   /// not required, we reserve argument space for call sites in the function
118   /// immediately on entry to the current function. This eliminates the need for
119   /// add/sub sp brackets around call sites. Returns true if the call frame is
120   /// included as part of the stack frame.
121   virtual bool hasReservedCallFrame(const MachineFunction &MF) const {
122     return !hasFP(MF);
123   }
124
125   /// canSimplifyCallFramePseudos - When possible, it's best to simplify the
126   /// call frame pseudo ops before doing frame index elimination. This is
127   /// possible only when frame index references between the pseudos won't
128   /// need adjusting for the call frame adjustments. Normally, that's true
129   /// if the function has a reserved call frame or a frame pointer. Some
130   /// targets (Thumb2, for example) may have more complicated criteria,
131   /// however, and can override this behavior.
132   virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const {
133     return hasReservedCallFrame(MF) || hasFP(MF);
134   }
135
136   /// getInitialFrameState - Returns a list of machine moves that are assumed
137   /// on entry to all functions.  Note that LabelID is ignored (assumed to be
138   /// the beginning of the function.)
139   virtual void getInitialFrameState(std::vector<MachineMove> &Moves) const;
140
141   /// getFrameIndexOffset - Returns the displacement from the frame register to
142   /// the stack frame of the specified index.
143   virtual int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
144
145   /// getFrameIndexReference - This method should return the base register
146   /// and offset used to reference a frame index location. The offset is
147   /// returned directly, and the base register is returned via FrameReg.
148   virtual int getFrameIndexReference(const MachineFunction &MF, int FI,
149                                      unsigned &FrameReg) const;
150 };
151
152 } // End llvm namespace
153
154 #endif