Skip to content

Commit 88399e1

Browse files
committed
Remove two subclasses
1 parent c85f7ff commit 88399e1

File tree

4 files changed

+61
-132
lines changed

4 files changed

+61
-132
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,11 +1085,11 @@ void RISCVAsmPrinter::emitMachineConstantPoolValue(
10851085
MCSymbol *MCSym;
10861086

10871087
if (RCPV->isGlobalValue()) {
1088-
auto *GV = cast<RISCVConstantPoolConstant>(RCPV)->getGlobalValue();
1088+
auto *GV = RCPV->getGlobalValue();
10891089
MCSym = getSymbol(GV);
10901090
} else {
10911091
assert(RCPV->isExtSymbol() && "unrecognized constant pool value");
1092-
auto Sym = cast<RISCVConstantPoolSymbol>(RCPV)->getSymbol();
1092+
auto Sym = RCPV->getSymbol();
10931093
MCSym = GetExternalSymbolSymbol(Sym);
10941094
}
10951095

llvm/lib/Target/RISCV/RISCVConstantPoolValue.cpp

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,71 +21,61 @@
2121

2222
using namespace llvm;
2323

24-
RISCVConstantPoolValue::RISCVConstantPoolValue(LLVMContext &C, RISCVCPKind Kind)
25-
: MachineConstantPoolValue((Type *)Type::getInt64Ty(C)), Kind(Kind) {}
24+
RISCVConstantPoolValue::RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV)
25+
: MachineConstantPoolValue(Ty), GV(GV), Kind(RISCVCPKind::GlobalValue) {}
2626

27-
RISCVConstantPoolValue::RISCVConstantPoolValue(Type *Ty, RISCVCPKind Kind)
28-
: MachineConstantPoolValue(Ty), Kind(Kind) {}
27+
RISCVConstantPoolValue::RISCVConstantPoolValue(LLVMContext &C, StringRef S)
28+
: MachineConstantPoolValue((Type *)Type::getInt64Ty(C)), S(S),
29+
Kind(RISCVCPKind::ExtSymbol) {}
2930

30-
int RISCVConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
31-
Align Alignment) {
32-
llvm_unreachable("Shouldn't be calling this directly!");
33-
}
34-
35-
RISCVConstantPoolConstant::RISCVConstantPoolConstant(Type *Ty,
36-
const Constant *GV,
37-
RISCVCPKind Kind)
38-
: RISCVConstantPoolValue(Ty, Kind), CVal(GV) {}
39-
40-
RISCVConstantPoolConstant *
41-
RISCVConstantPoolConstant::Create(const GlobalValue *GV) {
42-
return new RISCVConstantPoolConstant(GV->getType(), GV,
43-
RISCVCPKind::GlobalValue);
44-
}
45-
46-
RISCVConstantPoolConstant *
47-
RISCVConstantPoolConstant::Create(const BlockAddress *BA) {
48-
return new RISCVConstantPoolConstant(BA->getType(), BA,
49-
RISCVCPKind::BlockAddress);
50-
}
51-
52-
int RISCVConstantPoolConstant::getExistingMachineCPValue(
53-
MachineConstantPool *CP, Align Alignment) {
54-
return getExistingMachineCPValueImpl<RISCVConstantPoolConstant>(CP,
55-
Alignment);
56-
}
57-
58-
void RISCVConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
59-
ID.AddPointer(CVal);
31+
RISCVConstantPoolValue *RISCVConstantPoolValue::Create(const GlobalValue *GV) {
32+
return new RISCVConstantPoolValue(GV->getType(), GV);
6033
}
6134

62-
void RISCVConstantPoolConstant::print(raw_ostream &O) const {
63-
O << CVal->getName();
35+
RISCVConstantPoolValue *RISCVConstantPoolValue::Create(LLVMContext &C,
36+
StringRef s) {
37+
return new RISCVConstantPoolValue(C, s);
6438
}
6539

66-
const GlobalValue *RISCVConstantPoolConstant::getGlobalValue() const {
67-
return dyn_cast_or_null<GlobalValue>(CVal);
40+
int RISCVConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
41+
Align Alignment) {
42+
const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
43+
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
44+
if (Constants[i].isMachineConstantPoolEntry() &&
45+
Constants[i].getAlign() >= Alignment) {
46+
auto *CPV =
47+
static_cast<RISCVConstantPoolValue *>(Constants[i].Val.MachineCPVal);
48+
if (equals(CPV))
49+
return i;
50+
}
51+
}
52+
53+
return -1;
6854
}
6955

70-
const BlockAddress *RISCVConstantPoolConstant::getBlockAddress() const {
71-
return dyn_cast_or_null<BlockAddress>(CVal);
56+
void RISCVConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
57+
if (isGlobalValue())
58+
ID.AddPointer(GV);
59+
else {
60+
assert(isExtSymbol() && "unrecognized constant pool type");
61+
ID.AddString(S);
62+
}
7263
}
7364

74-
RISCVConstantPoolSymbol::RISCVConstantPoolSymbol(LLVMContext &C, StringRef s)
75-
: RISCVConstantPoolValue(C, RISCVCPKind::ExtSymbol), S(s) {}
76-
77-
RISCVConstantPoolSymbol *RISCVConstantPoolSymbol::Create(LLVMContext &C,
78-
StringRef s) {
79-
return new RISCVConstantPoolSymbol(C, s);
65+
void RISCVConstantPoolValue::print(raw_ostream &O) const {
66+
if (isGlobalValue())
67+
O << GV->getName();
68+
else {
69+
assert(isExtSymbol() && "unrecognized constant pool type");
70+
O << S;
71+
}
8072
}
8173

82-
int RISCVConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
83-
Align Alignment) {
84-
return getExistingMachineCPValueImpl<RISCVConstantPoolSymbol>(CP, Alignment);
85-
}
74+
bool RISCVConstantPoolValue::equals(const RISCVConstantPoolValue *A) const {
75+
if (isGlobalValue() && A->isGlobalValue())
76+
return GV == A->GV;
77+
else if (isExtSymbol() && A->isExtSymbol())
78+
return S == A->S;
8679

87-
void RISCVConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
88-
ID.AddString(S);
80+
return false;
8981
}
90-
91-
void RISCVConstantPoolSymbol::print(raw_ostream &O) const { O << S; }

llvm/lib/Target/RISCV/RISCVConstantPoolValue.h

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,82 +26,26 @@ class LLVMContext;
2626

2727
/// A RISCV-specific constant pool value.
2828
class RISCVConstantPoolValue : public MachineConstantPoolValue {
29-
protected:
30-
enum class RISCVCPKind { ExtSymbol, GlobalValue, BlockAddress };
31-
32-
RISCVConstantPoolValue(LLVMContext &C, RISCVCPKind Kind);
33-
34-
RISCVConstantPoolValue(Type *Ty, RISCVCPKind Kind);
35-
36-
template <typename Derived>
37-
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment) {
38-
const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
39-
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
40-
if (Constants[i].isMachineConstantPoolEntry() &&
41-
Constants[i].getAlign() >= Alignment) {
42-
auto *CPV = static_cast<RISCVConstantPoolValue *>(
43-
Constants[i].Val.MachineCPVal);
44-
if (Derived *APC = dyn_cast<Derived>(CPV))
45-
if (cast<Derived>(this)->equals(APC))
46-
return i;
47-
}
48-
}
49-
50-
return -1;
51-
}
29+
const GlobalValue *GV;
30+
const StringRef S;
31+
32+
RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV);
33+
RISCVConstantPoolValue(LLVMContext &C, StringRef s);
5234

5335
private:
36+
enum class RISCVCPKind { ExtSymbol, GlobalValue };
5437
RISCVCPKind Kind;
5538

5639
public:
5740
~RISCVConstantPoolValue() = default;
5841

59-
bool isExtSymbol() const { return Kind == RISCVCPKind::ExtSymbol; }
60-
bool isGlobalValue() const { return Kind == RISCVCPKind::GlobalValue; }
61-
bool isBlockAddress() const { return Kind == RISCVCPKind::BlockAddress; }
62-
63-
int getExistingMachineCPValue(MachineConstantPool *CP,
64-
Align Alignment) override;
65-
66-
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override {}
67-
};
68-
69-
class RISCVConstantPoolConstant : public RISCVConstantPoolValue {
70-
const Constant *CVal;
71-
72-
RISCVConstantPoolConstant(Type *Ty, const Constant *GV, RISCVCPKind Kind);
73-
74-
public:
75-
static RISCVConstantPoolConstant *Create(const GlobalValue *GV);
76-
static RISCVConstantPoolConstant *Create(const BlockAddress *BA);
77-
78-
const GlobalValue *getGlobalValue() const;
79-
const BlockAddress *getBlockAddress() const;
42+
static RISCVConstantPoolValue *Create(const GlobalValue *GV);
43+
static RISCVConstantPoolValue *Create(LLVMContext &C, StringRef s);
8044

81-
int getExistingMachineCPValue(MachineConstantPool *CP,
82-
Align Alignment) override;
83-
84-
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
85-
86-
void print(raw_ostream &O) const override;
87-
88-
bool equals(const RISCVConstantPoolConstant *A) const {
89-
return CVal == A->CVal;
90-
}
91-
92-
static bool classof(const RISCVConstantPoolValue *RCPV) {
93-
return RCPV->isGlobalValue() || RCPV->isBlockAddress();
94-
}
95-
};
96-
97-
class RISCVConstantPoolSymbol : public RISCVConstantPoolValue {
98-
const StringRef S;
99-
100-
RISCVConstantPoolSymbol(LLVMContext &C, StringRef s);
101-
102-
public:
103-
static RISCVConstantPoolSymbol *Create(LLVMContext &C, StringRef s);
45+
bool isGlobalValue() const { return Kind == RISCVCPKind::GlobalValue; }
46+
bool isExtSymbol() const { return Kind == RISCVCPKind::ExtSymbol; }
10447

48+
const GlobalValue *getGlobalValue() const { return GV; }
10549
StringRef getSymbol() const { return S; }
10650

10751
int getExistingMachineCPValue(MachineConstantPool *CP,
@@ -111,11 +55,7 @@ class RISCVConstantPoolSymbol : public RISCVConstantPoolValue {
11155

11256
void print(raw_ostream &O) const override;
11357

114-
bool equals(const RISCVConstantPoolSymbol *A) const { return S == A->S; }
115-
116-
static bool classof(const RISCVConstantPoolValue *RCPV) {
117-
return RCPV->isExtSymbol();
118-
}
58+
bool equals(const RISCVConstantPoolValue *A) const;
11959
};
12060

12161
} // end namespace llvm

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7303,8 +7303,7 @@ static SDValue getTargetNode(JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
73037303

73047304
static SDValue getLargeGlobalAddress(GlobalAddressSDNode *N, SDLoc DL, EVT Ty,
73057305
SelectionDAG &DAG) {
7306-
RISCVConstantPoolConstant *CPV =
7307-
RISCVConstantPoolConstant::Create(N->getGlobal());
7306+
RISCVConstantPoolValue *CPV = RISCVConstantPoolValue::Create(N->getGlobal());
73087307
SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
73097308
SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
73107309
return DAG.getLoad(
@@ -7314,8 +7313,8 @@ static SDValue getLargeGlobalAddress(GlobalAddressSDNode *N, SDLoc DL, EVT Ty,
73147313

73157314
static SDValue getLargeExternalSymbol(ExternalSymbolSDNode *N, SDLoc DL, EVT Ty,
73167315
SelectionDAG &DAG) {
7317-
RISCVConstantPoolSymbol *CPV =
7318-
RISCVConstantPoolSymbol::Create(*DAG.getContext(), N->getSymbol());
7316+
RISCVConstantPoolValue *CPV =
7317+
RISCVConstantPoolValue::Create(*DAG.getContext(), N->getSymbol());
73197318
SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
73207319
SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
73217320
return DAG.getLoad(

0 commit comments

Comments
 (0)