1 //===-- ARMMachineFunctionInfo.h - ARM machine function info ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares ARM-specific per-machine-function information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
15 #define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
17 #include "ARMSubtarget.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/Target/TargetRegisterInfo.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
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;
46 /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
48 unsigned ArgRegsSaveSize;
50 /// ReturnRegsCount - Number of registers used up in the return.
51 unsigned ReturnRegsCount;
53 /// HasStackFrame - True if this function has a stack frame. Set by
54 /// determineCalleeSaves().
57 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
61 /// LRSpilledForFarJump - True if the LR register has been for spilled to
63 bool LRSpilledForFarJump;
65 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
66 /// spill stack offset.
67 unsigned FramePtrSpillOffset;
69 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
70 /// register spills areas. For Mac OS X:
72 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
73 /// --------------------------------------------
74 /// GPR callee-saved (2) : r8, r10, r11
75 /// --------------------------------------------
76 /// DPR callee-saved : d8 - d15
78 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
79 /// Some may be spilled after the stack has been realigned.
80 unsigned GPRCS1Offset;
81 unsigned GPRCS2Offset;
84 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
88 unsigned DPRCSAlignGapSize;
91 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
92 /// the aligned portion of the stack frame. This is always a contiguous
93 /// sequence of D-registers starting from d8.
95 /// We do not keep track of the frame indices used for these registers - they
96 /// behave like any other frame index in the aligned stack frame. These
97 /// registers also aren't included in DPRCSSize above.
98 unsigned NumAlignedDPRCS2Regs;
100 unsigned PICLabelUId;
102 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
103 int VarArgsFrameIndex;
105 /// HasITBlocks - True if IT blocks have been inserted.
108 /// CPEClones - Track constant pool entries clones created by Constant Island
110 DenseMap<unsigned, unsigned> CPEClones;
112 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
113 /// being passed on the stack
114 unsigned ArgumentStackSize;
116 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
117 /// coalesced weights.
118 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
120 /// True if this function has a subset of CSRs that is handled explicitly via
124 /// Globals that have had their storage promoted into the constant pool.
125 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
127 /// The amount the literal pool has been increasedby due to promoted globals.
128 int PromotedGlobalsIncrease;
134 ArgRegsSaveSize(0), ReturnRegsCount(0), HasStackFrame(false),
135 RestoreSPFromFP(false),
136 LRSpilledForFarJump(false),
137 FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
138 GPRCS1Size(0), GPRCS2Size(0), DPRCSAlignGapSize(0), DPRCSSize(0),
139 NumAlignedDPRCS2Regs(0), PICLabelUId(0),
140 VarArgsFrameIndex(0), HasITBlocks(false), IsSplitCSR(false),
141 PromotedGlobalsIncrease(0) {}
143 explicit ARMFunctionInfo(MachineFunction &MF);
145 bool isThumbFunction() const { return isThumb; }
146 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
147 bool isThumb2Function() const { return isThumb && hasThumb2; }
149 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
150 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
152 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
153 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
155 unsigned getReturnRegsCount() const { return ReturnRegsCount; }
156 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
158 bool hasStackFrame() const { return HasStackFrame; }
159 void setHasStackFrame(bool s) { HasStackFrame = s; }
161 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
162 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = 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 } // End llvm namespace