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