5adb68992cb8ab4a8530dc80b16a4a035af638c6
[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   /// ReturnRegsCount - Number of registers used up in the return.
52   unsigned ReturnRegsCount;
53
54   /// HasStackFrame - True if this function has a stack frame. Set by
55   /// processFunctionBeforeCalleeSavedScan().
56   bool HasStackFrame;
57
58   /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
59   /// emitPrologue.
60   bool RestoreSPFromFP;
61
62   /// LRSpilledForFarJump - True if the LR register has been for spilled to
63   /// enable far jump.
64   bool LRSpilledForFarJump;
65
66   /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
67   /// spill stack offset.
68   unsigned FramePtrSpillOffset;
69
70   /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
71   /// register spills areas. For Mac OS X:
72   ///
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
78   ///
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;
83   unsigned DPRCSOffset;
84
85   /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
86   /// areas.
87   unsigned GPRCS1Size;
88   unsigned GPRCS2Size;
89   unsigned DPRCSSize;
90
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.
94   ///
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;
99
100   /// JumpTableUId - Unique id for jumptables.
101   ///
102   unsigned JumpTableUId;
103
104   unsigned PICLabelUId;
105
106   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
107   int VarArgsFrameIndex;
108
109   /// HasITBlocks - True if IT blocks have been inserted.
110   bool HasITBlocks;
111
112   /// CPEClones - Track constant pool entries clones created by Constant Island
113   /// pass.
114   DenseMap<unsigned, unsigned> CPEClones;
115
116   /// GlobalBaseReg - keeps track of the virtual register initialized for
117   /// use as the global base register. This is used for PIC in some PIC
118   /// relocation models.
119   unsigned GlobalBaseReg;
120
121   /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
122   /// being passed on the stack
123   unsigned ArgumentStackSize;
124
125   /// CoalescedWeights - mapping of basic blocks to the rolling counter of
126   /// coalesced weights.
127   DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
128
129 public:
130   ARMFunctionInfo() :
131     isThumb(false),
132     hasThumb2(false),
133     ArgRegsSaveSize(0), ReturnRegsCount(0), HasStackFrame(false),
134     RestoreSPFromFP(false),
135     LRSpilledForFarJump(false),
136     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
137     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
138     NumAlignedDPRCS2Regs(0),
139     JumpTableUId(0), PICLabelUId(0),
140     VarArgsFrameIndex(0), HasITBlocks(false), GlobalBaseReg(0) {}
141
142   explicit ARMFunctionInfo(MachineFunction &MF);
143
144   bool isThumbFunction() const { return isThumb; }
145   bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
146   bool isThumb2Function() const { return isThumb && hasThumb2; }
147
148   unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
149   void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
150
151   unsigned getArgRegsSaveSize(unsigned Align = 0) const {
152     if (!Align)
153       return ArgRegsSaveSize;
154     return (ArgRegsSaveSize + Align - 1) & ~(Align - 1);
155   }
156   void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
157
158   unsigned getReturnRegsCount() const { return ReturnRegsCount; }
159   void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
160
161   bool hasStackFrame() const { return HasStackFrame; }
162   void setHasStackFrame(bool s) { HasStackFrame = s; }
163
164   bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
165   void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
166
167   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
168   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
169
170   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
171   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
172
173   unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
174   void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
175
176   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
177   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
178   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
179
180   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
181   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
182   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
183
184   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
185   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
186   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
187
188   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
189   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
190   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
191
192   unsigned getArgumentStackSize() const { return ArgumentStackSize; }
193   void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
194
195   unsigned createJumpTableUId() {
196     return JumpTableUId++;
197   }
198
199   unsigned getNumJumpTables() const {
200     return JumpTableUId;
201   }
202
203   void initPICLabelUId(unsigned UId) {
204     PICLabelUId = UId;
205   }
206
207   unsigned getNumPICLabels() const {
208     return PICLabelUId;
209   }
210
211   unsigned createPICLabelUId() {
212     return PICLabelUId++;
213   }
214
215   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
216   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
217
218   bool hasITBlocks() const { return HasITBlocks; }
219   void setHasITBlocks(bool h) { HasITBlocks = h; }
220
221   unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
222   void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
223
224   void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
225     if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
226       llvm_unreachable("Duplicate entries!");
227   }
228
229   unsigned getOriginalCPIdx(unsigned CloneIdx) const {
230     DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
231     if (I != CPEClones.end())
232       return I->second;
233     else
234       return -1U;
235   }
236
237   DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
238                                                   MachineBasicBlock* MBB) {
239     auto It = CoalescedWeights.find(MBB);
240     if (It == CoalescedWeights.end()) {
241       It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
242     }
243     return It;
244   }
245 };
246 } // End llvm namespace
247
248 #endif // ARMMACHINEFUNCTIONINFO_H