Unweaken vtables as per http://llvm.org/docs/CodingStandards.html#ll_virtual_anch
[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/CodeGen/MachineFunction.h"
19 #include "llvm/Target/TargetRegisterInfo.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/ADT/BitVector.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   /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
40   ///
41   unsigned VarArgsRegSaveSize;
42
43   /// HasStackFrame - True if this function has a stack frame. Set by
44   /// processFunctionBeforeCalleeSavedScan().
45   bool HasStackFrame;
46
47   /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
48   /// emitPrologue.
49   bool RestoreSPFromFP;
50
51   /// LRSpilledForFarJump - True if the LR register has been for spilled to
52   /// enable far jump.
53   bool LRSpilledForFarJump;
54
55   /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
56   /// spill stack offset.
57   unsigned FramePtrSpillOffset;
58
59   /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
60   /// register spills areas. For Mac OS X:
61   ///
62   /// GPR callee-saved (1) : r4, r5, r6, r7, lr
63   /// --------------------------------------------
64   /// GPR callee-saved (2) : r8, r10, r11
65   /// --------------------------------------------
66   /// DPR callee-saved : d8 - d15
67   unsigned GPRCS1Offset;
68   unsigned GPRCS2Offset;
69   unsigned DPRCSOffset;
70
71   /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
72   /// areas.
73   unsigned GPRCS1Size;
74   unsigned GPRCS2Size;
75   unsigned DPRCSSize;
76
77   /// GPRCS1Frames, GPRCS2Frames, DPRCSFrames - Keeps track of frame indices
78   /// which belong to these spill areas.
79   BitVector GPRCS1Frames;
80   BitVector GPRCS2Frames;
81   BitVector DPRCSFrames;
82
83   /// JumpTableUId - Unique id for jumptables.
84   ///
85   unsigned JumpTableUId;
86
87   unsigned PICLabelUId;
88
89   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
90   int VarArgsFrameIndex;
91
92   /// HasITBlocks - True if IT blocks have been inserted.
93   bool HasITBlocks;
94
95   /// CPEClones - Track constant pool entries clones created by Constant Island
96   /// pass.
97   DenseMap<unsigned, unsigned> CPEClones;
98
99 public:
100   ARMFunctionInfo() :
101     isThumb(false),
102     hasThumb2(false),
103     VarArgsRegSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
104     LRSpilledForFarJump(false),
105     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
106     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
107     GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
108     JumpTableUId(0), PICLabelUId(0),
109     VarArgsFrameIndex(0), HasITBlocks(false) {}
110
111   explicit ARMFunctionInfo(MachineFunction &MF) :
112     isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
113     hasThumb2(MF.getTarget().getSubtarget<ARMSubtarget>().hasThumb2()),
114     VarArgsRegSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
115     LRSpilledForFarJump(false),
116     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
117     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
118     GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
119     JumpTableUId(0), PICLabelUId(0),
120     VarArgsFrameIndex(0), HasITBlocks(false) {}
121
122   bool isThumbFunction() const { return isThumb; }
123   bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
124   bool isThumb2Function() const { return isThumb && hasThumb2; }
125
126   unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
127   void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
128
129   bool hasStackFrame() const { return HasStackFrame; }
130   void setHasStackFrame(bool s) { HasStackFrame = s; }
131
132   bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
133   void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
134
135   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
136   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
137
138   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
139   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
140
141   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
142   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
143   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
144
145   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
146   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
147   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
148
149   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
150   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
151   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
152
153   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
154   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
155   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
156
157   bool isGPRCalleeSavedArea1Frame(int fi) const {
158     if (fi < 0 || fi >= (int)GPRCS1Frames.size())
159       return false;
160     return GPRCS1Frames[fi];
161   }
162   bool isGPRCalleeSavedArea2Frame(int fi) const {
163     if (fi < 0 || fi >= (int)GPRCS2Frames.size())
164       return false;
165     return GPRCS2Frames[fi];
166   }
167   bool isDPRCalleeSavedAreaFrame(int fi) const {
168     if (fi < 0 || fi >= (int)DPRCSFrames.size())
169       return false;
170     return DPRCSFrames[fi];
171   }
172
173   void addGPRCalleeSavedArea1Frame(int fi) {
174     if (fi >= 0) {
175       int Size = GPRCS1Frames.size();
176       if (fi >= Size) {
177         Size *= 2;
178         if (fi >= Size)
179           Size = fi+1;
180         GPRCS1Frames.resize(Size);
181       }
182       GPRCS1Frames[fi] = true;
183     }
184   }
185   void addGPRCalleeSavedArea2Frame(int fi) {
186     if (fi >= 0) {
187       int Size = GPRCS2Frames.size();
188       if (fi >= Size) {
189         Size *= 2;
190         if (fi >= Size)
191           Size = fi+1;
192         GPRCS2Frames.resize(Size);
193       }
194       GPRCS2Frames[fi] = true;
195     }
196   }
197   void addDPRCalleeSavedAreaFrame(int fi) {
198     if (fi >= 0) {
199       int Size = DPRCSFrames.size();
200       if (fi >= Size) {
201         Size *= 2;
202         if (fi >= Size)
203           Size = fi+1;
204         DPRCSFrames.resize(Size);
205       }
206       DPRCSFrames[fi] = true;
207     }
208   }
209
210   unsigned createJumpTableUId() {
211     return JumpTableUId++;
212   }
213
214   unsigned getNumJumpTables() const {
215     return JumpTableUId;
216   }
217
218   void initPICLabelUId(unsigned UId) {
219     PICLabelUId = UId;
220   }
221
222   unsigned getNumPICLabels() const {
223     return PICLabelUId;
224   }
225
226   unsigned createPICLabelUId() {
227     return PICLabelUId++;
228   }
229
230   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
231   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
232
233   bool hasITBlocks() const { return HasITBlocks; }
234   void setHasITBlocks(bool h) { HasITBlocks = h; }
235
236   void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
237     if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
238       assert(0 && "Duplicate entries!");
239   }
240
241   unsigned getOriginalCPIdx(unsigned CloneIdx) const {
242     DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
243     if (I != CPEClones.end())
244       return I->second;
245     else
246       return -1U;
247   }
248 };
249 } // End llvm namespace
250
251 #endif // ARMMACHINEFUNCTIONINFO_H