[Lldb-commits] [lldb] Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (PR #102835)

Dmitrii Galimzianov via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 12 10:49:26 PDT 2024


https://github.com/DmT021 updated https://github.com/llvm/llvm-project/pull/102835

>From 45c91e403a36360727a5cd51e1a84f86027a77bc Mon Sep 17 00:00:00 2001
From: Dmitrii Galimzianov <dmt021 at gmail.com>
Date: Mon, 12 Aug 2024 01:09:33 +0200
Subject: [PATCH] Remove redundant symbol lookups in
 IRExecutionUnit::FindInSymbols

When we search for a symbol, we first check if it is in the module_sp of the current SymbolContext, and if not, we check in the target's modules. However, the target's ModuleList also includes the already checked module, which leads to a redundant search in it.
---
 lldb/source/Expression/IRExecutionUnit.cpp | 27 ++++++++++++----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index f220704423627d..aaf9cc3cfc9a23 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -785,6 +785,10 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
     return LLDB_INVALID_ADDRESS;
   }
 
+  ModuleList images = target->GetImages();
+  // We'll process module_sp separately, before the other modules.
+  images.Remove(sc.module_sp);
+
   LoadAddressResolver resolver(target, symbol_was_missing_weak);
 
   ModuleFunctionSearchOptions function_options;
@@ -799,23 +803,22 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
                                   sc_list);
       if (auto load_addr = resolver.Resolve(sc_list))
         return *load_addr;
-    }
 
-    if (sc.target_sp) {
-      SymbolContextList sc_list;
-      sc.target_sp->GetImages().FindFunctions(name, lldb::eFunctionNameTypeFull,
-                                              function_options, sc_list);
+      sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
+                                               sc_list);
       if (auto load_addr = resolver.Resolve(sc_list))
         return *load_addr;
     }
 
-    if (sc.target_sp) {
-      SymbolContextList sc_list;
-      sc.target_sp->GetImages().FindSymbolsWithNameAndType(
-          name, lldb::eSymbolTypeAny, sc_list);
-      if (auto load_addr = resolver.Resolve(sc_list))
-        return *load_addr;
-    }
+    SymbolContextList sc_list;
+    images.FindFunctions(name, lldb::eFunctionNameTypeFull, function_options,
+                         sc_list);
+    if (auto load_addr = resolver.Resolve(sc_list))
+      return *load_addr;
+
+    images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, sc_list);
+    if (auto load_addr = resolver.Resolve(sc_list))
+      return *load_addr;
 
     lldb::addr_t best_internal_load_address =
         resolver.GetBestInternalLoadAddress();



More information about the lldb-commits mailing list