Path: blob/main/contrib/llvm-project/llvm/lib/Target/Xtensa/XtensaConstantPoolValue.h
35271 views
//===- XtensaConstantPoolValue.h - Xtensa 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 Xtensa specific constantpool value class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H13#define LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H1415#include "llvm/CodeGen/MachineConstantPool.h"16#include "llvm/Support/Casting.h"17#include "llvm/Support/ErrorHandling.h"18#include <cstddef>19#include <string>20#include <vector>2122namespace llvm {2324class BlockAddress;25class Constant;26class GlobalValue;27class LLVMContext;28class MachineBasicBlock;2930namespace XtensaCP {31enum XtensaCPKind {32CPExtSymbol,33CPBlockAddress,34CPMachineBasicBlock,35CPJumpTable36};3738enum XtensaCPModifier {39no_modifier, // None40TPOFF // Thread Pointer Offset41};42} // namespace XtensaCP4344/// XtensaConstantPoolValue - Xtensa specific constantpool value. This is used45/// to represent PC-relative displacement between the address of the load46/// instruction and the constant being loaded.47class XtensaConstantPoolValue : public MachineConstantPoolValue {48unsigned LabelId; // Label id of the load.49XtensaCP::XtensaCPKind Kind; // Kind of constant.50XtensaCP::XtensaCPModifier Modifier; // Symbol name modifier51//(for example Global Variable name)5253protected:54XtensaConstantPoolValue(55Type *Ty, unsigned ID, XtensaCP::XtensaCPKind Kind,56XtensaCP::XtensaCPModifier Modifier = XtensaCP::no_modifier);5758XtensaConstantPoolValue(59LLVMContext &C, unsigned id, XtensaCP::XtensaCPKind Kind,60XtensaCP::XtensaCPModifier Modifier = XtensaCP::no_modifier);6162template <typename Derived>63int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment) {64const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();65for (unsigned i = 0, e = Constants.size(); i != e; ++i) {66if (Constants[i].isMachineConstantPoolEntry() &&67(Constants[i].getAlign() >= Alignment)) {68auto *CPV = static_cast<XtensaConstantPoolValue *>(69Constants[i].Val.MachineCPVal);70if (Derived *APC = dyn_cast<Derived>(CPV))71if (cast<Derived>(this)->equals(APC))72return i;73}74}7576return -1;77}7879public:80~XtensaConstantPoolValue() override;8182XtensaCP::XtensaCPModifier getModifier() const { return Modifier; }83bool hasModifier() const { return Modifier != XtensaCP::no_modifier; }84StringRef getModifierText() const;8586unsigned getLabelId() const { return LabelId; }87void setLabelId(unsigned ID) { LabelId = ID; }8889bool isExtSymbol() const { return Kind == XtensaCP::CPExtSymbol; }90bool isBlockAddress() const { return Kind == XtensaCP::CPBlockAddress; }91bool isMachineBasicBlock() const {92return Kind == XtensaCP::CPMachineBasicBlock;93}94bool isJumpTable() const { return Kind == XtensaCP::CPJumpTable; }9596int getExistingMachineCPValue(MachineConstantPool *CP,97Align Alignment) override;9899void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;100101/// hasSameValue - Return true if this Xtensa constpool value can share the102/// same constantpool entry as another Xtensa constpool value.103virtual bool hasSameValue(XtensaConstantPoolValue *ACPV);104105bool equals(const XtensaConstantPoolValue *A) const {106return this->LabelId == A->LabelId && this->Modifier == A->Modifier;107}108109void print(raw_ostream &O) const override;110111#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)112void dump() const;113#endif114};115116inline raw_ostream &operator<<(raw_ostream &O,117const XtensaConstantPoolValue &V) {118V.print(O);119return O;120}121122/// XtensaConstantPoolConstant - Xtensa-specific constant pool values for123/// Constants (for example BlockAddresses).124class XtensaConstantPoolConstant : public XtensaConstantPoolValue {125const Constant *CVal; // Constant being loaded.126127XtensaConstantPoolConstant(const Constant *C, unsigned ID,128XtensaCP::XtensaCPKind Kind);129130public:131static XtensaConstantPoolConstant *Create(const Constant *C, unsigned ID,132XtensaCP::XtensaCPKind Kind);133134const BlockAddress *getBlockAddress() const;135136int getExistingMachineCPValue(MachineConstantPool *CP,137Align Alignment) override;138139/// hasSameValue - Return true if this Xtensa constpool value can share the140/// same constantpool entry as another Xtensa constpool value.141bool hasSameValue(XtensaConstantPoolValue *ACPV) override;142143void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;144145void print(raw_ostream &O) const override;146static bool classof(const XtensaConstantPoolValue *APV) {147return APV->isBlockAddress();148}149150bool equals(const XtensaConstantPoolConstant *A) const {151return CVal == A->CVal && XtensaConstantPoolValue::equals(A);152}153};154155/// XtensaConstantPoolSymbol - Xtensa-specific constantpool values for external156/// symbols.157class XtensaConstantPoolSymbol : public XtensaConstantPoolValue {158const std::string S; // ExtSymbol being loaded.159bool PrivateLinkage;160161XtensaConstantPoolSymbol(162LLVMContext &C, const char *S, unsigned Id, bool PrivLinkage,163XtensaCP::XtensaCPModifier Modifier = XtensaCP::no_modifier);164165public:166static XtensaConstantPoolSymbol *167Create(LLVMContext &C, const char *S, unsigned ID, bool PrivLinkage,168XtensaCP::XtensaCPModifier Modifier = XtensaCP::no_modifier);169170const char *getSymbol() const { return S.c_str(); }171172int getExistingMachineCPValue(MachineConstantPool *CP,173Align Alignment) override;174175void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;176177/// hasSameValue - Return true if this Xtensa constpool value can share the178/// same constantpool entry as another Xtensa constpool value.179bool hasSameValue(XtensaConstantPoolValue *ACPV) override;180181bool isPrivateLinkage() { return PrivateLinkage; }182183void print(raw_ostream &O) const override;184185static bool classof(const XtensaConstantPoolValue *ACPV) {186return ACPV->isExtSymbol();187}188189bool equals(const XtensaConstantPoolSymbol *A) const {190return S == A->S && XtensaConstantPoolValue::equals(A);191}192};193194/// XtensaConstantPoolMBB - Xtensa-specific constantpool value of a machine195/// basic block.196class XtensaConstantPoolMBB : public XtensaConstantPoolValue {197const MachineBasicBlock *MBB; // Machine basic block.198199XtensaConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *M,200unsigned ID);201202public:203static XtensaConstantPoolMBB *Create(LLVMContext &C,204const MachineBasicBlock *M, unsigned ID);205206const MachineBasicBlock *getMBB() const { return MBB; }207208int getExistingMachineCPValue(MachineConstantPool *CP,209Align Alignment) override;210211void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;212213/// hasSameValue - Return true if this Xtensa constpool value can share the214/// same constantpool entry as another Xtensa constpool value.215bool hasSameValue(XtensaConstantPoolValue *ACPV) override;216217void print(raw_ostream &O) const override;218219static bool classof(const XtensaConstantPoolValue *ACPV) {220return ACPV->isMachineBasicBlock();221}222223bool equals(const XtensaConstantPoolMBB *A) const {224return MBB == A->MBB && XtensaConstantPoolValue::equals(A);225}226};227228/// XtensaConstantPoolJumpTable - Xtensa-specific constantpool values for Jump229/// Table symbols.230class XtensaConstantPoolJumpTable : public XtensaConstantPoolValue {231unsigned Idx; // Jump Table Index.232233XtensaConstantPoolJumpTable(LLVMContext &C, unsigned Idx);234235public:236static XtensaConstantPoolJumpTable *Create(LLVMContext &C, unsigned Idx);237238unsigned getIndex() const { return Idx; }239240int getExistingMachineCPValue(MachineConstantPool *CP,241Align Alignment) override;242243void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;244245/// hasSameValue - Return true if this Xtensa constpool value can share the246/// same constantpool entry as another Xtensa constpool value.247bool hasSameValue(XtensaConstantPoolValue *ACPV) override;248249void print(raw_ostream &O) const override;250251static bool classof(const XtensaConstantPoolValue *ACPV) {252return ACPV->isJumpTable();253}254255bool equals(const XtensaConstantPoolJumpTable *A) const {256return Idx == A->Idx && XtensaConstantPoolValue::equals(A);257}258};259260} // namespace llvm261262#endif /* LLVM_LIB_TARGET_XTENSA_XTENSACONSTANTPOOLVALUE_H */263264265