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