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