1 //===-- ARMMachineFuctionInfo.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/BitVector.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetRegisterInfo.h"
26 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
27 /// contains private ARM-specific information for each MachineFunction.
28 class ARMFunctionInfo : public MachineFunctionInfo {
29 virtual void anchor();
31 /// isThumb - True if this function is compiled under Thumb mode.
32 /// Used to initialized Align, so must precede it.
35 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
36 /// to determine if function is compiled under Thumb mode, for that use
40 /// StByValParamsPadding - For parameter that is split between
41 /// GPRs and memory; while recovering GPRs part, when
42 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
43 /// we need to insert gap before parameter start address. It allows to
44 /// "attach" GPR-part to the part that was passed via stack.
45 unsigned StByValParamsPadding;
47 /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
49 unsigned ArgRegsSaveSize;
51 /// ReturnRegsCount - Number of registers used up in the return.
52 unsigned ReturnRegsCount;
54 /// HasStackFrame - True if this function has a stack frame. Set by
55 /// processFunctionBeforeCalleeSavedScan().
58 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
62 /// LRSpilledForFarJump - True if the LR register has been for spilled to
64 bool LRSpilledForFarJump;
66 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
67 /// spill stack offset.
68 unsigned FramePtrSpillOffset;
70 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
71 /// register spills areas. For Mac OS X:
73 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
74 /// --------------------------------------------
75 /// GPR callee-saved (2) : r8, r10, r11
76 /// --------------------------------------------
77 /// DPR callee-saved : d8 - d15
79 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
80 /// Some may be spilled after the stack has been realigned.
81 unsigned GPRCS1Offset;
82 unsigned GPRCS2Offset;
85 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
89 unsigned DPRCSAlignGapSize;
92 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
93 /// the aligned portion of the stack frame. This is always a contiguous
94 /// sequence of D-registers starting from d8.
96 /// We do not keep track of the frame indices used for these registers - they
97 /// behave like any other frame index in the aligned stack frame. These
98 /// registers also aren't included in DPRCSSize above.
99 unsigned NumAlignedDPRCS2Regs;
101 /// JumpTableUId - Unique id for jumptables.
103 unsigned JumpTableUId;
105 unsigned PICLabelUId;
107 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
108 int VarArgsFrameIndex;
110 /// HasITBlocks - True if IT blocks have been inserted.
113 /// CPEClones - Track constant pool entries clones created by Constant Island
115 DenseMap<unsigned, unsigned> CPEClones;
117 /// GlobalBaseReg - keeps track of the virtual register initialized for
118 /// use as the global base register. This is used for PIC in some PIC
119 /// relocation models.
120 unsigned GlobalBaseReg;
122 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
123 /// being passed on the stack
124 unsigned ArgumentStackSize;
126 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
127 /// coalesced weights.
128 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
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),
140 JumpTableUId(0), PICLabelUId(0),
141 VarArgsFrameIndex(0), HasITBlocks(false), GlobalBaseReg(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 unsigned createJumpTableUId() {
195 return JumpTableUId++;
198 unsigned getNumJumpTables() const {
202 void initPICLabelUId(unsigned UId) {
206 unsigned getNumPICLabels() const {
210 unsigned createPICLabelUId() {
211 return PICLabelUId++;
214 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
215 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
217 bool hasITBlocks() const { return HasITBlocks; }
218 void setHasITBlocks(bool h) { HasITBlocks = h; }
220 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
221 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
223 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
224 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
225 llvm_unreachable("Duplicate entries!");
228 unsigned getOriginalCPIdx(unsigned CloneIdx) const {
229 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
230 if (I != CPEClones.end())
236 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
237 MachineBasicBlock* MBB) {
238 auto It = CoalescedWeights.find(MBB);
239 if (It == CoalescedWeights.end()) {
240 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
245 } // End llvm namespace