Path: blob/main/contrib/llvm-project/llvm/lib/Target/Xtensa/XtensaConstantPoolValue.cpp
35271 views
//===- XtensaConstantPoolValue.cpp - Xtensa constantpool value ------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the Xtensa specific constantpool value class.9//10//===----------------------------------------------------------------------===//1112#include "XtensaConstantPoolValue.h"13#include "llvm/ADT/FoldingSet.h"14#include "llvm/CodeGen/MachineBasicBlock.h"15#include "llvm/IR/Constant.h"16#include "llvm/IR/Constants.h"17#include "llvm/IR/GlobalValue.h"18#include "llvm/IR/Type.h"19#include "llvm/Support/raw_ostream.h"20#include <cstdlib>21using namespace llvm;2223XtensaConstantPoolValue::XtensaConstantPoolValue(24Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,25XtensaCP::XtensaCPModifier modifier)26: MachineConstantPoolValue(Ty), LabelId(ID), Kind(Kind),27Modifier(modifier) {}2829XtensaConstantPoolValue::XtensaConstantPoolValue(30LLVMContext &C, unsigned ID, XtensaCP::XtensaCPKind Kind,31XtensaCP::XtensaCPModifier Modifier)32: MachineConstantPoolValue((Type *)Type::getInt32Ty(C)), LabelId(ID),33Kind(Kind), Modifier(Modifier) {}3435XtensaConstantPoolValue::~XtensaConstantPoolValue() {}3637StringRef XtensaConstantPoolValue::getModifierText() const {38switch (Modifier) {39case XtensaCP::no_modifier:40return "";41case XtensaCP::TPOFF:42return "@TPOFF";43}44report_fatal_error("Unknown modifier!");45}4647int XtensaConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,48Align Alignment) {49report_fatal_error("Shouldn't be calling this directly!");50}5152void XtensaConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {53ID.AddInteger(LabelId);54}5556bool XtensaConstantPoolValue::hasSameValue(XtensaConstantPoolValue *ACPV) {57if (ACPV->Kind == Kind) {58if (ACPV->LabelId == LabelId)59return true;60}61return false;62}6364#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)65void XtensaConstantPoolValue::dump() const { errs() << " " << *this; }66#endif6768void XtensaConstantPoolValue::print(raw_ostream &O) const {}6970//===----------------------------------------------------------------------===//71// XtensaConstantPoolConstant72//===----------------------------------------------------------------------===//7374XtensaConstantPoolConstant::XtensaConstantPoolConstant(75const Constant *C, unsigned ID, XtensaCP::XtensaCPKind Kind)76: XtensaConstantPoolValue(C->getType(), ID, Kind), CVal(C) {}7778XtensaConstantPoolConstant *79XtensaConstantPoolConstant::Create(const Constant *C, unsigned ID,80XtensaCP::XtensaCPKind Kind) {81return new XtensaConstantPoolConstant(C, ID, Kind);82}8384const BlockAddress *XtensaConstantPoolConstant::getBlockAddress() const {85return dyn_cast_or_null<BlockAddress>(CVal);86}8788int XtensaConstantPoolConstant::getExistingMachineCPValue(89MachineConstantPool *CP, Align Alignment) {90return getExistingMachineCPValueImpl<XtensaConstantPoolConstant>(CP,91Alignment);92}9394bool XtensaConstantPoolConstant::hasSameValue(XtensaConstantPoolValue *ACPV) {95const XtensaConstantPoolConstant *ACPC =96dyn_cast<XtensaConstantPoolConstant>(ACPV);97return ACPC && ACPC->CVal == CVal &&98XtensaConstantPoolValue::hasSameValue(ACPV);99}100101void XtensaConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {102ID.AddPointer(CVal);103XtensaConstantPoolValue::addSelectionDAGCSEId(ID);104}105106void XtensaConstantPoolConstant::print(raw_ostream &O) const {107O << CVal->getName();108XtensaConstantPoolValue::print(O);109}110111XtensaConstantPoolSymbol::XtensaConstantPoolSymbol(112LLVMContext &C, const char *Str, unsigned ID, bool PrivLinkage,113XtensaCP::XtensaCPModifier Modifier)114: XtensaConstantPoolValue(C, ID, XtensaCP::CPExtSymbol, Modifier), S(Str),115PrivateLinkage(PrivLinkage) {}116117XtensaConstantPoolSymbol *118XtensaConstantPoolSymbol::Create(LLVMContext &C, const char *Str, unsigned ID,119bool PrivLinkage,120XtensaCP::XtensaCPModifier Modifier)121122{123return new XtensaConstantPoolSymbol(C, Str, ID, PrivLinkage, Modifier);124}125126int XtensaConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,127Align Alignment) {128return getExistingMachineCPValueImpl<XtensaConstantPoolSymbol>(CP, Alignment);129}130131bool XtensaConstantPoolSymbol::hasSameValue(XtensaConstantPoolValue *ACPV) {132const XtensaConstantPoolSymbol *ACPS =133dyn_cast<XtensaConstantPoolSymbol>(ACPV);134return ACPS && ACPS->S == S && XtensaConstantPoolValue::hasSameValue(ACPV);135}136137void XtensaConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {138ID.AddString(S);139XtensaConstantPoolValue::addSelectionDAGCSEId(ID);140}141142void XtensaConstantPoolSymbol::print(raw_ostream &O) const {143O << S;144XtensaConstantPoolValue::print(O);145}146147XtensaConstantPoolMBB::XtensaConstantPoolMBB(LLVMContext &C,148const MachineBasicBlock *M,149unsigned Id)150: XtensaConstantPoolValue(C, 0, XtensaCP::CPMachineBasicBlock), MBB(M) {}151152XtensaConstantPoolMBB *XtensaConstantPoolMBB::Create(LLVMContext &C,153const MachineBasicBlock *M,154unsigned Idx) {155return new XtensaConstantPoolMBB(C, M, Idx);156}157158int XtensaConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,159Align Alignment) {160return getExistingMachineCPValueImpl<XtensaConstantPoolMBB>(CP, Alignment);161}162163bool XtensaConstantPoolMBB::hasSameValue(XtensaConstantPoolValue *ACPV) {164const XtensaConstantPoolMBB *ACPMBB = dyn_cast<XtensaConstantPoolMBB>(ACPV);165return ACPMBB && ACPMBB->MBB == MBB &&166XtensaConstantPoolValue::hasSameValue(ACPV);167}168169void XtensaConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {170ID.AddPointer(MBB);171XtensaConstantPoolValue::addSelectionDAGCSEId(ID);172}173174void XtensaConstantPoolMBB::print(raw_ostream &O) const {175O << "BB#" << MBB->getNumber();176XtensaConstantPoolValue::print(O);177}178179XtensaConstantPoolJumpTable::XtensaConstantPoolJumpTable(LLVMContext &C,180unsigned Index)181: XtensaConstantPoolValue(C, 0, XtensaCP::CPJumpTable), Idx(Index) {}182183XtensaConstantPoolJumpTable *XtensaConstantPoolJumpTable::Create(LLVMContext &C,184unsigned Idx) {185return new XtensaConstantPoolJumpTable(C, Idx);186}187188int XtensaConstantPoolJumpTable::getExistingMachineCPValue(189MachineConstantPool *CP, Align Alignment) {190return getExistingMachineCPValueImpl<XtensaConstantPoolJumpTable>(CP,191Alignment);192}193194bool XtensaConstantPoolJumpTable::hasSameValue(XtensaConstantPoolValue *ACPV) {195const XtensaConstantPoolJumpTable *ACPJT =196dyn_cast<XtensaConstantPoolJumpTable>(ACPV);197return ACPJT && ACPJT->Idx == Idx &&198XtensaConstantPoolValue::hasSameValue(ACPV);199}200201void XtensaConstantPoolJumpTable::addSelectionDAGCSEId(FoldingSetNodeID &ID) {}202203void XtensaConstantPoolJumpTable::print(raw_ostream &O) const {204O << "JT" << Idx;205XtensaConstantPoolValue::print(O);206}207208209