[PATCH] D81793: [IR] Support efficient lookup of AssertingVH/PoisoningVH

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 13 17:37:30 PDT 2020


MaskRay added a comment.

Thanks! Seems reasonable. Can you please add a DenseMap test to `llvm/unittests/IR/ValueHandleTest.cpp`?



================
Comment at: llvm/include/llvm/IR/ValueHandle.h:313
 template<typename T>
-struct DenseMapInfo<AssertingVH<T>> {
-  static inline AssertingVH<T> getEmptyKey() {
-    AssertingVH<T> Res;
-    Res.setRawValPtr(DenseMapInfo<Value *>::getEmptyKey());
-    return Res;
-  }
-
-  static inline AssertingVH<T> getTombstoneKey() {
-    AssertingVH<T> Res;
-    Res.setRawValPtr(DenseMapInfo<Value *>::getTombstoneKey());
-    return Res;
-  }
-
-  static unsigned getHashValue(const AssertingVH<T> &Val) {
-    return DenseMapInfo<Value *>::getHashValue(Val.getRawValPtr());
-  }
-
-  static bool isEqual(const AssertingVH<T> &LHS, const AssertingVH<T> &RHS) {
-    return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
-                                          RHS.getRawValPtr());
-  }
-};
+struct DenseMapInfo<AssertingVH<T>> : public DenseMapInfo<T *> {};
 
----------------
`public` can be omitted.

Reusing `DenseMapInfo<T *>` is clever and more efficient.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81793/new/

https://reviews.llvm.org/D81793





More information about the llvm-commits mailing list