Skip to content

[llvm-mca] Avoid repeated hash lookups (NFC) #129656

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-tools-llvm-mca

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/tools/llvm-mca/CodeRegion.cpp (+2-3)
diff --git a/llvm/tools/llvm-mca/CodeRegion.cpp b/llvm/tools/llvm-mca/CodeRegion.cpp
index ba5188076c2e7..eacbc062cb113 100644
--- a/llvm/tools/llvm-mca/CodeRegion.cpp
+++ b/llvm/tools/llvm-mca/CodeRegion.cpp
@@ -123,8 +123,8 @@ void InstrumentRegions::beginRegion(StringRef Description, SMLoc Loc,
     return;
   }
 
-  auto It = ActiveRegions.find(Description);
-  if (It != ActiveRegions.end()) {
+  auto [It, Inserted] = ActiveRegions.try_emplace(Description, Regions.size());
+  if (!Inserted) {
     const CodeRegion &R = *Regions[It->second];
     SM.PrintMessage(
         Loc, llvm::SourceMgr::DK_Error,
@@ -136,7 +136,6 @@ void InstrumentRegions::beginRegion(StringRef Description, SMLoc Loc,
     return;
   }
 
-  ActiveRegions[Description] = Regions.size();
   Regions.emplace_back(
       std::make_unique<InstrumentRegion>(Description, Loc, std::move(I)));
 }

@kazutakahirata kazutakahirata merged commit c61c888 into llvm:main Mar 4, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_mca branch March 4, 2025 08:08
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants