d3fabc3ebb0401e4e0648eed19a3fff9fdc8bee6
[oota-llvm.git] / lib / Target / ARM / ARMMachineFunctionInfo.h
1 //===-- ARMMachineFuctionInfo.h - ARM machine function info -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares ARM-specific per-machine-function information.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ARMMACHINEFUNCTIONINFO_H
15 #define ARMMACHINEFUNCTIONINFO_H
16
17 #include "ARMSubtarget.h"
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/Target/TargetRegisterInfo.h"
22 #include "llvm/ADT/DenseMap.h"
23
24 namespace llvm {
25
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();
30
31   /// isThumb - True if this function is compiled under Thumb mode.
32   /// Used to initialized Align, so must precede it.
33   bool isThumb;
34
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
37   /// 'isThumb'.
38   bool hasThumb2;
39
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;
46
47   /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
48   ///
49   unsigned ArgRegsSaveSize;
50
51   /// HasStackFrame - True if this function has a stack frame. Set by
52   /// processFunctionBeforeCalleeSavedScan().
53   bool HasStackFrame;
54
55   /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
56   /// emitPrologue.
57   bool RestoreSPFromFP;
58
59   /// LRSpilledForFarJump - True if the LR register has been for spilled to
60   /// enable far jump.
61   bool LRSpilledForFarJump;
62
63   /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
64   /// spill stack offset.
65   unsigned FramePtrSpillOffset;
66
67   /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
68   /// register spills areas. For Mac OS X:
69   ///
70   /// GPR callee-saved (1) : r4, r5, r6, r7, lr
71   /// --------------------------------------------
72   /// GPR callee-saved (2) : r8, r10, r11
73   /// --------------------------------------------
74   /// DPR callee-saved : d8 - d15
75   ///
76   /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
77   /// Some may be spilled after the stack has been realigned.
78   unsigned GPRCS1Offset;
79   unsigned GPRCS2Offset;
80   unsigned DPRCSOffset;
81
82   /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
83   /// areas.
84   unsigned GPRCS1Size;
85   unsigned GPRCS2Size;
86   unsigned DPRCSSize;
87
88   /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
89   /// the aligned portion of the stack frame.  This is always a contiguous
90   /// sequence of D-registers starting from d8.
91   ///
92   /// We do not keep track of the frame indices used for these registers - they
93   /// behave like any other frame index in the aligned stack frame.  These
94   /// registers also aren't included in DPRCSSize above.
95   unsigned NumAlignedDPRCS2Regs;
96
97   /// JumpTableUId - Unique id for jumptables.
98   ///
99   unsigned JumpTableUId;
100
101   unsigned PICLabelUId;
102
103   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
104   int VarArgsFrameIndex;
105
106   /// HasITBlocks - True if IT blocks have been inserted.
107   bool HasITBlocks;
108
109   /// CPEClones - Track constant pool entries clones created by Constant Island
110   /// pass.
111   DenseMap<unsigned, unsigned> CPEClones;
112
113   /// GlobalBaseReg - keeps track of the virtual register initialized for
114   /// use as the global base register. This is used for PIC in some PIC
115   /// relocation models.
116   unsigned GlobalBaseReg;
117
118   /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
119   /// being passed on the stack
120   unsigned ArgumentStackSize;
121
122   /// CoalescedWeights - mapping of basic blocks to the rolling counter of
123   /// coalesced weights.
124   DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
125
126 public:
127   ARMFunctionInfo() :
128     isThumb(false),
129     hasThumb2(false),
130     ArgRegsSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
131     LRSpilledForFarJump(false),
132     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
133     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
134     NumAlignedDPRCS2Regs(0),
135     JumpTableUId(0), PICLabelUId(0),
136     VarArgsFrameIndex(0), HasITBlocks(false), GlobalBaseReg(0) {}
137
138   explicit ARMFunctionInfo(MachineFunction &MF);
139
140   bool isThumbFunction() const { return isThumb; }
141   bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
142   bool isThumb2Function() const { return isThumb && hasThumb2; }
143
144   unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
145   void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
146
147   unsigned getArgRegsSaveSize(unsigned Align = 0) const {
148     if (!Align)
149       return ArgRegsSaveSize;
150     return (ArgRegsSaveSize + Align - 1) & ~(Align - 1);
151   }
152   void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
153
154   bool hasStackFrame() const { return HasStackFrame; }
155   void setHasStackFrame(bool s) { HasStackFrame = s; }
156
157   bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
158   void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
159
160   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
161   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
162
163   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
164   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
165
166   unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
167   void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
168
169   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
170   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
171   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
172
173   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
174   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
175   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
176
177   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
178   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
179   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
180
181   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
182   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
183   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
184
185   unsigned getArgumentStackSize() const { return ArgumentStackSize; }
186   void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
187
188   unsigned createJumpTableUId() {
189     return JumpTableUId++;
190   }
191
192   unsigned getNumJumpTables() const {
193     return JumpTableUId;
194   }
195
196   void initPICLabelUId(unsigned UId) {
197     PICLabelUId = UId;
198   }
199
200   unsigned getNumPICLabels() const {
201     return PICLabelUId;
202   }
203
204   unsigned createPICLabelUId() {
205     return PICLabelUId++;
206   }
207
208   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
209   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
210
211   bool hasITBlocks() const { return HasITBlocks; }
212   void setHasITBlocks(bool h) { HasITBlocks = h; }
213
214   unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
215   void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
216
217   void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
218     if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
219       llvm_unreachable("Duplicate entries!");
220   }
221
222   unsigned getOriginalCPIdx(unsigned CloneIdx) const {
223     DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
224     if (I != CPEClones.end())
225       return I->second;
226     else
227       return -1U;
228   }
229
230   DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
231                                                   MachineBasicBlock* MBB) {
232     auto It = CoalescedWeights.find(MBB);
233     if (It == CoalescedWeights.end()) {
234       It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
235     }
236     return It;
237   }
238 };
239 } // End llvm namespace
240
241 #endif // ARMMACHINEFUNCTIONINFO_H