LLVM  9.0.0svn
ARMMachineFunctionInfo.h
Go to the documentation of this file.
1 //===-- ARMMachineFunctionInfo.h - ARM machine function info ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares ARM-specific per-machine-function information.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallPtrSet.h"
20 #include <utility>
21 
22 namespace llvm {
23 
24 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
25 /// contains private ARM-specific information for each MachineFunction.
27  virtual void anchor();
28 
29  /// isThumb - True if this function is compiled under Thumb mode.
30  /// Used to initialized Align, so must precede it.
31  bool isThumb = false;
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 = false;
37 
38  /// StByValParamsPadding - For parameter that is split between
39  /// GPRs and memory; while recovering GPRs part, when
40  /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
41  /// we need to insert gap before parameter start address. It allows to
42  /// "attach" GPR-part to the part that was passed via stack.
43  unsigned StByValParamsPadding = 0;
44 
45  /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
46  ///
47  unsigned ArgRegsSaveSize = 0;
48 
49  /// ReturnRegsCount - Number of registers used up in the return.
50  unsigned ReturnRegsCount = 0;
51 
52  /// HasStackFrame - True if this function has a stack frame. Set by
53  /// determineCalleeSaves().
54  bool HasStackFrame = false;
55 
56  /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
57  /// emitPrologue.
58  bool RestoreSPFromFP = false;
59 
60  /// LRSpilledForFarJump - True if the LR register has been for spilled to
61  /// enable far jump.
62  bool LRSpilledForFarJump = false;
63 
64  /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
65  /// spill stack offset.
66  unsigned FramePtrSpillOffset = 0;
67 
68  /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
69  /// register spills areas. For Mac OS X:
70  ///
71  /// GPR callee-saved (1) : r4, r5, r6, r7, lr
72  /// --------------------------------------------
73  /// GPR callee-saved (2) : r8, r10, r11
74  /// --------------------------------------------
75  /// DPR callee-saved : d8 - d15
76  ///
77  /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
78  /// Some may be spilled after the stack has been realigned.
79  unsigned GPRCS1Offset = 0;
80  unsigned GPRCS2Offset = 0;
81  unsigned DPRCSOffset = 0;
82 
83  /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
84  /// areas.
85  unsigned GPRCS1Size = 0;
86  unsigned GPRCS2Size = 0;
87  unsigned DPRCSAlignGapSize = 0;
88  unsigned DPRCSSize = 0;
89 
90  /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
91  /// the aligned portion of the stack frame. This is always a contiguous
92  /// sequence of D-registers starting from d8.
93  ///
94  /// We do not keep track of the frame indices used for these registers - they
95  /// behave like any other frame index in the aligned stack frame. These
96  /// registers also aren't included in DPRCSSize above.
97  unsigned NumAlignedDPRCS2Regs = 0;
98 
99  unsigned PICLabelUId = 0;
100 
101  /// VarArgsFrameIndex - FrameIndex for start of varargs area.
102  int VarArgsFrameIndex = 0;
103 
104  /// HasITBlocks - True if IT blocks have been inserted.
105  bool HasITBlocks = false;
106 
107  /// CPEClones - Track constant pool entries clones created by Constant Island
108  /// pass.
110 
111  /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
112  /// being passed on the stack
113  unsigned ArgumentStackSize = 0;
114 
115  /// CoalescedWeights - mapping of basic blocks to the rolling counter of
116  /// coalesced weights.
118 
119  /// True if this function has a subset of CSRs that is handled explicitly via
120  /// copies.
121  bool IsSplitCSR = false;
122 
123  /// Globals that have had their storage promoted into the constant pool.
124  SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
125 
126  /// The amount the literal pool has been increasedby due to promoted globals.
127  int PromotedGlobalsIncrease = 0;
128 
129 public:
130  ARMFunctionInfo() = default;
131 
132  explicit ARMFunctionInfo(MachineFunction &MF);
133 
134  bool isThumbFunction() const { return isThumb; }
135  bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
136  bool isThumb2Function() const { return isThumb && hasThumb2; }
137 
138  unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
139  void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
140 
141  unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
142  void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
143 
144  unsigned getReturnRegsCount() const { return ReturnRegsCount; }
145  void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
146 
147  bool hasStackFrame() const { return HasStackFrame; }
148  void setHasStackFrame(bool s) { HasStackFrame = s; }
149 
150  bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
151  void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
152 
153  bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
154  void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
155 
156  unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
157  void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
158 
159  unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
160  void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
161 
162  unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
163  unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
164  unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
165 
166  void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
167  void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
168  void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
169 
170  unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
171  unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
172  unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
173  unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
174 
175  void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
176  void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
177  void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
178  void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
179 
180  unsigned getArgumentStackSize() const { return ArgumentStackSize; }
181  void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
182 
183  void initPICLabelUId(unsigned UId) {
184  PICLabelUId = UId;
185  }
186 
187  unsigned getNumPICLabels() const {
188  return PICLabelUId;
189  }
190 
191  unsigned createPICLabelUId() {
192  return PICLabelUId++;
193  }
194 
195  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
196  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
197 
198  bool hasITBlocks() const { return HasITBlocks; }
199  void setHasITBlocks(bool h) { HasITBlocks = h; }
200 
201  bool isSplitCSR() const { return IsSplitCSR; }
202  void setIsSplitCSR(bool s) { IsSplitCSR = s; }
203 
204  void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
205  if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
206  llvm_unreachable("Duplicate entries!");
207  }
208 
209  unsigned getOriginalCPIdx(unsigned CloneIdx) const {
211  if (I != CPEClones.end())
212  return I->second;
213  else
214  return -1U;
215  }
216 
218  MachineBasicBlock* MBB) {
219  auto It = CoalescedWeights.find(MBB);
220  if (It == CoalescedWeights.end()) {
221  It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
222  }
223  return It;
224  }
225 
226  /// Indicate to the backend that \c GV has had its storage changed to inside
227  /// a constant pool. This means it no longer needs to be emitted as a
228  /// global variable.
230  PromotedGlobals.insert(GV);
231  }
233  return PromotedGlobals;
234  }
236  return PromotedGlobalsIncrease;
237  }
239  PromotedGlobalsIncrease = Sz;
240  }
241 };
242 
243 } // end namespace llvm
244 
245 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV)
Indicate to the backend that GV has had its storage changed to inside a constant pool.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void setGPRCalleeSavedArea2Offset(unsigned o)
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:221
void setDPRCalleeSavedAreaOffset(unsigned o)
unsigned getArgRegsSaveSize() const
void setFramePtrSpillOffset(unsigned o)
unsigned getDPRCalleeSavedAreaSize() const
void setDPRCalleeSavedGapSize(unsigned s)
unsigned getNumAlignedDPRCS2Regs() const
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:176
void setReturnRegsCount(unsigned s)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:370
unsigned getGPRCalleeSavedArea1Size() const
void setGPRCalleeSavedArea2Size(unsigned s)
void initPICLabelUId(unsigned UId)
unsigned getReturnRegsCount() const
SmallPtrSet< const GlobalVariable *, 2 > & getGlobalsPromotedToConstantPool()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getDPRCalleeSavedGapSize() const
void setPromotedConstpoolIncrease(int Sz)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:417
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1166
void setGPRCalleeSavedArea1Size(unsigned s)
void setNumAlignedDPRCS2Regs(unsigned n)
unsigned getOriginalCPIdx(unsigned CloneIdx) const
unsigned getGPRCalleeSavedArea2Offset() const
unsigned getStoredByValParamsPadding() const
unsigned getGPRCalleeSavedArea1Offset() const
void setArgumentStackSize(unsigned size)
unsigned getArgumentStackSize() const
void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx)
void setVarArgsFrameIndex(int Index)
unsigned getGPRCalleeSavedArea2Size() const
void setGPRCalleeSavedArea1Offset(unsigned o)
void setStoredByValParamsPadding(unsigned p)
unsigned getNumPICLabels() const
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
void setArgRegsSaveSize(unsigned s)
#define I(x, y, z)
Definition: MD5.cpp:58
iterator end()
Definition: DenseMap.h:108
void setDPRCalleeSavedAreaSize(unsigned s)
unsigned getFramePtrSpillOffset() const
DenseMap< const MachineBasicBlock *, unsigned >::iterator getCoalescedWeight(MachineBasicBlock *MBB)
unsigned getDPRCalleeSavedAreaOffset() const