[llvm] [BOLT] Avoid repeated map lookups (NFC) (PR #112118)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 12 21:12:58 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112118

None

>From 19acd2549b8fd024f281482e3b391bc06ecb1066 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 12 Oct 2024 08:11:05 -0700
Subject: [PATCH] [BOLT] Avoid repeated map lookups (NFC)

---
 bolt/lib/Core/BinaryFunction.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 36c42fced93d08..ef3fba37817daa 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -3684,9 +3684,8 @@ BinaryFunction::BasicBlockListType BinaryFunction::dfs() const {
     BinaryBasicBlock *BB = Stack.top();
     Stack.pop();
 
-    if (Visited.find(BB) != Visited.end())
+    if (!Visited.insert(BB).second)
       continue;
-    Visited.insert(BB);
     DFS.push_back(BB);
 
     for (BinaryBasicBlock *SuccBB : BB->landing_pads()) {
@@ -3879,11 +3878,8 @@ void BinaryFunction::disambiguateJumpTables(
       JumpTable *JT = getJumpTable(Inst);
       if (!JT)
         continue;
-      auto Iter = JumpTables.find(JT);
-      if (Iter == JumpTables.end()) {
-        JumpTables.insert(JT);
+      if (JumpTables.insert(JT).second)
         continue;
-      }
       // This instruction is an indirect jump using a jump table, but it is
       // using the same jump table of another jump. Try all our tricks to
       // extract the jump table symbol and make it point to a new, duplicated JT



More information about the llvm-commits mailing list