X86MachineFunctionInfo.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //===-- X86MachineFunctionInfo.h - X86 machine function info ----*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file declares X86-specific per-machine-function information.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_X86_X86MACHINEFUNCTIONINFO_H
  13. #define LLVM_LIB_TARGET_X86_X86MACHINEFUNCTIONINFO_H
  14. #include "llvm/ADT/ArrayRef.h"
  15. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/CodeGen/CallingConvLower.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. namespace llvm {
  19. /// X86MachineFunctionInfo - This class is derived from MachineFunction and
  20. /// contains private X86 target-specific information for each MachineFunction.
  21. class X86MachineFunctionInfo : public MachineFunctionInfo {
  22. virtual void anchor();
  23. /// ForceFramePointer - True if the function is required to use of frame
  24. /// pointer for reasons other than it containing dynamic allocation or
  25. /// that FP eliminatation is turned off. For example, Cygwin main function
  26. /// contains stack pointer re-alignment code which requires FP.
  27. bool ForceFramePointer = false;
  28. /// RestoreBasePointerOffset - Non-zero if the function has base pointer
  29. /// and makes call to llvm.eh.sjlj.setjmp. When non-zero, the value is a
  30. /// displacement from the frame pointer to a slot where the base pointer
  31. /// is stashed.
  32. signed char RestoreBasePointerOffset = 0;
  33. /// WinEHXMMSlotInfo - Slot information of XMM registers in the stack frame
  34. /// in bytes.
  35. DenseMap<int, unsigned> WinEHXMMSlotInfo;
  36. /// CalleeSavedFrameSize - Size of the callee-saved register portion of the
  37. /// stack frame in bytes.
  38. unsigned CalleeSavedFrameSize = 0;
  39. /// BytesToPopOnReturn - Number of bytes function pops on return (in addition
  40. /// to the space used by the return address).
  41. /// Used on windows platform for stdcall & fastcall name decoration
  42. unsigned BytesToPopOnReturn = 0;
  43. /// ReturnAddrIndex - FrameIndex for return slot.
  44. int ReturnAddrIndex = 0;
  45. /// FrameIndex for return slot.
  46. int FrameAddrIndex = 0;
  47. /// TailCallReturnAddrDelta - The number of bytes by which return address
  48. /// stack slot is moved as the result of tail call optimization.
  49. int TailCallReturnAddrDelta = 0;
  50. /// SRetReturnReg - Some subtargets require that sret lowering includes
  51. /// returning the value of the returned struct in a register. This field
  52. /// holds the virtual register into which the sret argument is passed.
  53. Register SRetReturnReg;
  54. /// GlobalBaseReg - keeps track of the virtual register initialized for
  55. /// use as the global base register. This is used for PIC in some PIC
  56. /// relocation models.
  57. Register GlobalBaseReg;
  58. /// VarArgsFrameIndex - FrameIndex for start of varargs area.
  59. int VarArgsFrameIndex = 0;
  60. /// RegSaveFrameIndex - X86-64 vararg func register save area.
  61. int RegSaveFrameIndex = 0;
  62. /// VarArgsGPOffset - X86-64 vararg func int reg offset.
  63. unsigned VarArgsGPOffset = 0;
  64. /// VarArgsFPOffset - X86-64 vararg func fp reg offset.
  65. unsigned VarArgsFPOffset = 0;
  66. /// ArgumentStackSize - The number of bytes on stack consumed by the arguments
  67. /// being passed on the stack.
  68. unsigned ArgumentStackSize = 0;
  69. /// NumLocalDynamics - Number of local-dynamic TLS accesses.
  70. unsigned NumLocalDynamics = 0;
  71. /// HasPushSequences - Keeps track of whether this function uses sequences
  72. /// of pushes to pass function parameters.
  73. bool HasPushSequences = false;
  74. /// True if the function recovers from an SEH exception, and therefore needs
  75. /// to spill and restore the frame pointer.
  76. bool HasSEHFramePtrSave = false;
  77. /// The frame index of a stack object containing the original frame pointer
  78. /// used to address arguments in a function using a base pointer.
  79. int SEHFramePtrSaveIndex = 0;
  80. /// True if this function has a subset of CSRs that is handled explicitly via
  81. /// copies.
  82. bool IsSplitCSR = false;
  83. /// True if this function uses the red zone.
  84. bool UsesRedZone = false;
  85. /// True if this function has DYN_ALLOCA instructions.
  86. bool HasDynAlloca = false;
  87. /// True if this function has any preallocated calls.
  88. bool HasPreallocatedCall = false;
  89. /// Whether this function has an extended frame record [Ctx, RBP, Return
  90. /// addr]. If so, bit 60 of the in-memory frame pointer will be 1 to enable
  91. /// other tools to detect the extended record.
  92. bool HasSwiftAsyncContext = false;
  93. /// True if this function has tile virtual register. This is used to
  94. /// determine if we should insert tilerelease in frame lowering.
  95. bool HasVirtualTileReg = false;
  96. std::optional<int> SwiftAsyncContextFrameIdx;
  97. // Preallocated fields are only used during isel.
  98. // FIXME: Can we find somewhere else to store these?
  99. DenseMap<const Value *, size_t> PreallocatedIds;
  100. SmallVector<size_t, 0> PreallocatedStackSizes;
  101. SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;
  102. private:
  103. /// ForwardedMustTailRegParms - A list of virtual and physical registers
  104. /// that must be forwarded to every musttail call.
  105. SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
  106. public:
  107. X86MachineFunctionInfo() = default;
  108. X86MachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI) {}
  109. X86MachineFunctionInfo(const X86MachineFunctionInfo &) = default;
  110. MachineFunctionInfo *
  111. clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
  112. const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
  113. const override;
  114. bool getForceFramePointer() const { return ForceFramePointer;}
  115. void setForceFramePointer(bool forceFP) { ForceFramePointer = forceFP; }
  116. bool getHasPushSequences() const { return HasPushSequences; }
  117. void setHasPushSequences(bool HasPush) { HasPushSequences = HasPush; }
  118. bool getRestoreBasePointer() const { return RestoreBasePointerOffset!=0; }
  119. void setRestoreBasePointer(const MachineFunction *MF);
  120. int getRestoreBasePointerOffset() const {return RestoreBasePointerOffset; }
  121. DenseMap<int, unsigned>& getWinEHXMMSlotInfo() { return WinEHXMMSlotInfo; }
  122. const DenseMap<int, unsigned>& getWinEHXMMSlotInfo() const {
  123. return WinEHXMMSlotInfo; }
  124. unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
  125. void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
  126. unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
  127. void setBytesToPopOnReturn (unsigned bytes) { BytesToPopOnReturn = bytes;}
  128. int getRAIndex() const { return ReturnAddrIndex; }
  129. void setRAIndex(int Index) { ReturnAddrIndex = Index; }
  130. int getFAIndex() const { return FrameAddrIndex; }
  131. void setFAIndex(int Index) { FrameAddrIndex = Index; }
  132. int getTCReturnAddrDelta() const { return TailCallReturnAddrDelta; }
  133. void setTCReturnAddrDelta(int delta) {TailCallReturnAddrDelta = delta;}
  134. Register getSRetReturnReg() const { return SRetReturnReg; }
  135. void setSRetReturnReg(Register Reg) { SRetReturnReg = Reg; }
  136. Register getGlobalBaseReg() const { return GlobalBaseReg; }
  137. void setGlobalBaseReg(Register Reg) { GlobalBaseReg = Reg; }
  138. int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
  139. void setVarArgsFrameIndex(int Idx) { VarArgsFrameIndex = Idx; }
  140. int getRegSaveFrameIndex() const { return RegSaveFrameIndex; }
  141. void setRegSaveFrameIndex(int Idx) { RegSaveFrameIndex = Idx; }
  142. unsigned getVarArgsGPOffset() const { return VarArgsGPOffset; }
  143. void setVarArgsGPOffset(unsigned Offset) { VarArgsGPOffset = Offset; }
  144. unsigned getVarArgsFPOffset() const { return VarArgsFPOffset; }
  145. void setVarArgsFPOffset(unsigned Offset) { VarArgsFPOffset = Offset; }
  146. unsigned getArgumentStackSize() const { return ArgumentStackSize; }
  147. void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
  148. unsigned getNumLocalDynamicTLSAccesses() const { return NumLocalDynamics; }
  149. void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamics; }
  150. bool getHasSEHFramePtrSave() const { return HasSEHFramePtrSave; }
  151. void setHasSEHFramePtrSave(bool V) { HasSEHFramePtrSave = V; }
  152. int getSEHFramePtrSaveIndex() const { return SEHFramePtrSaveIndex; }
  153. void setSEHFramePtrSaveIndex(int Index) { SEHFramePtrSaveIndex = Index; }
  154. SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
  155. return ForwardedMustTailRegParms;
  156. }
  157. bool isSplitCSR() const { return IsSplitCSR; }
  158. void setIsSplitCSR(bool s) { IsSplitCSR = s; }
  159. bool getUsesRedZone() const { return UsesRedZone; }
  160. void setUsesRedZone(bool V) { UsesRedZone = V; }
  161. bool hasDynAlloca() const { return HasDynAlloca; }
  162. void setHasDynAlloca(bool v) { HasDynAlloca = v; }
  163. bool hasPreallocatedCall() const { return HasPreallocatedCall; }
  164. void setHasPreallocatedCall(bool v) { HasPreallocatedCall = v; }
  165. bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
  166. void setHasSwiftAsyncContext(bool v) { HasSwiftAsyncContext = v; }
  167. bool hasVirtualTileReg() const { return HasVirtualTileReg; }
  168. void setHasVirtualTileReg(bool v) { HasVirtualTileReg = v; }
  169. std::optional<int> getSwiftAsyncContextFrameIdx() const {
  170. return SwiftAsyncContextFrameIdx;
  171. }
  172. void setSwiftAsyncContextFrameIdx(int v) { SwiftAsyncContextFrameIdx = v; }
  173. size_t getPreallocatedIdForCallSite(const Value *CS) {
  174. auto Insert = PreallocatedIds.insert({CS, PreallocatedIds.size()});
  175. if (Insert.second) {
  176. PreallocatedStackSizes.push_back(0);
  177. PreallocatedArgOffsets.emplace_back();
  178. }
  179. return Insert.first->second;
  180. }
  181. void setPreallocatedStackSize(size_t Id, size_t StackSize) {
  182. PreallocatedStackSizes[Id] = StackSize;
  183. }
  184. size_t getPreallocatedStackSize(const size_t Id) {
  185. assert(PreallocatedStackSizes[Id] != 0 && "stack size not set");
  186. return PreallocatedStackSizes[Id];
  187. }
  188. void setPreallocatedArgOffsets(size_t Id, ArrayRef<size_t> AO) {
  189. PreallocatedArgOffsets[Id].assign(AO.begin(), AO.end());
  190. }
  191. ArrayRef<size_t> getPreallocatedArgOffsets(const size_t Id) {
  192. assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
  193. return PreallocatedArgOffsets[Id];
  194. }
  195. };
  196. } // End llvm namespace
  197. #endif