LLVM 20.0.0git
XtensaConstantPoolValue.h
Go to the documentation of this file.
1//===- XtensaConstantPoolValue.h - Xtensa 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 Xtensa specific constantpool value class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H
14#define LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H
15
19#include <cstddef>
20#include <string>
21#include <vector>
22
23namespace llvm {
24
25class BlockAddress;
26class Constant;
27class GlobalValue;
28class LLVMContext;
29class MachineBasicBlock;
30
31namespace XtensaCP {
37};
38
40 no_modifier, // None
41 TPOFF // Thread Pointer Offset
42};
43} // namespace XtensaCP
44
45/// XtensaConstantPoolValue - Xtensa specific constantpool value. This is used
46/// to represent PC-relative displacement between the address of the load
47/// instruction and the constant being loaded.
49 unsigned LabelId; // Label id of the load.
50 XtensaCP::XtensaCPKind Kind; // Kind of constant.
51 XtensaCP::XtensaCPModifier Modifier; // Symbol name modifier
52 //(for example Global Variable name)
53
54protected:
56 Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,
58
60 LLVMContext &C, unsigned id, XtensaCP::XtensaCPKind Kind,
62
63 template <typename Derived>
65 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
66 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
67 if (Constants[i].isMachineConstantPoolEntry() &&
68 (Constants[i].getAlign() >= Alignment)) {
69 auto *CPV = static_cast<XtensaConstantPoolValue *>(
70 Constants[i].Val.MachineCPVal);
71 if (Derived *APC = dyn_cast<Derived>(CPV))
72 if (cast<Derived>(this)->equals(APC))
73 return i;
74 }
75 }
76
77 return -1;
78 }
79
80public:
81 ~XtensaConstantPoolValue() override;
82
83 XtensaCP::XtensaCPModifier getModifier() const { return Modifier; }
84 bool hasModifier() const { return Modifier != XtensaCP::no_modifier; }
86
87 unsigned getLabelId() const { return LabelId; }
88 void setLabelId(unsigned ID) { LabelId = ID; }
89
90 bool isExtSymbol() const { return Kind == XtensaCP::CPExtSymbol; }
91 bool isBlockAddress() const { return Kind == XtensaCP::CPBlockAddress; }
92 bool isMachineBasicBlock() const {
93 return Kind == XtensaCP::CPMachineBasicBlock;
94 }
95 bool isJumpTable() const { return Kind == XtensaCP::CPJumpTable; }
96
98 Align Alignment) override;
99
101
102 /// hasSameValue - Return true if this Xtensa constpool value can share the
103 /// same constantpool entry as another Xtensa constpool value.
104 virtual bool hasSameValue(XtensaConstantPoolValue *ACPV);
105
106 bool equals(const XtensaConstantPoolValue *A) const {
107 return this->LabelId == A->LabelId && this->Modifier == A->Modifier;
108 }
109
110 void print(raw_ostream &O) const override;
111
112#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
113 void dump() const;
114#endif
115};
116
118 const XtensaConstantPoolValue &V) {
119 V.print(O);
120 return O;
121}
122
123/// XtensaConstantPoolConstant - Xtensa-specific constant pool values for
124/// Constants (for example BlockAddresses).
126 const Constant *CVal; // Constant being loaded.
127
128 XtensaConstantPoolConstant(const Constant *C, unsigned ID,
130
131public:
132 static XtensaConstantPoolConstant *Create(const Constant *C, unsigned ID,
134
135 const BlockAddress *getBlockAddress() const;
136
138 Align Alignment) override;
139
140 /// hasSameValue - Return true if this Xtensa constpool value can share the
141 /// same constantpool entry as another Xtensa constpool value.
142 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
143
145
146 void print(raw_ostream &O) const override;
147 static bool classof(const XtensaConstantPoolValue *APV) {
148 return APV->isBlockAddress();
149 }
150
152 return CVal == A->CVal && XtensaConstantPoolValue::equals(A);
153 }
154};
155
156/// XtensaConstantPoolSymbol - Xtensa-specific constantpool values for external
157/// symbols.
159 const std::string S; // ExtSymbol being loaded.
160 bool PrivateLinkage;
161
163 LLVMContext &C, const char *S, unsigned Id, bool PrivLinkage,
165
166public:
168 Create(LLVMContext &C, const char *S, unsigned ID, bool PrivLinkage,
170
171 const char *getSymbol() const { return S.c_str(); }
172
174 Align Alignment) override;
175
177
178 /// hasSameValue - Return true if this Xtensa constpool value can share the
179 /// same constantpool entry as another Xtensa constpool value.
180 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
181
182 bool isPrivateLinkage() { return PrivateLinkage; }
183
184 void print(raw_ostream &O) const override;
185
186 static bool classof(const XtensaConstantPoolValue *ACPV) {
187 return ACPV->isExtSymbol();
188 }
189
190 bool equals(const XtensaConstantPoolSymbol *A) const {
191 return S == A->S && XtensaConstantPoolValue::equals(A);
192 }
193};
194
195/// XtensaConstantPoolMBB - Xtensa-specific constantpool value of a machine
196/// basic block.
198 const MachineBasicBlock *MBB; // Machine basic block.
199
201 unsigned ID);
202
203public:
205 const MachineBasicBlock *M, unsigned ID);
206
207 const MachineBasicBlock *getMBB() const { return MBB; }
208
210 Align Alignment) override;
211
213
214 /// hasSameValue - Return true if this Xtensa constpool value can share the
215 /// same constantpool entry as another Xtensa constpool value.
216 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
217
218 void print(raw_ostream &O) const override;
219
220 static bool classof(const XtensaConstantPoolValue *ACPV) {
221 return ACPV->isMachineBasicBlock();
222 }
223
224 bool equals(const XtensaConstantPoolMBB *A) const {
225 return MBB == A->MBB && XtensaConstantPoolValue::equals(A);
226 }
227};
228
229/// XtensaConstantPoolJumpTable - Xtensa-specific constantpool values for Jump
230/// Table symbols.
232 unsigned Idx; // Jump Table Index.
233
235
236public:
238
239 unsigned getIndex() const { return Idx; }
240
242 Align Alignment) override;
243
245
246 /// hasSameValue - Return true if this Xtensa constpool value can share the
247 /// same constantpool entry as another Xtensa constpool value.
248 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
249
250 void print(raw_ostream &O) const override;
251
252 static bool classof(const XtensaConstantPoolValue *ACPV) {
253 return ACPV->isJumpTable();
254 }
255
257 return Idx == A->Idx && XtensaConstantPoolValue::equals(A);
258 }
259};
260
261} // namespace llvm
262
263#endif /* LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H */
MachineBasicBlock & MBB
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
The address of a basic block.
Definition: Constants.h:890
This is an important base class in LLVM.
Definition: Constant.h:42
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:327
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
XtensaConstantPoolConstant - Xtensa-specific constant pool values for Constants (for example BlockAdd...
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
bool hasSameValue(XtensaConstantPoolValue *ACPV) override
hasSameValue - Return true if this Xtensa constpool value can share the same constantpool entry as an...
static bool classof(const XtensaConstantPoolValue *APV)
const BlockAddress * getBlockAddress() const
bool equals(const XtensaConstantPoolConstant *A) const
static XtensaConstantPoolConstant * Create(const Constant *C, unsigned ID, XtensaCP::XtensaCPKind Kind)
void print(raw_ostream &O) const override
print - Implement operator<<
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
XtensaConstantPoolJumpTable - Xtensa-specific constantpool values for Jump Table symbols.
static XtensaConstantPoolJumpTable * Create(LLVMContext &C, unsigned Idx)
bool equals(const XtensaConstantPoolJumpTable *A) const
static bool classof(const XtensaConstantPoolValue *ACPV)
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
bool hasSameValue(XtensaConstantPoolValue *ACPV) override
hasSameValue - Return true if this Xtensa constpool value can share the same constantpool entry as an...
XtensaConstantPoolMBB - Xtensa-specific constantpool value of a machine basic block.
static bool classof(const XtensaConstantPoolValue *ACPV)
bool equals(const XtensaConstantPoolMBB *A) const
static XtensaConstantPoolMBB * Create(LLVMContext &C, const MachineBasicBlock *M, unsigned ID)
void print(raw_ostream &O) const override
print - Implement operator<<
bool hasSameValue(XtensaConstantPoolValue *ACPV) override
hasSameValue - Return true if this Xtensa constpool value can share the same constantpool entry as an...
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
const MachineBasicBlock * getMBB() const
XtensaConstantPoolSymbol - Xtensa-specific constantpool values for external symbols.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
bool equals(const XtensaConstantPoolSymbol *A) const
static bool classof(const XtensaConstantPoolValue *ACPV)
void print(raw_ostream &O) const override
print - Implement operator<<
static XtensaConstantPoolSymbol * Create(LLVMContext &C, const char *S, unsigned ID, bool PrivLinkage, XtensaCP::XtensaCPModifier Modifier=XtensaCP::no_modifier)
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
bool hasSameValue(XtensaConstantPoolValue *ACPV) override
hasSameValue - Return true if this Xtensa constpool value can share the same constantpool entry as an...
XtensaConstantPoolValue - Xtensa specific constantpool value.
virtual bool hasSameValue(XtensaConstantPoolValue *ACPV)
hasSameValue - Return true if this Xtensa constpool value can share the same constantpool entry as an...
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment)
void print(raw_ostream &O) const override
print - Implement operator<<
bool equals(const XtensaConstantPoolValue *A) const
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
XtensaCP::XtensaCPModifier getModifier() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ BlockAddress
Definition: ISDOpcodes.h:84
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MaybeAlign getAlign(const Function &F, unsigned Index)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:293
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39