[llvm] [CodeGen] Avoid repeated hash lookups (NFC) (PR #128300)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 22 00:08:09 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/128300
None
>From ff8a93ba0f826da9eea465b780e2996641fc851f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 21 Feb 2025 11:23:16 -0800
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)
---
llvm/lib/CodeGen/InlineSpiller.cpp | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index 3834a6d7a355e..919dca112b69f 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -1545,24 +1545,21 @@ void HoistSpillHelper::runHoistSpills(
for (MachineDomTreeNode *Child : (*RIt)->children()) {
if (!SpillsInSubTreeMap.contains(Child))
continue;
- // The stmt "SpillsInSubTree = SpillsInSubTreeMap[*RIt].first" below
+ // The stmt "auto &[...] = SpillsInSubTreeMap[*RIt]" below
// should be placed before getting the begin and end iterators of
// SpillsInSubTreeMap[Child].first, or else the iterators may be
// invalidated when SpillsInSubTreeMap[*RIt] is seen the first time
// and the map grows and then the original buckets in the map are moved.
- SmallPtrSet<MachineDomTreeNode *, 16> &SpillsInSubTree =
- SpillsInSubTreeMap[*RIt].first;
- BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
- SubTreeCost += SpillsInSubTreeMap[Child].second;
- auto BI = SpillsInSubTreeMap[Child].first.begin();
- auto EI = SpillsInSubTreeMap[Child].first.end();
+ auto &[SpillsInSubTree, SubTreeCost] = SpillsInSubTreeMap[*RIt];
+ auto ChildIt = SpillsInSubTreeMap.find(Child);
+ SubTreeCost += ChildIt->second.second;
+ auto BI = ChildIt->second.first.begin();
+ auto EI = ChildIt->second.first.end();
SpillsInSubTree.insert(BI, EI);
- SpillsInSubTreeMap.erase(Child);
+ SpillsInSubTreeMap.erase(ChildIt);
}
- SmallPtrSet<MachineDomTreeNode *, 16> &SpillsInSubTree =
- SpillsInSubTreeMap[*RIt].first;
- BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
+ auto &[SpillsInSubTree, SubTreeCost] = SpillsInSubTreeMap[*RIt];
// No spills in subtree, simply continue.
if (SpillsInSubTree.empty())
continue;
More information about the llvm-commits
mailing list