[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #126011)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 21:44:26 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/126011
None
>From d502cd4cd3af963451bee2b9af66d59c683dadd1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 5 Feb 2025 21:31:03 -0800
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)
---
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 7a7a9594f47603d..c0b6b526cd8f4df 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1143,14 +1143,15 @@ void BlockFrequencyInfoImpl<BT>::calculate(const FunctionT &F,
template <class BT>
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
BlockFrequency Freq) {
- if (Nodes.count(BB))
+ auto [It, Inserted] = Nodes.try_emplace(BB);
+ if (!Inserted)
BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
else {
// If BB is a newly added block after BFI is done, we need to create a new
// BlockNode for it assigned with a new index. The index can be determined
// by the size of Freqs.
BlockNode NewNode(Freqs.size());
- Nodes[BB] = {NewNode, BFICallbackVH(BB, this)};
+ It->second = {NewNode, BFICallbackVH(BB, this)};
Freqs.emplace_back();
BlockFrequencyInfoImplBase::setBlockFreq(NewNode, Freq);
}
More information about the llvm-commits
mailing list