Simplify ARM callee-saved register handling by removing the distinction
[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   /// 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   /// GPRCSOffset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
59   /// register spills areas (excluding R9 for Mac OS X):
60   ///
61   /// GPR callee-saved (1) : r4, r5, r6, r7, r8, r9, r10, r11, lr
62   /// --------------------------------------------
63   /// DPR callee-saved : d8 - d15
64   unsigned GPRCSOffset;
65   unsigned DPRCSOffset;
66
67   /// GPRCSSize, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
68   /// areas.
69   unsigned GPRCSSize;
70   unsigned DPRCSSize;
71
72   /// GPRCSFrames, GPRCS2Frames, DPRCSFrames - Keeps track of frame indices
73   /// which belong to these spill areas.
74   BitVector GPRCSFrames;
75   BitVector DPRCSFrames;
76
77   /// SpilledCSRegs - A BitVector mask of all spilled callee-saved registers.
78   ///
79   BitVector SpilledCSRegs;
80
81   /// JumpTableUId - Unique id for jumptables.
82   ///
83   unsigned JumpTableUId;
84
85   unsigned ConstPoolEntryUId;
86
87   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
88   int VarArgsFrameIndex;
89
90   /// HasITBlocks - True if IT blocks have been inserted.
91   bool HasITBlocks;
92
93 public:
94   ARMFunctionInfo() :
95     isThumb(false),
96     hasThumb2(false),
97     VarArgsRegSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
98     LRSpilledForFarJump(false),
99     FramePtrSpillOffset(0), GPRCSOffset(0), DPRCSOffset(0),
100     GPRCSSize(0), DPRCSSize(0),
101     GPRCSFrames(0), DPRCSFrames(0),
102     JumpTableUId(0), ConstPoolEntryUId(0), VarArgsFrameIndex(0),
103     HasITBlocks(false) {}
104
105   explicit ARMFunctionInfo(MachineFunction &MF) :
106     isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
107     hasThumb2(MF.getTarget().getSubtarget<ARMSubtarget>().hasThumb2()),
108     VarArgsRegSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false),
109     LRSpilledForFarJump(false),
110     FramePtrSpillOffset(0), GPRCSOffset(0), DPRCSOffset(0),
111     GPRCSSize(0), DPRCSSize(0),
112     GPRCSFrames(32), DPRCSFrames(32),
113     SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
114     JumpTableUId(0), ConstPoolEntryUId(0), VarArgsFrameIndex(0),
115     HasITBlocks(false) {}
116
117   bool isThumbFunction() const { return isThumb; }
118   bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
119   bool isThumb2Function() const { return isThumb && hasThumb2; }
120
121   unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
122   void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
123
124   bool hasStackFrame() const { return HasStackFrame; }
125   void setHasStackFrame(bool s) { HasStackFrame = s; }
126
127   bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
128   void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
129
130   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
131   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
132
133   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
134   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
135
136   unsigned getGPRCalleeSavedAreaOffset() const { return GPRCSOffset; }
137   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
138
139   void setGPRCalleeSavedAreaOffset(unsigned o) { GPRCSOffset = o; }
140   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
141
142   unsigned getGPRCalleeSavedAreaSize() const { return GPRCSSize; }
143   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
144
145   void setGPRCalleeSavedAreaSize(unsigned s) { GPRCSSize = s; }
146   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
147
148   bool isGPRCalleeSavedAreaFrame(int fi) const {
149     if (fi < 0 || fi >= (int)GPRCSFrames.size())
150       return false;
151     return GPRCSFrames[fi];
152   }
153   bool isDPRCalleeSavedAreaFrame(int fi) const {
154     if (fi < 0 || fi >= (int)DPRCSFrames.size())
155       return false;
156     return DPRCSFrames[fi];
157   }
158
159   void addGPRCalleeSavedAreaFrame(int fi) {
160     if (fi >= 0) {
161       int Size = GPRCSFrames.size();
162       if (fi >= Size) {
163         Size *= 2;
164         if (fi >= Size)
165           Size = fi+1;
166         GPRCSFrames.resize(Size);
167       }
168       GPRCSFrames[fi] = true;
169     }
170   }
171   void addDPRCalleeSavedAreaFrame(int fi) {
172     if (fi >= 0) {
173       int Size = DPRCSFrames.size();
174       if (fi >= Size) {
175         Size *= 2;
176         if (fi >= Size)
177           Size = fi+1;
178         DPRCSFrames.resize(Size);
179       }
180       DPRCSFrames[fi] = true;
181     }
182   }
183
184   void setCSRegisterIsSpilled(unsigned Reg) {
185     SpilledCSRegs.set(Reg);
186   }
187
188   bool isCSRegisterSpilled(unsigned Reg) const {
189     return SpilledCSRegs[Reg];
190   }
191
192   const BitVector &getSpilledCSRegisters() const {
193     return SpilledCSRegs;
194   }
195
196   unsigned createJumpTableUId() {
197     return JumpTableUId++;
198   }
199
200   unsigned getNumJumpTables() const {
201     return JumpTableUId;
202   }
203
204   void initConstPoolEntryUId(unsigned UId) {
205     ConstPoolEntryUId = UId;
206   }
207
208   unsigned getNumConstPoolEntries() const {
209     return ConstPoolEntryUId;
210   }
211
212   unsigned createConstPoolEntryUId() {
213     return ConstPoolEntryUId++;
214   }
215
216   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
217   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
218
219   bool hasITBlocks() const { return HasITBlocks; }
220   void setHasITBlocks(bool h) { HasITBlocks = h; }
221 };
222 } // End llvm namespace
223
224 #endif // ARMMACHINEFUNCTIONINFO_H