ARMMachineFunctionInfo.h revision 280031
16629Ssos//===-- ARMMachineFuctionInfo.h - ARM machine function info -----*- C++ -*-===//
26629Ssos//
36629Ssos//                     The LLVM Compiler Infrastructure
46629Ssos//
56629Ssos// This file is distributed under the University of Illinois Open Source
66629Ssos// License. See LICENSE.TXT for details.
76629Ssos//
86629Ssos//===----------------------------------------------------------------------===//
96629Ssos//
106629Ssos// This file declares ARM-specific per-machine-function information.
116629Ssos//
126629Ssos//===----------------------------------------------------------------------===//
136629Ssos
146629Ssos#ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
156629Ssos#define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
166629Ssos
176629Ssos#include "ARMSubtarget.h"
186629Ssos#include "llvm/ADT/BitVector.h"
196629Ssos#include "llvm/ADT/DenseMap.h"
206629Ssos#include "llvm/CodeGen/MachineFunction.h"
216629Ssos#include "llvm/Target/TargetMachine.h"
226629Ssos#include "llvm/Target/TargetRegisterInfo.h"
236629Ssos
246629Ssosnamespace llvm {
256629Ssos
266629Ssos/// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
276629Ssos/// contains private ARM-specific information for each MachineFunction.
286629Ssosclass ARMFunctionInfo : public MachineFunctionInfo {
296629Ssos  virtual void anchor();
306629Ssos
316629Ssos  /// isThumb - True if this function is compiled under Thumb mode.
326629Ssos  /// Used to initialized Align, so must precede it.
336629Ssos  bool isThumb;
346629Ssos
356629Ssos  /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
366629Ssos  /// to determine if function is compiled under Thumb mode, for that use
376629Ssos  /// 'isThumb'.
386629Ssos  bool hasThumb2;
396629Ssos
406629Ssos  /// StByValParamsPadding - For parameter that is split between
416629Ssos  /// GPRs and memory; while recovering GPRs part, when
426629Ssos  /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
436629Ssos  /// we need to insert gap before parameter start address. It allows to
446629Ssos  /// "attach" GPR-part to the part that was passed via stack.
456629Ssos  unsigned StByValParamsPadding;
466629Ssos
476629Ssos  /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
486629Ssos  ///
496629Ssos  unsigned ArgRegsSaveSize;
506629Ssos
516629Ssos  /// ReturnRegsCount - Number of registers used up in the return.
526629Ssos  unsigned ReturnRegsCount;
536629Ssos
546629Ssos  /// HasStackFrame - True if this function has a stack frame. Set by
556629Ssos  /// processFunctionBeforeCalleeSavedScan().
566629Ssos  bool HasStackFrame;
576629Ssos
586629Ssos  /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
596629Ssos  /// emitPrologue.
606629Ssos  bool RestoreSPFromFP;
616629Ssos
626629Ssos  /// LRSpilledForFarJump - True if the LR register has been for spilled to
636629Ssos  /// enable far jump.
646629Ssos  bool LRSpilledForFarJump;
656629Ssos
666629Ssos  /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
676629Ssos  /// spill stack offset.
686629Ssos  unsigned FramePtrSpillOffset;
696629Ssos
706629Ssos  /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
716629Ssos  /// register spills areas. For Mac OS X:
726629Ssos  ///
736629Ssos  /// GPR callee-saved (1) : r4, r5, r6, r7, lr
746629Ssos  /// --------------------------------------------
756629Ssos  /// GPR callee-saved (2) : r8, r10, r11
766629Ssos  /// --------------------------------------------
776629Ssos  /// DPR callee-saved : d8 - d15
786629Ssos  ///
796629Ssos  /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
806629Ssos  /// Some may be spilled after the stack has been realigned.
816629Ssos  unsigned GPRCS1Offset;
826629Ssos  unsigned GPRCS2Offset;
836629Ssos  unsigned DPRCSOffset;
846629Ssos
856629Ssos  /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
866629Ssos  /// areas.
876629Ssos  unsigned GPRCS1Size;
886629Ssos  unsigned GPRCS2Size;
896629Ssos  unsigned DPRCSAlignGapSize;
906629Ssos  unsigned DPRCSSize;
916629Ssos
926629Ssos  /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
936629Ssos  /// the aligned portion of the stack frame.  This is always a contiguous
946629Ssos  /// sequence of D-registers starting from d8.
956629Ssos  ///
96  /// We do not keep track of the frame indices used for these registers - they
97  /// behave like any other frame index in the aligned stack frame.  These
98  /// registers also aren't included in DPRCSSize above.
99  unsigned NumAlignedDPRCS2Regs;
100
101  /// JumpTableUId - Unique id for jumptables.
102  ///
103  unsigned JumpTableUId;
104
105  unsigned PICLabelUId;
106
107  /// VarArgsFrameIndex - FrameIndex for start of varargs area.
108  int VarArgsFrameIndex;
109
110  /// HasITBlocks - True if IT blocks have been inserted.
111  bool HasITBlocks;
112
113  /// CPEClones - Track constant pool entries clones created by Constant Island
114  /// pass.
115  DenseMap<unsigned, unsigned> CPEClones;
116
117  /// GlobalBaseReg - keeps track of the virtual register initialized for
118  /// use as the global base register. This is used for PIC in some PIC
119  /// relocation models.
120  unsigned GlobalBaseReg;
121
122  /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
123  /// being passed on the stack
124  unsigned ArgumentStackSize;
125
126  /// CoalescedWeights - mapping of basic blocks to the rolling counter of
127  /// coalesced weights.
128  DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
129
130public:
131  ARMFunctionInfo() :
132    isThumb(false),
133    hasThumb2(false),
134    ArgRegsSaveSize(0), ReturnRegsCount(0), HasStackFrame(false),
135    RestoreSPFromFP(false),
136    LRSpilledForFarJump(false),
137    FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
138    GPRCS1Size(0), GPRCS2Size(0), DPRCSAlignGapSize(0), DPRCSSize(0),
139    NumAlignedDPRCS2Regs(0),
140    JumpTableUId(0), PICLabelUId(0),
141    VarArgsFrameIndex(0), HasITBlocks(false), GlobalBaseReg(0) {}
142
143  explicit ARMFunctionInfo(MachineFunction &MF);
144
145  bool isThumbFunction() const { return isThumb; }
146  bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
147  bool isThumb2Function() const { return isThumb && hasThumb2; }
148
149  unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
150  void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
151
152  unsigned getArgRegsSaveSize(unsigned Align = 0) const {
153    if (!Align)
154      return ArgRegsSaveSize;
155    return (ArgRegsSaveSize + Align - 1) & ~(Align - 1);
156  }
157  void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
158
159  unsigned getReturnRegsCount() const { return ReturnRegsCount; }
160  void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
161
162  bool hasStackFrame() const { return HasStackFrame; }
163  void setHasStackFrame(bool s) { HasStackFrame = s; }
164
165  bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
166  void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
167
168  bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
169  void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
170
171  unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
172  void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
173
174  unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
175  void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
176
177  unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
178  unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
179  unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
180
181  void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
182  void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
183  void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
184
185  unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
186  unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
187  unsigned getDPRCalleeSavedGapSize() const   { return DPRCSAlignGapSize; }
188  unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
189
190  void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
191  void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
192  void setDPRCalleeSavedGapSize(unsigned s)   { DPRCSAlignGapSize = s; }
193  void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
194
195  unsigned getArgumentStackSize() const { return ArgumentStackSize; }
196  void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
197
198  unsigned createJumpTableUId() {
199    return JumpTableUId++;
200  }
201
202  unsigned getNumJumpTables() const {
203    return JumpTableUId;
204  }
205
206  void initPICLabelUId(unsigned UId) {
207    PICLabelUId = UId;
208  }
209
210  unsigned getNumPICLabels() const {
211    return PICLabelUId;
212  }
213
214  unsigned createPICLabelUId() {
215    return PICLabelUId++;
216  }
217
218  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
219  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
220
221  bool hasITBlocks() const { return HasITBlocks; }
222  void setHasITBlocks(bool h) { HasITBlocks = h; }
223
224  unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
225  void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
226
227  void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
228    if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
229      llvm_unreachable("Duplicate entries!");
230  }
231
232  unsigned getOriginalCPIdx(unsigned CloneIdx) const {
233    DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
234    if (I != CPEClones.end())
235      return I->second;
236    else
237      return -1U;
238  }
239
240  DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
241                                                  MachineBasicBlock* MBB) {
242    auto It = CoalescedWeights.find(MBB);
243    if (It == CoalescedWeights.end()) {
244      It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
245    }
246    return It;
247  }
248};
249} // End llvm namespace
250
251#endif
252