[Mlir-commits] [mlir] [MLIR] Allow comparison of opaque properties (PR #66378)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 14 11:01:07 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
<details>
<summary>Changes</summary>
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.
--
Full diff: https://github.com/llvm/llvm-project/pull/66378.diff
3 Files Affected:
- (modified) mlir/include/mlir/IR/ExtensibleDialect.h (+1)
- (modified) mlir/include/mlir/IR/OperationSupport.h (+13)
- (modified) mlir/lib/IR/MLIRContext.cpp (+4)
<pre>
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 *>());
</pre>
</details>
https://github.com/llvm/llvm-project/pull/66378
More information about the Mlir-commits
mailing list