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

Kazu Hirata llvmlistbot at llvm.org
Tue Oct 8 19:21:48 PDT 2024


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

None

>From 30aad2c20d0a3059e563c3f39e5f049a38ab7133 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 8 Oct 2024 07:35:01 -0700
Subject: [PATCH] [Transform] Avoid repeated hash lookups (NFC)

---
 mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp b/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp
index 561d3d5b05af64..e6db819b51c22c 100644
--- a/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp
+++ b/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp
@@ -39,11 +39,11 @@ template <typename FnTy>
 const llvm::SmallPtrSet<Block *, 4> &
 getReachableImpl(Block *block, FnTy getNextNodes,
                  DenseMap<Block *, llvm::SmallPtrSet<Block *, 4>> &cache) {
-  auto it = cache.find(block);
-  if (it != cache.end())
+  auto [it, inserted] = cache.try_emplace(block);
+  if (!inserted)
     return it->getSecond();
 
-  llvm::SmallPtrSet<Block *, 4> &reachable = cache[block];
+  llvm::SmallPtrSet<Block *, 4> &reachable = it->second;
   SmallVector<Block *> worklist;
   worklist.push_back(block);
   while (!worklist.empty()) {



More information about the Mlir-commits mailing list