LLVM 17.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
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"
21#include "llvm/IR/Type.h"
26
27using namespace llvm;
28
29//===----------------------------------------------------------------------===//
30// ARMConstantPoolValue
31//===----------------------------------------------------------------------===//
32
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
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.
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
80void
82 ID.AddInteger(LabelId);
83 ID.AddInteger(PCAdjust);
84}
85
86bool
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
120ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty,
121 const Constant *C,
122 unsigned ID,
123 ARMCP::ARMCPKind Kind,
124 unsigned char PCAdj,
125 ARMCP::ARMCPModifier Modifier,
126 bool AddCurrentAddress)
127 : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress),
128 CVal(C) {}
129
130ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
131 unsigned ID,
132 ARMCP::ARMCPKind Kind,
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
140ARMConstantPoolConstant::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
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
225ARMConstantPoolSymbol::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
263ARMConstantPoolMBB::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}
MachineBasicBlock & MBB
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:492
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines a hash set that can be used to remove duplication of nodes in a graph.
static M68kRelType getType(unsigned Kind, MCSymbolRefExpr::VariantKind &Modifier, bool &IsPCRel)
ARMConstantPoolConstant - ARM-specific constant pool values for Constants, Functions,...
const GlobalValue * getGV() const
static ARMConstantPoolConstant * Create(const Constant *C, unsigned ID)
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
void print(raw_ostream &O) const override
print - Implement operator<<
const BlockAddress * getBlockAddress() const
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic block.
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
static ARMConstantPoolMBB * Create(LLVMContext &C, const MachineBasicBlock *mbb, unsigned ID, unsigned char PCAdj)
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
void print(raw_ostream &O) const override
print - Implement operator<<
ARMConstantPoolSymbol - ARM-specific constantpool values for external symbols.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
void print(raw_ostream &O) const override
print - Implement operator<<
static ARMConstantPoolSymbol * Create(LLVMContext &C, StringRef s, unsigned ID, unsigned char PCAdj)
ARMConstantPoolValue - ARM specific constantpool value.
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress)
void print(raw_ostream &O) const override
print - Implement operator<<
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
The address of a basic block.
Definition: Constants.h:875
This is an important base class in LLVM.
Definition: Constant.h:41
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:318
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Abstract base class for all machine specific constantpool value subclasses.
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt32Ty(LLVMContext &C)
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SECREL
Thread Pointer Offset.
@ GOT_PREL
Thread Local Storage (General Dynamic Mode)
@ SBREL
Section Relative (Windows TLS)
@ GOTTPOFF
Global Offset Table, PC Relative.
@ TPOFF
Global Offset Table, Thread Pointer Offset.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Definition: BitVector.h:851
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39