LLVM 24.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 LLVMContext;
29
30namespace XtensaCP {
37
39 no_modifier, // None
40 TPOFF // Thread Pointer Offset
41};
42} // namespace XtensaCP
43
44/// XtensaConstantPoolValue - Xtensa specific constantpool value. This is used
45/// to represent PC-relative displacement between the address of the load
46/// instruction and the constant being loaded.
48 unsigned LabelId; // Label id of the load.
49 XtensaCP::XtensaCPKind Kind; // Kind of constant.
50 XtensaCP::XtensaCPModifier Modifier; // Symbol name modifier
51 //(for example Global Variable name)
52
53protected:
55 Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,
57
59 LLVMContext &C, unsigned id, XtensaCP::XtensaCPKind Kind,
61
62 template <typename Derived>
64 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
65 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
66 if (Constants[i].isMachineConstantPoolEntry() &&
67 (Constants[i].getAlign() >= Alignment)) {
68 auto *CPV = static_cast<XtensaConstantPoolValue *>(
69 Constants[i].Val.MachineCPVal);
70 if (Derived *APC = dyn_cast<Derived>(CPV))
71 if (cast<Derived>(this)->equals(APC))
72 return i;
73 }
74 }
75
76 return -1;
77 }
78
79public:
80 ~XtensaConstantPoolValue() override;
81
82 XtensaCP::XtensaCPModifier getModifier() const { return Modifier; }
83 bool hasModifier() const { return Modifier != XtensaCP::no_modifier; }
85
86 unsigned getLabelId() const { return LabelId; }
87 void setLabelId(unsigned ID) { LabelId = ID; }
88
89 bool isExtSymbol() const { return Kind == XtensaCP::CPExtSymbol; }
90 bool isBlockAddress() const { return Kind == XtensaCP::CPBlockAddress; }
91 bool isMachineBasicBlock() const {
92 return Kind == XtensaCP::CPMachineBasicBlock;
93 }
94 bool isJumpTable() const { return Kind == XtensaCP::CPJumpTable; }
95
97 Align Alignment) override;
98
99 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
100
101 /// hasSameValue - Return true if this Xtensa constpool value can share the
102 /// same constantpool entry as another Xtensa constpool value.
103 virtual bool hasSameValue(XtensaConstantPoolValue *ACPV);
104
105 bool equals(const XtensaConstantPoolValue *A) const {
106 return this->LabelId == A->LabelId && this->Modifier == A->Modifier;
107 }
108
109 void print(raw_ostream &O) const override;
110
111#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
112 void dump() const;
113#endif
114};
115
117 const XtensaConstantPoolValue &V) {
118 V.print(O);
119 return O;
120}
121
122/// XtensaConstantPoolConstant - Xtensa-specific constant pool values for
123/// Constants (for example BlockAddresses).
124class XtensaConstantPoolConstant : public XtensaConstantPoolValue {
125 const Constant *CVal; // Constant being loaded.
126
127 XtensaConstantPoolConstant(const Constant *C, unsigned ID,
129
130public:
131 static XtensaConstantPoolConstant *Create(const Constant *C, unsigned ID,
133
134 const BlockAddress *getBlockAddress() const;
135
137 Align Alignment) override;
138
139 /// hasSameValue - Return true if this Xtensa constpool value can share the
140 /// same constantpool entry as another Xtensa constpool value.
141 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
142
143 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
144
145 void print(raw_ostream &O) const override;
146 static bool classof(const XtensaConstantPoolValue *APV) {
147 return APV->isBlockAddress();
148 }
149
150 bool equals(const XtensaConstantPoolConstant *A) const {
151 return CVal == A->CVal && XtensaConstantPoolValue::equals(A);
152 }
153};
154
155/// XtensaConstantPoolSymbol - Xtensa-specific constantpool values for external
156/// symbols.
157class XtensaConstantPoolSymbol : public XtensaConstantPoolValue {
158 const std::string S; // ExtSymbol being loaded.
159 bool PrivateLinkage;
160
161 XtensaConstantPoolSymbol(
162 LLVMContext &C, const char *S, unsigned Id, bool PrivLinkage,
164
165public:
166 static XtensaConstantPoolSymbol *
167 Create(LLVMContext &C, const char *S, unsigned ID, bool PrivLinkage,
169
170 const char *getSymbol() const { return S.c_str(); }
171
173 Align Alignment) override;
174
175 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
176
177 /// hasSameValue - Return true if this Xtensa constpool value can share the
178 /// same constantpool entry as another Xtensa constpool value.
179 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
180
181 bool isPrivateLinkage() { return PrivateLinkage; }
182
183 void print(raw_ostream &O) const override;
184
185 static bool classof(const XtensaConstantPoolValue *ACPV) {
186 return ACPV->isExtSymbol();
187 }
188
189 bool equals(const XtensaConstantPoolSymbol *A) const {
190 return S == A->S && XtensaConstantPoolValue::equals(A);
191 }
192};
193
194/// XtensaConstantPoolMBB - Xtensa-specific constantpool value of a machine
195/// basic block.
196class XtensaConstantPoolMBB : public XtensaConstantPoolValue {
197 const MachineBasicBlock *MBB; // Machine basic block.
198
199 XtensaConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *M,
200 unsigned ID);
201
202public:
203 static XtensaConstantPoolMBB *Create(LLVMContext &C,
204 const MachineBasicBlock *M, unsigned ID);
205
206 const MachineBasicBlock *getMBB() const { return MBB; }
207
209 Align Alignment) override;
210
211 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
212
213 /// hasSameValue - Return true if this Xtensa constpool value can share the
214 /// same constantpool entry as another Xtensa constpool value.
215 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
216
217 void print(raw_ostream &O) const override;
218
219 static bool classof(const XtensaConstantPoolValue *ACPV) {
220 return ACPV->isMachineBasicBlock();
221 }
222
223 bool equals(const XtensaConstantPoolMBB *A) const {
224 return MBB == A->MBB && XtensaConstantPoolValue::equals(A);
225 }
226};
227
228/// XtensaConstantPoolJumpTable - Xtensa-specific constantpool values for Jump
229/// Table symbols.
230class XtensaConstantPoolJumpTable : public XtensaConstantPoolValue {
231 unsigned Idx; // Jump Table Index.
232
233 XtensaConstantPoolJumpTable(LLVMContext &C, unsigned Idx);
234
235public:
236 static XtensaConstantPoolJumpTable *Create(LLVMContext &C, unsigned Idx);
237
238 unsigned getIndex() const { return Idx; }
239
241 Align Alignment) override;
242
243 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
244
245 /// hasSameValue - Return true if this Xtensa constpool value can share the
246 /// same constantpool entry as another Xtensa constpool value.
247 bool hasSameValue(XtensaConstantPoolValue *ACPV) override;
248
249 void print(raw_ostream &O) const override;
250
251 static bool classof(const XtensaConstantPoolValue *ACPV) {
252 return ACPV->isJumpTable();
253 }
254
255 bool equals(const XtensaConstantPoolJumpTable *A) const {
256 return Idx == A->Idx && XtensaConstantPoolValue::equals(A);
257 }
258};
259
260} // namespace llvm
261
262#endif /* LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H */
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static MaybeAlign getAlign(Value *Ptr)
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:1088
This is an important base class in LLVM.
Definition Constant.h:44
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:162
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
const std::vector< MachineConstantPoolEntry > & getConstants() const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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
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...
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
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
XtensaConstantPoolValue(Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind, XtensaCP::XtensaCPModifier Modifier=XtensaCP::no_modifier)
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:53
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39