LLVM  16.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"
18 #include "llvm/Support/Casting.h"
20 #include <cstddef>
21 
22 namespace llvm {
23 
24 class BlockAddress;
25 class Constant;
26 class GlobalValue;
27 class LLVMContext;
28 class MachineBasicBlock;
29 
30 namespace CSKYCP {
31 enum CSKYCPKind {
38 };
39 
41 } // namespace CSKYCP
42 
43 /// CSKYConstantPoolValue - CSKY specific constantpool value. This is used to
44 /// represent PC-relative displacement between the address of the load
45 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
47 protected:
48  CSKYCP::CSKYCPKind Kind; // Kind of constant.
49  unsigned PCAdjust; // Extra adjustment if constantpool is pc-relative.
52 
53  unsigned LabelId = 0;
54 
57  unsigned ID = 0);
58 
59 public:
60  const char *getModifierText() const;
61  unsigned getPCAdjustment() const { return PCAdjust; }
62  bool mustAddCurrentAddress() const { return AddCurrentAddress; }
64  unsigned getLabelID() const { return LabelId; }
65 
66  bool isGlobalValue() const { return Kind == CSKYCP::CPValue; }
67  bool isExtSymbol() const { return Kind == CSKYCP::CPExtSymbol; }
68  bool isBlockAddress() const { return Kind == CSKYCP::CPBlockAddress; }
69  bool isMachineBasicBlock() const {
71  }
72  bool isJT() const { return Kind == CSKYCP::CPJT; }
73  bool isConstPool() const { return Kind == CSKYCP::CPConstPool; }
74 
76  Align Alignment) override;
77 
79 
80  void print(raw_ostream &O) const override;
81 
82  bool equals(const CSKYConstantPoolValue *A) const {
83  return this->LabelId == A->LabelId && this->PCAdjust == A->PCAdjust &&
84  this->Modifier == A->Modifier;
85  }
86 
87  template <typename Derived>
89  const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
90  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
91  if (Constants[i].isMachineConstantPoolEntry() &&
92  Constants[i].getAlign() >= Alignment) {
93  auto *CPV =
94  static_cast<CSKYConstantPoolValue *>(Constants[i].Val.MachineCPVal);
95  if (Derived *APC = dyn_cast<Derived>(CPV))
96  if (cast<Derived>(this)->equals(APC))
97  return i;
98  }
99  }
100 
101  return -1;
102  }
103 };
104 
105 /// CSKY-specific constant pool values for Constants,
106 /// Functions, and BlockAddresses.
108  const Constant *CVal; // Constant being loaded.
109 
112  bool AddCurrentAddress, unsigned ID);
113 
114 public:
115  static CSKYConstantPoolConstant *
116  Create(const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust,
118  unsigned ID = 0);
119  static CSKYConstantPoolConstant *
122  bool AddCurrentAddress, unsigned ID = 0);
123  const GlobalValue *getGV() const;
124  const BlockAddress *getBlockAddress() const;
125  const Constant *getConstantPool() const;
126 
128  Align Alignment) override;
129  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
130  void print(raw_ostream &O) const override;
131 
132  bool equals(const CSKYConstantPoolConstant *A) const {
133  return CVal == A->CVal && CSKYConstantPoolValue::equals(A);
134  }
135 
136  static bool classof(const CSKYConstantPoolValue *APV) {
137  return APV->isGlobalValue() || APV->isBlockAddress() || APV->isConstPool();
138  }
139 };
140 
141 /// CSKYConstantPoolSymbol - CSKY-specific constantpool values for external
142 /// symbols.
144  const std::string S; // ExtSymbol being loaded.
145 
146  CSKYConstantPoolSymbol(Type *Ty, const char *S, unsigned PCAdjust,
148  bool AddCurrentAddress);
149 
150 public:
151  static CSKYConstantPoolSymbol *Create(Type *Ty, const char *S,
152  unsigned PCAdjust,
154 
155  StringRef getSymbol() const { return S; }
156 
158  Align Alignment) override;
159  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
160  void print(raw_ostream &O) const override;
161 
162  bool equals(const CSKYConstantPoolSymbol *A) const {
163  return S == A->S && CSKYConstantPoolValue::equals(A);
164  }
165 
166  static bool classof(const CSKYConstantPoolValue *ACPV) {
167  return ACPV->isExtSymbol();
168  }
169 };
170 
171 /// CSKYConstantPoolMBB - CSKY-specific constantpool value of a machine basic
172 /// block.
174  const MachineBasicBlock *MBB; // Machine basic block.
175 
176  CSKYConstantPoolMBB(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust,
178 
179 public:
180  static CSKYConstantPoolMBB *Create(Type *Ty, const MachineBasicBlock *Mbb,
181  unsigned PCAdjust);
182 
183  const MachineBasicBlock *getMBB() const { return MBB; }
184 
186  Align Alignment) override;
187  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
188  void print(raw_ostream &O) const override;
189 
190  bool equals(const CSKYConstantPoolMBB *A) const {
191  return MBB == A->MBB && CSKYConstantPoolValue::equals(A);
192  }
193 
194  static bool classof(const CSKYConstantPoolValue *ACPV) {
195  return ACPV->isMachineBasicBlock();
196  }
197 };
198 
199 /// CSKY-specific constantpool value of a jump table.
201  signed JTI; // Machine basic block.
202 
203  CSKYConstantPoolJT(Type *Ty, int JTIndex, unsigned PCAdj,
205 
206 public:
207  static CSKYConstantPoolJT *Create(Type *Ty, int JTI, unsigned PCAdj,
209 
210  signed getJTI() { return JTI; }
211 
213  Align Alignment) override;
214  void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
215  void print(raw_ostream &O) const override;
216 
217  bool equals(const CSKYConstantPoolJT *A) const {
218  return JTI == A->JTI && CSKYConstantPoolValue::equals(A);
219  }
220 
221  static bool classof(const CSKYConstantPoolValue *ACPV) {
222  return ACPV->isJT();
223  }
224 };
225 
226 } // namespace llvm
227 
228 #endif
i
i
Definition: README.txt:29
llvm::CSKYConstantPoolValue::isMachineBasicBlock
bool isMachineBasicBlock() const
Definition: CSKYConstantPoolValue.h:69
llvm::CSKYConstantPoolSymbol::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:154
llvm::CSKYCP::PLT
@ PLT
Definition: CSKYConstantPoolValue.h:40
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::dwarf::Constants
Constants
Definition: Dwarf.h:432
llvm::CSKYCP::TLSGD
@ TLSGD
Definition: CSKYConstantPoolValue.h:40
llvm::CSKYConstantPoolJT::Create
static CSKYConstantPoolJT * Create(Type *Ty, int JTI, unsigned PCAdj, CSKYCP::CSKYCPModifier Modifier)
Definition: CSKYConstantPoolValue.cpp:209
llvm::CSKYConstantPoolValue::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:68
llvm::CSKYCP::CPBlockAddress
@ CPBlockAddress
Definition: CSKYConstantPoolValue.h:34
llvm::CSKYConstantPoolJT::getJTI
signed getJTI()
Definition: CSKYConstantPoolValue.h:210
StringRef.h
llvm::CSKYConstantPoolConstant::classof
static bool classof(const CSKYConstantPoolValue *APV)
Definition: CSKYConstantPoolValue.h:136
llvm::CSKYConstantPoolValue::getExistingMachineCPValueImpl
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment)
Definition: CSKYConstantPoolValue.h:88
llvm::CSKYConstantPoolJT
CSKY-specific constantpool value of a jump table.
Definition: CSKYConstantPoolValue.h:200
llvm::CSKYConstantPoolMBB::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:192
llvm::CSKYConstantPoolValue::Modifier
CSKYCP::CSKYCPModifier Modifier
Definition: CSKYConstantPoolValue.h:50
llvm::CSKYConstantPoolValue::isExtSymbol
bool isExtSymbol() const
Definition: CSKYConstantPoolValue.h:67
llvm::CSKYConstantPoolConstant::Create
static CSKYConstantPoolConstant * Create(const Constant *C, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
Definition: CSKYConstantPoolValue.cpp:86
ErrorHandling.h
llvm::CSKYConstantPoolJT::equals
bool equals(const CSKYConstantPoolJT *A) const
Definition: CSKYConstantPoolValue.h:217
llvm::MachineConstantPoolValue
Abstract base class for all machine specific constantpool value subclasses.
Definition: MachineConstantPool.h:35
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::CSKYConstantPoolValue::isJT
bool isJT() const
Definition: CSKYConstantPoolValue.h:72
llvm::CSKYConstantPoolJT::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:224
llvm::CSKYCP::GOT
@ GOT
Definition: CSKYConstantPoolValue.h:40
llvm::CSKYConstantPoolValue::isGlobalValue
bool isGlobalValue() const
Definition: CSKYConstantPoolValue.h:66
llvm::CSKYCP::CPConstPool
@ CPConstPool
Definition: CSKYConstantPoolValue.h:37
llvm::CSKYConstantPoolJT::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:214
llvm::CSKYConstantPoolConstant::getConstantPool
const Constant * getConstantPool() const
Definition: CSKYConstantPoolValue.cpp:110
llvm::CSKYConstantPoolJT::classof
static bool classof(const CSKYConstantPoolValue *ACPV)
Definition: CSKYConstantPoolValue.h:221
llvm::CSKYConstantPoolConstant::equals
bool equals(const CSKYConstantPoolConstant *A) const
Definition: CSKYConstantPoolValue.h:132
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::CSKYConstantPoolValue::isBlockAddress
bool isBlockAddress() const
Definition: CSKYConstantPoolValue.h:68
llvm::CSKYCP::NO_MOD
@ NO_MOD
Definition: CSKYConstantPoolValue.h:40
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::CSKYCP::CPJT
@ CPJT
Definition: CSKYConstantPoolValue.h:36
llvm::CSKYConstantPoolJT::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:219
llvm::CSKYConstantPoolValue::mustAddCurrentAddress
bool mustAddCurrentAddress() const
Definition: CSKYConstantPoolValue.h:62
llvm::CSKYConstantPoolSymbol::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:159
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::CSKYCP::CPExtSymbol
@ CPExtSymbol
Definition: CSKYConstantPoolValue.h:33
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::CSKYConstantPoolValue::getModifierText
const char * getModifierText() const
Definition: CSKYConstantPoolValue.cpp:35
llvm::CSKYConstantPoolValue::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:62
llvm::CSKYConstantPoolSymbol::Create
static CSKYConstantPoolSymbol * Create(Type *Ty, const char *S, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier)
Definition: CSKYConstantPoolValue.cpp:143
llvm::CSKYConstantPoolConstant
CSKY-specific constant pool values for Constants, Functions, and BlockAddresses.
Definition: CSKYConstantPoolValue.h:107
llvm::ISD::BlockAddress
@ BlockAddress
Definition: ISDOpcodes.h:84
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::CSKYConstantPoolValue::getLabelID
unsigned getLabelID() const
Definition: CSKYConstantPoolValue.h:64
llvm::CSKYConstantPoolValue::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:57
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::MachineConstantPool
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
Definition: MachineConstantPool.h:117
llvm::CSKYConstantPoolValue
CSKYConstantPoolValue - CSKY specific constantpool value.
Definition: CSKYConstantPoolValue.h:46
llvm::CSKYCP::GOTOFF
@ GOTOFF
Definition: CSKYConstantPoolValue.h:40
llvm::CSKYConstantPoolSymbol::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:148
llvm::CSKYCP::ADDR
@ ADDR
Definition: CSKYConstantPoolValue.h:40
MachineConstantPool.h
llvm::CSKYConstantPoolConstant::print
void print(raw_ostream &O) const override
print - Implement operator<<
Definition: CSKYConstantPoolValue.cpp:125
llvm::CSKYConstantPoolMBB::Create
static CSKYConstantPoolMBB * Create(Type *Ty, const MachineBasicBlock *Mbb, unsigned PCAdjust)
Definition: CSKYConstantPoolValue.cpp:176
llvm::CSKYConstantPoolValue::getModifier
CSKYCP::CSKYCPModifier getModifier() const
Definition: CSKYConstantPoolValue.h:63
llvm::CSKYCP::CPValue
@ CPValue
Definition: CSKYConstantPoolValue.h:32
llvm::CSKYConstantPoolMBB::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:187
llvm::CSKYCP::CSKYCPKind
CSKYCPKind
Definition: CSKYConstantPoolValue.h:31
llvm::CSKYConstantPoolConstant::addSelectionDAGCSEId
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
Definition: CSKYConstantPoolValue.cpp:119
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:849
llvm::CSKYCP::TLSLE
@ TLSLE
Definition: CSKYConstantPoolValue.h:40
llvm::CSKYConstantPoolValue::PCAdjust
unsigned PCAdjust
Definition: CSKYConstantPoolValue.h:49
llvm::CSKYConstantPoolValue::LabelId
unsigned LabelId
Definition: CSKYConstantPoolValue.h:53
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::CSKYCP::CSKYCPModifier
CSKYCPModifier
Definition: CSKYConstantPoolValue.h:40
llvm::CSKYCP::CPMachineBasicBlock
@ CPMachineBasicBlock
Definition: CSKYConstantPoolValue.h:35
llvm::CSKYConstantPoolConstant::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:114
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:318
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::CSKYConstantPoolConstant::getBlockAddress
const BlockAddress * getBlockAddress() const
Definition: CSKYConstantPoolValue.cpp:105
llvm::CSKYConstantPoolValue::isConstPool
bool isConstPool() const
Definition: CSKYConstantPoolValue.h:73
llvm::CSKYConstantPoolValue::CSKYConstantPoolValue
CSKYConstantPoolValue(Type *Ty, CSKYCP::CSKYCPKind Kind, unsigned PCAdjust, CSKYCP::CSKYCPModifier Modifier, bool AddCurrentAddress, unsigned ID=0)
Definition: CSKYConstantPoolValue.cpp:27
llvm::CSKYConstantPoolSymbol::classof
static bool classof(const CSKYConstantPoolValue *ACPV)
Definition: CSKYConstantPoolValue.h:166
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
llvm::CSKYConstantPoolValue::Kind
CSKYCP::CSKYCPKind Kind
Definition: CSKYConstantPoolValue.h:48
llvm::CSKYConstantPoolConstant::getGV
const GlobalValue * getGV() const
Definition: CSKYConstantPoolValue.cpp:100
llvm::CSKYConstantPoolValue::AddCurrentAddress
bool AddCurrentAddress
Definition: CSKYConstantPoolValue.h:51
Casting.h
llvm::CSKYConstantPoolSymbol
CSKYConstantPoolSymbol - CSKY-specific constantpool values for external symbols.
Definition: CSKYConstantPoolValue.h:143
llvm::CSKYConstantPoolValue::getPCAdjustment
unsigned getPCAdjustment() const
Definition: CSKYConstantPoolValue.h:61
llvm::CSKYConstantPoolMBB::getExistingMachineCPValue
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
Definition: CSKYConstantPoolValue.cpp:182
llvm::getAlign
bool getAlign(const Function &F, unsigned index, unsigned &align)
Definition: NVPTXUtilities.cpp:294
llvm::CSKYConstantPoolMBB
CSKYConstantPoolMBB - CSKY-specific constantpool value of a machine basic block.
Definition: CSKYConstantPoolValue.h:173
llvm::CSKYConstantPoolMBB::getMBB
const MachineBasicBlock * getMBB() const
Definition: CSKYConstantPoolValue.h:183
llvm::CSKYConstantPoolValue::equals
bool equals(const CSKYConstantPoolValue *A) const
Definition: CSKYConstantPoolValue.h:82
llvm::CSKYCP::TLSIE
@ TLSIE
Definition: CSKYConstantPoolValue.h:40
llvm::CSKYConstantPoolSymbol::getSymbol
StringRef getSymbol() const
Definition: CSKYConstantPoolValue.h:155
llvm::CSKYConstantPoolMBB::equals
bool equals(const CSKYConstantPoolMBB *A) const
Definition: CSKYConstantPoolValue.h:190
llvm::CSKYConstantPoolMBB::classof
static bool classof(const CSKYConstantPoolValue *ACPV)
Definition: CSKYConstantPoolValue.h:194
llvm::CSKYConstantPoolSymbol::equals
bool equals(const CSKYConstantPoolSymbol *A) const
Definition: CSKYConstantPoolValue.h:162