Path: blob/main/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYConstantPoolValue.cpp
35266 views
//===-- CSKYConstantPoolValue.cpp - CSKY 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 CSKY specific constantpool value class.9//10//===----------------------------------------------------------------------===//1112#include "CSKYConstantPoolValue.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"20using namespace llvm;2122//===----------------------------------------------------------------------===//23// CSKYConstantPoolValue24//===----------------------------------------------------------------------===//2526CSKYConstantPoolValue::CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind,27unsigned PCAdjust,28CSKYCP::CSKYCPModifier Modifier,29bool AddCurrentAddress,30unsigned ID)31: MachineConstantPoolValue(Ty), Kind(Kind), PCAdjust(PCAdjust),32Modifier(Modifier), AddCurrentAddress(AddCurrentAddress), LabelId(ID) {}3334const char *CSKYConstantPoolValue::getModifierText() const {35switch (Modifier) {36case CSKYCP::ADDR:37return "ADDR";38case CSKYCP::GOT:39return "GOT";40case CSKYCP::GOTOFF:41return "GOTOFF";42case CSKYCP::PLT:43return "PLT";44case CSKYCP::TLSIE:45return "TLSIE";46case CSKYCP::TLSLE:47return "TLSLE";48case CSKYCP::TLSGD:49return "TLSGD";50case CSKYCP::NO_MOD:51return "";52}53llvm_unreachable("Unknown modifier!");54}5556int CSKYConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,57Align Alignment) {58llvm_unreachable("Shouldn't be calling this directly!");59}6061void CSKYConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {62ID.AddInteger(LabelId);63ID.AddInteger(PCAdjust);64ID.AddInteger(Modifier);65}6667void CSKYConstantPoolValue::print(raw_ostream &O) const {68if (Modifier)69O << "(" << getModifierText() << ")";70if (PCAdjust)71O << " + " << PCAdjust;72}7374//===----------------------------------------------------------------------===//75// CSKYConstantPoolConstant76//===----------------------------------------------------------------------===//7778CSKYConstantPoolConstant::CSKYConstantPoolConstant(79const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,80CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID)81: CSKYConstantPoolValue(Ty, Kind, PCAdjust, Modifier, AddCurrentAddress,82ID),83CVal(C) {}8485CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(86const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,87CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID) {88return new CSKYConstantPoolConstant(C, C->getType(), Kind, PCAdjust, Modifier,89AddCurrentAddress, ID);90}9192CSKYConstantPoolConstant *CSKYConstantPoolConstant::Create(93const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,94CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID) {95return new CSKYConstantPoolConstant(C, Ty, Kind, PCAdjust, Modifier,96AddCurrentAddress, ID);97}9899const GlobalValue *CSKYConstantPoolConstant::getGV() const {100assert(isa<GlobalValue>(CVal) && "CVal should be GlobalValue");101return cast<GlobalValue>(CVal);102}103104const BlockAddress *CSKYConstantPoolConstant::getBlockAddress() const {105assert(isa<BlockAddress>(CVal) && "CVal should be BlockAddress");106return cast<BlockAddress>(CVal);107}108109const Constant *CSKYConstantPoolConstant::getConstantPool() const {110return CVal;111}112113int CSKYConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool *CP,114Align Alignment) {115return getExistingMachineCPValueImpl<CSKYConstantPoolConstant>(CP, Alignment);116}117118void CSKYConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {119ID.AddPointer(CVal);120121CSKYConstantPoolValue::addSelectionDAGCSEId(ID);122}123124void CSKYConstantPoolConstant::print(raw_ostream &O) const {125O << CVal->getName();126CSKYConstantPoolValue::print(O);127}128129//===----------------------------------------------------------------------===//130// CSKYConstantPoolSymbol131//===----------------------------------------------------------------------===//132133CSKYConstantPoolSymbol::CSKYConstantPoolSymbol(Type *Ty, const char *S,134unsigned PCAdjust,135CSKYCP::CSKYCPModifier Modifier,136bool AddCurrentAddress)137: CSKYConstantPoolValue(Ty, CSKYCP::CPExtSymbol, PCAdjust, Modifier,138AddCurrentAddress),139S(strdup(S)) {}140141CSKYConstantPoolSymbol *142CSKYConstantPoolSymbol::Create(Type *Ty, const char *S, unsigned PCAdjust,143CSKYCP::CSKYCPModifier Modifier) {144return new CSKYConstantPoolSymbol(Ty, S, PCAdjust, Modifier, false);145}146147int CSKYConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,148Align Alignment) {149150return getExistingMachineCPValueImpl<CSKYConstantPoolSymbol>(CP, Alignment);151}152153void CSKYConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {154ID.AddString(S);155CSKYConstantPoolValue::addSelectionDAGCSEId(ID);156}157158void CSKYConstantPoolSymbol::print(raw_ostream &O) const {159O << S;160CSKYConstantPoolValue::print(O);161}162163//===----------------------------------------------------------------------===//164// CSKYConstantPoolMBB165//===----------------------------------------------------------------------===//166167CSKYConstantPoolMBB::CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb,168unsigned PCAdjust,169CSKYCP::CSKYCPModifier Modifier,170bool AddCurrentAddress)171: CSKYConstantPoolValue(Ty, CSKYCP::CPMachineBasicBlock, PCAdjust, Modifier,172AddCurrentAddress),173MBB(Mbb) {}174175CSKYConstantPoolMBB *CSKYConstantPoolMBB::Create(Type *Ty,176const MachineBasicBlock *Mbb,177unsigned PCAdjust) {178return new CSKYConstantPoolMBB(Ty, Mbb, PCAdjust, CSKYCP::ADDR, false);179}180181int CSKYConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,182Align Alignment) {183return getExistingMachineCPValueImpl<CSKYConstantPoolMBB>(CP, Alignment);184}185186void CSKYConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {187ID.AddPointer(MBB);188CSKYConstantPoolValue::addSelectionDAGCSEId(ID);189}190191void CSKYConstantPoolMBB::print(raw_ostream &O) const {192O << "BB#" << MBB->getNumber();193CSKYConstantPoolValue::print(O);194}195196//===----------------------------------------------------------------------===//197// CSKYConstantPoolJT198//===----------------------------------------------------------------------===//199200CSKYConstantPoolJT::CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,201CSKYCP::CSKYCPModifier Modifier,202bool AddCurrentAddress)203: CSKYConstantPoolValue(Ty, CSKYCP::CPJT, PCAdj, Modifier,204AddCurrentAddress),205JTI(JTIndex) {}206207CSKYConstantPoolJT *208CSKYConstantPoolJT::Create(Type *Ty, int JTI, unsigned PCAdj,209CSKYCP::CSKYCPModifier Modifier) {210return new CSKYConstantPoolJT(Ty, JTI, PCAdj, Modifier, false);211}212213int CSKYConstantPoolJT::getExistingMachineCPValue(MachineConstantPool *CP,214Align Alignment) {215return getExistingMachineCPValueImpl<CSKYConstantPoolJT>(CP, Alignment);216}217218void CSKYConstantPoolJT::addSelectionDAGCSEId(FoldingSetNodeID &ID) {219ID.AddInteger(JTI);220CSKYConstantPoolValue::addSelectionDAGCSEId(ID);221}222223void CSKYConstantPoolJT::print(raw_ostream &O) const {224O << "JTI#" << JTI;225CSKYConstantPoolValue::print(O);226}227228229