Add gfx950 mfma instructions to ROCDL dialect (#123361)
[llvm-project.git] / llvm / lib / Target / Xtensa / XtensaConstantPoolValue.cpp
blob4e53aa5736c72ce11724fc2f94f0e6652cdf5b10
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.
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"
21 #include <cstdlib>
22 using namespace llvm;
24 XtensaConstantPoolValue::XtensaConstantPoolValue(
25 Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,
26 XtensaCP::XtensaCPModifier modifier)
27 : MachineConstantPoolValue(Ty), LabelId(ID), Kind(Kind),
28 Modifier(modifier) {}
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 {
39 switch (Modifier) {
40 case XtensaCP::no_modifier:
41 return "";
42 case XtensaCP::TPOFF:
43 return "@TPOFF";
45 report_fatal_error("Unknown modifier!");
48 int XtensaConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
49 Align Alignment) {
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)
60 return true;
62 return false;
65 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
66 void XtensaConstantPoolValue::dump() const { errs() << " " << *this; }
67 #endif
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,
92 Alignment);
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) {
103 ID.AddPointer(CVal);
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,
120 bool PrivLinkage,
121 XtensaCP::XtensaCPModifier Modifier)
124 return new XtensaConstantPoolSymbol(C, Str, ID, PrivLinkage, Modifier);
127 int XtensaConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
128 Align Alignment) {
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) {
139 ID.AddString(S);
140 XtensaConstantPoolValue::addSelectionDAGCSEId(ID);
143 void XtensaConstantPoolSymbol::print(raw_ostream &O) const {
144 O << S;
145 XtensaConstantPoolValue::print(O);
148 XtensaConstantPoolMBB::XtensaConstantPoolMBB(LLVMContext &C,
149 const MachineBasicBlock *M,
150 unsigned Id)
151 : XtensaConstantPoolValue(C, 0, XtensaCP::CPMachineBasicBlock), MBB(M) {}
153 XtensaConstantPoolMBB *XtensaConstantPoolMBB::Create(LLVMContext &C,
154 const MachineBasicBlock *M,
155 unsigned Idx) {
156 return new XtensaConstantPoolMBB(C, M, Idx);
159 int XtensaConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
160 Align Alignment) {
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) {
171 ID.AddPointer(MBB);
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,
181 unsigned Index)
182 : XtensaConstantPoolValue(C, 0, XtensaCP::CPJumpTable), Idx(Index) {}
184 XtensaConstantPoolJumpTable *XtensaConstantPoolJumpTable::Create(LLVMContext &C,
185 unsigned Idx) {
186 return new XtensaConstantPoolJumpTable(C, Idx);
189 int XtensaConstantPoolJumpTable::getExistingMachineCPValue(
190 MachineConstantPool *CP, Align Alignment) {
191 return getExistingMachineCPValueImpl<XtensaConstantPoolJumpTable>(CP,
192 Alignment);
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 {
205 O << "JT" << Idx;
206 XtensaConstantPoolValue::print(O);