[llvm] [PassManager] Simplify code with DenseMap::try_emplace (NFC) (PR #140402)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 17 13:48:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/140402
More information about the llvm-commits
mailing list