LLVM  14.0.0git
ARMConstantPoolValue.h
Go to the documentation of this file.
1 //===- ARMConstantPoolValue.h - ARM constantpool value ----------*- 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 implements the ARM specific constantpool value class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
14 #define LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
15 
16 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/Casting.h"
21 #include <string>
22 #include <vector>
23 
24 namespace llvm {
25 
26 class BlockAddress;
27 class Constant;
28 class GlobalValue;
29 class GlobalVariable;
30 class LLVMContext;
31 class MachineBasicBlock;
32 class raw_ostream;
33 class Type;
34 
35 namespace ARMCP {
36 
37  enum ARMCPKind {
44  };
45 
47  no_modifier, /// None
48  TLSGD, /// Thread Local Storage (General Dynamic Mode)
49  GOT_PREL, /// Global Offset Table, PC Relative
50  GOTTPOFF, /// Global Offset Table, Thread Pointer Offset
51  TPOFF, /// Thread Pointer Offset
52  SECREL, /// Section Relative (Windows TLS)
53  SBREL, /// Static Base Relative (RWPI)
54  };
55 
56 } // end namespace ARMCP
57 
58 /// ARMConstantPoolValue - ARM specific constantpool value. This is used to
59 /// represent PC-relative displacement between the address of the load
60 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
62  unsigned LabelId; // Label id of the load.
63  ARMCP::ARMCPKind Kind; // Kind of constant.
64  unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
65  // 8 for ARM, 4 for Thumb.
66  ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
67  bool AddCurrentAddress;
68 
69 protected:
70  ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
71  unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
72  bool AddCurrentAddress);
73 
75  unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
76  bool AddCurrentAddress);
77 
78  template <typename Derived>
80  const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
81  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
82  if (Constants[i].isMachineConstantPoolEntry() &&
83  Constants[i].getAlign() >= Alignment) {
84  auto *CPV =
85  static_cast<ARMConstantPoolValue*>(Constants[i].Val.MachineCPVal);
86  if (Derived *APC = dyn_cast<Derived>(CPV))
87  if (cast<Derived>(this)->equals(APC))
88  return i;
89  }
90  }
91 
92  return -1;
93  }
94 
95 public:
96  ~ARMConstantPoolValue() override;
97 
98  ARMCP::ARMCPModifier getModifier() const { return Modifier; }
99  StringRef getModifierText() const;
100  bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
101 
102  bool mustAddCurrentAddress() const { return AddCurrentAddress; }
103 
104  unsigned getLabelId() const { return LabelId; }
105  unsigned char getPCAdjustment() const { return PCAdjust; }
106 
107  bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
108  bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
109  bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
110  bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
111  bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; }
112  bool isPromotedGlobal() const{ return Kind == ARMCP::CPPromotedGlobal; }
113 
115  Align Alignment) override;
116 
117  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
118 
119  /// hasSameValue - Return true if this ARM constpool value can share the same
120  /// constantpool entry as another ARM constpool value.
121  virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
122 
123  bool equals(const ARMConstantPoolValue *A) const {
124  return this->LabelId == A->LabelId &&
125  this->PCAdjust == A->PCAdjust &&
126  this->Modifier == A->Modifier;
127  }
128 
129  void print(raw_ostream &O) const override;
130  void print(raw_ostream *O) const { if (O) print(*O); }
131  void dump() const;
132 };
133 
135  V.print(O);
136  return O;
137 }
138 
139 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
140 /// Functions, and BlockAddresses.
142  const Constant *CVal; // Constant being loaded.
144 
146  unsigned ID,
147  ARMCP::ARMCPKind Kind,
148  unsigned char PCAdj,
149  ARMCP::ARMCPModifier Modifier,
150  bool AddCurrentAddress);
152  unsigned ID,
153  ARMCP::ARMCPKind Kind,
154  unsigned char PCAdj,
155  ARMCP::ARMCPModifier Modifier,
156  bool AddCurrentAddress);
158 
159 public:
160  static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
161  static ARMConstantPoolConstant *Create(const GlobalValue *GV,
162  ARMCP::ARMCPModifier Modifier);
164  const Constant *Initializer);
165  static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
166  ARMCP::ARMCPKind Kind,
167  unsigned char PCAdj);
168  static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
169  ARMCP::ARMCPKind Kind,
170  unsigned char PCAdj,
171  ARMCP::ARMCPModifier Modifier,
172  bool AddCurrentAddress);
173 
174  const GlobalValue *getGV() const;
175  const BlockAddress *getBlockAddress() const;
176 
178 
180  return iterator_range<promoted_iterator>(GVars.begin(), GVars.end());
181  }
182 
184  return CVal;
185  }
186 
188  Align Alignment) override;
189 
190  /// hasSameValue - Return true if this ARM constpool value can share the same
191  /// constantpool entry as another ARM constpool value.
192  bool hasSameValue(ARMConstantPoolValue *ACPV) override;
193 
194  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
195 
196  void print(raw_ostream &O) const override;
197 
198  static bool classof(const ARMConstantPoolValue *APV) {
199  return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA() ||
200  APV->isPromotedGlobal();
201  }
202 
203  bool equals(const ARMConstantPoolConstant *A) const {
204  return CVal == A->CVal && ARMConstantPoolValue::equals(A);
205  }
206 };
207 
208 /// ARMConstantPoolSymbol - ARM-specific constantpool values for external
209 /// symbols.
211  const std::string S; // ExtSymbol being loaded.
212 
214  unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
215  bool AddCurrentAddress);
216 
217 public:
218  static ARMConstantPoolSymbol *Create(LLVMContext &C, StringRef s, unsigned ID,
219  unsigned char PCAdj);
220 
221  StringRef getSymbol() const { return S; }
222 
224  Align Alignment) override;
225 
226  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
227 
228  /// hasSameValue - Return true if this ARM constpool value can share the same
229  /// constantpool entry as another ARM constpool value.
230  bool hasSameValue(ARMConstantPoolValue *ACPV) override;
231 
232  void print(raw_ostream &O) const override;
233 
234  static bool classof(const ARMConstantPoolValue *ACPV) {
235  return ACPV->isExtSymbol();
236  }
237 
238  bool equals(const ARMConstantPoolSymbol *A) const {
239  return S == A->S && ARMConstantPoolValue::equals(A);
240  }
241 };
242 
243 /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
244 /// block.
246  const MachineBasicBlock *MBB; // Machine basic block.
247 
248  ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
249  unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
250  bool AddCurrentAddress);
251 
252 public:
254  const MachineBasicBlock *mbb,
255  unsigned ID, unsigned char PCAdj);
256 
257  const MachineBasicBlock *getMBB() const { return MBB; }
258 
260  Align Alignment) override;
261 
262  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
263 
264  /// hasSameValue - Return true if this ARM constpool value can share the same
265  /// constantpool entry as another ARM constpool value.
266  bool hasSameValue(ARMConstantPoolValue *ACPV) override;
267 
268  void print(raw_ostream &O) const override;
269 
270  static bool classof(const ARMConstantPoolValue *ACPV) {
271  return ACPV->isMachineBasicBlock();
272  }
273 
274  bool equals(const ARMConstantPoolMBB *A) const {
275  return MBB == A->MBB && ARMConstantPoolValue::equals(A);
276  }
277 };
278 
279 } // end namespace llvm
280 
281 #endif // LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
i
i
Definition: README.txt:29
llvm::ARMCP::ARMCPModifier
ARMCPModifier
Definition: ARMConstantPoolValue.h:46
llvm::ARMConstantPoolMBB::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:290
llvm::ARMConstantPoolValue::getPCAdjustment
unsigned char getPCAdjustment() const
Definition: ARMConstantPoolValue.h:105
llvm::ARMConstantPoolConstant::getBlockAddress
const BlockAddress * getBlockAddress() const
Definition: ARMConstantPoolValue.cpp:187
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::ARMConstantPoolSymbol::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: ARMConstantPoolValue.cpp:254
llvm::dwarf::Constants
Constants
Definition: Dwarf.h:427
llvm::ARMConstantPoolValue
ARMConstantPoolValue - ARM specific constantpool value.
Definition: ARMConstantPoolValue.h:61
llvm::ARMConstantPoolValue::print
void print(raw_ostream *O) const
Definition: ARMConstantPoolValue.h:130
llvm::ARMCP::TPOFF
@ TPOFF
Global Offset Table, Thread Pointer Offset.
Definition: ARMConstantPoolValue.h:51
llvm::ARMConstantPoolMBB::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: ARMConstantPoolValue.cpp:295
StringRef.h
llvm::ARMConstantPoolConstant::classof
static bool classof(const ARMConstantPoolValue *APV)
Definition: ARMConstantPoolValue.h:198
llvm::ARMCP::CPMachineBasicBlock
@ CPMachineBasicBlock
Definition: ARMConstantPoolValue.h:42
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::ARMConstantPoolSymbol::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: ARMConstantPoolValue.cpp:239
llvm::ARMConstantPoolSymbol
ARMConstantPoolSymbol - ARM-specific constantpool values for external symbols.
Definition: ARMConstantPoolValue.h:210
llvm::MachineConstantPoolValue
Abstract base class for all machine specific constantpool value subclasses.
Definition: MachineConstantPool.h:35
llvm::ARMConstantPoolValue::isLSDA
bool isLSDA() const
Definition: ARMConstantPoolValue.h:110
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::ARMConstantPoolValue::getModifierText
StringRef getModifierText() const
Definition: ARMConstantPoolValue.cpp:53
llvm::ARMConstantPoolConstant::getGV
const GlobalValue * getGV() const
Definition: ARMConstantPoolValue.cpp:183
llvm::ARMConstantPoolMBB::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: ARMConstantPoolValue.cpp:279
llvm::SmallPtrSetIterator
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
Definition: SmallPtrSet.h:266
llvm::ARMConstantPoolSymbol::equals
bool equals(const ARMConstantPoolSymbol *A) const
Definition: ARMConstantPoolValue.h:238
llvm::ARMConstantPoolValue::dump
void dump() const
Definition: ARMConstantPoolValue.cpp:102
llvm::ARMCP::no_modifier
@ no_modifier
Definition: ARMConstantPoolValue.h:47
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::ARMConstantPoolValue::isGlobalValue
bool isGlobalValue() const
Definition: ARMConstantPoolValue.h:107
llvm::ARMCP::SECREL
@ SECREL
Thread Pointer Offset.
Definition: ARMConstantPoolValue.h:52
llvm::ARMConstantPoolValue::isExtSymbol
bool isExtSymbol() const
Definition: ARMConstantPoolValue.h:108
llvm::ARMConstantPoolValue::ARMConstantPoolValue
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress)
Definition: ARMConstantPoolValue.cpp:33
llvm::ARMCP::CPBlockAddress
@ CPBlockAddress
Definition: ARMConstantPoolValue.h:40
llvm::ARMConstantPoolConstant::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: ARMConstantPoolValue.cpp:216
llvm::ARMConstantPoolValue::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:81
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::ARMCP::CPExtSymbol
@ CPExtSymbol
Definition: ARMConstantPoolValue.h:39
llvm::ARMConstantPoolMBB::getMBB
const MachineBasicBlock * getMBB() const
Definition: ARMConstantPoolValue.h:257
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ARMConstantPoolValue::~ARMConstantPoolValue
~ARMConstantPoolValue() override
llvm::ARMConstantPoolSymbol::Create
static ARMConstantPoolSymbol * Create(LLVMContext &C, StringRef s, unsigned ID, unsigned char PCAdj)
Definition: ARMConstantPoolValue.cpp:233
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
SmallPtrSet.h
llvm::ARMConstantPoolValue::getModifier
ARMCP::ARMCPModifier getModifier() const
Definition: ARMConstantPoolValue.h:98
llvm::ARMConstantPoolConstant::promotedGlobals
iterator_range< promoted_iterator > promotedGlobals()
Definition: ARMConstantPoolValue.h:179
llvm::ARMConstantPoolValue::equals
bool equals(const ARMConstantPoolValue *A) const
Definition: ARMConstantPoolValue.h:123
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::ARMConstantPoolSymbol::getSymbol
StringRef getSymbol() const
Definition: ARMConstantPoolValue.h:221
llvm::ARMConstantPoolMBB::Create
static ARMConstantPoolMBB * Create(LLVMContext &C, const MachineBasicBlock *mbb, unsigned ID, unsigned char PCAdj)
Definition: ARMConstantPoolValue.cpp:272
llvm::ARMCP::CPPromotedGlobal
@ CPPromotedGlobal
Definition: ARMConstantPoolValue.h:43
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::ARMConstantPoolMBB::classof
static bool classof(const ARMConstantPoolValue *ACPV)
Definition: ARMConstantPoolValue.h:270
llvm::ARMConstantPoolSymbol::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:249
llvm::ISD::BlockAddress
@ BlockAddress
Definition: ISDOpcodes.h:84
llvm::ARMConstantPoolConstant::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:209
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:192
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::ARMCP::TLSGD
@ TLSGD
None.
Definition: ARMConstantPoolValue.h:48
llvm::ARMCP::GOT_PREL
@ GOT_PREL
Thread Local Storage (General Dynamic Mode)
Definition: ARMConstantPoolValue.h:49
llvm::SmallPtrSetImpl::end
iterator end() const
Definition: SmallPtrSet.h:407
llvm::ARMCP::ARMCPKind
ARMCPKind
Definition: ARMConstantPoolValue.h:37
s
multiplies can be turned into SHL s
Definition: README.txt:370
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::ARMConstantPoolConstant::equals
bool equals(const ARMConstantPoolConstant *A) const
Definition: ARMConstantPoolValue.h:203
llvm::MachineConstantPool
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
Definition: MachineConstantPool.h:117
MachineConstantPool.h
llvm::SmallPtrSetImpl::begin
iterator begin() const
Definition: SmallPtrSet.h:402
llvm::ARMConstantPoolConstant
ARMConstantPoolConstant - ARM-specific constant pool values for Constants, Functions,...
Definition: ARMConstantPoolValue.h:141
TemplateParamKind::Type
@ Type
llvm::ARMConstantPoolValue::hasModifier
bool hasModifier() const
Definition: ARMConstantPoolValue.h:100
iterator_range.h
llvm::ARMConstantPoolMBB::hasSameValue
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
Definition: ARMConstantPoolValue.cpp:284
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:848
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::ARMConstantPoolSymbol::hasSameValue
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
Definition: ARMConstantPoolValue.cpp:244
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:313
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::Init
Definition: Record.h:271
llvm::ARMConstantPoolValue::getLabelId
unsigned getLabelId() const
Definition: ARMConstantPoolValue.h:104
llvm::ARMConstantPoolConstant::getPromotedGlobalInit
const Constant * getPromotedGlobalInit() const
Definition: ARMConstantPoolValue.h:183
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
llvm::ARMConstantPoolValue::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: ARMConstantPoolValue.cpp:107
llvm::ARMConstantPoolValue::isBlockAddress
bool isBlockAddress() const
Definition: ARMConstantPoolValue.h:109
llvm::ARMConstantPoolValue::mustAddCurrentAddress
bool mustAddCurrentAddress() const
Definition: ARMConstantPoolValue.h:102
llvm::ARMConstantPoolConstant::Create
static ARMConstantPoolConstant * Create(const Constant *C, unsigned ID)
Definition: ARMConstantPoolValue.cpp:148
Casting.h
llvm::ARMCP::CPLSDA
@ CPLSDA
Definition: ARMConstantPoolValue.h:41
llvm::ARMConstantPoolSymbol::classof
static bool classof(const ARMConstantPoolValue *ACPV)
Definition: ARMConstantPoolValue.h:234
llvm::ARMConstantPoolValue::isPromotedGlobal
bool isPromotedGlobal() const
Definition: ARMConstantPoolValue.h:112
llvm::ARMConstantPoolConstant::hasSameValue
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
Definition: ARMConstantPoolValue.cpp:204
llvm::getAlign
bool getAlign(const Function &F, unsigned index, unsigned &align)
Definition: NVPTXUtilities.cpp:284
llvm::ARMConstantPoolMBB::equals
bool equals(const ARMConstantPoolMBB *A) const
Definition: ARMConstantPoolValue.h:274
llvm::ARMCP::GOTTPOFF
@ GOTTPOFF
Global Offset Table, PC Relative.
Definition: ARMConstantPoolValue.h:50
llvm::ARMConstantPoolValue::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: ARMConstantPoolValue.cpp:75
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::ARMConstantPoolConstant::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: ARMConstantPoolValue.cpp:191
llvm::ARMConstantPoolMBB
ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic block.
Definition: ARMConstantPoolValue.h:245
llvm::ARMConstantPoolValue::hasSameValue
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
Definition: ARMConstantPoolValue.cpp:87
llvm::ARMConstantPoolValue::isMachineBasicBlock
bool isMachineBasicBlock() const
Definition: ARMConstantPoolValue.h:111
llvm::ARMConstantPoolValue::getExistingMachineCPValueImpl
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment)
Definition: ARMConstantPoolValue.h:79
llvm::ARMCP::CPValue
@ CPValue
Definition: ARMConstantPoolValue.h:38
llvm::ARMCP::SBREL
@ SBREL
Section Relative (Windows TLS)
Definition: ARMConstantPoolValue.h:53
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37