From d72034352cef9d0baa721477740493ab9ccf6bba Mon Sep 17 00:00:00 2001 From: Dmitrii Galimzianov Date: Mon, 7 Oct 2024 22:45:27 +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 | 39 ++++++++++++++++------ 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index 621182458ab73..aa649a1a3e46f 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -815,6 +815,15 @@ IRExecutionUnit::FindInSymbols(const std::vector &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); + // BEGIN SWIFT + if (m_in_populate_symtab) + if (lldb::ModuleSP module_sp = m_jit_module_wp.lock()) + non_local_images.Remove(module_sp); + // END SWIFT + LoadAddressResolver resolver(target, symbol_was_missing_weak); ModuleFunctionSearchOptions function_options; @@ -822,6 +831,11 @@ IRExecutionUnit::FindInSymbols(const std::vector &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(), @@ -831,21 +845,26 @@ IRExecutionUnit::FindInSymbols(const std::vector &names, return *load_addr; } - if (sc.target_sp) { - ModuleList images = sc.target_sp->GetImages(); - // BEGIN SWIFT - if (m_in_populate_symtab) - if (lldb::ModuleSP module_sp = m_jit_module_wp.lock()) - images.Remove(module_sp); - // END SWIFT + { + 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; - images.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; + } - images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, sc_list); + { + SymbolContextList sc_list; + non_local_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, + sc_list); if (auto load_addr = resolver.Resolve(sc_list)) return *load_addr; }