LLVM 20.0.0git
RISCVConstantPoolValue.cpp
Go to the documentation of this file.
1//===------- RISCVConstantPoolValue.cpp - RISC-V constantpool value -------===//
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 RISC-V specific constantpool value class.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/FoldingSet.h"
16#include "llvm/IR/GlobalValue.h"
17#include "llvm/IR/Type.h"
19
20using namespace llvm;
21
22RISCVConstantPoolValue::RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV)
23 : MachineConstantPoolValue(Ty), GV(GV), Kind(RISCVCPKind::GlobalValue) {}
24
25RISCVConstantPoolValue::RISCVConstantPoolValue(LLVMContext &C, StringRef S)
26 : MachineConstantPoolValue(Type::getInt64Ty(C)), S(S),
27 Kind(RISCVCPKind::ExtSymbol) {}
28
30 return new RISCVConstantPoolValue(GV->getType(), GV);
31}
32
34 StringRef S) {
35 return new RISCVConstantPoolValue(C, S);
36}
37
39 Align Alignment) {
40 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
41 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
42 if (Constants[i].isMachineConstantPoolEntry() &&
43 Constants[i].getAlign() >= Alignment) {
44 auto *CPV =
45 static_cast<RISCVConstantPoolValue *>(Constants[i].Val.MachineCPVal);
46 if (equals(CPV))
47 return i;
48 }
49 }
50
51 return -1;
52}
53
55 if (isGlobalValue())
56 ID.AddPointer(GV);
57 else {
58 assert(isExtSymbol() && "unrecognized constant pool type");
59 ID.AddString(S);
60 }
61}
62
64 if (isGlobalValue())
65 O << GV->getName();
66 else {
67 assert(isExtSymbol() && "unrecognized constant pool type");
68 O << S;
69 }
70}
71
73 if (isGlobalValue() && A->isGlobalValue())
74 return GV == A->GV;
75 if (isExtSymbol() && A->isExtSymbol())
76 return S == A->S;
77
78 return false;
79}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines a hash set that can be used to remove duplication of nodes in a graph.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:327
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:294
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Abstract base class for all machine specific constantpool value subclasses.
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
A RISCV-specific constant pool value.
static RISCVConstantPoolValue * Create(const GlobalValue *GV)
bool equals(const RISCVConstantPoolValue *A) const
void print(raw_ostream &O) const override
print - Implement operator<<
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment) override
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MaybeAlign getAlign(const Function &F, unsigned Index)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39