[Mlir-commits] [mlir] [mlir] Avoid repeated hash lookups (NFC) (PR #107518)

Kazu Hirata llvmlistbot at llvm.org
Thu Sep 5 21:29:39 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107518

None

>From ae9a4bd25cd8b03853bf1687b9e0e79b28f4f3b0 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 5 Sep 2024 21:26:01 -0700
Subject: [PATCH] [mlir] Avoid repeated hash lookups (NFC)

---
 .../mlir/Dialect/Transform/IR/TransformDialect.h      | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

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



More information about the Mlir-commits mailing list