PPCMachineFunctionInfo.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //===-- PPCMachineFunctionInfo.h - Private data used for PowerPC --*- 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 the PowerPC specific subclass of MachineFunctionInfo.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
  13. #define LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
  14. #include "llvm/ADT/SmallVector.h"
  15. #include "llvm/CodeGen/MachineFunction.h"
  16. #include "llvm/CodeGen/TargetCallingConv.h"
  17. namespace llvm {
  18. /// PPCFunctionInfo - This class is derived from MachineFunction private
  19. /// PowerPC target-specific information for each MachineFunction.
  20. class PPCFunctionInfo : public MachineFunctionInfo {
  21. public:
  22. enum ParamType {
  23. FixedType,
  24. ShortFloatingPoint,
  25. LongFloatingPoint,
  26. VectorChar,
  27. VectorShort,
  28. VectorInt,
  29. VectorFloat
  30. };
  31. private:
  32. virtual void anchor();
  33. /// FramePointerSaveIndex - Frame index of where the old frame pointer is
  34. /// stored. Also used as an anchor for instructions that need to be altered
  35. /// when using frame pointers (dyna_add, dyna_sub.)
  36. int FramePointerSaveIndex = 0;
  37. /// ReturnAddrSaveIndex - Frame index of where the return address is stored.
  38. ///
  39. int ReturnAddrSaveIndex = 0;
  40. /// Frame index where the old base pointer is stored.
  41. int BasePointerSaveIndex = 0;
  42. /// Frame index where the old PIC base pointer is stored.
  43. int PICBasePointerSaveIndex = 0;
  44. /// Frame index where the ROP Protection Hash is stored.
  45. int ROPProtectionHashSaveIndex = 0;
  46. /// MustSaveLR - Indicates whether LR is defined (or clobbered) in the current
  47. /// function. This is only valid after the initial scan of the function by
  48. /// PEI.
  49. bool MustSaveLR = false;
  50. /// MustSaveTOC - Indicates that the TOC save needs to be performed in the
  51. /// prologue of the function. This is typically the case when there are
  52. /// indirect calls in the function and it is more profitable to save the
  53. /// TOC pointer in the prologue than in the block(s) containing the call(s).
  54. bool MustSaveTOC = false;
  55. /// Do we have to disable shrink-wrapping? This has to be set if we emit any
  56. /// instructions that clobber LR in the entry block because discovering this
  57. /// in PEI is too late (happens after shrink-wrapping);
  58. bool ShrinkWrapDisabled = false;
  59. /// Does this function have any stack spills.
  60. bool HasSpills = false;
  61. /// Does this function spill using instructions with only r+r (not r+i)
  62. /// forms.
  63. bool HasNonRISpills = false;
  64. /// SpillsCR - Indicates whether CR is spilled in the current function.
  65. bool SpillsCR = false;
  66. /// DisableNonVolatileCR - Indicates whether non-volatile CR fields would be
  67. /// disabled.
  68. bool DisableNonVolatileCR = false;
  69. /// LRStoreRequired - The bool indicates whether there is some explicit use of
  70. /// the LR/LR8 stack slot that is not obvious from scanning the code. This
  71. /// requires that the code generator produce a store of LR to the stack on
  72. /// entry, even though LR may otherwise apparently not be used.
  73. bool LRStoreRequired = false;
  74. /// This function makes use of the PPC64 ELF TOC base pointer (register r2).
  75. bool UsesTOCBasePtr = false;
  76. /// MinReservedArea - This is the frame size that is at least reserved in a
  77. /// potential caller (parameter+linkage area).
  78. unsigned MinReservedArea = 0;
  79. /// TailCallSPDelta - Stack pointer delta used when tail calling. Maximum
  80. /// amount the stack pointer is adjusted to make the frame bigger for tail
  81. /// calls. Used for creating an area before the register spill area.
  82. int TailCallSPDelta = 0;
  83. /// HasFastCall - Does this function contain a fast call. Used to determine
  84. /// how the caller's stack pointer should be calculated (epilog/dynamicalloc).
  85. bool HasFastCall = false;
  86. /// VarArgsFrameIndex - FrameIndex for start of varargs area.
  87. int VarArgsFrameIndex = 0;
  88. /// VarArgsStackOffset - StackOffset for start of stack
  89. /// arguments.
  90. int VarArgsStackOffset = 0;
  91. /// VarArgsNumGPR - Index of the first unused integer
  92. /// register for parameter passing.
  93. unsigned VarArgsNumGPR = 0;
  94. /// VarArgsNumFPR - Index of the first unused double
  95. /// register for parameter passing.
  96. unsigned VarArgsNumFPR = 0;
  97. /// FixedParmsNum - The number of fixed parameters.
  98. unsigned FixedParmsNum = 0;
  99. /// FloatingParmsNum - The number of floating parameters.
  100. unsigned FloatingParmsNum = 0;
  101. /// VectorParmsNum - The number of vector parameters.
  102. unsigned VectorParmsNum = 0;
  103. /// ParamtersType - Store all the parameter's type that are saved on
  104. /// registers.
  105. SmallVector<ParamType, 32> ParamtersType;
  106. /// CRSpillFrameIndex - FrameIndex for CR spill slot for 32-bit SVR4.
  107. int CRSpillFrameIndex = 0;
  108. /// If any of CR[2-4] need to be saved in the prologue and restored in the
  109. /// epilogue then they are added to this array. This is used for the
  110. /// 64-bit SVR4 ABI.
  111. SmallVector<Register, 3> MustSaveCRs;
  112. /// Whether this uses the PIC Base register or not.
  113. bool UsesPICBase = false;
  114. /// We keep track attributes for each live-in virtual registers
  115. /// to use SExt/ZExt flags in later optimization.
  116. std::vector<std::pair<Register, ISD::ArgFlagsTy>> LiveInAttrs;
  117. public:
  118. explicit PPCFunctionInfo(const MachineFunction &MF);
  119. int getFramePointerSaveIndex() const { return FramePointerSaveIndex; }
  120. void setFramePointerSaveIndex(int Idx) { FramePointerSaveIndex = Idx; }
  121. int getReturnAddrSaveIndex() const { return ReturnAddrSaveIndex; }
  122. void setReturnAddrSaveIndex(int idx) { ReturnAddrSaveIndex = idx; }
  123. int getBasePointerSaveIndex() const { return BasePointerSaveIndex; }
  124. void setBasePointerSaveIndex(int Idx) { BasePointerSaveIndex = Idx; }
  125. int getPICBasePointerSaveIndex() const { return PICBasePointerSaveIndex; }
  126. void setPICBasePointerSaveIndex(int Idx) { PICBasePointerSaveIndex = Idx; }
  127. int getROPProtectionHashSaveIndex() const {
  128. return ROPProtectionHashSaveIndex;
  129. }
  130. void setROPProtectionHashSaveIndex(int Idx) {
  131. ROPProtectionHashSaveIndex = Idx;
  132. }
  133. unsigned getMinReservedArea() const { return MinReservedArea; }
  134. void setMinReservedArea(unsigned size) { MinReservedArea = size; }
  135. int getTailCallSPDelta() const { return TailCallSPDelta; }
  136. void setTailCallSPDelta(int size) { TailCallSPDelta = size; }
  137. /// MustSaveLR - This is set when the prolog/epilog inserter does its initial
  138. /// scan of the function. It is true if the LR/LR8 register is ever explicitly
  139. /// defined/clobbered in the machine function (e.g. by calls and movpctolr,
  140. /// which is used in PIC generation), or if the LR stack slot is explicitly
  141. /// referenced by builtin_return_address.
  142. void setMustSaveLR(bool U) { MustSaveLR = U; }
  143. bool mustSaveLR() const { return MustSaveLR; }
  144. void setMustSaveTOC(bool U) { MustSaveTOC = U; }
  145. bool mustSaveTOC() const { return MustSaveTOC; }
  146. /// We certainly don't want to shrink wrap functions if we've emitted a
  147. /// MovePCtoLR8 as that has to go into the entry, so the prologue definitely
  148. /// has to go into the entry block.
  149. void setShrinkWrapDisabled(bool U) { ShrinkWrapDisabled = U; }
  150. bool shrinkWrapDisabled() const { return ShrinkWrapDisabled; }
  151. void setHasSpills() { HasSpills = true; }
  152. bool hasSpills() const { return HasSpills; }
  153. void setHasNonRISpills() { HasNonRISpills = true; }
  154. bool hasNonRISpills() const { return HasNonRISpills; }
  155. void setSpillsCR() { SpillsCR = true; }
  156. bool isCRSpilled() const { return SpillsCR; }
  157. void setDisableNonVolatileCR() { DisableNonVolatileCR = true; }
  158. bool isNonVolatileCRDisabled() const { return DisableNonVolatileCR; }
  159. void setLRStoreRequired() { LRStoreRequired = true; }
  160. bool isLRStoreRequired() const { return LRStoreRequired; }
  161. void setUsesTOCBasePtr() { UsesTOCBasePtr = true; }
  162. bool usesTOCBasePtr() const { return UsesTOCBasePtr; }
  163. void setHasFastCall() { HasFastCall = true; }
  164. bool hasFastCall() const { return HasFastCall;}
  165. int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
  166. void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
  167. int getVarArgsStackOffset() const { return VarArgsStackOffset; }
  168. void setVarArgsStackOffset(int Offset) { VarArgsStackOffset = Offset; }
  169. unsigned getVarArgsNumGPR() const { return VarArgsNumGPR; }
  170. void setVarArgsNumGPR(unsigned Num) { VarArgsNumGPR = Num; }
  171. unsigned getFixedParmsNum() const { return FixedParmsNum; }
  172. unsigned getFloatingPointParmsNum() const { return FloatingParmsNum; }
  173. unsigned getVectorParmsNum() const { return VectorParmsNum; }
  174. bool hasVectorParms() const { return VectorParmsNum != 0; }
  175. uint32_t getParmsType() const;
  176. uint32_t getVecExtParmsType() const;
  177. void appendParameterType(ParamType Type);
  178. unsigned getVarArgsNumFPR() const { return VarArgsNumFPR; }
  179. void setVarArgsNumFPR(unsigned Num) { VarArgsNumFPR = Num; }
  180. /// This function associates attributes for each live-in virtual register.
  181. void addLiveInAttr(Register VReg, ISD::ArgFlagsTy Flags) {
  182. LiveInAttrs.push_back(std::make_pair(VReg, Flags));
  183. }
  184. /// This function returns true if the specified vreg is
  185. /// a live-in register and sign-extended.
  186. bool isLiveInSExt(Register VReg) const;
  187. /// This function returns true if the specified vreg is
  188. /// a live-in register and zero-extended.
  189. bool isLiveInZExt(Register VReg) const;
  190. int getCRSpillFrameIndex() const { return CRSpillFrameIndex; }
  191. void setCRSpillFrameIndex(int idx) { CRSpillFrameIndex = idx; }
  192. const SmallVectorImpl<Register> &
  193. getMustSaveCRs() const { return MustSaveCRs; }
  194. void addMustSaveCR(Register Reg) { MustSaveCRs.push_back(Reg); }
  195. void setUsesPICBase(bool uses) { UsesPICBase = uses; }
  196. bool usesPICBase() const { return UsesPICBase; }
  197. MCSymbol *getPICOffsetSymbol(MachineFunction &MF) const;
  198. MCSymbol *getGlobalEPSymbol(MachineFunction &MF) const;
  199. MCSymbol *getLocalEPSymbol(MachineFunction &MF) const;
  200. MCSymbol *getTOCOffsetSymbol(MachineFunction &MF) const;
  201. };
  202. } // end namespace llvm
  203. #endif // LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H