[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #126011)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 6 12:05:25 PST 2025
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/126011
>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 1/2] [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);
}
>From 51f77e2a66e1179e994b1684230cc99ed73efb9d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 6 Feb 2025 11:34:47 -0800
Subject: [PATCH 2/2] Address a comment.
---
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index c0b6b526cd8f4df..9509e5234840fba 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1145,7 +1145,7 @@ void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
BlockFrequency Freq) {
auto [It, Inserted] = Nodes.try_emplace(BB);
if (!Inserted)
- BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
+ BlockFrequencyInfoImplBase::setBlockFreq(It->second.first, 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
More information about the llvm-commits
mailing list