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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 8 19:22:21 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/111620.diff


1 Files Affected:

- (modified) mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp (+3-3) 


``````````diff
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()) {

``````````

</details>


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


More information about the Mlir-commits mailing list