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

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 4 00:08:54 PST 2025


Author: Kazu Hirata
Date: 2025-03-04T00:08:51-08:00
New Revision: c61c88862805905dfa8a2c2f8c9f8ef7e1874720

URL: https://github.com/llvm/llvm-project/commit/c61c88862805905dfa8a2c2f8c9f8ef7e1874720
DIFF: https://github.com/llvm/llvm-project/commit/c61c88862805905dfa8a2c2f8c9f8ef7e1874720.diff

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

Added: 
    

Modified: 
    llvm/tools/llvm-mca/CodeRegion.cpp

Removed: 
    


################################################################################
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)));
 }


        


More information about the llvm-commits mailing list