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   /// Align - required alignment.  ARM functions and Thumb functions with
39   /// constant pools require 4-byte alignment; other Thumb functions
40   /// require only 2-byte alignment.
41   unsigned Align;
42 
43   /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
44   ///
45   unsigned VarArgsRegSaveSize;
46 
47   /// HasStackFrame - True if this function has a stack frame. Set by
48   /// processFunctionBeforeCalleeSavedScan().
49   bool HasStackFrame;
50 
51   /// LRSpilledForFarJump - True if the LR register has been for spilled to
52   /// enable far jump.
53   bool LRSpilledForFarJump;
54 
55   /// R3IsLiveIn - True if R3 is live in to this function.
56   /// FIXME: Remove when register scavenger for Thumb is done.
57   bool R3IsLiveIn;
58 
59   /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
60   /// spill stack offset.
61   unsigned FramePtrSpillOffset;
62 
63   /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
64   /// register spills areas. For Mac OS X:
65   ///
66   /// GPR callee-saved (1) : r4, r5, r6, r7, lr
67   /// --------------------------------------------
68   /// GPR callee-saved (2) : r8, r10, r11
69   /// --------------------------------------------
70   /// DPR callee-saved : d8 - d15
71   unsigned GPRCS1Offset;
72   unsigned GPRCS2Offset;
73   unsigned DPRCSOffset;
74 
75   /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
76   /// areas.
77   unsigned GPRCS1Size;
78   unsigned GPRCS2Size;
79   unsigned DPRCSSize;
80 
81   /// GPRCS1Frames, GPRCS2Frames, DPRCSFrames - Keeps track of frame indices
82   /// which belong to these spill areas.
83   BitVector GPRCS1Frames;
84   BitVector GPRCS2Frames;
85   BitVector DPRCSFrames;
86 
87   /// SpilledCSRegs - A BitVector mask of all spilled callee-saved registers.
88   ///
89   BitVector SpilledCSRegs;
90 
91   /// JumpTableUId - Unique id for jumptables.
92   ///
93   unsigned JumpTableUId;
94 
95   unsigned ConstPoolEntryUId;
96 
97 public:
98   ARMFunctionInfo() :
99     isThumb(false),
100     hasThumb2(false),
101     Align(2U),
102     VarArgsRegSaveSize(0), HasStackFrame(false),
103     LRSpilledForFarJump(false), R3IsLiveIn(false),
104     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
105     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
106     GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
107     JumpTableUId(0), ConstPoolEntryUId(0) {}
108 
109   explicit ARMFunctionInfo(MachineFunction &MF) :
110     isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
111     hasThumb2(MF.getTarget().getSubtarget<ARMSubtarget>().hasThumb2()),
112     Align(isThumb ? 1U : 2U),
113     VarArgsRegSaveSize(0), HasStackFrame(false),
114     LRSpilledForFarJump(false), R3IsLiveIn(false),
115     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
116     GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
117     GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
118     SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
119     JumpTableUId(0), ConstPoolEntryUId(0) {}
120 
121   bool isThumbFunction() const { return isThumb; }
122   bool isThumb2Function() const { return isThumb && hasThumb2; }
123 
124   unsigned getAlign() const { return Align; }
125   void setAlign(unsigned a) { Align = a; }
126 
127   unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
128   void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
129 
130   bool hasStackFrame() const { return HasStackFrame; }
131   void setHasStackFrame(bool s) { HasStackFrame = s; }
132 
133   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
134   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
135 
136   // FIXME: Remove when register scavenger for Thumb is done.
137   bool isR3LiveIn() const { return R3IsLiveIn; }
138   void setR3IsLiveIn(bool l) { R3IsLiveIn = l; }
139 
140   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
141   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
142 
143   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
144   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
145   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
146 
147   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
148   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
149   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
150 
151   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
152   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
153   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
154 
155   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
156   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
157   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
158 
159   bool isGPRCalleeSavedArea1Frame(int fi) const {
160     if (fi < 0 || fi >= (int)GPRCS1Frames.size())
161       return false;
162     return GPRCS1Frames[fi];
163   }
164   bool isGPRCalleeSavedArea2Frame(int fi) const {
165     if (fi < 0 || fi >= (int)GPRCS2Frames.size())
166       return false;
167     return GPRCS2Frames[fi];
168   }
169   bool isDPRCalleeSavedAreaFrame(int fi) const {
170     if (fi < 0 || fi >= (int)DPRCSFrames.size())
171       return false;
172     return DPRCSFrames[fi];
173   }
174 
175   void addGPRCalleeSavedArea1Frame(int fi) {
176     if (fi >= 0) {
177       int Size = GPRCS1Frames.size();
178       if (fi >= Size) {
179         Size *= 2;
180         if (fi >= Size)
181           Size = fi+1;
182         GPRCS1Frames.resize(Size);
183       }
184       GPRCS1Frames[fi] = true;
185     }
186   }
187   void addGPRCalleeSavedArea2Frame(int fi) {
188     if (fi >= 0) {
189       int Size = GPRCS2Frames.size();
190       if (fi >= Size) {
191         Size *= 2;
192         if (fi >= Size)
193           Size = fi+1;
194         GPRCS2Frames.resize(Size);
195       }
196       GPRCS2Frames[fi] = true;
197     }
198   }
199   void addDPRCalleeSavedAreaFrame(int fi) {
200     if (fi >= 0) {
201       int Size = DPRCSFrames.size();
202       if (fi >= Size) {
203         Size *= 2;
204         if (fi >= Size)
205           Size = fi+1;
206         DPRCSFrames.resize(Size);
207       }
208       DPRCSFrames[fi] = true;
209     }
210   }
211 
212   void setCSRegisterIsSpilled(unsigned Reg) {
213     SpilledCSRegs.set(Reg);
214   }
215 
216   bool isCSRegisterSpilled(unsigned Reg) const {
217     return SpilledCSRegs[Reg];
218   }
219 
220   const BitVector &getSpilledCSRegisters() const {
221     return SpilledCSRegs;
222   }
223 
224   unsigned createJumpTableUId() {
225     return JumpTableUId++;
226   }
227 
228   unsigned getNumJumpTables() const {
229     return JumpTableUId;
230   }
231 
232   void initConstPoolEntryUId(unsigned UId) {
233     ConstPoolEntryUId = UId;
234   }
235 
236   unsigned getNumConstPoolEntries() const {
237     return ConstPoolEntryUId;
238   }
239 
240   unsigned createConstPoolEntryUId() {
241     return ConstPoolEntryUId++;
242   }
243 };
244 } // End llvm namespace
245 
246 #endif // ARMMACHINEFUNCTIONINFO_H
247