[llvm] [PassManager] Simplify code with DenseMap::try_emplace (NFC) (PR #140402)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat May 17 13:47:45 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/140402

We can simplify the code with DenseMap::try_emplace and structured
binding.  Note that DenseMap::try_emplace default-constructs the value
if omitted.


>From 586e11a4fa8e74d23178ff4ccbdff1507ca6cc27 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 17 May 2025 13:09:59 -0700
Subject: [PATCH] [PassManager] Simplify code with DenseMap::try_emplace (NFC)

We can simplify the code with DenseMap::try_emplace and structured
binding.  Note that DenseMap::try_emplace default-constructs the value
if omitted.
---
 llvm/include/llvm/IR/PassManagerImpl.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/llvm/include/llvm/IR/PassManagerImpl.h b/llvm/include/llvm/IR/PassManagerImpl.h
index 67e3fbe4f3068..55f504c921852 100644
--- a/llvm/include/llvm/IR/PassManagerImpl.h
+++ b/llvm/include/llvm/IR/PassManagerImpl.h
@@ -136,10 +136,7 @@ template <typename IRUnitT, typename... ExtraArgTs>
 inline typename AnalysisManager<IRUnitT, ExtraArgTs...>::ResultConceptT &
 AnalysisManager<IRUnitT, ExtraArgTs...>::getResultImpl(
     AnalysisKey *ID, IRUnitT &IR, ExtraArgTs... ExtraArgs) {
-  typename AnalysisResultMapT::iterator RI;
-  bool Inserted;
-  std::tie(RI, Inserted) = AnalysisResults.insert(std::make_pair(
-      std::make_pair(ID, &IR), typename AnalysisResultListT::iterator()));
+  auto [RI, Inserted] = AnalysisResults.try_emplace(std::make_pair(ID, &IR));
 
   // If we don't have a cached result for this function, look up the pass and
   // run it to produce a result, which we then add to the cache.



More information about the llvm-commits mailing list