Skip to content

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

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.

@kazutakahirata kazutakahirata requested a review from nikic October 22, 2024 02:13
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

@llvm/pr-subscribers-mlir-core

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) mlir/lib/Pass/IRPrinting.cpp (+1-4)
diff --git a/mlir/lib/Pass/IRPrinting.cpp b/mlir/lib/Pass/IRPrinting.cpp
index 9ffda6402cc07a..99e0601e4749cc 100644
--- a/mlir/lib/Pass/IRPrinting.cpp
+++ b/mlir/lib/Pass/IRPrinting.cpp
@@ -216,11 +216,8 @@ getOpAndSymbolNames(Operation *op, StringRef passName,
   SmallVector<std::pair<std::string, StringRef>> pathElements;
   SmallVector<unsigned> countPrefix;
 
-  if (!counters.contains(op))
-    counters[op] = -1;
-
   Operation *iter = op;
-  ++counters[op];
+  ++counters.try_emplace(op, -1).first->second;
   while (iter) {
     countPrefix.push_back(counters[iter]);
     StringAttr symbolName =

@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) mlir/lib/Pass/IRPrinting.cpp (+1-4)
diff --git a/mlir/lib/Pass/IRPrinting.cpp b/mlir/lib/Pass/IRPrinting.cpp
index 9ffda6402cc07a..99e0601e4749cc 100644
--- a/mlir/lib/Pass/IRPrinting.cpp
+++ b/mlir/lib/Pass/IRPrinting.cpp
@@ -216,11 +216,8 @@ getOpAndSymbolNames(Operation *op, StringRef passName,
   SmallVector<std::pair<std::string, StringRef>> pathElements;
   SmallVector<unsigned> countPrefix;
 
-  if (!counters.contains(op))
-    counters[op] = -1;
-
   Operation *iter = op;
-  ++counters[op];
+  ++counters.try_emplace(op, -1).first->second;
   while (iter) {
     countPrefix.push_back(counters[iter]);
     StringAttr symbolName =

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit c5ea7b8 into llvm:main Oct 22, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_mlir branch October 22, 2024 15:00
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