LLVM  14.0.0git
ARMConstantPoolValue.cpp
Go to the documentation of this file.
1 //===- ARMConstantPoolValue.cpp - ARM constantpool value ------------------===//
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 #include "ARMConstantPoolValue.h"
14 #include "llvm/ADT/FoldingSet.h"
16 #include "llvm/Config/llvm-config.h"
17 #include "llvm/IR/Constant.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/GlobalVariable.h"
21 #include "llvm/IR/Type.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/Compiler.h"
26 
27 using namespace llvm;
28 
29 //===----------------------------------------------------------------------===//
30 // ARMConstantPoolValue
31 //===----------------------------------------------------------------------===//
32 
34  ARMCP::ARMCPKind kind,
35  unsigned char PCAdj,
36  ARMCP::ARMCPModifier modifier,
37  bool addCurrentAddress)
38  : MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
39  PCAdjust(PCAdj), Modifier(modifier),
40  AddCurrentAddress(addCurrentAddress) {}
41 
43  ARMCP::ARMCPKind kind,
44  unsigned char PCAdj,
45  ARMCP::ARMCPModifier modifier,
46  bool addCurrentAddress)
47  : MachineConstantPoolValue((Type*)Type::getInt32Ty(C)),
48  LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier),
49  AddCurrentAddress(addCurrentAddress) {}
50 
52 
54  switch (Modifier) {
55  // FIXME: Are these case sensitive? It'd be nice to lower-case all the
56  // strings if that's legal.
57  case ARMCP::no_modifier:
58  return "none";
59  case ARMCP::TLSGD:
60  return "tlsgd";
61  case ARMCP::GOT_PREL:
62  return "GOT_PREL";
63  case ARMCP::GOTTPOFF:
64  return "gottpoff";
65  case ARMCP::TPOFF:
66  return "tpoff";
67  case ARMCP::SBREL:
68  return "SBREL";
69  case ARMCP::SECREL:
70  return "secrel32";
71  }
72  llvm_unreachable("Unknown modifier!");
73 }
74 
76  Align Alignment) {
77  llvm_unreachable("Shouldn't be calling this directly!");
78 }
79 
80 void
82  ID.AddInteger(LabelId);
83  ID.AddInteger(PCAdjust);
84 }
85 
86 bool
88  if (ACPV->Kind == Kind &&
89  ACPV->PCAdjust == PCAdjust &&
90  ACPV->Modifier == Modifier &&
91  ACPV->LabelId == LabelId &&
92  ACPV->AddCurrentAddress == AddCurrentAddress) {
93  // Two PC relative constpool entries containing the same GV address or
94  // external symbols. FIXME: What about blockaddress?
95  if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
96  return true;
97  }
98  return false;
99 }
100 
101 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
103  errs() << " " << *this;
104 }
105 #endif
106 
108  if (Modifier) O << "(" << getModifierText() << ")";
109  if (PCAdjust != 0) {
110  O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
111  if (AddCurrentAddress) O << "-.";
112  O << ")";
113  }
114 }
115 
116 //===----------------------------------------------------------------------===//
117 // ARMConstantPoolConstant
118 //===----------------------------------------------------------------------===//
119 
120 ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty,
121  const Constant *C,
122  unsigned ID,
124  unsigned char PCAdj,
125  ARMCP::ARMCPModifier Modifier,
126  bool AddCurrentAddress)
127  : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress),
128  CVal(C) {}
129 
130 ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
131  unsigned ID,
133  unsigned char PCAdj,
134  ARMCP::ARMCPModifier Modifier,
135  bool AddCurrentAddress)
136  : ARMConstantPoolValue((Type*)C->getType(), ID, Kind, PCAdj, Modifier,
137  AddCurrentAddress),
138  CVal(C) {}
139 
140 ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
141  const Constant *C)
142  : ARMConstantPoolValue((Type *)C->getType(), 0, ARMCP::CPPromotedGlobal, 0,
143  ARMCP::no_modifier, false), CVal(C) {
144  GVars.insert(GV);
145 }
146 
149  return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
150  ARMCP::no_modifier, false);
151 }
152 
155  const Constant *Initializer) {
156  return new ARMConstantPoolConstant(GVar, Initializer);
157 }
158 
161  ARMCP::ARMCPModifier Modifier) {
163  GV, 0, ARMCP::CPValue, 0,
164  Modifier, false);
165 }
166 
169  ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
170  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
171  ARMCP::no_modifier, false);
172 }
173 
176  ARMCP::ARMCPKind Kind, unsigned char PCAdj,
177  ARMCP::ARMCPModifier Modifier,
178  bool AddCurrentAddress) {
179  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
180  AddCurrentAddress);
181 }
182 
184  return dyn_cast_or_null<GlobalValue>(CVal);
185 }
186 
188  return dyn_cast_or_null<BlockAddress>(CVal);
189 }
190 
192  Align Alignment) {
193  int index =
194  getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
195  if (index != -1) {
196  auto *CPV = static_cast<ARMConstantPoolValue*>(
197  CP->getConstants()[index].Val.MachineCPVal);
198  auto *Constant = cast<ARMConstantPoolConstant>(CPV);
199  Constant->GVars.insert(GVars.begin(), GVars.end());
200  }
201  return index;
202 }
203 
205  const ARMConstantPoolConstant *ACPC = dyn_cast<ARMConstantPoolConstant>(ACPV);
206  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
207 }
208 
210  ID.AddPointer(CVal);
211  for (const auto *GV : GVars)
212  ID.AddPointer(GV);
214 }
215 
217  O << CVal->getName();
219 }
220 
221 //===----------------------------------------------------------------------===//
222 // ARMConstantPoolSymbol
223 //===----------------------------------------------------------------------===//
224 
225 ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, StringRef s,
226  unsigned id, unsigned char PCAdj,
227  ARMCP::ARMCPModifier Modifier,
228  bool AddCurrentAddress)
229  : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
230  AddCurrentAddress),
231  S(std::string(s)) {}
232 
234  StringRef s, unsigned ID,
235  unsigned char PCAdj) {
236  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
237 }
238 
240  Align Alignment) {
241  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
242 }
243 
245  const ARMConstantPoolSymbol *ACPS = dyn_cast<ARMConstantPoolSymbol>(ACPV);
246  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
247 }
248 
250  ID.AddString(S);
252 }
253 
255  O << S;
257 }
258 
259 //===----------------------------------------------------------------------===//
260 // ARMConstantPoolMBB
261 //===----------------------------------------------------------------------===//
262 
263 ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
264  const MachineBasicBlock *mbb,
265  unsigned id, unsigned char PCAdj,
266  ARMCP::ARMCPModifier Modifier,
267  bool AddCurrentAddress)
268  : ARMConstantPoolValue(C, id, ARMCP::CPMachineBasicBlock, PCAdj,
269  Modifier, AddCurrentAddress),
270  MBB(mbb) {}
271 
273  const MachineBasicBlock *mbb,
274  unsigned ID,
275  unsigned char PCAdj) {
276  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
277 }
278 
280  Align Alignment) {
281  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
282 }
283 
285  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
286  return ACPMBB && ACPMBB->MBB == MBB &&
288 }
289 
291  ID.AddPointer(MBB);
293 }
294 
296  O << printMBBReference(*MBB);
298 }
llvm::ARMCP::ARMCPModifier
ARMCPModifier
Definition: ARMConstantPoolValue.h:46
llvm::ARMConstantPoolMBB::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:290
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:491
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::ARMConstantPoolValue
ARMConstantPoolValue - ARM specific constantpool value.
Definition: ARMConstantPoolValue.h:61
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
llvm::printMBBReference
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Definition: MachineBasicBlock.cpp:119
ErrorHandling.h
llvm::ARMCP::CPMachineBasicBlock
@ CPMachineBasicBlock
Definition: ARMConstantPoolValue.h:42
llvm::GlobalVariable
Definition: GlobalVariable.h:40
MachineBasicBlock.h
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::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::ARMConstantPoolValue::dump
void dump() const
Definition: ARMConstantPoolValue.cpp:102
llvm::ARMCP::no_modifier
@ no_modifier
Definition: ARMConstantPoolValue.h:47
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::ARMCP::SECREL
@ SECREL
Thread Pointer Offset.
Definition: ARMConstantPoolValue.h:52
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:203
llvm::ARMConstantPoolValue::ARMConstantPoolValue
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress)
Definition: ARMConstantPoolValue.cpp:33
ARMConstantPoolValue.h
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1335
GlobalValue.h
llvm::ARMConstantPoolConstant::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: ARMConstantPoolValue.cpp:216
Constants.h
llvm::ARMConstantPoolValue::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:81
llvm::ARMCP::CPExtSymbol
@ CPExtSymbol
Definition: ARMConstantPoolValue.h:39
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ARMConstantPoolValue::~ARMConstantPoolValue
~ARMConstantPoolValue() override
false
Definition: StackSlotColoring.cpp:142
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::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
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::lltok::Kind
Kind
Definition: LLToken.h:18
Type.h
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::ARMConstantPoolSymbol::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:249
llvm::ARMConstantPoolConstant::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: ARMConstantPoolValue.cpp:209
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:197
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
index
splat index
Definition: README_ALTIVEC.txt:181
llvm::ARMCP::GOT_PREL
@ GOT_PREL
Thread Local Storage (General Dynamic Mode)
Definition: ARMConstantPoolValue.h:49
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::MachineConstantPool
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
Definition: MachineConstantPool.h:117
llvm::ARMConstantPoolConstant
ARMConstantPoolConstant - ARM-specific constant pool values for Constants, Functions,...
Definition: ARMConstantPoolValue.h:141
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_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
Compiler.h
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:990
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::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
FoldingSet.h
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
Constant.h
llvm::ARMConstantPoolValue::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: ARMConstantPoolValue.cpp:107
std
Definition: BitVector.h:838
llvm::ARMConstantPoolConstant::Create
static ARMConstantPoolConstant * Create(const Constant *C, unsigned ID)
Definition: ARMConstantPoolValue.cpp:148
GlobalVariable.h
Casting.h
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::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::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
raw_ostream.h
llvm::ARMCP::CPValue
@ CPValue
Definition: ARMConstantPoolValue.h:38
llvm::ARMCP::SBREL
@ SBREL
Section Relative (Windows TLS)
Definition: ARMConstantPoolValue.h:53
SpecialSubKind::string
@ string
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37