1 //===-- ARMMachineFunctionInfo.h - ARM machine function info ----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares ARM-specific per-machine-function information.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/Support/ErrorHandling.h"
24 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
25 /// contains private ARM-specific information for each MachineFunction.
26 class ARMFunctionInfo : public MachineFunctionInfo {
27 virtual void anchor();
29 /// isThumb - True if this function is compiled under Thumb mode.
30 /// Used to initialized Align, so must precede it.
33 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
34 /// to determine if function is compiled under Thumb mode, for that use
36 bool hasThumb2 = false;
38 /// StByValParamsPadding - For parameter that is split between
39 /// GPRs and memory; while recovering GPRs part, when
40 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
41 /// we need to insert gap before parameter start address. It allows to
42 /// "attach" GPR-part to the part that was passed via stack.
43 unsigned StByValParamsPadding = 0;
45 /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
47 unsigned ArgRegsSaveSize = 0;
49 /// ReturnRegsCount - Number of registers used up in the return.
50 unsigned ReturnRegsCount = 0;
52 /// HasStackFrame - True if this function has a stack frame. Set by
53 /// determineCalleeSaves().
54 bool HasStackFrame = false;
56 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
58 bool RestoreSPFromFP = false;
60 /// LRSpilledForFarJump - True if the LR register has been for spilled to
62 bool LRSpilledForFarJump = false;
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;
68 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
69 /// spill stack offset.
70 unsigned FramePtrSpillOffset = 0;
72 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
73 /// register spills areas. For Mac OS X:
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
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 DPRCSOffset = 0;
87 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
89 unsigned GPRCS1Size = 0;
90 unsigned GPRCS2Size = 0;
91 unsigned DPRCSAlignGapSize = 0;
92 unsigned DPRCSSize = 0;
94 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
95 /// the aligned portion of the stack frame. This is always a contiguous
96 /// sequence of D-registers starting from d8.
98 /// We do not keep track of the frame indices used for these registers - they
99 /// behave like any other frame index in the aligned stack frame. These
100 /// registers also aren't included in DPRCSSize above.
101 unsigned NumAlignedDPRCS2Regs = 0;
103 unsigned PICLabelUId = 0;
105 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
106 int VarArgsFrameIndex = 0;
108 /// HasITBlocks - True if IT blocks have been inserted.
109 bool HasITBlocks = false;
111 /// CPEClones - Track constant pool entries clones created by Constant Island
113 DenseMap<unsigned, unsigned> CPEClones;
115 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
116 /// being passed on the stack
117 unsigned ArgumentStackSize = 0;
119 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
120 /// coalesced weights.
121 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
123 /// True if this function has a subset of CSRs that is handled explicitly via
125 bool IsSplitCSR = false;
127 /// Globals that have had their storage promoted into the constant pool.
128 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
130 /// The amount the literal pool has been increasedby due to promoted globals.
131 int PromotedGlobalsIncrease = 0;
134 ARMFunctionInfo() = default;
136 explicit ARMFunctionInfo(MachineFunction &MF);
138 bool isThumbFunction() const { return isThumb; }
139 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
140 bool isThumb2Function() const { return isThumb && hasThumb2; }
142 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
143 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
145 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
146 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
148 unsigned getReturnRegsCount() const { return ReturnRegsCount; }
149 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
151 bool hasStackFrame() const { return HasStackFrame; }
152 void setHasStackFrame(bool s) { HasStackFrame = s; }
154 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
155 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
157 bool isLRSpilled() const { return LRSpilled; }
158 void setLRIsSpilled(bool s) { LRSpilled = s; }
160 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
161 void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
163 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
164 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
166 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
167 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
169 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
170 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
171 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
173 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
174 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
175 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
177 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
178 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
179 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
180 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
182 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
183 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
184 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
185 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
187 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
188 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
190 void initPICLabelUId(unsigned UId) {
194 unsigned getNumPICLabels() const {
198 unsigned createPICLabelUId() {
199 return PICLabelUId++;
202 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
203 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
205 bool hasITBlocks() const { return HasITBlocks; }
206 void setHasITBlocks(bool h) { HasITBlocks = h; }
208 bool isSplitCSR() const { return IsSplitCSR; }
209 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
211 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
212 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
213 llvm_unreachable("Duplicate entries!");
216 unsigned getOriginalCPIdx(unsigned CloneIdx) const {
217 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
218 if (I != CPEClones.end())
224 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
225 MachineBasicBlock* MBB) {
226 auto It = CoalescedWeights.find(MBB);
227 if (It == CoalescedWeights.end()) {
228 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
233 /// Indicate to the backend that \c GV has had its storage changed to inside
234 /// a constant pool. This means it no longer needs to be emitted as a
236 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) {
237 PromotedGlobals.insert(GV);
239 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() {
240 return PromotedGlobals;
242 int getPromotedConstpoolIncrease() const {
243 return PromotedGlobalsIncrease;
245 void setPromotedConstpoolIncrease(int Sz) {
246 PromotedGlobalsIncrease = Sz;
249 DenseMap<unsigned, unsigned> EHPrologueRemappedRegs;
252 } // end namespace llvm
254 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H