|
21 | 21 |
|
22 | 22 | using namespace llvm;
|
23 | 23 |
|
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) {} |
26 | 26 |
|
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) {} |
29 | 30 |
|
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); |
60 | 33 | }
|
61 | 34 |
|
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); |
64 | 38 | }
|
65 | 39 |
|
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; |
68 | 54 | }
|
69 | 55 |
|
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 | + } |
72 | 63 | }
|
73 | 64 |
|
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 | + } |
80 | 72 | }
|
81 | 73 |
|
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; |
86 | 79 |
|
87 |
| -void RISCVConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) { |
88 |
| - ID.AddString(S); |
| 80 | + return false; |
89 | 81 | }
|
90 |
| - |
91 |
| -void RISCVConstantPoolSymbol::print(raw_ostream &O) const { O << S; } |
0 commit comments