LLVM  13.0.0git
PPCMachineFunctionInfo.h
Go to the documentation of this file.
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 
13 #ifndef LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
15 
16 #include "llvm/ADT/SmallVector.h"
19 
20 namespace llvm {
21 
22 /// PPCFunctionInfo - This class is derived from MachineFunction private
23 /// PowerPC target-specific information for each MachineFunction.
25 public:
26  // The value in the ParamType are used to indicate the bitstrings used in the
27  // encoding format.
28  enum ParamType {
29  FixedType = 0x0,
32  };
33 
34 private:
35  virtual void anchor();
36 
37  /// FramePointerSaveIndex - Frame index of where the old frame pointer is
38  /// stored. Also used as an anchor for instructions that need to be altered
39  /// when using frame pointers (dyna_add, dyna_sub.)
40  int FramePointerSaveIndex = 0;
41 
42  /// ReturnAddrSaveIndex - Frame index of where the return address is stored.
43  ///
44  int ReturnAddrSaveIndex = 0;
45 
46  /// Frame index where the old base pointer is stored.
47  int BasePointerSaveIndex = 0;
48 
49  /// Frame index where the old PIC base pointer is stored.
50  int PICBasePointerSaveIndex = 0;
51 
52  /// Frame index where the ROP Protection Hash is stored.
53  int ROPProtectionHashSaveIndex = 0;
54 
55  /// MustSaveLR - Indicates whether LR is defined (or clobbered) in the current
56  /// function. This is only valid after the initial scan of the function by
57  /// PEI.
58  bool MustSaveLR = false;
59 
60  /// MustSaveTOC - Indicates that the TOC save needs to be performed in the
61  /// prologue of the function. This is typically the case when there are
62  /// indirect calls in the function and it is more profitable to save the
63  /// TOC pointer in the prologue than in the block(s) containing the call(s).
64  bool MustSaveTOC = false;
65 
66  /// Do we have to disable shrink-wrapping? This has to be set if we emit any
67  /// instructions that clobber LR in the entry block because discovering this
68  /// in PEI is too late (happens after shrink-wrapping);
69  bool ShrinkWrapDisabled = false;
70 
71  /// Does this function have any stack spills.
72  bool HasSpills = false;
73 
74  /// Does this function spill using instructions with only r+r (not r+i)
75  /// forms.
76  bool HasNonRISpills = false;
77 
78  /// SpillsCR - Indicates whether CR is spilled in the current function.
79  bool SpillsCR = false;
80 
81  /// DisableNonVolatileCR - Indicates whether non-volatile CR fields would be
82  /// disabled.
83  bool DisableNonVolatileCR = false;
84 
85  /// LRStoreRequired - The bool indicates whether there is some explicit use of
86  /// the LR/LR8 stack slot that is not obvious from scanning the code. This
87  /// requires that the code generator produce a store of LR to the stack on
88  /// entry, even though LR may otherwise apparently not be used.
89  bool LRStoreRequired = false;
90 
91  /// This function makes use of the PPC64 ELF TOC base pointer (register r2).
92  bool UsesTOCBasePtr = false;
93 
94  /// MinReservedArea - This is the frame size that is at least reserved in a
95  /// potential caller (parameter+linkage area).
96  unsigned MinReservedArea = 0;
97 
98  /// TailCallSPDelta - Stack pointer delta used when tail calling. Maximum
99  /// amount the stack pointer is adjusted to make the frame bigger for tail
100  /// calls. Used for creating an area before the register spill area.
101  int TailCallSPDelta = 0;
102 
103  /// HasFastCall - Does this function contain a fast call. Used to determine
104  /// how the caller's stack pointer should be calculated (epilog/dynamicalloc).
105  bool HasFastCall = false;
106 
107  /// VarArgsFrameIndex - FrameIndex for start of varargs area.
108  int VarArgsFrameIndex = 0;
109 
110  /// VarArgsStackOffset - StackOffset for start of stack
111  /// arguments.
112 
113  int VarArgsStackOffset = 0;
114 
115  /// VarArgsNumGPR - Index of the first unused integer
116  /// register for parameter passing.
117  unsigned VarArgsNumGPR = 0;
118 
119  /// VarArgsNumFPR - Index of the first unused double
120  /// register for parameter passing.
121  unsigned VarArgsNumFPR = 0;
122 
123  /// FixedParamNum - Number of fixed parameter.
124  unsigned FixedParamNum = 0;
125 
126  /// FloatingParamNum - Number of floating point parameter.
127  unsigned FloatingPointParamNum = 0;
128 
129  /// ParamType - Encode type for every parameter
130  /// in the order of parameters passing in.
131  /// Bitstring starts from the most significant (leftmost) bit.
132  /// '0'b => fixed parameter.
133  /// '10'b => floating point short parameter.
134  /// '11'b => floating point long parameter.
135  uint32_t ParameterType = 0;
136 
137  /// CRSpillFrameIndex - FrameIndex for CR spill slot for 32-bit SVR4.
138  int CRSpillFrameIndex = 0;
139 
140  /// If any of CR[2-4] need to be saved in the prologue and restored in the
141  /// epilogue then they are added to this array. This is used for the
142  /// 64-bit SVR4 ABI.
143  SmallVector<Register, 3> MustSaveCRs;
144 
145  /// Whether this uses the PIC Base register or not.
146  bool UsesPICBase = false;
147 
148  /// We keep track attributes for each live-in virtual registers
149  /// to use SExt/ZExt flags in later optimization.
150  std::vector<std::pair<Register, ISD::ArgFlagsTy>> LiveInAttrs;
151 
152 public:
153  explicit PPCFunctionInfo(const MachineFunction &MF);
154 
155  int getFramePointerSaveIndex() const { return FramePointerSaveIndex; }
156  void setFramePointerSaveIndex(int Idx) { FramePointerSaveIndex = Idx; }
157 
158  int getReturnAddrSaveIndex() const { return ReturnAddrSaveIndex; }
159  void setReturnAddrSaveIndex(int idx) { ReturnAddrSaveIndex = idx; }
160 
161  int getBasePointerSaveIndex() const { return BasePointerSaveIndex; }
162  void setBasePointerSaveIndex(int Idx) { BasePointerSaveIndex = Idx; }
163 
164  int getPICBasePointerSaveIndex() const { return PICBasePointerSaveIndex; }
165  void setPICBasePointerSaveIndex(int Idx) { PICBasePointerSaveIndex = Idx; }
166 
168  return ROPProtectionHashSaveIndex;
169  }
171  ROPProtectionHashSaveIndex = Idx;
172  }
173 
174  unsigned getMinReservedArea() const { return MinReservedArea; }
175  void setMinReservedArea(unsigned size) { MinReservedArea = size; }
176 
177  int getTailCallSPDelta() const { return TailCallSPDelta; }
178  void setTailCallSPDelta(int size) { TailCallSPDelta = size; }
179 
180  /// MustSaveLR - This is set when the prolog/epilog inserter does its initial
181  /// scan of the function. It is true if the LR/LR8 register is ever explicitly
182  /// defined/clobbered in the machine function (e.g. by calls and movpctolr,
183  /// which is used in PIC generation), or if the LR stack slot is explicitly
184  /// referenced by builtin_return_address.
185  void setMustSaveLR(bool U) { MustSaveLR = U; }
186  bool mustSaveLR() const { return MustSaveLR; }
187 
188  void setMustSaveTOC(bool U) { MustSaveTOC = U; }
189  bool mustSaveTOC() const { return MustSaveTOC; }
190 
191  /// We certainly don't want to shrink wrap functions if we've emitted a
192  /// MovePCtoLR8 as that has to go into the entry, so the prologue definitely
193  /// has to go into the entry block.
194  void setShrinkWrapDisabled(bool U) { ShrinkWrapDisabled = U; }
195  bool shrinkWrapDisabled() const { return ShrinkWrapDisabled; }
196 
197  void setHasSpills() { HasSpills = true; }
198  bool hasSpills() const { return HasSpills; }
199 
200  void setHasNonRISpills() { HasNonRISpills = true; }
201  bool hasNonRISpills() const { return HasNonRISpills; }
202 
203  void setSpillsCR() { SpillsCR = true; }
204  bool isCRSpilled() const { return SpillsCR; }
205 
206  void setDisableNonVolatileCR() { DisableNonVolatileCR = true; }
207  bool isNonVolatileCRDisabled() const { return DisableNonVolatileCR; }
208 
209  void setLRStoreRequired() { LRStoreRequired = true; }
210  bool isLRStoreRequired() const { return LRStoreRequired; }
211 
212  void setUsesTOCBasePtr() { UsesTOCBasePtr = true; }
213  bool usesTOCBasePtr() const { return UsesTOCBasePtr; }
214 
215  void setHasFastCall() { HasFastCall = true; }
216  bool hasFastCall() const { return HasFastCall;}
217 
218  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
219  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
220 
221  int getVarArgsStackOffset() const { return VarArgsStackOffset; }
222  void setVarArgsStackOffset(int Offset) { VarArgsStackOffset = Offset; }
223 
224  unsigned getVarArgsNumGPR() const { return VarArgsNumGPR; }
225  void setVarArgsNumGPR(unsigned Num) { VarArgsNumGPR = Num; }
226 
227  unsigned getFixedParamNum() const { return FixedParamNum; }
228 
229  unsigned getFloatingPointParamNum() const { return FloatingPointParamNum; }
230 
231  uint32_t getParameterType() const { return ParameterType; }
233 
234  unsigned getVarArgsNumFPR() const { return VarArgsNumFPR; }
235  void setVarArgsNumFPR(unsigned Num) { VarArgsNumFPR = Num; }
236 
237  /// This function associates attributes for each live-in virtual register.
239  LiveInAttrs.push_back(std::make_pair(VReg, Flags));
240  }
241 
242  /// This function returns true if the specified vreg is
243  /// a live-in register and sign-extended.
244  bool isLiveInSExt(Register VReg) const;
245 
246  /// This function returns true if the specified vreg is
247  /// a live-in register and zero-extended.
248  bool isLiveInZExt(Register VReg) const;
249 
250  int getCRSpillFrameIndex() const { return CRSpillFrameIndex; }
251  void setCRSpillFrameIndex(int idx) { CRSpillFrameIndex = idx; }
252 
254  getMustSaveCRs() const { return MustSaveCRs; }
255  void addMustSaveCR(Register Reg) { MustSaveCRs.push_back(Reg); }
256 
257  void setUsesPICBase(bool uses) { UsesPICBase = uses; }
258  bool usesPICBase() const { return UsesPICBase; }
259 
261 
265 };
266 
267 } // end namespace llvm
268 
269 #endif // LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
llvm::PPCFunctionInfo::getBasePointerSaveIndex
int getBasePointerSaveIndex() const
Definition: PPCMachineFunctionInfo.h:161
llvm::PPCFunctionInfo::addMustSaveCR
void addMustSaveCR(Register Reg)
Definition: PPCMachineFunctionInfo.h:255
llvm::PPCFunctionInfo::getCRSpillFrameIndex
int getCRSpillFrameIndex() const
Definition: PPCMachineFunctionInfo.h:250
llvm
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::PPCFunctionInfo::appendParameterType
void appendParameterType(ParamType Type)
Definition: PPCMachineFunctionInfo.cpp:68
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::PPCFunctionInfo::setTailCallSPDelta
void setTailCallSPDelta(int size)
Definition: PPCMachineFunctionInfo.h:178
llvm::PPCFunctionInfo::getMinReservedArea
unsigned getMinReservedArea() const
Definition: PPCMachineFunctionInfo.h:174
llvm::PPCFunctionInfo::setSpillsCR
void setSpillsCR()
Definition: PPCMachineFunctionInfo.h:203
llvm::PPCFunctionInfo::getVarArgsFrameIndex
int getVarArgsFrameIndex() const
Definition: PPCMachineFunctionInfo.h:218
uses
This might compile to this xmm1 xorps xmm0 movss xmm0 ret Now consider if the code caused xmm1 to get spilled This might produce this xmm1 movaps xmm0 movaps xmm1 movss xmm0 ret since the reload is only used by these we could fold it into the uses
Definition: README-SSE.txt:258
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
llvm::PPCFunctionInfo::addLiveInAttr
void addLiveInAttr(Register VReg, ISD::ArgFlagsTy Flags)
This function associates attributes for each live-in virtual register.
Definition: PPCMachineFunctionInfo.h:238
llvm::PPCFunctionInfo::LongFloatPoint
@ LongFloatPoint
Definition: PPCMachineFunctionInfo.h:31
llvm::PPCFunctionInfo::getParameterType
uint32_t getParameterType() const
Definition: PPCMachineFunctionInfo.h:231
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::PPCFunctionInfo::getLocalEPSymbol
MCSymbol * getLocalEPSymbol(MachineFunction &MF) const
Definition: PPCMachineFunctionInfo.cpp:40
llvm::PPCFunctionInfo::setVarArgsNumGPR
void setVarArgsNumGPR(unsigned Num)
Definition: PPCMachineFunctionInfo.h:225
llvm::PPCFunctionInfo
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
Definition: PPCMachineFunctionInfo.h:24
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::PPCFunctionInfo::setHasSpills
void setHasSpills()
Definition: PPCMachineFunctionInfo.h:197
llvm::PPCFunctionInfo::getFixedParamNum
unsigned getFixedParamNum() const
Definition: PPCMachineFunctionInfo.h:227
llvm::PPCFunctionInfo::getPICOffsetSymbol
MCSymbol * getPICOffsetSymbol(MachineFunction &MF) const
Definition: PPCMachineFunctionInfo.cpp:26
llvm::PPCFunctionInfo::setMustSaveTOC
void setMustSaveTOC(bool U)
Definition: PPCMachineFunctionInfo.h:188
llvm::PPCFunctionInfo::setROPProtectionHashSaveIndex
void setROPProtectionHashSaveIndex(int Idx)
Definition: PPCMachineFunctionInfo.h:170
llvm::PPCFunctionInfo::setReturnAddrSaveIndex
void setReturnAddrSaveIndex(int idx)
Definition: PPCMachineFunctionInfo.h:159
llvm::PPCFunctionInfo::usesPICBase
bool usesPICBase() const
Definition: PPCMachineFunctionInfo.h:258
llvm::PPCFunctionInfo::setVarArgsNumFPR
void setVarArgsNumFPR(unsigned Num)
Definition: PPCMachineFunctionInfo.h:235
llvm::PPCFunctionInfo::setUsesTOCBasePtr
void setUsesTOCBasePtr()
Definition: PPCMachineFunctionInfo.h:212
llvm::PPCFunctionInfo::setHasNonRISpills
void setHasNonRISpills()
Definition: PPCMachineFunctionInfo.h:200
llvm::PPCFunctionInfo::getPICBasePointerSaveIndex
int getPICBasePointerSaveIndex() const
Definition: PPCMachineFunctionInfo.h:164
llvm::PPCFunctionInfo::setCRSpillFrameIndex
void setCRSpillFrameIndex(int idx)
Definition: PPCMachineFunctionInfo.h:251
llvm::PPCFunctionInfo::hasFastCall
bool hasFastCall() const
Definition: PPCMachineFunctionInfo.h:216
llvm::PPCFunctionInfo::ParamType
ParamType
Definition: PPCMachineFunctionInfo.h:28
llvm::PPCFunctionInfo::setShrinkWrapDisabled
void setShrinkWrapDisabled(bool U)
We certainly don't want to shrink wrap functions if we've emitted a MovePCtoLR8 as that has to go int...
Definition: PPCMachineFunctionInfo.h:194
llvm::PPCFunctionInfo::setHasFastCall
void setHasFastCall()
Definition: PPCMachineFunctionInfo.h:215
llvm::PPCFunctionInfo::isLRStoreRequired
bool isLRStoreRequired() const
Definition: PPCMachineFunctionInfo.h:210
llvm::PPCFunctionInfo::getFloatingPointParamNum
unsigned getFloatingPointParamNum() const
Definition: PPCMachineFunctionInfo.h:229
llvm::PPCFunctionInfo::getTOCOffsetSymbol
MCSymbol * getTOCOffsetSymbol(MachineFunction &MF) const
Definition: PPCMachineFunctionInfo.cpp:47
llvm::PPCFunctionInfo::mustSaveLR
bool mustSaveLR() const
Definition: PPCMachineFunctionInfo.h:186
TargetCallingConv.h
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::PPCFunctionInfo::hasNonRISpills
bool hasNonRISpills() const
Definition: PPCMachineFunctionInfo.h:201
llvm::PPCFunctionInfo::getVarArgsNumFPR
unsigned getVarArgsNumFPR() const
Definition: PPCMachineFunctionInfo.h:234
llvm::PPCFunctionInfo::ShortFloatPoint
@ ShortFloatPoint
Definition: PPCMachineFunctionInfo.h:30
llvm::PPCFunctionInfo::setVarArgsStackOffset
void setVarArgsStackOffset(int Offset)
Definition: PPCMachineFunctionInfo.h:222
llvm::PPCFunctionInfo::getGlobalEPSymbol
MCSymbol * getGlobalEPSymbol(MachineFunction &MF) const
Definition: PPCMachineFunctionInfo.cpp:33
llvm::PPCFunctionInfo::isNonVolatileCRDisabled
bool isNonVolatileCRDisabled() const
Definition: PPCMachineFunctionInfo.h:207
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1463
llvm::PPCFunctionInfo::setDisableNonVolatileCR
void setDisableNonVolatileCR()
Definition: PPCMachineFunctionInfo.h:206
uint32_t
llvm::ISD::ArgFlagsTy
Definition: TargetCallingConv.h:27
llvm::PPCFunctionInfo::getVarArgsStackOffset
int getVarArgsStackOffset() const
Definition: PPCMachineFunctionInfo.h:221
llvm::PPCFunctionInfo::mustSaveTOC
bool mustSaveTOC() const
Definition: PPCMachineFunctionInfo.h:189
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::PPCFunctionInfo::isCRSpilled
bool isCRSpilled() const
Definition: PPCMachineFunctionInfo.h:204
llvm::PPCFunctionInfo::PPCFunctionInfo
PPCFunctionInfo(const MachineFunction &MF)
Definition: PPCMachineFunctionInfo.cpp:23
llvm::PPCFunctionInfo::setBasePointerSaveIndex
void setBasePointerSaveIndex(int Idx)
Definition: PPCMachineFunctionInfo.h:162
llvm::PPCFunctionInfo::FixedType
@ FixedType
Definition: PPCMachineFunctionInfo.h:29
llvm::PPCFunctionInfo::setUsesPICBase
void setUsesPICBase(bool uses)
Definition: PPCMachineFunctionInfo.h:257
llvm::PPCFunctionInfo::getTailCallSPDelta
int getTailCallSPDelta() const
Definition: PPCMachineFunctionInfo.h:177
llvm::PPCFunctionInfo::getVarArgsNumGPR
unsigned getVarArgsNumGPR() const
Definition: PPCMachineFunctionInfo.h:224
llvm::PPCFunctionInfo::hasSpills
bool hasSpills() const
Definition: PPCMachineFunctionInfo.h:198
llvm::PPCFunctionInfo::isLiveInSExt
bool isLiveInSExt(Register VReg) const
This function returns true if the specified vreg is a live-in register and sign-extended.
Definition: PPCMachineFunctionInfo.cpp:54
llvm::PPCFunctionInfo::setMustSaveLR
void setMustSaveLR(bool U)
MustSaveLR - This is set when the prolog/epilog inserter does its initial scan of the function.
Definition: PPCMachineFunctionInfo.h:185
llvm::PPCFunctionInfo::shrinkWrapDisabled
bool shrinkWrapDisabled() const
Definition: PPCMachineFunctionInfo.h:195
llvm::PPCFunctionInfo::isLiveInZExt
bool isLiveInZExt(Register VReg) const
This function returns true if the specified vreg is a live-in register and zero-extended.
Definition: PPCMachineFunctionInfo.cpp:61
SmallVector.h
llvm::PPCFunctionInfo::getMustSaveCRs
const SmallVectorImpl< Register > & getMustSaveCRs() const
Definition: PPCMachineFunctionInfo.h:254
llvm::PPCFunctionInfo::getFramePointerSaveIndex
int getFramePointerSaveIndex() const
Definition: PPCMachineFunctionInfo.h:155
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::PPCFunctionInfo::setLRStoreRequired
void setLRStoreRequired()
Definition: PPCMachineFunctionInfo.h:209
llvm::PPCFunctionInfo::setFramePointerSaveIndex
void setFramePointerSaveIndex(int Idx)
Definition: PPCMachineFunctionInfo.h:156
llvm::PPCFunctionInfo::setVarArgsFrameIndex
void setVarArgsFrameIndex(int Index)
Definition: PPCMachineFunctionInfo.h:219
llvm::PPCFunctionInfo::usesTOCBasePtr
bool usesTOCBasePtr() const
Definition: PPCMachineFunctionInfo.h:213
MachineFunction.h
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition: MachineFunction.h:95
llvm::PPCFunctionInfo::getROPProtectionHashSaveIndex
int getROPProtectionHashSaveIndex() const
Definition: PPCMachineFunctionInfo.h:167
llvm::PPCFunctionInfo::getReturnAddrSaveIndex
int getReturnAddrSaveIndex() const
Definition: PPCMachineFunctionInfo.h:158
llvm::PPCFunctionInfo::setMinReservedArea
void setMinReservedArea(unsigned size)
Definition: PPCMachineFunctionInfo.h:175
llvm::PPCFunctionInfo::setPICBasePointerSaveIndex
void setPICBasePointerSaveIndex(int Idx)
Definition: PPCMachineFunctionInfo.h:165