[PATCH] D81793: [IR] Support efficient lookup of AssertingVH/PoisoningVH
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 13:20:49 PDT 2020
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.
Closed by commit rG5f565c04194b: [IR] Support efficient AssertingVH/PoisoningVH lookup (authored by nikic).
Changed prior to commit:
https://reviews.llvm.org/D81793?vs=270619&id=270635#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81793/new/
https://reviews.llvm.org/D81793
Files:
llvm/include/llvm/IR/ValueHandle.h
llvm/unittests/IR/ValueHandleTest.cpp
Index: llvm/unittests/IR/ValueHandleTest.cpp
===================================================================
--- llvm/unittests/IR/ValueHandleTest.cpp
+++ llvm/unittests/IR/ValueHandleTest.cpp
@@ -491,6 +491,30 @@
EXPECT_TRUE(DenseMapInfo<PoisoningVH<Value>>::isEqual(VH, BitcastV.get()));
}
+TEST_F(ValueHandle, AssertingVH_DenseMap) {
+ DenseMap<AssertingVH<Value>, int> Map;
+ Map.insert({BitcastV.get(), 1});
+ Map.insert({ConstantV, 2});
+ // These will create a temporary AssertingVH during lookup.
+ EXPECT_TRUE(Map.find(BitcastV.get()) != Map.end());
+ EXPECT_TRUE(Map.find(ConstantV) != Map.end());
+ // These will not create a temporary AssertingVH.
+ EXPECT_TRUE(Map.find_as(BitcastV.get()) != Map.end());
+ EXPECT_TRUE(Map.find_as(ConstantV) != Map.end());
+}
+
+TEST_F(ValueHandle, PoisoningVH_DenseMap) {
+ DenseMap<PoisoningVH<Value>, int> Map;
+ Map.insert({BitcastV.get(), 1});
+ Map.insert({ConstantV, 2});
+ // These will create a temporary PoisoningVH during lookup.
+ EXPECT_TRUE(Map.find(BitcastV.get()) != Map.end());
+ EXPECT_TRUE(Map.find(ConstantV) != Map.end());
+ // These will not create a temporary PoisoningVH.
+ EXPECT_TRUE(Map.find_as(BitcastV.get()) != Map.end());
+ EXPECT_TRUE(Map.find_as(ConstantV) != Map.end());
+}
+
#ifdef NDEBUG
TEST_F(ValueHandle, PoisoningVH_ReducesToPointer) {
Index: llvm/include/llvm/IR/ValueHandle.h
===================================================================
--- llvm/include/llvm/IR/ValueHandle.h
+++ llvm/include/llvm/IR/ValueHandle.h
@@ -307,30 +307,10 @@
ValueTy &operator*() const { return *getValPtr(); }
};
-// Specialize DenseMapInfo to allow AssertingVH to participate in DenseMap.
+// Treat AssertingVH<T> like T* inside maps. This also allows using find_as()
+// to look up a value without constructing a value handle.
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>> : DenseMapInfo<T *> {};
/// Value handle that tracks a Value across RAUW.
///
@@ -562,6 +542,17 @@
return DenseMapInfo<Value *>::isEqual(LHS.getRawValPtr(),
RHS.getRawValPtr());
}
+
+ // Allow lookup by T* via find_as(), without constructing a temporary
+ // value handle.
+
+ static unsigned getHashValue(const T *Val) {
+ return DenseMapInfo<Value *>::getHashValue(Val);
+ }
+
+ static bool isEqual(const T *LHS, const PoisoningVH<T> &RHS) {
+ return DenseMapInfo<Value *>::isEqual(LHS, RHS.getRawValPtr());
+ }
};
} // end namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81793.270635.patch
Type: text/x-patch
Size: 3227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200614/81ea9c39/attachment.bin>
More information about the llvm-commits
mailing list