Skip to content

Commit d483a8a

Browse files
committed
[cxx-interop] Workaround a template instantiation issue
`class GVNPass` has a private member `ValueTable VN`, where `ValueTable` uses a forward-declared type `Expression`, which is declared in a .cpp file. This is currently causing issues since Swift started importing private fields of C++ types. rdar://145070564
1 parent 7883558 commit d483a8a

File tree

2 files changed

+34
-34
lines changed
  • llvm
    • include/llvm/Transforms/Scalar
    • lib/Transforms/Scalar

2 files changed

+34
-34
lines changed

llvm/include/llvm/Transforms/Scalar/GVN.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,38 @@ struct GVNSinkPass : PassInfoMixin<GVNSinkPass> {
410410

411411
} // end namespace llvm
412412

413+
struct llvm::GVNPass::Expression {
414+
uint32_t opcode;
415+
bool commutative = false;
416+
// The type is not necessarily the result type of the expression, it may be
417+
// any additional type needed to disambiguate the expression.
418+
Type *type = nullptr;
419+
SmallVector<uint32_t, 4> varargs;
420+
421+
AttributeList attrs;
422+
423+
Expression(uint32_t o = ~2U) : opcode(o) {}
424+
425+
bool operator==(const Expression &other) const {
426+
if (opcode != other.opcode)
427+
return false;
428+
if (opcode == ~0U || opcode == ~1U)
429+
return true;
430+
if (type != other.type)
431+
return false;
432+
if (varargs != other.varargs)
433+
return false;
434+
if ((!attrs.isEmpty() || !other.attrs.isEmpty()) &&
435+
!attrs.intersectWith(type->getContext(), other.attrs).has_value())
436+
return false;
437+
return true;
438+
}
439+
440+
friend hash_code hash_value(const Expression &Value) {
441+
return hash_combine(
442+
Value.opcode, Value.type,
443+
hash_combine_range(Value.varargs.begin(), Value.varargs.end()));
444+
}
445+
};
446+
413447
#endif // LLVM_TRANSFORMS_SCALAR_GVN_H

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -137,40 +137,6 @@ static cl::opt<uint32_t> MaxNumInsnsPerBlock(
137137
cl::desc("Max number of instructions to scan in each basic block in GVN "
138138
"(default = 100)"));
139139

140-
struct llvm::GVNPass::Expression {
141-
uint32_t opcode;
142-
bool commutative = false;
143-
// The type is not necessarily the result type of the expression, it may be
144-
// any additional type needed to disambiguate the expression.
145-
Type *type = nullptr;
146-
SmallVector<uint32_t, 4> varargs;
147-
148-
AttributeList attrs;
149-
150-
Expression(uint32_t o = ~2U) : opcode(o) {}
151-
152-
bool operator==(const Expression &other) const {
153-
if (opcode != other.opcode)
154-
return false;
155-
if (opcode == ~0U || opcode == ~1U)
156-
return true;
157-
if (type != other.type)
158-
return false;
159-
if (varargs != other.varargs)
160-
return false;
161-
if ((!attrs.isEmpty() || !other.attrs.isEmpty()) &&
162-
!attrs.intersectWith(type->getContext(), other.attrs).has_value())
163-
return false;
164-
return true;
165-
}
166-
167-
friend hash_code hash_value(const Expression &Value) {
168-
return hash_combine(
169-
Value.opcode, Value.type,
170-
hash_combine_range(Value.varargs.begin(), Value.varargs.end()));
171-
}
172-
};
173-
174140
namespace llvm {
175141

176142
template <> struct DenseMapInfo<GVNPass::Expression> {

0 commit comments

Comments
 (0)