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
22namespace llvm {
23
24/// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
25/// contains private AArch64-specific information for each MachineFunction.
26class 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 Number of TLS accesses using the special (combinable)
52  /// _TLS_MODULE_BASE_ symbol.
53  unsigned NumLocalDynamicTLSAccesses;
54
55  /// \brief FrameIndex for start of varargs area for arguments passed on the
56  /// stack.
57  int VarArgsStackIndex;
58
59  /// \brief FrameIndex for start of varargs area for arguments passed in
60  /// general purpose registers.
61  int VarArgsGPRIndex;
62
63  /// \brief Size of the varargs area for arguments passed in general purpose
64  /// registers.
65  unsigned VarArgsGPRSize;
66
67  /// \brief FrameIndex for start of varargs area for arguments passed in
68  /// floating-point registers.
69  int VarArgsFPRIndex;
70
71  /// \brief Size of the varargs area for arguments passed in floating-point
72  /// registers.
73  unsigned VarArgsFPRSize;
74
75  /// True if this function has a subset of CSRs that is handled explicitly via
76  /// copies.
77  bool IsSplitCSR;
78
79public:
80  AArch64FunctionInfo()
81      : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false),
82        NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0),
83        VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0),
84        IsSplitCSR(false) {}
85
86  explicit AArch64FunctionInfo(MachineFunction &MF)
87      : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false),
88        NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0),
89        VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0),
90        IsSplitCSR(false) {
91    (void)MF;
92  }
93
94  unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
95  void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
96
97  unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
98  void setArgumentStackToRestore(unsigned bytes) {
99    ArgumentStackToRestore = bytes;
100  }
101
102  bool hasStackFrame() const { return HasStackFrame; }
103  void setHasStackFrame(bool s) { HasStackFrame = s; }
104
105  bool isSplitCSR() const { return IsSplitCSR; }
106  void setIsSplitCSR(bool s) { IsSplitCSR = s; }
107
108  void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
109  unsigned getLocalStackSize() const { return LocalStackSize; }
110
111  void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
112  unsigned getNumLocalDynamicTLSAccesses() const {
113    return NumLocalDynamicTLSAccesses;
114  }
115
116  int getVarArgsStackIndex() const { return VarArgsStackIndex; }
117  void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
118
119  int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
120  void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
121
122  unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
123  void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
124
125  int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
126  void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
127
128  unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
129  void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
130
131  typedef SmallPtrSet<const MachineInstr *, 16> SetOfInstructions;
132
133  const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
134
135  // Shortcuts for LOH related types.
136  class MILOHDirective {
137    MCLOHType Kind;
138
139    /// Arguments of this directive. Order matters.
140    SmallVector<const MachineInstr *, 3> Args;
141
142  public:
143    typedef SmallVectorImpl<const MachineInstr *> LOHArgs;
144
145    MILOHDirective(MCLOHType Kind, const LOHArgs &Args)
146        : Kind(Kind), Args(Args.begin(), Args.end()) {
147      assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
148    }
149
150    MCLOHType getKind() const { return Kind; }
151    const LOHArgs &getArgs() const { return Args; }
152  };
153
154  typedef MILOHDirective::LOHArgs MILOHArgs;
155  typedef SmallVector<MILOHDirective, 32> MILOHContainer;
156
157  const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
158
159  /// Add a LOH directive of this @p Kind and this @p Args.
160  void addLOHDirective(MCLOHType Kind, const MILOHArgs &Args) {
161    LOHContainerSet.push_back(MILOHDirective(Kind, Args));
162    LOHRelated.insert(Args.begin(), Args.end());
163  }
164
165private:
166  // Hold the lists of LOHs.
167  MILOHContainer LOHContainerSet;
168  SetOfInstructions LOHRelated;
169};
170} // End llvm namespace
171
172#endif
173