1 //=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- 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 // This file declares AArch64-specific per-machine-function information.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
15 #define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
16 
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/MC/MCLinkerOptimizationHint.h"
21 
22 namespace llvm {
23 
24 /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
25 /// contains private AArch64-specific information for each MachineFunction.
26 class AArch64FunctionInfo : public MachineFunctionInfo {
27 
28   /// Number of bytes of arguments this function has on the stack. If the callee
29   /// is expected to restore the argument stack this should be a multiple of 16,
30   /// all usable during a tail call.
31   ///
32   /// The alternative would forbid tail call optimisation in some cases: if we
33   /// want to transfer control from a function with 8-bytes of stack-argument
34   /// space to a function with 16-bytes then misalignment of this value would
35   /// make a stack adjustment necessary, which could not be undone by the
36   /// callee.
37   unsigned BytesInStackArgArea;
38 
39   /// The number of bytes to restore to deallocate space for incoming
40   /// arguments. Canonically 0 in the C calling convention, but non-zero when
41   /// callee is expected to pop the args.
42   unsigned ArgumentStackToRestore;
43 
44   /// HasStackFrame - True if this function has a stack frame. Set by
45   /// determineCalleeSaves().
46   bool HasStackFrame;
47 
48   /// \brief Amount of stack frame size, not including callee-saved registers.
49   unsigned LocalStackSize;
50 
51   /// \brief Amount of stack frame size used for saving callee-saved registers.
52   unsigned CalleeSavedStackSize;
53 
54   /// \brief Number of TLS accesses using the special (combinable)
55   /// _TLS_MODULE_BASE_ symbol.
56   unsigned NumLocalDynamicTLSAccesses;
57 
58   /// \brief FrameIndex for start of varargs area for arguments passed on the
59   /// stack.
60   int VarArgsStackIndex;
61 
62   /// \brief FrameIndex for start of varargs area for arguments passed in
63   /// general purpose registers.
64   int VarArgsGPRIndex;
65 
66   /// \brief Size of the varargs area for arguments passed in general purpose
67   /// registers.
68   unsigned VarArgsGPRSize;
69 
70   /// \brief FrameIndex for start of varargs area for arguments passed in
71   /// floating-point registers.
72   int VarArgsFPRIndex;
73 
74   /// \brief Size of the varargs area for arguments passed in floating-point
75   /// registers.
76   unsigned VarArgsFPRSize;
77 
78   /// True if this function has a subset of CSRs that is handled explicitly via
79   /// copies.
80   bool IsSplitCSR;
81 
82 public:
83   AArch64FunctionInfo()
84       : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false),
85         NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0),
86         VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0),
87         IsSplitCSR(false) {}
88 
89   explicit AArch64FunctionInfo(MachineFunction &MF)
90       : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false),
91         NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0),
92         VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0),
93         IsSplitCSR(false) {
94     (void)MF;
95   }
96 
97   unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
98   void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
99 
100   unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
101   void setArgumentStackToRestore(unsigned bytes) {
102     ArgumentStackToRestore = bytes;
103   }
104 
105   bool hasStackFrame() const { return HasStackFrame; }
106   void setHasStackFrame(bool s) { HasStackFrame = s; }
107 
108   bool isSplitCSR() const { return IsSplitCSR; }
109   void setIsSplitCSR(bool s) { IsSplitCSR = s; }
110 
111   void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
112   unsigned getLocalStackSize() const { return LocalStackSize; }
113 
114   void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
115   unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
116 
117   void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
118   unsigned getNumLocalDynamicTLSAccesses() const {
119     return NumLocalDynamicTLSAccesses;
120   }
121 
122   int getVarArgsStackIndex() const { return VarArgsStackIndex; }
123   void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
124 
125   int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
126   void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
127 
128   unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
129   void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
130 
131   int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
132   void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
133 
134   unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
135   void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
136 
137   typedef SmallPtrSet<const MachineInstr *, 16> SetOfInstructions;
138 
139   const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
140 
141   // Shortcuts for LOH related types.
142   class MILOHDirective {
143     MCLOHType Kind;
144 
145     /// Arguments of this directive. Order matters.
146     SmallVector<const MachineInstr *, 3> Args;
147 
148   public:
149     typedef SmallVectorImpl<const MachineInstr *> LOHArgs;
150 
151     MILOHDirective(MCLOHType Kind, const LOHArgs &Args)
152         : Kind(Kind), Args(Args.begin(), Args.end()) {
153       assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
154     }
155 
156     MCLOHType getKind() const { return Kind; }
157     const LOHArgs &getArgs() const { return Args; }
158   };
159 
160   typedef MILOHDirective::LOHArgs MILOHArgs;
161   typedef SmallVector<MILOHDirective, 32> MILOHContainer;
162 
163   const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
164 
165   /// Add a LOH directive of this @p Kind and this @p Args.
166   void addLOHDirective(MCLOHType Kind, const MILOHArgs &Args) {
167     LOHContainerSet.push_back(MILOHDirective(Kind, Args));
168     LOHRelated.insert(Args.begin(), Args.end());
169   }
170 
171 private:
172   // Hold the lists of LOHs.
173   MILOHContainer LOHContainerSet;
174   SetOfInstructions LOHRelated;
175 };
176 } // End llvm namespace
177 
178 #endif
179