[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #126465)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 9 21:29:03 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) llvm/include/llvm/Analysis/RegionInfoImpl.h (+3-5) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/RegionInfoImpl.h b/llvm/include/llvm/Analysis/RegionInfoImpl.h
index db3a9027549cefe..eb99d8bc6fb23ef 100644
--- a/llvm/include/llvm/Analysis/RegionInfoImpl.h
+++ b/llvm/include/llvm/Analysis/RegionInfoImpl.h
@@ -720,16 +720,14 @@ void RegionInfoBase<Tr>::buildRegionsTree(DomTreeNodeT *N, RegionT *region) {
   while (BB == region->getExit())
     region = region->getParent();
 
-  typename BBtoRegionMap::iterator it = BBtoRegion.find(BB);
+  auto [It, Inserted] = BBtoRegion.try_emplace(BB, region);
 
   // This basic block is a start block of a region. It is already in the
   // BBtoRegion relation. Only the child basic blocks have to be updated.
-  if (it != BBtoRegion.end()) {
-    RegionT *newRegion = it->second;
+  if (!Inserted) {
+    RegionT *newRegion = It->second;
     region->addSubRegion(getTopMostParent(newRegion));
     region = newRegion;
-  } else {
-    BBtoRegion[BB] = region;
   }
 
   for (DomTreeNodeBase<BlockT> *C : *N) {

``````````

</details>


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


More information about the llvm-commits mailing list