Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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

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

llvmbot commented May 17, 2025

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

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


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

1 Files Affected:

  • (modified) llvm/include/llvm/IR/PassManagerImpl.h (+1-4)
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.

@kazutakahirata kazutakahirata merged commit 9b93c9a into llvm:main May 17, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_try_emplace_llvm_PassManager branch May 17, 2025 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants