Use ARMFunctionInfo to track number of constpool entries and jumptables.
[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 MachineFunction private
26 /// ARM target-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   /// Align - required alignment.  ARM functions and Thumb functions with
34   /// constant pools require 4-byte alignment; other Thumb functions
35   /// require only 2-byte alignment.
36   unsigned Align;
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   /// LRSpilledForFarJump - True if the LR register has been for spilled to
47   /// enable far jump.
48   bool LRSpilledForFarJump;
49
50   /// R3IsLiveIn - True if R3 is live in to this function.
51   /// FIXME: Remove when register scavenger for Thumb is done.
52   bool R3IsLiveIn;
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 ConstPoolEntryUId;
91
92 public:
93   ARMFunctionInfo() :
94     isThumb(false), 
95     Align(2U),
96     VarArgsRegSaveSize(0), HasStackFrame(false),
97     LRSpilledForFarJump(false), R3IsLiveIn(false),
98     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
99     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
100     GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
101     JumpTableUId(0), ConstPoolEntryUId(0) {}
102
103   ARMFunctionInfo(MachineFunction &MF) :
104     isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
105     Align(isThumb ? 1U : 2U),
106     VarArgsRegSaveSize(0), HasStackFrame(false),
107     LRSpilledForFarJump(false), R3IsLiveIn(false),
108     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
109     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
110     GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
111     SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
112     JumpTableUId(0), ConstPoolEntryUId(0) {}
113
114   bool isThumbFunction() const { return isThumb; }
115
116   unsigned getAlign() const { return Align; }
117   void setAlign(unsigned a) { Align = a; }
118
119   unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
120   void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
121
122   bool hasStackFrame() const { return HasStackFrame; }
123   void setHasStackFrame(bool s) { HasStackFrame = s; }
124
125   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
126   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
127
128   // FIXME: Remove when register scavenger for Thumb is done.
129   bool isR3LiveIn() const { return R3IsLiveIn; }
130   void setR3IsLiveIn(bool l) { R3IsLiveIn = l; }
131
132   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
133   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
134   
135   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
136   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
137   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
138
139   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
140   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
141   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
142
143   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
144   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
145   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
146
147   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
148   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
149   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
150
151   bool isGPRCalleeSavedArea1Frame(int fi) const {
152     if (fi < 0 || fi >= (int)GPRCS1Frames.size())
153       return false;
154     return GPRCS1Frames[fi];
155   }
156   bool isGPRCalleeSavedArea2Frame(int fi) const {
157     if (fi < 0 || fi >= (int)GPRCS2Frames.size())
158       return false;
159     return GPRCS2Frames[fi];
160   }
161   bool isDPRCalleeSavedAreaFrame(int fi) const {
162     if (fi < 0 || fi >= (int)DPRCSFrames.size())
163       return false;
164     return DPRCSFrames[fi];
165   }
166
167   void addGPRCalleeSavedArea1Frame(int fi) {
168     if (fi >= 0) {
169       int Size = GPRCS1Frames.size();
170       if (fi >= Size) {
171         Size *= 2;
172         if (fi >= Size)
173           Size = fi+1;
174         GPRCS1Frames.resize(Size);
175       }
176       GPRCS1Frames[fi] = true;
177     }
178   }
179   void addGPRCalleeSavedArea2Frame(int fi) {
180     if (fi >= 0) {
181       int Size = GPRCS2Frames.size();
182       if (fi >= Size) {
183         Size *= 2;
184         if (fi >= Size)
185           Size = fi+1;
186         GPRCS2Frames.resize(Size);
187       }
188       GPRCS2Frames[fi] = true;
189     }
190   }
191   void addDPRCalleeSavedAreaFrame(int fi) {
192     if (fi >= 0) {
193       int Size = DPRCSFrames.size();
194       if (fi >= Size) {
195         Size *= 2;
196         if (fi >= Size)
197           Size = fi+1;
198         DPRCSFrames.resize(Size);
199       }
200       DPRCSFrames[fi] = true;
201     }
202   }
203
204   void setCSRegisterIsSpilled(unsigned Reg) {
205     SpilledCSRegs.set(Reg);
206   }
207
208   bool isCSRegisterSpilled(unsigned Reg) const {
209     return SpilledCSRegs[Reg];
210   }
211
212   const BitVector &getSpilledCSRegisters() const {
213     return SpilledCSRegs;
214   }
215
216   unsigned createJumpTableUId() {
217     return JumpTableUId++;
218   }
219
220   unsigned getNumJumpTables() const {
221     return JumpTableUId;
222   }
223
224   void initConstPoolEntryUId(unsigned UId) {
225     ConstPoolEntryUId = UId;
226   }
227
228   unsigned getNumConstPoolEntries() const {
229     return ConstPoolEntryUId;
230   }
231
232   unsigned createConstPoolEntryUId() {
233     return ConstPoolEntryUId++;
234   }
235 };
236 } // End llvm namespace
237
238 #endif // ARMMACHINEFUNCTIONINFO_H