ARMMachineFunctionInfo.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. //===-- ARMMachineFunctionInfo.h - ARM 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 ARM-specific per-machine-function information.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
  13. #define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
  14. #include "llvm/ADT/DenseMap.h"
  15. #include "llvm/ADT/SmallPtrSet.h"
  16. #include "llvm/CodeGen/MachineFunction.h"
  17. #include "llvm/IR/GlobalVariable.h"
  18. #include "llvm/Support/ErrorHandling.h"
  19. #include <utility>
  20. namespace llvm {
  21. /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
  22. /// contains private ARM-specific information for each MachineFunction.
  23. class ARMFunctionInfo : public MachineFunctionInfo {
  24. virtual void anchor();
  25. /// isThumb - True if this function is compiled under Thumb mode.
  26. /// Used to initialized Align, so must precede it.
  27. bool isThumb = false;
  28. /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
  29. /// to determine if function is compiled under Thumb mode, for that use
  30. /// 'isThumb'.
  31. bool hasThumb2 = false;
  32. /// StByValParamsPadding - For parameter that is split between
  33. /// GPRs and memory; while recovering GPRs part, when
  34. /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
  35. /// we need to insert gap before parameter start address. It allows to
  36. /// "attach" GPR-part to the part that was passed via stack.
  37. unsigned StByValParamsPadding = 0;
  38. /// ArgsRegSaveSize - Size of the register save area for vararg functions or
  39. /// those making guaranteed tail calls that need more stack argument space
  40. /// than is provided by this functions incoming parameters.
  41. ///
  42. unsigned ArgRegsSaveSize = 0;
  43. /// ReturnRegsCount - Number of registers used up in the return.
  44. unsigned ReturnRegsCount = 0;
  45. /// HasStackFrame - True if this function has a stack frame. Set by
  46. /// determineCalleeSaves().
  47. bool HasStackFrame = false;
  48. /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
  49. /// emitPrologue.
  50. bool RestoreSPFromFP = false;
  51. /// LRSpilled - True if the LR register has been for spilled for
  52. /// any reason, so it's legal to emit an ARM::tBfar (i.e. "bl").
  53. bool LRSpilled = false;
  54. /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
  55. /// spill stack offset.
  56. unsigned FramePtrSpillOffset = 0;
  57. /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
  58. /// register spills areas. For Mac OS X:
  59. ///
  60. /// GPR callee-saved (1) : r4, r5, r6, r7, lr
  61. /// --------------------------------------------
  62. /// GPR callee-saved (2) : r8, r10, r11
  63. /// --------------------------------------------
  64. /// DPR callee-saved : d8 - d15
  65. ///
  66. /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
  67. /// Some may be spilled after the stack has been realigned.
  68. unsigned GPRCS1Offset = 0;
  69. unsigned GPRCS2Offset = 0;
  70. unsigned DPRCSOffset = 0;
  71. /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
  72. /// areas.
  73. unsigned FPCXTSaveSize = 0;
  74. unsigned GPRCS1Size = 0;
  75. unsigned GPRCS2Size = 0;
  76. unsigned DPRCSAlignGapSize = 0;
  77. unsigned DPRCSSize = 0;
  78. /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
  79. /// the aligned portion of the stack frame. This is always a contiguous
  80. /// sequence of D-registers starting from d8.
  81. ///
  82. /// We do not keep track of the frame indices used for these registers - they
  83. /// behave like any other frame index in the aligned stack frame. These
  84. /// registers also aren't included in DPRCSSize above.
  85. unsigned NumAlignedDPRCS2Regs = 0;
  86. unsigned PICLabelUId = 0;
  87. /// VarArgsFrameIndex - FrameIndex for start of varargs area.
  88. int VarArgsFrameIndex = 0;
  89. /// HasITBlocks - True if IT blocks have been inserted.
  90. bool HasITBlocks = false;
  91. // Security Extensions
  92. bool IsCmseNSEntry;
  93. bool IsCmseNSCall;
  94. /// CPEClones - Track constant pool entries clones created by Constant Island
  95. /// pass.
  96. DenseMap<unsigned, unsigned> CPEClones;
  97. /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
  98. /// being passed on the stack
  99. unsigned ArgumentStackSize = 0;
  100. /// ArgumentStackToRestore - amount of bytes on stack consumed that we must
  101. /// restore on return.
  102. unsigned ArgumentStackToRestore = 0;
  103. /// CoalescedWeights - mapping of basic blocks to the rolling counter of
  104. /// coalesced weights.
  105. DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
  106. /// True if this function has a subset of CSRs that is handled explicitly via
  107. /// copies.
  108. bool IsSplitCSR = false;
  109. /// Globals that have had their storage promoted into the constant pool.
  110. SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
  111. /// The amount the literal pool has been increasedby due to promoted globals.
  112. int PromotedGlobalsIncrease = 0;
  113. /// True if r0 will be preserved by a call to this function (e.g. C++
  114. /// con/destructors).
  115. bool PreservesR0 = false;
  116. /// True if the function should sign its return address.
  117. bool SignReturnAddress = false;
  118. /// True if the fucntion should sign its return address, even if LR is not
  119. /// saved.
  120. bool SignReturnAddressAll = false;
  121. /// True if BTI instructions should be placed at potential indirect jump
  122. /// destinations.
  123. bool BranchTargetEnforcement = false;
  124. public:
  125. ARMFunctionInfo() = default;
  126. explicit ARMFunctionInfo(MachineFunction &MF);
  127. bool isThumbFunction() const { return isThumb; }
  128. bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
  129. bool isThumb2Function() const { return isThumb && hasThumb2; }
  130. bool isCmseNSEntryFunction() const { return IsCmseNSEntry; }
  131. bool isCmseNSCallFunction() const { return IsCmseNSCall; }
  132. unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
  133. void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
  134. unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
  135. void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
  136. unsigned getReturnRegsCount() const { return ReturnRegsCount; }
  137. void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
  138. bool hasStackFrame() const { return HasStackFrame; }
  139. void setHasStackFrame(bool s) { HasStackFrame = s; }
  140. bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
  141. void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
  142. bool isLRSpilled() const { return LRSpilled; }
  143. void setLRIsSpilled(bool s) { LRSpilled = s; }
  144. unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
  145. void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
  146. unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
  147. void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
  148. unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
  149. unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
  150. unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
  151. void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
  152. void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
  153. void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
  154. unsigned getFPCXTSaveAreaSize() const { return FPCXTSaveSize; }
  155. unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
  156. unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
  157. unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
  158. unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
  159. void setFPCXTSaveAreaSize(unsigned s) { FPCXTSaveSize = s; }
  160. void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
  161. void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
  162. void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
  163. void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
  164. unsigned getArgumentStackSize() const { return ArgumentStackSize; }
  165. void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
  166. unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
  167. void setArgumentStackToRestore(unsigned v) { ArgumentStackToRestore = v; }
  168. void initPICLabelUId(unsigned UId) {
  169. PICLabelUId = UId;
  170. }
  171. unsigned getNumPICLabels() const {
  172. return PICLabelUId;
  173. }
  174. unsigned createPICLabelUId() {
  175. return PICLabelUId++;
  176. }
  177. int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
  178. void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
  179. bool hasITBlocks() const { return HasITBlocks; }
  180. void setHasITBlocks(bool h) { HasITBlocks = h; }
  181. bool isSplitCSR() const { return IsSplitCSR; }
  182. void setIsSplitCSR(bool s) { IsSplitCSR = s; }
  183. void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
  184. if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
  185. llvm_unreachable("Duplicate entries!");
  186. }
  187. unsigned getOriginalCPIdx(unsigned CloneIdx) const {
  188. DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
  189. if (I != CPEClones.end())
  190. return I->second;
  191. else
  192. return -1U;
  193. }
  194. DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
  195. MachineBasicBlock* MBB) {
  196. auto It = CoalescedWeights.find(MBB);
  197. if (It == CoalescedWeights.end()) {
  198. It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
  199. }
  200. return It;
  201. }
  202. /// Indicate to the backend that \c GV has had its storage changed to inside
  203. /// a constant pool. This means it no longer needs to be emitted as a
  204. /// global variable.
  205. void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) {
  206. PromotedGlobals.insert(GV);
  207. }
  208. SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() {
  209. return PromotedGlobals;
  210. }
  211. int getPromotedConstpoolIncrease() const {
  212. return PromotedGlobalsIncrease;
  213. }
  214. void setPromotedConstpoolIncrease(int Sz) {
  215. PromotedGlobalsIncrease = Sz;
  216. }
  217. DenseMap<unsigned, unsigned> EHPrologueRemappedRegs;
  218. DenseMap<unsigned, unsigned> EHPrologueOffsetInRegs;
  219. void setPreservesR0() { PreservesR0 = true; }
  220. bool getPreservesR0() const { return PreservesR0; }
  221. bool shouldSignReturnAddress() const {
  222. return shouldSignReturnAddress(LRSpilled);
  223. }
  224. bool shouldSignReturnAddress(bool SpillsLR) const {
  225. if (!SignReturnAddress)
  226. return false;
  227. if (SignReturnAddressAll)
  228. return true;
  229. return SpillsLR;
  230. }
  231. bool branchTargetEnforcement() const { return BranchTargetEnforcement; }
  232. };
  233. } // end namespace llvm
  234. #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H