LLVM  10.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  /// LRSpilled - True if the LR register has been for spilled for
65  /// any reason, so it's legal to emit an ARM::tBfar (i.e. "bl").
66  bool LRSpilled = false;
67 
68  /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
69  /// spill stack offset.
70  unsigned FramePtrSpillOffset = 0;
71 
72  /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
73  /// register spills areas. For Mac OS X:
74  ///
75  /// GPR callee-saved (1) : r4, r5, r6, r7, lr
76  /// --------------------------------------------
77  /// GPR callee-saved (2) : r8, r10, r11
78  /// --------------------------------------------
79  /// DPR callee-saved : d8 - d15
80  ///
81  /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
82  /// Some may be spilled after the stack has been realigned.
83  unsigned GPRCS1Offset = 0;
84  unsigned GPRCS2Offset = 0;
85  unsigned DPRCSOffset = 0;
86 
87  /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
88  /// areas.
89  unsigned GPRCS1Size = 0;
90  unsigned GPRCS2Size = 0;
91  unsigned DPRCSAlignGapSize = 0;
92  unsigned DPRCSSize = 0;
93 
94  /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
95  /// the aligned portion of the stack frame. This is always a contiguous
96  /// sequence of D-registers starting from d8.
97  ///
98  /// We do not keep track of the frame indices used for these registers - they
99  /// behave like any other frame index in the aligned stack frame. These
100  /// registers also aren't included in DPRCSSize above.
101  unsigned NumAlignedDPRCS2Regs = 0;
102 
103  unsigned PICLabelUId = 0;
104 
105  /// VarArgsFrameIndex - FrameIndex for start of varargs area.
106  int VarArgsFrameIndex = 0;
107 
108  /// HasITBlocks - True if IT blocks have been inserted.
109  bool HasITBlocks = false;
110 
111  /// CPEClones - Track constant pool entries clones created by Constant Island
112  /// pass.
114 
115  /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
116  /// being passed on the stack
117  unsigned ArgumentStackSize = 0;
118 
119  /// CoalescedWeights - mapping of basic blocks to the rolling counter of
120  /// coalesced weights.
122 
123  /// True if this function has a subset of CSRs that is handled explicitly via
124  /// copies.
125  bool IsSplitCSR = false;
126 
127  /// Globals that have had their storage promoted into the constant pool.
128  SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
129 
130  /// The amount the literal pool has been increasedby due to promoted globals.
131  int PromotedGlobalsIncrease = 0;
132 
133  /// True if r0 will be preserved by a call to this function (e.g. C++
134  /// con/destructors).
135  bool PreservesR0 = false;
136 
137 public:
138  ARMFunctionInfo() = default;
139 
140  explicit ARMFunctionInfo(MachineFunction &MF);
141 
142  bool isThumbFunction() const { return isThumb; }
143  bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
144  bool isThumb2Function() const { return isThumb && hasThumb2; }
145 
146  unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
147  void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
148 
149  unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
150  void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
151 
152  unsigned getReturnRegsCount() const { return ReturnRegsCount; }
153  void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
154 
155  bool hasStackFrame() const { return HasStackFrame; }
156  void setHasStackFrame(bool s) { HasStackFrame = s; }
157 
158  bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
159  void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
160 
161  bool isLRSpilled() const { return LRSpilled; }
162  void setLRIsSpilled(bool s) { LRSpilled = s; }
163 
164  bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
165  void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
166 
167  unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
168  void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
169 
170  unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
171  void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
172 
173  unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
174  unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
175  unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
176 
177  void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
178  void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
179  void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
180 
181  unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
182  unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
183  unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
184  unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
185 
186  void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
187  void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
188  void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
189  void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
190 
191  unsigned getArgumentStackSize() const { return ArgumentStackSize; }
192  void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
193 
194  void initPICLabelUId(unsigned UId) {
195  PICLabelUId = UId;
196  }
197 
198  unsigned getNumPICLabels() const {
199  return PICLabelUId;
200  }
201 
202  unsigned createPICLabelUId() {
203  return PICLabelUId++;
204  }
205 
206  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
207  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
208 
209  bool hasITBlocks() const { return HasITBlocks; }
210  void setHasITBlocks(bool h) { HasITBlocks = h; }
211 
212  bool isSplitCSR() const { return IsSplitCSR; }
213  void setIsSplitCSR(bool s) { IsSplitCSR = s; }
214 
215  void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
216  if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
217  llvm_unreachable("Duplicate entries!");
218  }
219 
220  unsigned getOriginalCPIdx(unsigned CloneIdx) const {
222  if (I != CPEClones.end())
223  return I->second;
224  else
225  return -1U;
226  }
227 
229  MachineBasicBlock* MBB) {
230  auto It = CoalescedWeights.find(MBB);
231  if (It == CoalescedWeights.end()) {
232  It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
233  }
234  return It;
235  }
236 
237  /// Indicate to the backend that \c GV has had its storage changed to inside
238  /// a constant pool. This means it no longer needs to be emitted as a
239  /// global variable.
241  PromotedGlobals.insert(GV);
242  }
244  return PromotedGlobals;
245  }
247  return PromotedGlobalsIncrease;
248  }
250  PromotedGlobalsIncrease = Sz;
251  }
252 
254 
255  void setPreservesR0() { PreservesR0 = true; }
256  bool getPreservesR0() const { return PreservesR0; }
257 };
258 
259 } // end namespace llvm
260 
261 #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:195
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:150
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()
DenseMap< unsigned, unsigned > EHPrologueRemappedRegs
#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:1146
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:82
void setDPRCalleeSavedAreaSize(unsigned s)
unsigned getFramePtrSpillOffset() const
DenseMap< const MachineBasicBlock *, unsigned >::iterator getCoalescedWeight(MachineBasicBlock *MBB)
unsigned getDPRCalleeSavedAreaOffset() const