Skip to content

Commit 34172bb

Browse files
[CodeGen] Avoid repeated hash lookups (NFC) (#128300)
1 parent 48a6df3 commit 34172bb

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,24 +1545,22 @@ void HoistSpillHelper::runHoistSpills(
15451545
for (MachineDomTreeNode *Child : (*RIt)->children()) {
15461546
if (!SpillsInSubTreeMap.contains(Child))
15471547
continue;
1548-
// The stmt "SpillsInSubTree = SpillsInSubTreeMap[*RIt].first" below
1549-
// should be placed before getting the begin and end iterators of
1548+
// The stmt:
1549+
// "auto &[SpillsInSubTree, SubTreeCost] = SpillsInSubTreeMap[*RIt]"
1550+
// below should be placed before getting the begin and end iterators of
15501551
// SpillsInSubTreeMap[Child].first, or else the iterators may be
15511552
// invalidated when SpillsInSubTreeMap[*RIt] is seen the first time
15521553
// and the map grows and then the original buckets in the map are moved.
1553-
SmallPtrSet<MachineDomTreeNode *, 16> &SpillsInSubTree =
1554-
SpillsInSubTreeMap[*RIt].first;
1555-
BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
1556-
SubTreeCost += SpillsInSubTreeMap[Child].second;
1557-
auto BI = SpillsInSubTreeMap[Child].first.begin();
1558-
auto EI = SpillsInSubTreeMap[Child].first.end();
1554+
auto &[SpillsInSubTree, SubTreeCost] = SpillsInSubTreeMap[*RIt];
1555+
auto ChildIt = SpillsInSubTreeMap.find(Child);
1556+
SubTreeCost += ChildIt->second.second;
1557+
auto BI = ChildIt->second.first.begin();
1558+
auto EI = ChildIt->second.first.end();
15591559
SpillsInSubTree.insert(BI, EI);
1560-
SpillsInSubTreeMap.erase(Child);
1560+
SpillsInSubTreeMap.erase(ChildIt);
15611561
}
15621562

1563-
SmallPtrSet<MachineDomTreeNode *, 16> &SpillsInSubTree =
1564-
SpillsInSubTreeMap[*RIt].first;
1565-
BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
1563+
auto &[SpillsInSubTree, SubTreeCost] = SpillsInSubTreeMap[*RIt];
15661564
// No spills in subtree, simply continue.
15671565
if (SpillsInSubTree.empty())
15681566
continue;

0 commit comments

Comments
 (0)