[Mlir-commits] [mlir] [mlir][CSE] Introduce DialectInterface for CSE (PR #73520)

Ivan Butygin llvmlistbot at llvm.org
Wed Nov 29 16:53:33 PST 2023


================
@@ -35,8 +35,16 @@ using namespace mlir;
 namespace {
 struct SimpleOperationInfo : public llvm::DenseMapInfo<Operation *> {
   static unsigned getHashValue(const Operation *opC) {
+    auto *op = const_cast<Operation *>(opC);
+    // Use a custom hook if provided.
+    if (auto *interface = dyn_cast<DialectCSEInterface>(op->getDialect())) {
+      std::optional<unsigned> val = interface->getHashValue(op);
----------------
Hardcode84 wrote:

While we can remove the `optional` part, users will still need to remember the interface exists and they need to do `dyn_cast`. So, maybe instead add high-level functions `getOpHash` and `isEquvivalent` (they can be static methods of `DialectCSEInterface`) which encapsulate all these `dyn_cast`s and optional checks. CSE pass and any other potential users will then call to those methods, without caring of specific interface semantics.

https://github.com/llvm/llvm-project/pull/73520


More information about the Mlir-commits mailing list