• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- ARMMachineFunctionInfo.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 LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
15 #define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
16 
17 #include "ARMSubtarget.h"
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetRegisterInfo.h"
23 
24 namespace llvm {
25 
26 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
27 /// contains private ARM-specific information for each MachineFunction.
28 class ARMFunctionInfo : public MachineFunctionInfo {
29   virtual void anchor();
30 
31   /// isThumb - True if this function is compiled under Thumb mode.
32   /// Used to initialized Align, so must precede it.
33   bool isThumb;
34 
35   /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
36   /// to determine if function is compiled under Thumb mode, for that use
37   /// 'isThumb'.
38   bool hasThumb2;
39 
40   /// StByValParamsPadding - For parameter that is split between
41   /// GPRs and memory; while recovering GPRs part, when
42   /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
43   /// we need to insert gap before parameter start address. It allows to
44   /// "attach" GPR-part to the part that was passed via stack.
45   unsigned StByValParamsPadding;
46 
47   /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
48   ///
49   unsigned ArgRegsSaveSize;
50 
51   /// ReturnRegsCount - Number of registers used up in the return.
52   unsigned ReturnRegsCount;
53 
54   /// HasStackFrame - True if this function has a stack frame. Set by
55   /// determineCalleeSaves().
56   bool HasStackFrame;
57 
58   /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
59   /// emitPrologue.
60   bool RestoreSPFromFP;
61 
62   /// LRSpilledForFarJump - True if the LR register has been for spilled to
63   /// enable far jump.
64   bool LRSpilledForFarJump;
65 
66   /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
67   /// spill stack offset.
68   unsigned FramePtrSpillOffset;
69 
70   /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
71   /// register spills areas. For Mac OS X:
72   ///
73   /// GPR callee-saved (1) : r4, r5, r6, r7, lr
74   /// --------------------------------------------
75   /// GPR callee-saved (2) : r8, r10, r11
76   /// --------------------------------------------
77   /// DPR callee-saved : d8 - d15
78   ///
79   /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
80   /// Some may be spilled after the stack has been realigned.
81   unsigned GPRCS1Offset;
82   unsigned GPRCS2Offset;
83   unsigned DPRCSOffset;
84 
85   /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
86   /// areas.
87   unsigned GPRCS1Size;
88   unsigned GPRCS2Size;
89   unsigned DPRCSAlignGapSize;
90   unsigned DPRCSSize;
91 
92   /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
93   /// the aligned portion of the stack frame.  This is always a contiguous
94   /// sequence of D-registers starting from d8.
95   ///
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   unsigned PICLabelUId;
102 
103   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
104   int VarArgsFrameIndex;
105 
106   /// HasITBlocks - True if IT blocks have been inserted.
107   bool HasITBlocks;
108 
109   /// CPEClones - Track constant pool entries clones created by Constant Island
110   /// pass.
111   DenseMap<unsigned, unsigned> CPEClones;
112 
113   /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
114   /// being passed on the stack
115   unsigned ArgumentStackSize;
116 
117   /// CoalescedWeights - mapping of basic blocks to the rolling counter of
118   /// coalesced weights.
119   DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
120 
121 public:
ARMFunctionInfo()122   ARMFunctionInfo() :
123     isThumb(false),
124     hasThumb2(false),
125     ArgRegsSaveSize(0), ReturnRegsCount(0), HasStackFrame(false),
126     RestoreSPFromFP(false),
127     LRSpilledForFarJump(false),
128     FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0),
129     GPRCS1Size(0), GPRCS2Size(0), DPRCSAlignGapSize(0), DPRCSSize(0),
130     NumAlignedDPRCS2Regs(0), PICLabelUId(0),
131     VarArgsFrameIndex(0), HasITBlocks(false) {}
132 
133   explicit ARMFunctionInfo(MachineFunction &MF);
134 
isThumbFunction()135   bool isThumbFunction() const { return isThumb; }
isThumb1OnlyFunction()136   bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
isThumb2Function()137   bool isThumb2Function() const { return isThumb && hasThumb2; }
138 
getStoredByValParamsPadding()139   unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
setStoredByValParamsPadding(unsigned p)140   void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
141 
getArgRegsSaveSize()142   unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
setArgRegsSaveSize(unsigned s)143   void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
144 
getReturnRegsCount()145   unsigned getReturnRegsCount() const { return ReturnRegsCount; }
setReturnRegsCount(unsigned s)146   void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
147 
hasStackFrame()148   bool hasStackFrame() const { return HasStackFrame; }
setHasStackFrame(bool s)149   void setHasStackFrame(bool s) { HasStackFrame = s; }
150 
shouldRestoreSPFromFP()151   bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
setShouldRestoreSPFromFP(bool s)152   void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
153 
isLRSpilledForFarJump()154   bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
setLRIsSpilledForFarJump(bool s)155   void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
156 
getFramePtrSpillOffset()157   unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
setFramePtrSpillOffset(unsigned o)158   void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
159 
getNumAlignedDPRCS2Regs()160   unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
setNumAlignedDPRCS2Regs(unsigned n)161   void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
162 
getGPRCalleeSavedArea1Offset()163   unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
getGPRCalleeSavedArea2Offset()164   unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
getDPRCalleeSavedAreaOffset()165   unsigned getDPRCalleeSavedAreaOffset()  const { return DPRCSOffset; }
166 
setGPRCalleeSavedArea1Offset(unsigned o)167   void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
setGPRCalleeSavedArea2Offset(unsigned o)168   void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
setDPRCalleeSavedAreaOffset(unsigned o)169   void setDPRCalleeSavedAreaOffset(unsigned o)  { DPRCSOffset = o; }
170 
getGPRCalleeSavedArea1Size()171   unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
getGPRCalleeSavedArea2Size()172   unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
getDPRCalleeSavedGapSize()173   unsigned getDPRCalleeSavedGapSize() const   { return DPRCSAlignGapSize; }
getDPRCalleeSavedAreaSize()174   unsigned getDPRCalleeSavedAreaSize()  const { return DPRCSSize; }
175 
setGPRCalleeSavedArea1Size(unsigned s)176   void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
setGPRCalleeSavedArea2Size(unsigned s)177   void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
setDPRCalleeSavedGapSize(unsigned s)178   void setDPRCalleeSavedGapSize(unsigned s)   { DPRCSAlignGapSize = s; }
setDPRCalleeSavedAreaSize(unsigned s)179   void setDPRCalleeSavedAreaSize(unsigned s)  { DPRCSSize = s; }
180 
getArgumentStackSize()181   unsigned getArgumentStackSize() const { return ArgumentStackSize; }
setArgumentStackSize(unsigned size)182   void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
183 
initPICLabelUId(unsigned UId)184   void initPICLabelUId(unsigned UId) {
185     PICLabelUId = UId;
186   }
187 
getNumPICLabels()188   unsigned getNumPICLabels() const {
189     return PICLabelUId;
190   }
191 
createPICLabelUId()192   unsigned createPICLabelUId() {
193     return PICLabelUId++;
194   }
195 
getVarArgsFrameIndex()196   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
setVarArgsFrameIndex(int Index)197   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
198 
hasITBlocks()199   bool hasITBlocks() const { return HasITBlocks; }
setHasITBlocks(bool h)200   void setHasITBlocks(bool h) { HasITBlocks = h; }
201 
recordCPEClone(unsigned CPIdx,unsigned CPCloneIdx)202   void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
203     if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
204       llvm_unreachable("Duplicate entries!");
205   }
206 
getOriginalCPIdx(unsigned CloneIdx)207   unsigned getOriginalCPIdx(unsigned CloneIdx) const {
208     DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
209     if (I != CPEClones.end())
210       return I->second;
211     else
212       return -1U;
213   }
214 
getCoalescedWeight(MachineBasicBlock * MBB)215   DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
216                                                   MachineBasicBlock* MBB) {
217     auto It = CoalescedWeights.find(MBB);
218     if (It == CoalescedWeights.end()) {
219       It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
220     }
221     return It;
222   }
223 };
224 } // End llvm namespace
225 
226 #endif
227