[Mlir-commits] [mlir] [mlir] Optimize getting properties on concrete ops (PR #88259)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Apr 10 04:58:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-mlir
Author: Jeff Niu (Mogball)
<details>
<summary>Changes</summary>
This makes retrieving properties on concrete operations faster by removing a branch when it is known that the operation must have properties.
---
Full diff: https://github.com/llvm/llvm-project/pull/88259.diff
2 Files Affected:
- (modified) mlir/include/mlir/IR/OpDefinition.h (+1-1)
- (modified) mlir/include/mlir/IR/Operation.h (+7-2)
``````````diff
diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index c177ae3594d11f..2d1dee2303e8f0 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -1965,7 +1965,7 @@ class Op : public OpState, public Traits<ConcreteType>... {
if constexpr (!hasProperties())
return getEmptyProperties();
return *getOperation()
- ->getPropertiesStorage()
+ ->getPropertiesStorageUnsafe()
.template as<InferredProperties<T> *>();
}
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index 3ffd3517fe5a66..c52a6fcac10c1c 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -895,8 +895,7 @@ class alignas(8) Operation final
/// Returns the properties storage.
OpaqueProperties getPropertiesStorage() {
if (propertiesStorageSize)
- return {
- reinterpret_cast<void *>(getTrailingObjects<detail::OpProperties>())};
+ return getPropertiesStorageUnsafe();
return {nullptr};
}
OpaqueProperties getPropertiesStorage() const {
@@ -905,6 +904,12 @@ class alignas(8) Operation final
getTrailingObjects<detail::OpProperties>()))};
return {nullptr};
}
+ /// Returns the properties storage without checking whether properties are
+ /// present.
+ OpaqueProperties getPropertiesStorageUnsafe() {
+ return {
+ reinterpret_cast<void *>(getTrailingObjects<detail::OpProperties>())};
+ }
/// Return the properties converted to an attribute.
/// This is expensive, and mostly useful when dealing with unregistered
``````````
</details>
https://github.com/llvm/llvm-project/pull/88259
More information about the Mlir-commits
mailing list