1 //===- XtensaConstantPoolValue.cpp - Xtensa constantpool value ------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the Xtensa specific constantpool value class.
11 //===----------------------------------------------------------------------===//
13 #include "XtensaConstantPoolValue.h"
14 #include "llvm/ADT/FoldingSet.h"
15 #include "llvm/CodeGen/MachineBasicBlock.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"
20 #include "llvm/Support/raw_ostream.h"
24 XtensaConstantPoolValue::XtensaConstantPoolValue(
25 Type
*Ty
, unsigned ID
, XtensaCP::XtensaCPKind Kind
,
26 XtensaCP::XtensaCPModifier modifier
)
27 : MachineConstantPoolValue(Ty
), LabelId(ID
), Kind(Kind
),
30 XtensaConstantPoolValue::XtensaConstantPoolValue(
31 LLVMContext
&C
, unsigned ID
, XtensaCP::XtensaCPKind Kind
,
32 XtensaCP::XtensaCPModifier Modifier
)
33 : MachineConstantPoolValue((Type
*)Type::getInt32Ty(C
)), LabelId(ID
),
34 Kind(Kind
), Modifier(Modifier
) {}
36 XtensaConstantPoolValue::~XtensaConstantPoolValue() {}
38 StringRef
XtensaConstantPoolValue::getModifierText() const {
40 case XtensaCP::no_modifier
:
45 report_fatal_error("Unknown modifier!");
48 int XtensaConstantPoolValue::getExistingMachineCPValue(MachineConstantPool
*CP
,
50 report_fatal_error("Shouldn't be calling this directly!");
53 void XtensaConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
54 ID
.AddInteger(LabelId
);
57 bool XtensaConstantPoolValue::hasSameValue(XtensaConstantPoolValue
*ACPV
) {
58 if (ACPV
->Kind
== Kind
) {
59 if (ACPV
->LabelId
== LabelId
)
65 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
66 void XtensaConstantPoolValue::dump() const { errs() << " " << *this; }
69 void XtensaConstantPoolValue::print(raw_ostream
&O
) const {}
71 //===----------------------------------------------------------------------===//
72 // XtensaConstantPoolConstant
73 //===----------------------------------------------------------------------===//
75 XtensaConstantPoolConstant::XtensaConstantPoolConstant(
76 const Constant
*C
, unsigned ID
, XtensaCP::XtensaCPKind Kind
)
77 : XtensaConstantPoolValue(C
->getType(), ID
, Kind
), CVal(C
) {}
79 XtensaConstantPoolConstant
*
80 XtensaConstantPoolConstant::Create(const Constant
*C
, unsigned ID
,
81 XtensaCP::XtensaCPKind Kind
) {
82 return new XtensaConstantPoolConstant(C
, ID
, Kind
);
85 const BlockAddress
*XtensaConstantPoolConstant::getBlockAddress() const {
86 return dyn_cast_or_null
<BlockAddress
>(CVal
);
89 int XtensaConstantPoolConstant::getExistingMachineCPValue(
90 MachineConstantPool
*CP
, Align Alignment
) {
91 return getExistingMachineCPValueImpl
<XtensaConstantPoolConstant
>(CP
,
95 bool XtensaConstantPoolConstant::hasSameValue(XtensaConstantPoolValue
*ACPV
) {
96 const XtensaConstantPoolConstant
*ACPC
=
97 dyn_cast
<XtensaConstantPoolConstant
>(ACPV
);
98 return ACPC
&& ACPC
->CVal
== CVal
&&
99 XtensaConstantPoolValue::hasSameValue(ACPV
);
102 void XtensaConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
104 XtensaConstantPoolValue::addSelectionDAGCSEId(ID
);
107 void XtensaConstantPoolConstant::print(raw_ostream
&O
) const {
108 O
<< CVal
->getName();
109 XtensaConstantPoolValue::print(O
);
112 XtensaConstantPoolSymbol::XtensaConstantPoolSymbol(
113 LLVMContext
&C
, const char *Str
, unsigned ID
, bool PrivLinkage
,
114 XtensaCP::XtensaCPModifier Modifier
)
115 : XtensaConstantPoolValue(C
, ID
, XtensaCP::CPExtSymbol
, Modifier
), S(Str
),
116 PrivateLinkage(PrivLinkage
) {}
118 XtensaConstantPoolSymbol
*
119 XtensaConstantPoolSymbol::Create(LLVMContext
&C
, const char *Str
, unsigned ID
,
121 XtensaCP::XtensaCPModifier Modifier
)
124 return new XtensaConstantPoolSymbol(C
, Str
, ID
, PrivLinkage
, Modifier
);
127 int XtensaConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool
*CP
,
129 return getExistingMachineCPValueImpl
<XtensaConstantPoolSymbol
>(CP
, Alignment
);
132 bool XtensaConstantPoolSymbol::hasSameValue(XtensaConstantPoolValue
*ACPV
) {
133 const XtensaConstantPoolSymbol
*ACPS
=
134 dyn_cast
<XtensaConstantPoolSymbol
>(ACPV
);
135 return ACPS
&& ACPS
->S
== S
&& XtensaConstantPoolValue::hasSameValue(ACPV
);
138 void XtensaConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
140 XtensaConstantPoolValue::addSelectionDAGCSEId(ID
);
143 void XtensaConstantPoolSymbol::print(raw_ostream
&O
) const {
145 XtensaConstantPoolValue::print(O
);
148 XtensaConstantPoolMBB::XtensaConstantPoolMBB(LLVMContext
&C
,
149 const MachineBasicBlock
*M
,
151 : XtensaConstantPoolValue(C
, 0, XtensaCP::CPMachineBasicBlock
), MBB(M
) {}
153 XtensaConstantPoolMBB
*XtensaConstantPoolMBB::Create(LLVMContext
&C
,
154 const MachineBasicBlock
*M
,
156 return new XtensaConstantPoolMBB(C
, M
, Idx
);
159 int XtensaConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool
*CP
,
161 return getExistingMachineCPValueImpl
<XtensaConstantPoolMBB
>(CP
, Alignment
);
164 bool XtensaConstantPoolMBB::hasSameValue(XtensaConstantPoolValue
*ACPV
) {
165 const XtensaConstantPoolMBB
*ACPMBB
= dyn_cast
<XtensaConstantPoolMBB
>(ACPV
);
166 return ACPMBB
&& ACPMBB
->MBB
== MBB
&&
167 XtensaConstantPoolValue::hasSameValue(ACPV
);
170 void XtensaConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
172 XtensaConstantPoolValue::addSelectionDAGCSEId(ID
);
175 void XtensaConstantPoolMBB::print(raw_ostream
&O
) const {
176 O
<< "BB#" << MBB
->getNumber();
177 XtensaConstantPoolValue::print(O
);
180 XtensaConstantPoolJumpTable::XtensaConstantPoolJumpTable(LLVMContext
&C
,
182 : XtensaConstantPoolValue(C
, 0, XtensaCP::CPJumpTable
), Idx(Index
) {}
184 XtensaConstantPoolJumpTable
*XtensaConstantPoolJumpTable::Create(LLVMContext
&C
,
186 return new XtensaConstantPoolJumpTable(C
, Idx
);
189 int XtensaConstantPoolJumpTable::getExistingMachineCPValue(
190 MachineConstantPool
*CP
, Align Alignment
) {
191 return getExistingMachineCPValueImpl
<XtensaConstantPoolJumpTable
>(CP
,
195 bool XtensaConstantPoolJumpTable::hasSameValue(XtensaConstantPoolValue
*ACPV
) {
196 const XtensaConstantPoolJumpTable
*ACPJT
=
197 dyn_cast
<XtensaConstantPoolJumpTable
>(ACPV
);
198 return ACPJT
&& ACPJT
->Idx
== Idx
&&
199 XtensaConstantPoolValue::hasSameValue(ACPV
);
202 void XtensaConstantPoolJumpTable::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {}
204 void XtensaConstantPoolJumpTable::print(raw_ostream
&O
) const {
206 XtensaConstantPoolValue::print(O
);