LLVM 24.0.0git
ARMMachineFunctionInfo.h
Go to the documentation of this file.
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
13#ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
14#define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
15
16#include "llvm/ADT/DenseMap.h"
24
25namespace llvm {
26
27namespace yaml {
28struct ARMFunctionInfo;
29} // end namespace yaml
30
31class ARMSubtarget;
32
33/// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
34/// contains private ARM-specific information for each MachineFunction.
36 virtual void anchor();
37
38 /// isThumb - True if this function is compiled under Thumb mode.
39 /// Used to initialized Align, so must precede it.
40 bool isThumb = false;
41
42 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
43 /// to determine if function is compiled under Thumb mode, for that use
44 /// 'isThumb'.
45 bool hasThumb2 = false;
46
47 /// ArgsRegSaveSize - Size of the register save area for vararg functions or
48 /// those making guaranteed tail calls that need more stack argument space
49 /// than is provided by this functions incoming parameters.
50 ///
51 unsigned ArgRegsSaveSize = 0;
52
53 /// ReturnRegsCount - Number of registers used up in the return.
54 unsigned ReturnRegsCount = 0;
55
56 /// HasStackFrame - True if this function has a stack frame. Set by
57 /// determineCalleeSaves().
58 bool HasStackFrame = false;
59
60 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
61 /// emitPrologue.
62 bool RestoreSPFromFP = false;
63
64 /// LRSpilled - True if the LR register has been for spilled for
65 /// any reason, so it's legal to emit an ARM::tBfar (i.e. "bl").
66 bool LRSpilled = false;
67
68 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
69 /// spill stack offset.
70 unsigned FramePtrSpillOffset = 0;
71
72 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
73 /// register spills areas. For Mac OS X:
74 ///
75 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
76 /// --------------------------------------------
77 /// GPR callee-saved (2) : r8, r10, r11
78 /// --------------------------------------------
79 /// DPR callee-saved : d8 - d15
80 ///
81 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
82 /// Some may be spilled after the stack has been realigned.
83 unsigned GPRCS1Offset = 0;
84 unsigned GPRCS2Offset = 0;
85 unsigned DPRCS1Offset = 0;
86
87 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
88 /// areas.
89 unsigned FPCXTSaveSize = 0;
90 unsigned FRSaveSize = 0;
91 unsigned GPRCS1Size = 0;
92 unsigned GPRCS2Size = 0;
93 unsigned FPStatusSize = 0;
94 unsigned DPRCSAlignGapSize = 0;
95 unsigned DPRCS1Size = 0;
96 unsigned GPRCS3Size = 0;
97
98 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
99 /// the aligned portion of the stack frame. This is always a contiguous
100 /// sequence of D-registers starting from d8.
101 ///
102 /// We do not keep track of the frame indices used for these registers - they
103 /// behave like any other frame index in the aligned stack frame. These
104 /// registers also aren't included in DPRCSSize above.
105 unsigned NumAlignedDPRCS2Regs = 0;
106
107 unsigned PICLabelUId = 0;
108
109 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
110 int VarArgsFrameIndex = 0;
111
112 /// ForwardedMustTailRegParms - A list of virtual and physical registers that
113 /// must be forwarded to every musttail call.
114 SmallVector<ForwardedRegister, 4> ForwardedMustTailRegParms;
115
116 /// HasITBlocks - True if IT blocks have been inserted.
117 bool HasITBlocks = false;
118
119 // Security Extensions
120 bool IsCmseNSEntry;
121 bool IsCmseNSCall;
122
123 /// CPEClones - Track constant pool entries clones created by Constant Island
124 /// pass.
126
127 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
128 /// being passed on the stack
129 unsigned ArgumentStackSize = 0;
130
131 /// ArgumentStackToRestore - amount of bytes on stack consumed that we must
132 /// restore on return.
133 unsigned ArgumentStackToRestore = 0;
134
135 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
136 /// coalesced weights.
138
139 /// True if this function has a subset of CSRs that is handled explicitly via
140 /// copies.
141 bool IsSplitCSR = false;
142
143 /// Globals that have had their storage promoted into the constant pool.
145
146 /// The amount the literal pool has been increasedby due to promoted globals.
147 int PromotedGlobalsIncrease = 0;
148
149 /// True if r0 will be preserved by a call to this function (e.g. C++
150 /// con/destructors).
151 bool PreservesR0 = false;
152
153 /// True if the function should sign its return address.
154 bool SignReturnAddress = false;
155
156 /// True if the fucntion should sign its return address, even if LR is not
157 /// saved.
158 bool SignReturnAddressAll = false;
159
160 /// True if BTI instructions should be placed at potential indirect jump
161 /// destinations.
162 bool BranchTargetEnforcement = false;
163
164 /// The result of EstimateFunctionSizeInBytes, if that was run during frame
165 /// lowering. Used to check later that the estimate was conservative.
166 std::optional<unsigned> EstimatedFunctionSizeInBytes;
167
168public:
169 ARMFunctionInfo() = default;
170
171 explicit ARMFunctionInfo(const Function &F, const ARMSubtarget *STI);
172
176 const override;
177
178 bool isThumbFunction() const { return isThumb; }
179 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
180 bool isThumb2Function() const { return isThumb && hasThumb2; }
181
182 bool isCmseNSEntryFunction() const { return IsCmseNSEntry; }
183 bool isCmseNSCallFunction() const { return IsCmseNSCall; }
184
185 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
186 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
187
188 unsigned getReturnRegsCount() const { return ReturnRegsCount; }
189 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
190
191 bool hasStackFrame() const { return HasStackFrame; }
192 void setHasStackFrame(bool s) { HasStackFrame = s; }
193
194 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
195 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
196
197 bool isLRSpilled() const { return LRSpilled; }
198 void setLRIsSpilled(bool s) { LRSpilled = s; }
199
200 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
201 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
202
203 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
204 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
205
206 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
207 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
208 unsigned getDPRCalleeSavedArea1Offset() const { return DPRCS1Offset; }
209
210 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
211 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
212 void setDPRCalleeSavedArea1Offset(unsigned o) { DPRCS1Offset = o; }
213
214 unsigned getFPCXTSaveAreaSize() const { return FPCXTSaveSize; }
215 unsigned getFrameRecordSavedAreaSize() const { return FRSaveSize; }
216 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
217 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
218 unsigned getFPStatusSavesSize() const { return FPStatusSize; }
219 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
220 unsigned getDPRCalleeSavedArea1Size() const { return DPRCS1Size; }
221 unsigned getGPRCalleeSavedArea3Size() const { return GPRCS3Size; }
222
223 void setFPCXTSaveAreaSize(unsigned s) { FPCXTSaveSize = s; }
224 void setFrameRecordSavedAreaSize(unsigned s) { FRSaveSize = s; }
225 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
226 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
227 void setFPStatusSavesSize(unsigned s) { FPStatusSize = s; }
228 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
229 void setDPRCalleeSavedArea1Size(unsigned s) { DPRCS1Size = s; }
230 void setGPRCalleeSavedArea3Size(unsigned s) { GPRCS3Size = s; }
231
232 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
233 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
234
235 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
236 void setArgumentStackToRestore(unsigned v) { ArgumentStackToRestore = v; }
237
238 std::optional<unsigned> getEstimatedFunctionSizeInBytes() const {
239 return EstimatedFunctionSizeInBytes;
240 }
242 EstimatedFunctionSizeInBytes = v;
243 }
244
245 void initPICLabelUId(unsigned UId) {
246 PICLabelUId = UId;
247 }
248
249 unsigned getNumPICLabels() const {
250 return PICLabelUId;
251 }
252
253 unsigned createPICLabelUId() {
254 return PICLabelUId++;
255 }
256
257 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
258 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
259
261 return ForwardedMustTailRegParms;
262 }
263
264 bool hasITBlocks() const { return HasITBlocks; }
265 void setHasITBlocks(bool h) { HasITBlocks = h; }
266
267 bool isSplitCSR() const { return IsSplitCSR; }
268 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
269
270 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
271 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
272 llvm_unreachable("Duplicate entries!");
273 }
274
275 unsigned getOriginalCPIdx(unsigned CloneIdx) const {
276 auto I = CPEClones.find(CloneIdx);
277 if (I != CPEClones.end())
278 return I->second;
279 else
280 return -1U;
281 }
282
285 return CoalescedWeights.try_emplace(MBB, 0).first;
286 }
287
288 /// Indicate to the backend that \c GV has had its storage changed to inside
289 /// a constant pool. This means it no longer needs to be emitted as a
290 /// global variable.
292 PromotedGlobals.insert(GV);
293 }
298 return PromotedGlobalsIncrease;
299 }
301 PromotedGlobalsIncrease = Sz;
302 }
303
306
307 void setPreservesR0() { PreservesR0 = true; }
308 bool getPreservesR0() const { return PreservesR0; }
309
311 return shouldSignReturnAddress(LRSpilled);
312 }
313
314 bool shouldSignReturnAddress(bool SpillsLR) const {
315 if (!SignReturnAddress)
316 return false;
317 if (SignReturnAddressAll)
318 return true;
319 return SpillsLR;
320 }
321
322 bool branchTargetEnforcement() const { return BranchTargetEnforcement; }
323
325};
326
327namespace yaml {
330
331 ARMFunctionInfo() = default;
333
334 void mappingImpl(yaml::IO &YamlIO) override;
335 ~ARMFunctionInfo() override = default;
336};
337
338template <> struct MappingTraits<ARMFunctionInfo> {
339 static void mapping(IO &YamlIO, ARMFunctionInfo &MFI) {
340 YamlIO.mapOptional("isLRSpilled", MFI.LRSpilled);
341 }
342};
343
344} // end namespace yaml
345
346} // end namespace llvm
347
348#endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
MachineBasicBlock & MBB
This file defines the DenseMap class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Basic Register Allocator
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
unsigned getDPRCalleeSavedArea1Offset() const
void initPICLabelUId(unsigned UId)
unsigned getFPCXTSaveAreaSize() const
unsigned getGPRCalleeSavedArea2Offset() const
SmallVectorImpl< ForwardedRegister > & getForwardedMustTailRegParms()
unsigned getGPRCalleeSavedArea1Size() const
SmallPtrSet< const GlobalVariable *, 2 > & getGlobalsPromotedToConstantPool()
void setArgumentStackToRestore(unsigned v)
unsigned getDPRCalleeSavedGapSize() const
unsigned getDPRCalleeSavedArea1Size() const
void setDPRCalleeSavedArea1Offset(unsigned o)
unsigned getGPRCalleeSavedArea1Offset() const
void setGPRCalleeSavedArea2Size(unsigned s)
bool shouldSignReturnAddress(bool SpillsLR) const
DenseMap< unsigned, unsigned > EHPrologueRemappedRegs
void setFramePtrSpillOffset(unsigned o)
void setArgRegsSaveSize(unsigned s)
std::optional< unsigned > getEstimatedFunctionSizeInBytes() const
unsigned getGPRCalleeSavedArea2Size() const
unsigned getNumAlignedDPRCS2Regs() const
void setGPRCalleeSavedArea1Size(unsigned s)
unsigned getArgumentStackToRestore() const
void setFPCXTSaveAreaSize(unsigned s)
unsigned getGPRCalleeSavedArea3Size() const
unsigned getFramePtrSpillOffset() const
void setReturnRegsCount(unsigned s)
DenseMap< unsigned, unsigned > EHPrologueOffsetInRegs
unsigned getOriginalCPIdx(unsigned CloneIdx) const
void setFrameRecordSavedAreaSize(unsigned s)
unsigned getArgRegsSaveSize() const
void setEstimatedFunctionSizeInBytes(unsigned v)
void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx)
void initializeBaseYamlFields(const yaml::ARMFunctionInfo &YamlMFI)
void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV)
Indicate to the backend that GV has had its storage changed to inside a constant pool.
void setGPRCalleeSavedArea2Offset(unsigned o)
unsigned getFrameRecordSavedAreaSize() const
DenseMap< constMachineBasicBlock *, unsigned >::iterator getCoalescedWeight(MachineBasicBlock *MBB)
void setGPRCalleeSavedArea1Offset(unsigned o)
void setDPRCalleeSavedArea1Size(unsigned s)
void setDPRCalleeSavedGapSize(unsigned s)
void setArgumentStackSize(unsigned size)
void setFPStatusSavesSize(unsigned s)
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
void setNumAlignedDPRCS2Regs(unsigned n)
unsigned getArgumentStackSize() const
unsigned getReturnRegsCount() const
void setGPRCalleeSavedArea3Size(unsigned s)
unsigned getFPStatusSavesSize() const
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Definition DenseMap.h:678
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
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:1685
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
void mappingImpl(yaml::IO &YamlIO) override
~ARMFunctionInfo() override=default
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
static void mapping(IO &YamlIO, ARMFunctionInfo &MFI)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63