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