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;
133 /// True if r0 will be preserved by a call to this function (e.g. C++
134 /// con/destructors).
135 bool PreservesR0
= false;
138 ARMFunctionInfo() = default;
140 explicit ARMFunctionInfo(MachineFunction
&MF
);
142 bool isThumbFunction() const { return isThumb
; }
143 bool isThumb1OnlyFunction() const { return isThumb
&& !hasThumb2
; }
144 bool isThumb2Function() const { return isThumb
&& hasThumb2
; }
146 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding
; }
147 void setStoredByValParamsPadding(unsigned p
) { StByValParamsPadding
= p
; }
149 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize
; }
150 void setArgRegsSaveSize(unsigned s
) { ArgRegsSaveSize
= s
; }
152 unsigned getReturnRegsCount() const { return ReturnRegsCount
; }
153 void setReturnRegsCount(unsigned s
) { ReturnRegsCount
= s
; }
155 bool hasStackFrame() const { return HasStackFrame
; }
156 void setHasStackFrame(bool s
) { HasStackFrame
= s
; }
158 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP
; }
159 void setShouldRestoreSPFromFP(bool s
) { RestoreSPFromFP
= s
; }
161 bool isLRSpilled() const { return LRSpilled
; }
162 void setLRIsSpilled(bool s
) { LRSpilled
= s
; }
164 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump
; }
165 void setLRIsSpilledForFarJump(bool s
) { LRSpilledForFarJump
= s
; }
167 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset
; }
168 void setFramePtrSpillOffset(unsigned o
) { FramePtrSpillOffset
= o
; }
170 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs
; }
171 void setNumAlignedDPRCS2Regs(unsigned n
) { NumAlignedDPRCS2Regs
= n
; }
173 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset
; }
174 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset
; }
175 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset
; }
177 void setGPRCalleeSavedArea1Offset(unsigned o
) { GPRCS1Offset
= o
; }
178 void setGPRCalleeSavedArea2Offset(unsigned o
) { GPRCS2Offset
= o
; }
179 void setDPRCalleeSavedAreaOffset(unsigned o
) { DPRCSOffset
= o
; }
181 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size
; }
182 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size
; }
183 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize
; }
184 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize
; }
186 void setGPRCalleeSavedArea1Size(unsigned s
) { GPRCS1Size
= s
; }
187 void setGPRCalleeSavedArea2Size(unsigned s
) { GPRCS2Size
= s
; }
188 void setDPRCalleeSavedGapSize(unsigned s
) { DPRCSAlignGapSize
= s
; }
189 void setDPRCalleeSavedAreaSize(unsigned s
) { DPRCSSize
= s
; }
191 unsigned getArgumentStackSize() const { return ArgumentStackSize
; }
192 void setArgumentStackSize(unsigned size
) { ArgumentStackSize
= size
; }
194 void initPICLabelUId(unsigned UId
) {
198 unsigned getNumPICLabels() const {
202 unsigned createPICLabelUId() {
203 return PICLabelUId
++;
206 int getVarArgsFrameIndex() const { return VarArgsFrameIndex
; }
207 void setVarArgsFrameIndex(int Index
) { VarArgsFrameIndex
= Index
; }
209 bool hasITBlocks() const { return HasITBlocks
; }
210 void setHasITBlocks(bool h
) { HasITBlocks
= h
; }
212 bool isSplitCSR() const { return IsSplitCSR
; }
213 void setIsSplitCSR(bool s
) { IsSplitCSR
= s
; }
215 void recordCPEClone(unsigned CPIdx
, unsigned CPCloneIdx
) {
216 if (!CPEClones
.insert(std::make_pair(CPCloneIdx
, CPIdx
)).second
)
217 llvm_unreachable("Duplicate entries!");
220 unsigned getOriginalCPIdx(unsigned CloneIdx
) const {
221 DenseMap
<unsigned, unsigned>::const_iterator I
= CPEClones
.find(CloneIdx
);
222 if (I
!= CPEClones
.end())
228 DenseMap
<const MachineBasicBlock
*, unsigned>::iterator
getCoalescedWeight(
229 MachineBasicBlock
* MBB
) {
230 auto It
= CoalescedWeights
.find(MBB
);
231 if (It
== CoalescedWeights
.end()) {
232 It
= CoalescedWeights
.insert(std::make_pair(MBB
, 0)).first
;
237 /// Indicate to the backend that \c GV has had its storage changed to inside
238 /// a constant pool. This means it no longer needs to be emitted as a
240 void markGlobalAsPromotedToConstantPool(const GlobalVariable
*GV
) {
241 PromotedGlobals
.insert(GV
);
243 SmallPtrSet
<const GlobalVariable
*, 2>& getGlobalsPromotedToConstantPool() {
244 return PromotedGlobals
;
246 int getPromotedConstpoolIncrease() const {
247 return PromotedGlobalsIncrease
;
249 void setPromotedConstpoolIncrease(int Sz
) {
250 PromotedGlobalsIncrease
= Sz
;
253 DenseMap
<unsigned, unsigned> EHPrologueRemappedRegs
;
255 void setPreservesR0() { PreservesR0
= true; }
256 bool getPreservesR0() const { return PreservesR0
; }
259 } // end namespace llvm
261 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H