[mlir] Make OpResult usable with DenseSet etc.
authorMatthias Springer <springerm@google.com>
Wed, 13 Oct 2021 06:22:49 +0000 (15:22 +0900)
committerMatthias Springer <springerm@google.com>
Wed, 13 Oct 2021 06:58:08 +0000 (15:58 +0900)
`DenseSet<Value>` works but `DenseSet<OpResult>` currently results in a compile error.

Differential Revision: https://reviews.llvm.org/D111694

mlir/include/mlir/IR/Value.h

index 7ea8b26..8b83905 100644 (file)
@@ -489,6 +489,17 @@ struct DenseMapInfo<mlir::BlockArgument> : public DenseMapInfo<mlir::Value> {
     return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
   }
 };
+template <>
+struct DenseMapInfo<mlir::OpResult> : public DenseMapInfo<mlir::Value> {
+  static mlir::OpResult getEmptyKey() {
+    void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
+    return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
+  }
+  static mlir::OpResult getTombstoneKey() {
+    void *pointer = llvm::DenseMapInfo<void *>::getTombstoneKey();
+    return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
+  }
+};
 
 /// Allow stealing the low bits of a value.
 template <>
@@ -513,6 +524,14 @@ public:
     return reinterpret_cast<mlir::detail::BlockArgumentImpl *>(pointer);
   }
 };
+template <>
+struct PointerLikeTypeTraits<mlir::OpResult>
+    : public PointerLikeTypeTraits<mlir::Value> {
+public:
+  static inline mlir::OpResult getFromVoidPointer(void *pointer) {
+    return reinterpret_cast<mlir::detail::OpResultImpl *>(pointer);
+  }
+};
 
 } // end namespace llvm