[Mlir-commits] [mlir] [mlir] Avoid repeated hash lookups (NFC) (PR #107518)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 5 21:30:12 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/107518.diff
1 Files Affected:
- (modified) mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h (+4-7)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
index 128eacdbe6ab7a..494026d78af3fd 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
+++ b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
@@ -298,13 +298,10 @@ void TransformDialect::addTypeIfNotRegistered() {
template <typename DataTy>
DataTy &TransformDialect::getOrCreateExtraData() {
TypeID typeID = TypeID::get<DataTy>();
- auto it = extraData.find(typeID);
- if (it != extraData.end())
- return static_cast<DataTy &>(*it->getSecond());
-
- auto emplaced =
- extraData.try_emplace(typeID, std::make_unique<DataTy>(getContext()));
- return static_cast<DataTy &>(*emplaced.first->getSecond());
+ auto [it, inserted] = extraData.try_emplace(typeID);
+ if (inserted)
+ it->getSecond() = std::make_unique<DataTy>(getContext());
+ return static_cast<DataTy &>(*it->getSecond());
}
/// A wrapper for transform dialect extensions that forces them to be
``````````
</details>
https://github.com/llvm/llvm-project/pull/107518
More information about the Mlir-commits
mailing list