[Mlir-commits] [mlir] [MLIR] Allow comparison of opaque properties (PR #66378)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 15 12:35:39 PDT 2023
https://github.com/Dudeldu updated https://github.com/llvm/llvm-project/pull/66378
>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 1/2] [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 *>());
>From 09ddd513a58c1616c8ba68ff6e88e5c417103585 Mon Sep 17 00:00:00 2001
From: Dudeldu <mustermann.informatik at gmail.com>
Date: Fri, 15 Sep 2023 21:34:12 +0200
Subject: [PATCH 2/2] Use property comparison during Operation equivalence
checks
---
mlir/lib/IR/OperationSupport.cpp | 4 +++-
mlir/unittests/IR/OpPropertiesTest.cpp | 5 +++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp
index 0cb6a1cd191b161..25b59de39801ff8 100644
--- a/mlir/lib/IR/OperationSupport.cpp
+++ b/mlir/lib/IR/OperationSupport.cpp
@@ -768,7 +768,9 @@ OperationEquivalence::isRegionEquivalentTo(Region *lhs, Region *rhs,
lhs->getNumSuccessors() != rhs->getNumSuccessors() ||
lhs->getNumOperands() != rhs->getNumOperands() ||
lhs->getNumResults() != rhs->getNumResults() ||
- lhs->hashProperties() != rhs->hashProperties())
+ lhs->hashProperties() != rhs->hashProperties() ||
+ !lhs->getName().compareOpProperties(lhs->getPropertiesStorage(),
+ rhs->getPropertiesStorage()))
return false;
if (!(flags & IgnoreLocations) && lhs->getLoc() != rhs->getLoc())
return false;
diff --git a/mlir/unittests/IR/OpPropertiesTest.cpp b/mlir/unittests/IR/OpPropertiesTest.cpp
index 2d272dfb558c81c..e2d0599f1bd9548 100644
--- a/mlir/unittests/IR/OpPropertiesTest.cpp
+++ b/mlir/unittests/IR/OpPropertiesTest.cpp
@@ -28,6 +28,11 @@ struct TestProperties {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestProperties)
};
+bool operator==(const TestProperties &lhs, TestProperties &rhs) {
+ return lhs.a == rhs.a && lhs.b == rhs.b && lhs.array == rhs.array &&
+ lhs.label == rhs.label;
+}
+
/// Convert a DictionaryAttr to a TestProperties struct, optionally emit errors
/// through the provided diagnostic if any. This is used for example during
/// parsing with the generic format.
More information about the Mlir-commits
mailing list