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