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 | |
| 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. |
Ahmed Bougacha | 5e402ee | 2016-07-27 14:31:46 +0000 | [diff] [blame] | 26 | class AArch64FunctionInfo final : public MachineFunctionInfo { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 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 |
JF Bastien | c8f48c1 | 2015-07-14 23:06:07 +0000 | [diff] [blame] | 45 | /// determineCalleeSaves(). |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 46 | bool HasStackFrame; |
| 47 | |
| 48 | /// \brief Amount of stack frame size, not including callee-saved registers. |
| 49 | unsigned LocalStackSize; |
| 50 | |
Geoff Berry | 04bf91a | 2016-02-01 16:29:19 +0000 | [diff] [blame] | 51 | /// \brief Amount of stack frame size used for saving callee-saved registers. |
| 52 | unsigned CalleeSavedStackSize; |
| 53 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 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 | |
Manman Ren | cbe4f94 | 2015-12-16 21:04:19 +0000 | [diff] [blame] | 78 | /// True if this function has a subset of CSRs that is handled explicitly via |
| 79 | /// copies. |
| 80 | bool IsSplitCSR; |
| 81 | |
Chad Rosier | 6d98655 | 2016-03-14 18:17:41 +0000 | [diff] [blame] | 82 | /// True when the stack gets realigned dynamically because the size of stack |
| 83 | /// frame is unknown at compile time. e.g., in case of VLAs. |
| 84 | bool StackRealigned; |
| 85 | |
Geoff Berry | 66f6b65 | 2016-06-02 16:22:07 +0000 | [diff] [blame] | 86 | /// True when the callee-save stack area has unused gaps that may be used for |
| 87 | /// other stack allocations. |
| 88 | bool CalleeSaveStackHasFreeSpace; |
| 89 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 90 | public: |
| 91 | AArch64FunctionInfo() |
| 92 | : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false), |
| 93 | NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0), |
Manman Ren | cbe4f94 | 2015-12-16 21:04:19 +0000 | [diff] [blame] | 94 | VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0), |
Geoff Berry | 66f6b65 | 2016-06-02 16:22:07 +0000 | [diff] [blame] | 95 | IsSplitCSR(false), StackRealigned(false), |
| 96 | CalleeSaveStackHasFreeSpace(false) {} |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 97 | |
| 98 | explicit AArch64FunctionInfo(MachineFunction &MF) |
| 99 | : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false), |
| 100 | NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0), |
Manman Ren | cbe4f94 | 2015-12-16 21:04:19 +0000 | [diff] [blame] | 101 | VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0), |
Geoff Berry | 66f6b65 | 2016-06-02 16:22:07 +0000 | [diff] [blame] | 102 | IsSplitCSR(false), StackRealigned(false), |
| 103 | CalleeSaveStackHasFreeSpace(false) { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 104 | (void)MF; |
| 105 | } |
| 106 | |
| 107 | unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; } |
| 108 | void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; } |
| 109 | |
| 110 | unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; } |
| 111 | void setArgumentStackToRestore(unsigned bytes) { |
| 112 | ArgumentStackToRestore = bytes; |
| 113 | } |
| 114 | |
| 115 | bool hasStackFrame() const { return HasStackFrame; } |
| 116 | void setHasStackFrame(bool s) { HasStackFrame = s; } |
| 117 | |
Chad Rosier | 6d98655 | 2016-03-14 18:17:41 +0000 | [diff] [blame] | 118 | bool isStackRealigned() const { return StackRealigned; } |
| 119 | void setStackRealigned(bool s) { StackRealigned = s; } |
| 120 | |
Geoff Berry | 66f6b65 | 2016-06-02 16:22:07 +0000 | [diff] [blame] | 121 | bool hasCalleeSaveStackFreeSpace() const { |
| 122 | return CalleeSaveStackHasFreeSpace; |
| 123 | } |
| 124 | void setCalleeSaveStackHasFreeSpace(bool s) { |
| 125 | CalleeSaveStackHasFreeSpace = s; |
| 126 | } |
| 127 | |
Manman Ren | cbe4f94 | 2015-12-16 21:04:19 +0000 | [diff] [blame] | 128 | bool isSplitCSR() const { return IsSplitCSR; } |
| 129 | void setIsSplitCSR(bool s) { IsSplitCSR = s; } |
| 130 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 131 | void setLocalStackSize(unsigned Size) { LocalStackSize = Size; } |
| 132 | unsigned getLocalStackSize() const { return LocalStackSize; } |
| 133 | |
Geoff Berry | 04bf91a | 2016-02-01 16:29:19 +0000 | [diff] [blame] | 134 | void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; } |
| 135 | unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; } |
| 136 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 137 | void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; } |
| 138 | unsigned getNumLocalDynamicTLSAccesses() const { |
| 139 | return NumLocalDynamicTLSAccesses; |
| 140 | } |
| 141 | |
| 142 | int getVarArgsStackIndex() const { return VarArgsStackIndex; } |
| 143 | void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; } |
| 144 | |
| 145 | int getVarArgsGPRIndex() const { return VarArgsGPRIndex; } |
| 146 | void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; } |
| 147 | |
| 148 | unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; } |
| 149 | void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; } |
| 150 | |
| 151 | int getVarArgsFPRIndex() const { return VarArgsFPRIndex; } |
| 152 | void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; } |
| 153 | |
| 154 | unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; } |
| 155 | void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; } |
| 156 | |
| 157 | typedef SmallPtrSet<const MachineInstr *, 16> SetOfInstructions; |
| 158 | |
| 159 | const SetOfInstructions &getLOHRelated() const { return LOHRelated; } |
| 160 | |
| 161 | // Shortcuts for LOH related types. |
| 162 | class MILOHDirective { |
| 163 | MCLOHType Kind; |
| 164 | |
| 165 | /// Arguments of this directive. Order matters. |
| 166 | SmallVector<const MachineInstr *, 3> Args; |
| 167 | |
| 168 | public: |
Benjamin Kramer | 3bc1edf | 2016-07-02 11:41:39 +0000 | [diff] [blame] | 169 | typedef ArrayRef<const MachineInstr *> LOHArgs; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 170 | |
Benjamin Kramer | 3bc1edf | 2016-07-02 11:41:39 +0000 | [diff] [blame] | 171 | MILOHDirective(MCLOHType Kind, LOHArgs Args) |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 172 | : Kind(Kind), Args(Args.begin(), Args.end()) { |
| 173 | assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); |
| 174 | } |
| 175 | |
| 176 | MCLOHType getKind() const { return Kind; } |
Benjamin Kramer | 3bc1edf | 2016-07-02 11:41:39 +0000 | [diff] [blame] | 177 | LOHArgs getArgs() const { return Args; } |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | typedef MILOHDirective::LOHArgs MILOHArgs; |
| 181 | typedef SmallVector<MILOHDirective, 32> MILOHContainer; |
| 182 | |
| 183 | const MILOHContainer &getLOHContainer() const { return LOHContainerSet; } |
| 184 | |
| 185 | /// Add a LOH directive of this @p Kind and this @p Args. |
Benjamin Kramer | 3bc1edf | 2016-07-02 11:41:39 +0000 | [diff] [blame] | 186 | void addLOHDirective(MCLOHType Kind, MILOHArgs Args) { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 187 | LOHContainerSet.push_back(MILOHDirective(Kind, Args)); |
| 188 | LOHRelated.insert(Args.begin(), Args.end()); |
| 189 | } |
| 190 | |
| 191 | private: |
| 192 | // Hold the lists of LOHs. |
| 193 | MILOHContainer LOHContainerSet; |
| 194 | SetOfInstructions LOHRelated; |
| 195 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 196 | } // End llvm namespace |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 197 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 198 | #endif |