LLVM 20.0.0git
XtensaConstantPoolValue.cpp
Go to the documentation of this file.
1//===- XtensaConstantPoolValue.cpp - Xtensa 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 Xtensa specific constantpool value class.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/FoldingSet.h"
16#include "llvm/IR/Constant.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/GlobalValue.h"
19#include "llvm/IR/Type.h"
21#include <cstdlib>
22using namespace llvm;
23
25 Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,
27 : MachineConstantPoolValue(Ty), LabelId(ID), Kind(Kind),
28 Modifier(modifier) {}
29
31 LLVMContext &C, unsigned ID, XtensaCP::XtensaCPKind Kind,
33 : MachineConstantPoolValue((Type *)Type::getInt32Ty(C)), LabelId(ID),
34 Kind(Kind), Modifier(Modifier) {}
35
37
39 switch (Modifier) {
41 return "";
42 case XtensaCP::TPOFF:
43 return "@TPOFF";
44 }
45 report_fatal_error("Unknown modifier!");
46}
47
49 Align Alignment) {
50 report_fatal_error("Shouldn't be calling this directly!");
51}
52
54 ID.AddInteger(LabelId);
55}
56
58 if (ACPV->Kind == Kind) {
59 if (ACPV->LabelId == LabelId)
60 return true;
61 }
62 return false;
63}
64
65#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
66void XtensaConstantPoolValue::dump() const { errs() << " " << *this; }
67#endif
68
70
71//===----------------------------------------------------------------------===//
72// XtensaConstantPoolConstant
73//===----------------------------------------------------------------------===//
74
75XtensaConstantPoolConstant::XtensaConstantPoolConstant(
76 const Constant *C, unsigned ID, XtensaCP::XtensaCPKind Kind)
77 : XtensaConstantPoolValue(C->getType(), ID, Kind), CVal(C) {}
78
82 return new XtensaConstantPoolConstant(C, ID, Kind);
83}
84
86 return dyn_cast_or_null<BlockAddress>(CVal);
87}
88
90 MachineConstantPool *CP, Align Alignment) {
91 return getExistingMachineCPValueImpl<XtensaConstantPoolConstant>(CP,
92 Alignment);
93}
94
96 const XtensaConstantPoolConstant *ACPC =
97 dyn_cast<XtensaConstantPoolConstant>(ACPV);
98 return ACPC && ACPC->CVal == CVal &&
100}
101
103 ID.AddPointer(CVal);
105}
106
108 O << CVal->getName();
110}
111
112XtensaConstantPoolSymbol::XtensaConstantPoolSymbol(
113 LLVMContext &C, const char *Str, unsigned ID, bool PrivLinkage,
115 : XtensaConstantPoolValue(C, ID, XtensaCP::CPExtSymbol, Modifier), S(Str),
116 PrivateLinkage(PrivLinkage) {}
117
120 bool PrivLinkage,
122
123{
124 return new XtensaConstantPoolSymbol(C, Str, ID, PrivLinkage, Modifier);
125}
126
128 Align Alignment) {
129 return getExistingMachineCPValueImpl<XtensaConstantPoolSymbol>(CP, Alignment);
130}
131
133 const XtensaConstantPoolSymbol *ACPS =
134 dyn_cast<XtensaConstantPoolSymbol>(ACPV);
135 return ACPS && ACPS->S == S && XtensaConstantPoolValue::hasSameValue(ACPV);
136}
137
139 ID.AddString(S);
141}
142
144 O << S;
146}
147
148XtensaConstantPoolMBB::XtensaConstantPoolMBB(LLVMContext &C,
149 const MachineBasicBlock *M,
150 unsigned Id)
151 : XtensaConstantPoolValue(C, 0, XtensaCP::CPMachineBasicBlock), MBB(M) {}
152
154 const MachineBasicBlock *M,
155 unsigned Idx) {
156 return new XtensaConstantPoolMBB(C, M, Idx);
157}
158
160 Align Alignment) {
161 return getExistingMachineCPValueImpl<XtensaConstantPoolMBB>(CP, Alignment);
162}
163
165 const XtensaConstantPoolMBB *ACPMBB = dyn_cast<XtensaConstantPoolMBB>(ACPV);
166 return ACPMBB && ACPMBB->MBB == MBB &&
168}
169
171 ID.AddPointer(MBB);
173}
174
176 O << "BB#" << MBB->getNumber();
178}
179
180XtensaConstantPoolJumpTable::XtensaConstantPoolJumpTable(LLVMContext &C,
181 unsigned Index)
182 : XtensaConstantPoolValue(C, 0, XtensaCP::CPJumpTable), Idx(Index) {}
183
185 unsigned Idx) {
186 return new XtensaConstantPoolJumpTable(C, Idx);
187}
188
190 MachineConstantPool *CP, Align Alignment) {
191 return getExistingMachineCPValueImpl<XtensaConstantPoolJumpTable>(CP,
192 Alignment);
193}
194
196 const XtensaConstantPoolJumpTable *ACPJT =
197 dyn_cast<XtensaConstantPoolJumpTable>(ACPV);
198 return ACPJT && ACPJT->Idx == Idx &&
200}
201
203
205 O << "JT" << Idx;
207}
MachineBasicBlock & MBB
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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 defines a hash set that can be used to remove duplication of nodes in a graph.
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:40
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
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
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
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
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...
const BlockAddress * getBlockAddress() 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)
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 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
XtensaConstantPoolSymbol - Xtensa-specific constantpool values for external symbols.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
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
void print(raw_ostream &O) const override
print - Implement operator<<
XtensaConstantPoolValue(Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind, XtensaCP::XtensaCPModifier Modifier=XtensaCP::no_modifier)
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ 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
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39