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

via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 7 13:45:31 PDT 2024


Author: Dmitrii Galimzianov
Date: 2024-10-07T13:45:27-07:00
New Revision: d2457e6d8f62a12b3b74791cfd3f5808168c8a71

URL: https://github.com/llvm/llvm-project/commit/d2457e6d8f62a12b3b74791cfd3f5808168c8a71
DIFF: https://github.com/llvm/llvm-project/commit/d2457e6d8f62a12b3b74791cfd3f5808168c8a71.diff

LOG: Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (#102835)

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.

Added: 
    

Modified: 
    lldb/source/Expression/IRExecutionUnit.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index baf70cbccc8c5c..7bee183d2ff227 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -780,6 +780,10 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
     return LLDB_INVALID_ADDRESS;
   }
 
+  ModuleList non_local_images = target->GetImages();
+  // We'll process module_sp separately, before the other modules.
+  non_local_images.Remove(sc.module_sp);
+
   LoadAddressResolver resolver(target, symbol_was_missing_weak);
 
   ModuleFunctionSearchOptions function_options;
@@ -787,6 +791,11 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
   function_options.include_inlines = false;
 
   for (const ConstString &name : names) {
+    // The lookup order here is as follows:
+    // 1) Functions in `sc.module_sp`
+    // 2) Functions in the other modules
+    // 3) Symbols in `sc.module_sp`
+    // 4) Symbols in the other modules
     if (sc.module_sp) {
       SymbolContextList sc_list;
       sc.module_sp->FindFunctions(name, CompilerDeclContext(),
@@ -796,18 +805,26 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
         return *load_addr;
     }
 
-    if (sc.target_sp) {
+    {
+      SymbolContextList sc_list;
+      non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
+                                     function_options, sc_list);
+      if (auto load_addr = resolver.Resolve(sc_list))
+        return *load_addr;
+    }
+
+    if (sc.module_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);
+      non_local_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
+                                                  sc_list);
       if (auto load_addr = resolver.Resolve(sc_list))
         return *load_addr;
     }


        


More information about the lldb-commits mailing list