Skip to content

[mlir] Avoid repeated hash lookups (NFC) #107519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Sep 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

@llvm/pr-subscribers-mlir-core

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/107519.diff

1 Files Affected:

  • (modified) mlir/lib/IR/AttrTypeSubElements.cpp (+3-3)
diff --git a/mlir/lib/IR/AttrTypeSubElements.cpp b/mlir/lib/IR/AttrTypeSubElements.cpp
index 783236ed3a9df6..863e1aa95f2fb7 100644
--- a/mlir/lib/IR/AttrTypeSubElements.cpp
+++ b/mlir/lib/IR/AttrTypeSubElements.cpp
@@ -27,10 +27,10 @@ WalkResult AttrTypeWalker::walkImpl(T element, WalkFns &walkFns,
                                     WalkOrder order) {
   // Check if we've already walk this element before.
   auto key = std::make_pair(element.getAsOpaquePointer(), (int)order);
-  auto it = visitedAttrTypes.find(key);
-  if (it != visitedAttrTypes.end())
+  auto [it, inserted] =
+      visitedAttrTypes.try_emplace(key, WalkResult::advance());
+  if (!inserted)
     return it->second;
-  visitedAttrTypes.try_emplace(key, WalkResult::advance());
 
   // If we are walking in post order, walk the sub elements first.
   if (order == WalkOrder::PostOrder) {

@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/107519.diff

1 Files Affected:

  • (modified) mlir/lib/IR/AttrTypeSubElements.cpp (+3-3)
diff --git a/mlir/lib/IR/AttrTypeSubElements.cpp b/mlir/lib/IR/AttrTypeSubElements.cpp
index 783236ed3a9df6..863e1aa95f2fb7 100644
--- a/mlir/lib/IR/AttrTypeSubElements.cpp
+++ b/mlir/lib/IR/AttrTypeSubElements.cpp
@@ -27,10 +27,10 @@ WalkResult AttrTypeWalker::walkImpl(T element, WalkFns &walkFns,
                                     WalkOrder order) {
   // Check if we've already walk this element before.
   auto key = std::make_pair(element.getAsOpaquePointer(), (int)order);
-  auto it = visitedAttrTypes.find(key);
-  if (it != visitedAttrTypes.end())
+  auto [it, inserted] =
+      visitedAttrTypes.try_emplace(key, WalkResult::advance());
+  if (!inserted)
     return it->second;
-  visitedAttrTypes.try_emplace(key, WalkResult::advance());
 
   // If we are walking in post order, walk the sub elements first.
   if (order == WalkOrder::PostOrder) {

@kazutakahirata kazutakahirata merged commit 01eb071 into llvm:main Sep 6, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_AttrType branch September 6, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants