Path: blob/main/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYConstantPoolValue.h
35269 views
//===-- CSKYConstantPoolValue.h - CSKY constantpool value -----*- C++ -*---===//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#ifndef LLVM_TARGET_CSKY_CONSTANTPOOLVALUE_H13#define LLVM_TARGET_CSKY_CONSTANTPOOLVALUE_H1415#include "llvm/ADT/StringRef.h"16#include "llvm/CodeGen/MachineConstantPool.h"17#include "llvm/Support/Casting.h"18#include "llvm/Support/ErrorHandling.h"19#include <cstddef>2021namespace llvm {2223class BlockAddress;24class Constant;25class GlobalValue;26class LLVMContext;27class MachineBasicBlock;2829namespace CSKYCP {30enum CSKYCPKind {31CPValue,32CPExtSymbol,33CPBlockAddress,34CPMachineBasicBlock,35CPJT,36CPConstPool37};3839enum CSKYCPModifier { NO_MOD, ADDR, GOT, GOTOFF, PLT, TLSLE, TLSIE, TLSGD };40} // namespace CSKYCP4142/// CSKYConstantPoolValue - CSKY specific constantpool value. This is used to43/// represent PC-relative displacement between the address of the load44/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).45class CSKYConstantPoolValue : public MachineConstantPoolValue {46protected:47CSKYCP::CSKYCPKind Kind; // Kind of constant.48unsigned PCAdjust; // Extra adjustment if constantpool is pc-relative.49CSKYCP::CSKYCPModifier Modifier; // GV modifier50bool AddCurrentAddress;5152unsigned LabelId = 0;5354CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,55CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress,56unsigned ID = 0);5758public:59const char *getModifierText() const;60unsigned getPCAdjustment() const { return PCAdjust; }61bool mustAddCurrentAddress() const { return AddCurrentAddress; }62CSKYCP::CSKYCPModifier getModifier() const { return Modifier; }63unsigned getLabelID() const { return LabelId; }6465bool isGlobalValue() const { return Kind == CSKYCP::CPValue; }66bool isExtSymbol() const { return Kind == CSKYCP::CPExtSymbol; }67bool isBlockAddress() const { return Kind == CSKYCP::CPBlockAddress; }68bool isMachineBasicBlock() const {69return Kind == CSKYCP::CPMachineBasicBlock;70}71bool isJT() const { return Kind == CSKYCP::CPJT; }72bool isConstPool() const { return Kind == CSKYCP::CPConstPool; }7374int getExistingMachineCPValue(MachineConstantPool *CP,75Align Alignment) override;7677void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;7879void print(raw_ostream &O) const override;8081bool equals(const CSKYConstantPoolValue *A) const {82return this->LabelId == A->LabelId && this->PCAdjust == A->PCAdjust &&83this->Modifier == A->Modifier;84}8586template <typename Derived>87int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment) {88const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();89for (unsigned i = 0, e = Constants.size(); i != e; ++i) {90if (Constants[i].isMachineConstantPoolEntry() &&91Constants[i].getAlign() >= Alignment) {92auto *CPV =93static_cast<CSKYConstantPoolValue *>(Constants[i].Val.MachineCPVal);94if (Derived *APC = dyn_cast<Derived>(CPV))95if (cast<Derived>(this)->equals(APC))96return i;97}98}99100return -1;101}102};103104/// CSKY-specific constant pool values for Constants,105/// Functions, and BlockAddresses.106class CSKYConstantPoolConstant : public CSKYConstantPoolValue {107const Constant *CVal; // Constant being loaded.108109CSKYConstantPoolConstant(const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind,110unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier,111bool AddCurrentAddress, unsigned ID);112113public:114static CSKYConstantPoolConstant *115Create(const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,116CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress,117unsigned ID = 0);118static CSKYConstantPoolConstant *119Create(const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind,120unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier,121bool AddCurrentAddress, unsigned ID = 0);122const GlobalValue *getGV() const;123const BlockAddress *getBlockAddress() const;124const Constant *getConstantPool() const;125126int getExistingMachineCPValue(MachineConstantPool *CP,127Align Alignment) override;128void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;129void print(raw_ostream &O) const override;130131bool equals(const CSKYConstantPoolConstant *A) const {132return CVal == A->CVal && CSKYConstantPoolValue::equals(A);133}134135static bool classof(const CSKYConstantPoolValue *APV) {136return APV->isGlobalValue() || APV->isBlockAddress() || APV->isConstPool();137}138};139140/// CSKYConstantPoolSymbol - CSKY-specific constantpool values for external141/// symbols.142class CSKYConstantPoolSymbol : public CSKYConstantPoolValue {143const std::string S; // ExtSymbol being loaded.144145CSKYConstantPoolSymbol(Type *Ty, const char *S, unsigned PCAdjust,146CSKYCP::CSKYCPModifier Modifier,147bool AddCurrentAddress);148149public:150static CSKYConstantPoolSymbol *Create(Type *Ty, const char *S,151unsigned PCAdjust,152CSKYCP::CSKYCPModifier Modifier);153154StringRef getSymbol() const { return S; }155156int getExistingMachineCPValue(MachineConstantPool *CP,157Align Alignment) override;158void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;159void print(raw_ostream &O) const override;160161bool equals(const CSKYConstantPoolSymbol *A) const {162return S == A->S && CSKYConstantPoolValue::equals(A);163}164165static bool classof(const CSKYConstantPoolValue *ACPV) {166return ACPV->isExtSymbol();167}168};169170/// CSKYConstantPoolMBB - CSKY-specific constantpool value of a machine basic171/// block.172class CSKYConstantPoolMBB : public CSKYConstantPoolValue {173const MachineBasicBlock *MBB; // Machine basic block.174175CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust,176CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress);177178public:179static CSKYConstantPoolMBB *Create(Type *Ty, const MachineBasicBlock *Mbb,180unsigned PCAdjust);181182const MachineBasicBlock *getMBB() const { return MBB; }183184int getExistingMachineCPValue(MachineConstantPool *CP,185Align Alignment) override;186void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;187void print(raw_ostream &O) const override;188189bool equals(const CSKYConstantPoolMBB *A) const {190return MBB == A->MBB && CSKYConstantPoolValue::equals(A);191}192193static bool classof(const CSKYConstantPoolValue *ACPV) {194return ACPV->isMachineBasicBlock();195}196};197198/// CSKY-specific constantpool value of a jump table.199class CSKYConstantPoolJT : public CSKYConstantPoolValue {200signed JTI; // Machine basic block.201202CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,203CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress);204205public:206static CSKYConstantPoolJT *Create(Type *Ty, int JTI, unsigned PCAdj,207CSKYCP::CSKYCPModifier Modifier);208209signed getJTI() { return JTI; }210211int getExistingMachineCPValue(MachineConstantPool *CP,212Align Alignment) override;213void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;214void print(raw_ostream &O) const override;215216bool equals(const CSKYConstantPoolJT *A) const {217return JTI == A->JTI && CSKYConstantPoolValue::equals(A);218}219220static bool classof(const CSKYConstantPoolValue *ACPV) {221return ACPV->isJT();222}223};224225} // namespace llvm226227#endif228229230