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/IR/GlobalVariable.h"
20 #include "llvm/Support/ErrorHandling.h"
25 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
26 /// contains private ARM-specific information for each MachineFunction.
27 class ARMFunctionInfo
: public MachineFunctionInfo
{
28 virtual void anchor();
30 /// isThumb - True if this function is compiled under Thumb mode.
31 /// Used to initialized Align, so must precede it.
34 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
35 /// to determine if function is compiled under Thumb mode, for that use
37 bool hasThumb2
= false;
39 /// StByValParamsPadding - For parameter that is split between
40 /// GPRs and memory; while recovering GPRs part, when
41 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
42 /// we need to insert gap before parameter start address. It allows to
43 /// "attach" GPR-part to the part that was passed via stack.
44 unsigned StByValParamsPadding
= 0;
46 /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
48 unsigned ArgRegsSaveSize
= 0;
50 /// ReturnRegsCount - Number of registers used up in the return.
51 unsigned ReturnRegsCount
= 0;
53 /// HasStackFrame - True if this function has a stack frame. Set by
54 /// determineCalleeSaves().
55 bool HasStackFrame
= false;
57 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
59 bool RestoreSPFromFP
= false;
61 /// LRSpilledForFarJump - True if the LR register has been for spilled to
63 bool LRSpilledForFarJump
= false;
65 /// LRSpilled - True if the LR register has been for spilled for
66 /// any reason, so it's legal to emit an ARM::tBfar (i.e. "bl").
67 bool LRSpilled
= false;
69 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
70 /// spill stack offset.
71 unsigned FramePtrSpillOffset
= 0;
73 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
74 /// register spills areas. For Mac OS X:
76 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
77 /// --------------------------------------------
78 /// GPR callee-saved (2) : r8, r10, r11
79 /// --------------------------------------------
80 /// DPR callee-saved : d8 - d15
82 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
83 /// Some may be spilled after the stack has been realigned.
84 unsigned GPRCS1Offset
= 0;
85 unsigned GPRCS2Offset
= 0;
86 unsigned DPRCSOffset
= 0;
88 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
90 unsigned GPRCS1Size
= 0;
91 unsigned GPRCS2Size
= 0;
92 unsigned DPRCSAlignGapSize
= 0;
93 unsigned DPRCSSize
= 0;
95 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
96 /// the aligned portion of the stack frame. This is always a contiguous
97 /// sequence of D-registers starting from d8.
99 /// We do not keep track of the frame indices used for these registers - they
100 /// behave like any other frame index in the aligned stack frame. These
101 /// registers also aren't included in DPRCSSize above.
102 unsigned NumAlignedDPRCS2Regs
= 0;
104 unsigned PICLabelUId
= 0;
106 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
107 int VarArgsFrameIndex
= 0;
109 /// HasITBlocks - True if IT blocks have been inserted.
110 bool HasITBlocks
= false;
112 /// CPEClones - Track constant pool entries clones created by Constant Island
114 DenseMap
<unsigned, unsigned> CPEClones
;
116 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
117 /// being passed on the stack
118 unsigned ArgumentStackSize
= 0;
120 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
121 /// coalesced weights.
122 DenseMap
<const MachineBasicBlock
*, unsigned> CoalescedWeights
;
124 /// True if this function has a subset of CSRs that is handled explicitly via
126 bool IsSplitCSR
= false;
128 /// Globals that have had their storage promoted into the constant pool.
129 SmallPtrSet
<const GlobalVariable
*,2> PromotedGlobals
;
131 /// The amount the literal pool has been increasedby due to promoted globals.
132 int PromotedGlobalsIncrease
= 0;
134 /// True if r0 will be preserved by a call to this function (e.g. C++
135 /// con/destructors).
136 bool PreservesR0
= false;
139 ARMFunctionInfo() = default;
141 explicit ARMFunctionInfo(MachineFunction
&MF
);
143 bool isThumbFunction() const { return isThumb
; }
144 bool isThumb1OnlyFunction() const { return isThumb
&& !hasThumb2
; }
145 bool isThumb2Function() const { return isThumb
&& hasThumb2
; }
147 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding
; }
148 void setStoredByValParamsPadding(unsigned p
) { StByValParamsPadding
= p
; }
150 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize
; }
151 void setArgRegsSaveSize(unsigned s
) { ArgRegsSaveSize
= s
; }
153 unsigned getReturnRegsCount() const { return ReturnRegsCount
; }
154 void setReturnRegsCount(unsigned s
) { ReturnRegsCount
= s
; }
156 bool hasStackFrame() const { return HasStackFrame
; }
157 void setHasStackFrame(bool s
) { HasStackFrame
= s
; }
159 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP
; }
160 void setShouldRestoreSPFromFP(bool s
) { RestoreSPFromFP
= s
; }
162 bool isLRSpilled() const { return LRSpilled
; }
163 void setLRIsSpilled(bool s
) { LRSpilled
= s
; }
165 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump
; }
166 void setLRIsSpilledForFarJump(bool s
) { LRSpilledForFarJump
= s
; }
168 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset
; }
169 void setFramePtrSpillOffset(unsigned o
) { FramePtrSpillOffset
= o
; }
171 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs
; }
172 void setNumAlignedDPRCS2Regs(unsigned n
) { NumAlignedDPRCS2Regs
= n
; }
174 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset
; }
175 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset
; }
176 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset
; }
178 void setGPRCalleeSavedArea1Offset(unsigned o
) { GPRCS1Offset
= o
; }
179 void setGPRCalleeSavedArea2Offset(unsigned o
) { GPRCS2Offset
= o
; }
180 void setDPRCalleeSavedAreaOffset(unsigned o
) { DPRCSOffset
= o
; }
182 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size
; }
183 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size
; }
184 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize
; }
185 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize
; }
187 void setGPRCalleeSavedArea1Size(unsigned s
) { GPRCS1Size
= s
; }
188 void setGPRCalleeSavedArea2Size(unsigned s
) { GPRCS2Size
= s
; }
189 void setDPRCalleeSavedGapSize(unsigned s
) { DPRCSAlignGapSize
= s
; }
190 void setDPRCalleeSavedAreaSize(unsigned s
) { DPRCSSize
= s
; }
192 unsigned getArgumentStackSize() const { return ArgumentStackSize
; }
193 void setArgumentStackSize(unsigned size
) { ArgumentStackSize
= size
; }
195 void initPICLabelUId(unsigned UId
) {
199 unsigned getNumPICLabels() const {
203 unsigned createPICLabelUId() {
204 return PICLabelUId
++;
207 int getVarArgsFrameIndex() const { return VarArgsFrameIndex
; }
208 void setVarArgsFrameIndex(int Index
) { VarArgsFrameIndex
= Index
; }
210 bool hasITBlocks() const { return HasITBlocks
; }
211 void setHasITBlocks(bool h
) { HasITBlocks
= h
; }
213 bool isSplitCSR() const { return IsSplitCSR
; }
214 void setIsSplitCSR(bool s
) { IsSplitCSR
= s
; }
216 void recordCPEClone(unsigned CPIdx
, unsigned CPCloneIdx
) {
217 if (!CPEClones
.insert(std::make_pair(CPCloneIdx
, CPIdx
)).second
)
218 llvm_unreachable("Duplicate entries!");
221 unsigned getOriginalCPIdx(unsigned CloneIdx
) const {
222 DenseMap
<unsigned, unsigned>::const_iterator I
= CPEClones
.find(CloneIdx
);
223 if (I
!= CPEClones
.end())
229 DenseMap
<const MachineBasicBlock
*, unsigned>::iterator
getCoalescedWeight(
230 MachineBasicBlock
* MBB
) {
231 auto It
= CoalescedWeights
.find(MBB
);
232 if (It
== CoalescedWeights
.end()) {
233 It
= CoalescedWeights
.insert(std::make_pair(MBB
, 0)).first
;
238 /// Indicate to the backend that \c GV has had its storage changed to inside
239 /// a constant pool. This means it no longer needs to be emitted as a
241 void markGlobalAsPromotedToConstantPool(const GlobalVariable
*GV
) {
242 PromotedGlobals
.insert(GV
);
244 SmallPtrSet
<const GlobalVariable
*, 2>& getGlobalsPromotedToConstantPool() {
245 return PromotedGlobals
;
247 int getPromotedConstpoolIncrease() const {
248 return PromotedGlobalsIncrease
;
250 void setPromotedConstpoolIncrease(int Sz
) {
251 PromotedGlobalsIncrease
= Sz
;
254 DenseMap
<unsigned, unsigned> EHPrologueRemappedRegs
;
256 void setPreservesR0() { PreservesR0
= true; }
257 bool getPreservesR0() const { return PreservesR0
; }
260 } // end namespace llvm
262 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H