eeb61d76860e8beb164a539b67cc46d282d11781
[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 public:
91   ARMFunctionInfo() :
92     isThumb(false), 
93     Align(2U),
94     VarArgsRegSaveSize(0), HasStackFrame(false),
95     LRSpilledForFarJump(false), R3IsLiveIn(false),
96     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
97     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
98     GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
99     JumpTableUId(0) {}
100
101   ARMFunctionInfo(MachineFunction &MF) :
102     isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
103     Align(isThumb ? 1U : 2U),
104     VarArgsRegSaveSize(0), HasStackFrame(false),
105     LRSpilledForFarJump(false), R3IsLiveIn(false),
106     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
107     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
108     GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
109     SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
110     JumpTableUId(0) {}
111
112   bool isThumbFunction() const { return isThumb; }
113
114   unsigned getAlign() const { return Align; }
115   void setAlign(unsigned a) { Align = a; }
116
117   unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
118   void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
119
120   bool hasStackFrame() const { return HasStackFrame; }
121   void setHasStackFrame(bool s) { HasStackFrame = s; }
122
123   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
124   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
125
126   // FIXME: Remove when register scavenger for Thumb is done.
127   bool isR3LiveIn() const { return R3IsLiveIn; }
128   void setR3IsLiveIn(bool l) { R3IsLiveIn = l; }
129
130   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
131   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
132   
133   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
134   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
135   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
136
137   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
138   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
139   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
140
141   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
142   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
143   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
144
145   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
146   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
147   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
148
149   bool isGPRCalleeSavedArea1Frame(int fi) const {
150     if (fi < 0 || fi >= (int)GPRCS1Frames.size())
151       return false;
152     return GPRCS1Frames[fi];
153   }
154   bool isGPRCalleeSavedArea2Frame(int fi) const {
155     if (fi < 0 || fi >= (int)GPRCS2Frames.size())
156       return false;
157     return GPRCS2Frames[fi];
158   }
159   bool isDPRCalleeSavedAreaFrame(int fi) const {
160     if (fi < 0 || fi >= (int)DPRCSFrames.size())
161       return false;
162     return DPRCSFrames[fi];
163   }
164
165   void addGPRCalleeSavedArea1Frame(int fi) {
166     if (fi >= 0) {
167       int Size = GPRCS1Frames.size();
168       if (fi >= Size) {
169         Size *= 2;
170         if (fi >= Size)
171           Size = fi+1;
172         GPRCS1Frames.resize(Size);
173       }
174       GPRCS1Frames[fi] = true;
175     }
176   }
177   void addGPRCalleeSavedArea2Frame(int fi) {
178     if (fi >= 0) {
179       int Size = GPRCS2Frames.size();
180       if (fi >= Size) {
181         Size *= 2;
182         if (fi >= Size)
183           Size = fi+1;
184         GPRCS2Frames.resize(Size);
185       }
186       GPRCS2Frames[fi] = true;
187     }
188   }
189   void addDPRCalleeSavedAreaFrame(int fi) {
190     if (fi >= 0) {
191       int Size = DPRCSFrames.size();
192       if (fi >= Size) {
193         Size *= 2;
194         if (fi >= Size)
195           Size = fi+1;
196         DPRCSFrames.resize(Size);
197       }
198       DPRCSFrames[fi] = true;
199     }
200   }
201
202   void setCSRegisterIsSpilled(unsigned Reg) {
203     SpilledCSRegs.set(Reg);
204   }
205
206   bool isCSRegisterSpilled(unsigned Reg) {
207     return SpilledCSRegs[Reg];
208   }
209
210   const BitVector &getSpilledCSRegisters() const {
211     return SpilledCSRegs;
212   }
213
214   unsigned createJumpTableUId() {
215     return JumpTableUId++;
216   }
217 };
218 } // End llvm namespace
219
220 #endif // ARMMACHINEFUNCTIONINFO_H