Move hasFP() and few related 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
19 namespace llvm {
20   class MachineFunction;
21   class MachineBasicBlock;
22
23 /// Information about stack frame layout on the target.  It holds the direction
24 /// of stack growth, the known stack alignment on entry to each function, and
25 /// the offset to the locals area.
26 ///
27 /// The offset to the local area is the offset from the stack pointer on
28 /// function entry to the first location where function data (local variables,
29 /// spill locations) can be stored.
30 class TargetFrameInfo {
31 public:
32   enum StackDirection {
33     StackGrowsUp,        // Adding to the stack increases the stack address
34     StackGrowsDown       // Adding to the stack decreases the stack address
35   };
36
37   // Maps a callee saved register to a stack slot with a fixed offset.
38   struct SpillSlot {
39     unsigned Reg;
40     int Offset; // Offset relative to stack pointer on function entry.
41   };
42 private:
43   StackDirection StackDir;
44   unsigned StackAlignment;
45   unsigned TransientStackAlignment;
46   int LocalAreaOffset;
47 public:
48   TargetFrameInfo(StackDirection D, unsigned StackAl, int LAO,
49                   unsigned TransAl = 1)
50     : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
51       LocalAreaOffset(LAO) {}
52
53   virtual ~TargetFrameInfo();
54
55   // These methods return information that describes the abstract stack layout
56   // of the target machine.
57
58   /// getStackGrowthDirection - Return the direction the stack grows
59   ///
60   StackDirection getStackGrowthDirection() const { return StackDir; }
61
62   /// getStackAlignment - This method returns the number of bytes to which the
63   /// stack pointer must be aligned on entry to a function.  Typically, this
64   /// is the largest alignment for any data object in the target.
65   ///
66   unsigned getStackAlignment() const { return StackAlignment; }
67
68   /// getTransientStackAlignment - This method returns the number of bytes to
69   /// which the stack pointer must be aligned at all times, even between
70   /// calls.
71   ///
72   unsigned getTransientStackAlignment() const {
73     return TransientStackAlignment;
74   }
75
76   /// getOffsetOfLocalArea - This method returns the offset of the local area
77   /// from the stack pointer on entrance to a function.
78   ///
79   int getOffsetOfLocalArea() const { return LocalAreaOffset; }
80
81   /// getCalleeSavedSpillSlots - This method returns a pointer to an array of
82   /// pairs, that contains an entry for each callee saved register that must be
83   /// spilled to a particular stack location if it is spilled.
84   ///
85   /// Each entry in this array contains a <register,offset> pair, indicating the
86   /// fixed offset from the incoming stack pointer that each register should be
87   /// spilled at. If a register is not listed here, the code generator is
88   /// allowed to spill it anywhere it chooses.
89   ///
90   virtual const SpillSlot *
91   getCalleeSavedSpillSlots(unsigned &NumEntries) const {
92     NumEntries = 0;
93     return 0;
94   }
95
96   /// targetHandlesStackFrameRounding - Returns true if the target is
97   /// responsible for rounding up the stack frame (probably at emitPrologue
98   /// time).
99   virtual bool targetHandlesStackFrameRounding() const {
100     return false;
101   }
102
103   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
104   /// the function.
105   virtual void emitPrologue(MachineFunction &MF) const = 0;
106   virtual void emitEpilogue(MachineFunction &MF,
107                             MachineBasicBlock &MBB) const = 0;
108
109   /// hasFP - Return true if the specified function should have a dedicated
110   /// frame pointer register. For most targets this is true only if the function
111   /// has variable sized allocas or if frame pointer elimination is disabled.
112   virtual bool hasFP(const MachineFunction &MF) const = 0;
113
114   /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
115   /// not required, we reserve argument space for call sites in the function
116   /// immediately on entry to the current function. This eliminates the need for
117   /// add/sub sp brackets around call sites. Returns true if the call frame is
118   /// included as part of the stack frame.
119   virtual bool hasReservedCallFrame(const MachineFunction &MF) const {
120     return !hasFP(MF);
121   }
122
123   /// canSimplifyCallFramePseudos - When possible, it's best to simplify the
124   /// call frame pseudo ops before doing frame index elimination. This is
125   /// possible only when frame index references between the pseudos won't
126   /// need adjusting for the call frame adjustments. Normally, that's true
127   /// if the function has a reserved call frame or a frame pointer. Some
128   /// targets (Thumb2, for example) may have more complicated criteria,
129   /// however, and can override this behavior.
130   virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const {
131     return hasReservedCallFrame(MF) || hasFP(MF);
132   }
133
134 };
135
136 } // End llvm namespace
137
138 #endif