[Mlir-commits] [mlir] [MLIR] Allow comparison of opaque properties (PR #66378)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 14 06:55:58 PDT 2023


https://github.com/Dudeldu created https://github.com/llvm/llvm-project/pull/66378:

Add capabilities for comparing opaque properties. This is useful when dealing with arbitrary operations which can be compare based on their OperationName. Now you can furthermore compare their properties without the need to determine their actual type.

>From 41d07d895575a43431bbb66afa0475f3325769e8 Mon Sep 17 00:00:00 2001
From: Dudeldu <mustermann.informatik at gmail.com>
Date: Tue, 12 Sep 2023 16:28:38 +0200
Subject: [PATCH] [MLIR] Allow comparison of opque properties

---
 mlir/include/mlir/IR/ExtensibleDialect.h |  1 +
 mlir/include/mlir/IR/OperationSupport.h  | 13 +++++++++++++
 mlir/lib/IR/MLIRContext.cpp              |  4 ++++
 3 files changed, 18 insertions(+)

diff --git a/mlir/include/mlir/IR/ExtensibleDialect.h b/mlir/include/mlir/IR/ExtensibleDialect.h
index 37821d3a2a5163f..baff6011ff84651 100644
--- a/mlir/include/mlir/IR/ExtensibleDialect.h
+++ b/mlir/include/mlir/IR/ExtensibleDialect.h
@@ -495,6 +495,7 @@ class DynamicOpDefinition : public OperationName::Impl {
   }
   Attribute getPropertiesAsAttr(Operation *op) final { return {}; }
   void copyProperties(OpaqueProperties lhs, OpaqueProperties rhs) final {}
+  bool compareProperties(OpaqueProperties, OpaqueProperties) final { return false; }
   llvm::hash_code hashProperties(OpaqueProperties prop) final { return {}; }
 
 private:
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 19ffddc30904897..9e9f89b95e6fd50 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -141,6 +141,7 @@ class OperationName {
                           function_ref<InFlightDiagnostic &()> getDiag) = 0;
     virtual Attribute getPropertiesAsAttr(Operation *) = 0;
     virtual void copyProperties(OpaqueProperties, OpaqueProperties) = 0;
+    virtual bool compareProperties(OpaqueProperties, OpaqueProperties) = 0;
     virtual llvm::hash_code hashProperties(OpaqueProperties) = 0;
   };
 
@@ -221,6 +222,7 @@ class OperationName {
                           function_ref<InFlightDiagnostic &()> getDiag) final;
     Attribute getPropertiesAsAttr(Operation *) final;
     void copyProperties(OpaqueProperties, OpaqueProperties) final;
+    bool compareProperties(OpaqueProperties, OpaqueProperties) final;
     llvm::hash_code hashProperties(OpaqueProperties) final;
   };
 
@@ -445,6 +447,10 @@ class OperationName {
     return getImpl()->copyProperties(lhs, rhs);
   }
 
+  bool compareOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const {
+    return getImpl()->compareProperties(lhs, rhs);
+  }
+
   llvm::hash_code hashOpProperties(OpaqueProperties properties) const {
     return getImpl()->hashProperties(properties);
   }
@@ -646,6 +652,13 @@ class RegisteredOperationName : public OperationName {
       }
       return {};
     }
+    bool compareProperties(OpaqueProperties lhs, OpaqueProperties rhs) final {
+      if constexpr (hasProperties) {
+        return *lhs.as<Properties *>() == *rhs.as<Properties *>();
+      } else {
+        return true;
+      }
+    }
     void copyProperties(OpaqueProperties lhs, OpaqueProperties rhs) final {
       *lhs.as<Properties *>() = *rhs.as<Properties *>();
     }
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 5f1d036d22b918e..ed1029959639587 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -864,6 +864,10 @@ void OperationName::UnregisteredOpModel::copyProperties(OpaqueProperties lhs,
                                                         OpaqueProperties rhs) {
   *lhs.as<Attribute *>() = *rhs.as<Attribute *>();
 }
+bool OperationName::UnregisteredOpModel::compareProperties(OpaqueProperties lhs,
+                                                        OpaqueProperties rhs) {
+  return *lhs.as<Attribute *>() == *rhs.as<Attribute *>();
+}
 llvm::hash_code
 OperationName::UnregisteredOpModel::hashProperties(OpaqueProperties prop) {
   return llvm::hash_combine(*prop.as<Attribute *>());



More information about the Mlir-commits mailing list