[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #112297)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 20:27:41 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112297
None
>From b8d911aa7ab6969912640131ff50d8140bae3a33 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 14 Oct 2024 07:10:15 -0700
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)
---
llvm/include/llvm/Analysis/RegionInfoImpl.h | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/Analysis/RegionInfoImpl.h b/llvm/include/llvm/Analysis/RegionInfoImpl.h
index ebfb060ded3dd4..db3a9027549cef 100644
--- a/llvm/include/llvm/Analysis/RegionInfoImpl.h
+++ b/llvm/include/llvm/Analysis/RegionInfoImpl.h
@@ -338,14 +338,11 @@ template <class Tr>
typename Tr::RegionNodeT *RegionBase<Tr>::getBBNode(BlockT *BB) const {
assert(contains(BB) && "Can get BB node out of this region!");
- typename BBNodeMapT::const_iterator at = BBNodeMap.find(BB);
-
- if (at == BBNodeMap.end()) {
+ auto [at, Inserted] = BBNodeMap.try_emplace(BB);
+ if (Inserted) {
auto Deconst = const_cast<RegionBase<Tr> *>(this);
- typename BBNodeMapT::value_type V = {
- BB,
- std::make_unique<RegionNodeT>(static_cast<RegionT *>(Deconst), BB)};
- at = BBNodeMap.insert(std::move(V)).first;
+ at->second =
+ std::make_unique<RegionNodeT>(static_cast<RegionT *>(Deconst), BB);
}
return at->second.get();
}
More information about the llvm-commits
mailing list