[llvm] 9b93c9a - [PassManager] Simplify code with DenseMap::try_emplace (NFC) (#140402)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 17 14:44:30 PDT 2025


Author: Kazu Hirata
Date: 2025-05-17T14:44:26-07:00
New Revision: 9b93c9a28418febb1eb2642cf7dea034e877d158

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

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

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

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassManagerImpl.h

Removed: 
    


################################################################################
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