Skip to content

Commit fe0c37f

Browse files
[ADT] Avoid repeated hash lookups (NFC) (#125812)
1 parent c517edb commit fe0c37f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

llvm/include/llvm/ADT/GenericCycleImpl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ void GenericCycleInfoCompute<ContextT>::dfs(BlockT *EntryBlock) {
454454
BlockT *Block = TraverseStack.back();
455455
LLVM_DEBUG(errs() << "DFS visiting block: " << Info.Context.print(Block)
456456
<< "\n");
457-
if (!BlockDFSInfo.count(Block)) {
457+
if (BlockDFSInfo.try_emplace(Block, Counter + 1).second) {
458+
++Counter;
459+
458460
// We're visiting the block for the first time. Open its DFSInfo, add
459461
// successors to the traversal stack, and remember the traversal stack
460462
// depth at which the block was opened, so that we can correctly record
@@ -465,9 +467,6 @@ void GenericCycleInfoCompute<ContextT>::dfs(BlockT *EntryBlock) {
465467
DFSTreeStack.emplace_back(TraverseStack.size());
466468
llvm::append_range(TraverseStack, successors(Block));
467469

468-
bool Added = BlockDFSInfo.try_emplace(Block, ++Counter).second;
469-
(void)Added;
470-
assert(Added);
471470
BlockPreorder.push_back(Block);
472471
LLVM_DEBUG(errs() << " preorder number: " << Counter << "\n");
473472
} else {

0 commit comments

Comments
 (0)