Skip to content

Commit 4590f75

Browse files
[Analysis] Avoid repeated hash lookups (NFC) (#126011)
1 parent 5a056f9 commit 4590f75

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,14 +1143,15 @@ void BlockFrequencyInfoImpl<BT>::calculate(const FunctionT &F,
11431143
template <class BT>
11441144
void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
11451145
BlockFrequency Freq) {
1146-
if (Nodes.count(BB))
1147-
BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
1146+
auto [It, Inserted] = Nodes.try_emplace(BB);
1147+
if (!Inserted)
1148+
BlockFrequencyInfoImplBase::setBlockFreq(It->second.first, Freq);
11481149
else {
11491150
// If BB is a newly added block after BFI is done, we need to create a new
11501151
// BlockNode for it assigned with a new index. The index can be determined
11511152
// by the size of Freqs.
11521153
BlockNode NewNode(Freqs.size());
1153-
Nodes[BB] = {NewNode, BFICallbackVH(BB, this)};
1154+
It->second = {NewNode, BFICallbackVH(BB, this)};
11541155
Freqs.emplace_back();
11551156
BlockFrequencyInfoImplBase::setBlockFreq(NewNode, Freq);
11561157
}

0 commit comments

Comments
 (0)