LLVM 24.0.0git
CSKYConstantPoolValue.h
Go to the documentation of this file.
1//===-- CSKYConstantPoolValue.h - CSKY constantpool value -----*- C++ -*---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the CSKY specific constantpool value class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TARGET_CSKY_CONSTANTPOOLVALUE_H
14#define LLVM_TARGET_CSKY_CONSTANTPOOLVALUE_H
15
16#include "llvm/ADT/StringRef.h"
20#include <cstddef>
21
22namespace llvm {
23
24class BlockAddress;
25class Constant;
26class GlobalValue;
28
41
42/// CSKYConstantPoolValue - CSKY specific constantpool value. This is used to
43/// represent PC-relative displacement between the address of the load
44/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
46protected:
47 CSKYCP::CSKYCPKind Kind; // Kind of constant.
48 unsigned PCAdjust; // Extra adjustment if constantpool is pc-relative.
51
52 unsigned LabelId = 0;
53
56 unsigned ID = 0);
57
58public:
59 const char *getModifierText() const;
60 unsigned getPCAdjustment() const { return PCAdjust; }
63 unsigned getLabelID() const { return LabelId; }
64
65 bool isGlobalValue() const { return Kind == CSKYCP::CPValue; }
66 bool isExtSymbol() const { return Kind == CSKYCP::CPExtSymbol; }
67 bool isBlockAddress() const { return Kind == CSKYCP::CPBlockAddress; }
68 bool isMachineBasicBlock() const {
70 }
71 bool isJT() const { return Kind == CSKYCP::CPJT; }
72 bool isConstPool() const { return Kind == CSKYCP::CPConstPool; }
73
75 Align Alignment) override;
76
77 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
78
79 void print(raw_ostream &O) const override;
80
81 bool equals(const CSKYConstantPoolValue *A) const {
82 return this->LabelId == A->LabelId && this->PCAdjust == A->PCAdjust &&
83 this->Modifier == A->Modifier;
84 }
85
86 template <typename Derived>
88 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
89 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
90 if (Constants[i].isMachineConstantPoolEntry() &&
91 Constants[i].getAlign() >= Alignment) {
92 auto *CPV =
93 static_cast<CSKYConstantPoolValue *>(Constants[i].Val.MachineCPVal);
94 if (Derived *APC = dyn_cast<Derived>(CPV))
95 if (cast<Derived>(this)->equals(APC))
96 return i;
97 }
98 }
99
100 return -1;
101 }
102};
103
104/// CSKY-specific constant pool values for Constants,
105/// Functions, and BlockAddresses.
106class CSKYConstantPoolConstant : public CSKYConstantPoolValue {
107 const Constant *CVal; // Constant being loaded.
108
109 CSKYConstantPoolConstant(const Constant *C, Type *Ty, CSKYCP::CSKYCPKind Kind,
111 bool AddCurrentAddress, unsigned ID);
112
113public:
114 static CSKYConstantPoolConstant *
117 unsigned ID = 0);
118 static CSKYConstantPoolConstant *
121 bool AddCurrentAddress, unsigned ID = 0);
122 const GlobalValue *getGV() const;
123 const BlockAddress *getBlockAddress() const;
124 const Constant *getConstantPool() const;
125
127 Align Alignment) override;
128 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
129 void print(raw_ostream &O) const override;
130
131 bool equals(const CSKYConstantPoolConstant *A) const {
132 return CVal == A->CVal && CSKYConstantPoolValue::equals(A);
133 }
134
135 static bool classof(const CSKYConstantPoolValue *APV) {
136 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isConstPool();
137 }
138};
139
140/// CSKYConstantPoolSymbol - CSKY-specific constantpool values for external
141/// symbols.
142class CSKYConstantPoolSymbol : public CSKYConstantPoolValue {
143 const std::string S; // ExtSymbol being loaded.
144
145 CSKYConstantPoolSymbol(Type *Ty, const char *S, unsigned PCAdjust,
147 bool AddCurrentAddress);
148
149public:
150 static CSKYConstantPoolSymbol *Create(Type *Ty, const char *S,
151 unsigned PCAdjust,
153
154 StringRef getSymbol() const { return S; }
155
157 Align Alignment) override;
158 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
159 void print(raw_ostream &O) const override;
160
161 bool equals(const CSKYConstantPoolSymbol *A) const {
162 return S == A->S && CSKYConstantPoolValue::equals(A);
163 }
164
165 static bool classof(const CSKYConstantPoolValue *ACPV) {
166 return ACPV->isExtSymbol();
167 }
168};
169
170/// CSKYConstantPoolMBB - CSKY-specific constantpool value of a machine basic
171/// block.
172class CSKYConstantPoolMBB : public CSKYConstantPoolValue {
173 const MachineBasicBlock *MBB; // Machine basic block.
174
175 CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust,
177
178public:
179 static CSKYConstantPoolMBB *Create(Type *Ty, const MachineBasicBlock *Mbb,
180 unsigned PCAdjust);
181
182 const MachineBasicBlock *getMBB() const { return MBB; }
183
185 Align Alignment) override;
186 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
187 void print(raw_ostream &O) const override;
188
189 bool equals(const CSKYConstantPoolMBB *A) const {
190 return MBB == A->MBB && CSKYConstantPoolValue::equals(A);
191 }
192
193 static bool classof(const CSKYConstantPoolValue *ACPV) {
194 return ACPV->isMachineBasicBlock();
195 }
196};
197
198/// CSKY-specific constantpool value of a jump table.
199class CSKYConstantPoolJT : public CSKYConstantPoolValue {
200 signed JTI; // Machine basic block.
201
202 CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,
204
205public:
206 static CSKYConstantPoolJT *Create(Type *Ty, int JTI, unsigned PCAdj,
208
209 signed getJTI() { return JTI; }
210
212 Align Alignment) override;
213 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
214 void print(raw_ostream &O) const override;
215
216 bool equals(const CSKYConstantPoolJT *A) const {
217 return JTI == A->JTI && CSKYConstantPoolValue::equals(A);
218 }
219
220 static bool classof(const CSKYConstantPoolValue *ACPV) {
221 return ACPV->isJT();
222 }
223};
224
225} // namespace llvm
226
227#endif
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static MaybeAlign getAlign(Value *Ptr)
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
The address of a basic block.
Definition Constants.h:1088
const GlobalValue * getGV() const
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
static CSKYConstantPoolConstant * Create(const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
bool equals(const CSKYConstantPoolConstant *A) const
const BlockAddress * getBlockAddress() const
const Constant * getConstantPool() const
static bool classof(const CSKYConstantPoolValue *APV)
bool equals(const CSKYConstantPoolJT *A) const
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
static CSKYConstantPoolJT * Create(Type *Ty, int JTI, unsigned PCAdj, CSKYCP::CSKYCPModifier Modifier)
void print(raw_ostream &O) const override
print - Implement operator<<
static bool classof(const CSKYConstantPoolValue *ACPV)
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
static CSKYConstantPoolMBB * Create(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust)
static bool classof(const CSKYConstantPoolValue *ACPV)
bool equals(const CSKYConstantPoolMBB *A) const
void print(raw_ostream &O) const override
print - Implement operator<<
const MachineBasicBlock * getMBB() const
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
static bool classof(const CSKYConstantPoolValue *ACPV)
bool equals(const CSKYConstantPoolSymbol *A) const
static CSKYConstantPoolSymbol * Create(Type *Ty, const char *S, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier)
void print(raw_ostream &O) const override
print - Implement operator<<
CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
bool equals(const CSKYConstantPoolValue *A) const
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment)
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
CSKYCP::CSKYCPModifier Modifier
CSKYCP::CSKYCPModifier getModifier() const
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
This is an important base class in LLVM.
Definition Constant.h:44
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:162
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
const std::vector< MachineConstantPoolEntry > & getConstants() const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39