Path: blob/main/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVConstantPoolValue.cpp
213799 views
//===------- RISCVConstantPoolValue.cpp - RISC-V 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 RISC-V specific constantpool value class.9//10//===----------------------------------------------------------------------===//1112#include "RISCVConstantPoolValue.h"13#include "llvm/ADT/FoldingSet.h"14#include "llvm/IR/DerivedTypes.h"15#include "llvm/IR/GlobalValue.h"16#include "llvm/IR/Type.h"17#include "llvm/Support/raw_ostream.h"1819using namespace llvm;2021RISCVConstantPoolValue::RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV)22: MachineConstantPoolValue(Ty), GV(GV), Kind(RISCVCPKind::GlobalValue) {}2324RISCVConstantPoolValue::RISCVConstantPoolValue(LLVMContext &C, StringRef S)25: MachineConstantPoolValue(Type::getInt64Ty(C)), S(S),26Kind(RISCVCPKind::ExtSymbol) {}2728RISCVConstantPoolValue *RISCVConstantPoolValue::Create(const GlobalValue *GV) {29return new RISCVConstantPoolValue(GV->getType(), GV);30}3132RISCVConstantPoolValue *RISCVConstantPoolValue::Create(LLVMContext &C,33StringRef S) {34return new RISCVConstantPoolValue(C, S);35}3637int RISCVConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,38Align Alignment) {39const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();40for (unsigned i = 0, e = Constants.size(); i != e; ++i) {41if (Constants[i].isMachineConstantPoolEntry() &&42Constants[i].getAlign() >= Alignment) {43auto *CPV =44static_cast<RISCVConstantPoolValue *>(Constants[i].Val.MachineCPVal);45if (equals(CPV))46return i;47}48}4950return -1;51}5253void RISCVConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {54if (isGlobalValue())55ID.AddPointer(GV);56else {57assert(isExtSymbol() && "unrecognized constant pool type");58ID.AddString(S);59}60}6162void RISCVConstantPoolValue::print(raw_ostream &O) const {63if (isGlobalValue())64O << GV->getName();65else {66assert(isExtSymbol() && "unrecognized constant pool type");67O << S;68}69}7071bool RISCVConstantPoolValue::equals(const RISCVConstantPoolValue *A) const {72if (isGlobalValue() && A->isGlobalValue())73return GV == A->GV;74if (isExtSymbol() && A->isExtSymbol())75return S == A->S;7677return false;78}798081