ARMMachineFunctionInfo.h revision 198090
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
23namespace llvm {
24
25/// ARMFunctionInfo - This class is derived from MachineFunction private
26/// ARM target-specific information for each MachineFunction.
27class 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  /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
56  /// spill stack offset.
57  unsigned FramePtrSpillOffset;
58
59  /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
60  /// register spills areas. For Mac OS X:
61  ///
62  /// GPR callee-saved (1) : r4, r5, r6, r7, lr
63  /// --------------------------------------------
64  /// GPR callee-saved (2) : r8, r10, r11
65  /// --------------------------------------------
66  /// DPR callee-saved : d8 - d15
67  unsigned GPRCS1Offset;
68  unsigned GPRCS2Offset;
69  unsigned DPRCSOffset;
70
71  /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
72  /// areas.
73  unsigned GPRCS1Size;
74  unsigned GPRCS2Size;
75  unsigned DPRCSSize;
76
77  /// GPRCS1Frames, GPRCS2Frames, DPRCSFrames - Keeps track of frame indices
78  /// which belong to these spill areas.
79  BitVector GPRCS1Frames;
80  BitVector GPRCS2Frames;
81  BitVector DPRCSFrames;
82
83  /// SpilledCSRegs - A BitVector mask of all spilled callee-saved registers.
84  ///
85  BitVector SpilledCSRegs;
86
87  /// JumpTableUId - Unique id for jumptables.
88  ///
89  unsigned JumpTableUId;
90
91  unsigned ConstPoolEntryUId;
92
93public:
94  ARMFunctionInfo() :
95    isThumb(false),
96    hasThumb2(false),
97    Align(2U),
98    VarArgsRegSaveSize(0), HasStackFrame(false),
99    LRSpilledForFarJump(false),
100    FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
101    GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
102    GPRCS1Frames(0), GPRCS2Frames(0), DPRCSFrames(0),
103    JumpTableUId(0), ConstPoolEntryUId(0) {}
104
105  explicit ARMFunctionInfo(MachineFunction &MF) :
106    isThumb(MF.getTarget().getSubtarget<ARMSubtarget>().isThumb()),
107    hasThumb2(MF.getTarget().getSubtarget<ARMSubtarget>().hasThumb2()),
108    Align(isThumb ? 1U : 2U),
109    VarArgsRegSaveSize(0), HasStackFrame(false),
110    LRSpilledForFarJump(false),
111    FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
112    GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0),
113    GPRCS1Frames(32), GPRCS2Frames(32), DPRCSFrames(32),
114    SpilledCSRegs(MF.getTarget().getRegisterInfo()->getNumRegs()),
115    JumpTableUId(0), ConstPoolEntryUId(0) {}
116
117  bool isThumbFunction() const { return isThumb; }
118  bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
119  bool isThumb2Function() const { return isThumb && hasThumb2; }
120
121  unsigned getAlign() const { return Align; }
122  void setAlign(unsigned a) { Align = a; }
123
124  unsigned getVarArgsRegSaveSize() const { return VarArgsRegSaveSize; }
125  void setVarArgsRegSaveSize(unsigned s) { VarArgsRegSaveSize = s; }
126
127  bool hasStackFrame() const { return HasStackFrame; }
128  void setHasStackFrame(bool s) { HasStackFrame = 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 getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
137  unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
138  unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
139
140  void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
141  void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
142  void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
143
144  unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
145  unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
146  unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
147
148  void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
149  void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
150  void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
151
152  bool isGPRCalleeSavedArea1Frame(int fi) const {
153    if (fi < 0 || fi >= (int)GPRCS1Frames.size())
154      return false;
155    return GPRCS1Frames[fi];
156  }
157  bool isGPRCalleeSavedArea2Frame(int fi) const {
158    if (fi < 0 || fi >= (int)GPRCS2Frames.size())
159      return false;
160    return GPRCS2Frames[fi];
161  }
162  bool isDPRCalleeSavedAreaFrame(int fi) const {
163    if (fi < 0 || fi >= (int)DPRCSFrames.size())
164      return false;
165    return DPRCSFrames[fi];
166  }
167
168  void addGPRCalleeSavedArea1Frame(int fi) {
169    if (fi >= 0) {
170      int Size = GPRCS1Frames.size();
171      if (fi >= Size) {
172        Size *= 2;
173        if (fi >= Size)
174          Size = fi+1;
175        GPRCS1Frames.resize(Size);
176      }
177      GPRCS1Frames[fi] = true;
178    }
179  }
180  void addGPRCalleeSavedArea2Frame(int fi) {
181    if (fi >= 0) {
182      int Size = GPRCS2Frames.size();
183      if (fi >= Size) {
184        Size *= 2;
185        if (fi >= Size)
186          Size = fi+1;
187        GPRCS2Frames.resize(Size);
188      }
189      GPRCS2Frames[fi] = true;
190    }
191  }
192  void addDPRCalleeSavedAreaFrame(int fi) {
193    if (fi >= 0) {
194      int Size = DPRCSFrames.size();
195      if (fi >= Size) {
196        Size *= 2;
197        if (fi >= Size)
198          Size = fi+1;
199        DPRCSFrames.resize(Size);
200      }
201      DPRCSFrames[fi] = true;
202    }
203  }
204
205  void setCSRegisterIsSpilled(unsigned Reg) {
206    SpilledCSRegs.set(Reg);
207  }
208
209  bool isCSRegisterSpilled(unsigned Reg) const {
210    return SpilledCSRegs[Reg];
211  }
212
213  const BitVector &getSpilledCSRegisters() const {
214    return SpilledCSRegs;
215  }
216
217  unsigned createJumpTableUId() {
218    return JumpTableUId++;
219  }
220
221  unsigned getNumJumpTables() const {
222    return JumpTableUId;
223  }
224
225  void initConstPoolEntryUId(unsigned UId) {
226    ConstPoolEntryUId = UId;
227  }
228
229  unsigned getNumConstPoolEntries() const {
230    return ConstPoolEntryUId;
231  }
232
233  unsigned createConstPoolEntryUId() {
234    return ConstPoolEntryUId++;
235  }
236};
237} // End llvm namespace
238
239#endif // ARMMACHINEFUNCTIONINFO_H
240