PPCMachineFunctionInfo.h 9.9 KB

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