Move lookup_name_info creation into basic_lookup_transparent_type

I noticed that basic_lookup_transparent_type calls two different
functions that both proceed to create a lookup_name_info.  It's more
efficient to create this object in the outermost layer possible.
Making this change required a few related changes, resulting in this
patch.

There are still more changes of this sort that could be made.

Regression tested on x86-64 Fedora 38.
This commit is contained in:
Tom Tromey
2024-01-25 11:17:24 -07:00
parent 7921285b6c
commit e70d6457a6
7 changed files with 46 additions and 45 deletions

View File

@@ -679,17 +679,14 @@ better_symbol (struct symbol *a, struct symbol *b,
non-encoded names tested for a match. */ non-encoded names tested for a match. */
struct symbol * struct symbol *
block_lookup_symbol (const struct block *block, const char *name, block_lookup_symbol (const struct block *block, const lookup_name_info &name,
symbol_name_match_type match_type,
const domain_search_flags domain) const domain_search_flags domain)
{ {
lookup_name_info lookup_name (name, match_type);
if (!block->function ()) if (!block->function ())
{ {
struct symbol *other = NULL; struct symbol *other = NULL;
for (struct symbol *sym : block_iterator_range (block, &lookup_name)) for (struct symbol *sym : block_iterator_range (block, &name))
{ {
/* See comment related to PR gcc/debug/91507 in /* See comment related to PR gcc/debug/91507 in
block_lookup_symbol_primary. */ block_lookup_symbol_primary. */
@@ -717,7 +714,7 @@ block_lookup_symbol (const struct block *block, const char *name,
struct symbol *sym_found = NULL; struct symbol *sym_found = NULL;
for (struct symbol *sym : block_iterator_range (block, &lookup_name)) for (struct symbol *sym : block_iterator_range (block, &name))
{ {
if (sym->matches (domain)) if (sym->matches (domain))
{ {

View File

@@ -565,8 +565,7 @@ extern struct symbol *better_symbol (struct symbol *a, struct symbol *b,
/* Search BLOCK for symbol NAME in DOMAIN. */ /* Search BLOCK for symbol NAME in DOMAIN. */
extern struct symbol *block_lookup_symbol (const struct block *block, extern struct symbol *block_lookup_symbol (const struct block *block,
const char *name, const lookup_name_info &name,
symbol_name_match_type match_type,
const domain_search_flags domain); const domain_search_flags domain);
/* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of /* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of

View File

@@ -421,6 +421,10 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
lookup_name_info func_matcher (GCC_FE_WRAPPER_FUNCTION, lookup_name_info func_matcher (GCC_FE_WRAPPER_FUNCTION,
symbol_name_match_type::SEARCH_NAME); symbol_name_match_type::SEARCH_NAME);
lookup_name_info i_val_matcher (COMPILE_I_EXPR_VAL,
symbol_name_match_type::SEARCH_NAME);
lookup_name_info i_ptr_matcher (COMPILE_I_EXPR_PTR_TYPE,
symbol_name_match_type::SEARCH_NAME);
bv = func_sym->symtab ()->compunit ()->blockvector (); bv = func_sym->symtab ()->compunit ()->blockvector ();
nblocks = bv->num_blocks (); nblocks = bv->num_blocks ();
@@ -434,10 +438,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
block = bv->block (block_loop); block = bv->block (block_loop);
if (block->function () != NULL) if (block->function () != NULL)
continue; continue;
gdb_val_sym = block_lookup_symbol (block, gdb_val_sym = block_lookup_symbol (block, i_val_matcher, SEARCH_VFT);
COMPILE_I_EXPR_VAL,
symbol_name_match_type::SEARCH_NAME,
SEARCH_VFT);
if (gdb_val_sym == NULL) if (gdb_val_sym == NULL)
continue; continue;
@@ -461,9 +462,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
gdb_type = gdb_val_sym->type (); gdb_type = gdb_val_sym->type ();
gdb_type = check_typedef (gdb_type); gdb_type = check_typedef (gdb_type);
gdb_ptr_type_sym = block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE, gdb_ptr_type_sym = block_lookup_symbol (block, i_ptr_matcher, SEARCH_VFT);
symbol_name_match_type::SEARCH_NAME,
SEARCH_VFT);
if (gdb_ptr_type_sym == NULL) if (gdb_ptr_type_sym == NULL)
error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE); error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE);
gdb_ptr_type = gdb_ptr_type_sym->type (); gdb_ptr_type = gdb_ptr_type_sym->type ();

View File

@@ -561,7 +561,8 @@ public:
defined, or NULL if no such symbol table exists. If OBJFILE defined, or NULL if no such symbol table exists. If OBJFILE
contains !TYPE_OPAQUE symbol prefer its compunit. If it contains contains !TYPE_OPAQUE symbol prefer its compunit. If it contains
only TYPE_OPAQUE symbol(s), return at least that compunit. */ only TYPE_OPAQUE symbol(s), return at least that compunit. */
struct compunit_symtab *lookup_symbol (block_enum kind, const char *name, struct compunit_symtab *lookup_symbol (block_enum kind,
const lookup_name_info &name,
domain_search_flags domain); domain_search_flags domain);
/* See quick_symbol_functions. */ /* See quick_symbol_functions. */

View File

@@ -1505,8 +1505,9 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
&& psym->ginfo.value_address () == 0) && psym->ginfo.value_address () == 0)
continue; continue;
sym = block_lookup_symbol (b, psym->ginfo.search_name (), lookup_name_info lookup_name
symbol_name_match_type::SEARCH_NAME, (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME);
sym = block_lookup_symbol (b, lookup_name,
to_search_flags (psym->domain)); to_search_flags (psym->domain));
if (!sym) if (!sym)
{ {
@@ -1520,8 +1521,9 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
b = bv->global_block (); b = bv->global_block ();
for (partial_symbol *psym : ps->global_psymbols) for (partial_symbol *psym : ps->global_psymbols)
{ {
sym = block_lookup_symbol (b, psym->ginfo.search_name (), lookup_name_info lookup_name
symbol_name_match_type::SEARCH_NAME, (psym->ginfo.search_name (), symbol_name_match_type::SEARCH_NAME);
sym = block_lookup_symbol (b, lookup_name,
to_search_flags (psym->domain)); to_search_flags (psym->domain));
if (!sym) if (!sym)
{ {

View File

@@ -240,7 +240,7 @@ objfile::map_symtabs_matching_filename
} }
struct compunit_symtab * struct compunit_symtab *
objfile::lookup_symbol (block_enum kind, const char *name, objfile::lookup_symbol (block_enum kind, const lookup_name_info &name,
domain_search_flags domain) domain_search_flags domain)
{ {
struct compunit_symtab *retval = nullptr; struct compunit_symtab *retval = nullptr;
@@ -248,18 +248,16 @@ objfile::lookup_symbol (block_enum kind, const char *name,
if (debug_symfile) if (debug_symfile)
gdb_printf (gdb_stdlog, gdb_printf (gdb_stdlog,
"qf->lookup_symbol (%s, %d, \"%s\", %s)\n", "qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
objfile_debug_name (this), kind, name, objfile_debug_name (this), kind, name.c_str (),
domain_name (domain).c_str ()); domain_name (domain).c_str ());
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
auto search_one_symtab = [&] (compunit_symtab *stab) auto search_one_symtab = [&] (compunit_symtab *stab)
{ {
struct symbol *sym, *with_opaque = NULL; struct symbol *sym, *with_opaque = NULL;
const struct blockvector *bv = stab->blockvector (); const struct blockvector *bv = stab->blockvector ();
const struct block *block = bv->block (kind); const struct block *block = bv->block (kind);
sym = block_find_symbol (block, lookup_name, domain, &with_opaque); sym = block_find_symbol (block, name, domain, &with_opaque);
/* Some caution must be observed with overloaded functions /* Some caution must be observed with overloaded functions
and methods, since the index will not contain any overload and methods, since the index will not contain any overload
@@ -282,7 +280,7 @@ objfile::lookup_symbol (block_enum kind, const char *name,
{ {
if (!iter->expand_symtabs_matching (this, if (!iter->expand_symtabs_matching (this,
nullptr, nullptr,
&lookup_name, &name,
nullptr, nullptr,
search_one_symtab, search_one_symtab,
kind == GLOBAL_BLOCK kind == GLOBAL_BLOCK

View File

@@ -2023,13 +2023,14 @@ lookup_language_this (const struct language_defn *lang,
lang->name (), host_address_to_string (block), lang->name (), host_address_to_string (block),
objfile_debug_name (block->objfile ())); objfile_debug_name (block->objfile ()));
lookup_name_info this_name (lang->name_of_this (),
symbol_name_match_type::SEARCH_NAME);
while (block) while (block)
{ {
struct symbol *sym; struct symbol *sym;
sym = block_lookup_symbol (block, lang->name_of_this (), sym = block_lookup_symbol (block, this_name, SEARCH_VFT);
symbol_name_match_type::SEARCH_NAME,
SEARCH_VFT);
if (sym != NULL) if (sym != NULL)
{ {
symbol_lookup_debug_printf_v symbol_lookup_debug_printf_v
@@ -2264,7 +2265,8 @@ lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
domain_name (domain).c_str ()); domain_name (domain).c_str ());
} }
sym = block_lookup_symbol (block, name, match_type, domain); lookup_name_info lookup_name (name, match_type);
sym = block_lookup_symbol (block, lookup_name, domain);
if (sym) if (sym)
{ {
symbol_lookup_debug_printf_v ("lookup_symbol_in_block (...) = %s", symbol_lookup_debug_printf_v ("lookup_symbol_in_block (...) = %s",
@@ -2438,7 +2440,8 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK", block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
name, domain_name (domain).c_str ()); name, domain_name (domain).c_str ());
cust = objfile->lookup_symbol (block_index, name, domain); lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
cust = objfile->lookup_symbol (block_index, lookup_name, domain);
if (cust == NULL) if (cust == NULL)
{ {
symbol_lookup_debug_printf_v symbol_lookup_debug_printf_v
@@ -2448,8 +2451,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
bv = cust->blockvector (); bv = cust->blockvector ();
block = bv->block (block_index); block = bv->block (block_index);
result.symbol = block_lookup_symbol (block, name, result.symbol = block_lookup_symbol (block, lookup_name, domain);
symbol_name_match_type::FULL, domain);
if (result.symbol == NULL) if (result.symbol == NULL)
error_in_psymtab_expansion (block_index, name, cust); error_in_psymtab_expansion (block_index, name, cust);
@@ -2703,7 +2705,7 @@ lookup_transparent_type (const char *name)
static struct type * static struct type *
basic_lookup_transparent_type_quick (struct objfile *objfile, basic_lookup_transparent_type_quick (struct objfile *objfile,
enum block_enum block_index, enum block_enum block_index,
const char *name) const lookup_name_info &name)
{ {
struct compunit_symtab *cust; struct compunit_symtab *cust;
const struct blockvector *bv; const struct blockvector *bv;
@@ -2717,10 +2719,9 @@ basic_lookup_transparent_type_quick (struct objfile *objfile,
bv = cust->blockvector (); bv = cust->blockvector ();
block = bv->block (block_index); block = bv->block (block_index);
lookup_name_info lookup_name (name, symbol_name_match_type::FULL); sym = block_find_symbol (block, name, SEARCH_STRUCT_DOMAIN, nullptr);
sym = block_find_symbol (block, lookup_name, SEARCH_STRUCT_DOMAIN, nullptr);
if (sym == nullptr) if (sym == nullptr)
error_in_psymtab_expansion (block_index, name, cust); error_in_psymtab_expansion (block_index, name.c_str (), cust);
gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); gdb_assert (!TYPE_IS_OPAQUE (sym->type ()));
return sym->type (); return sym->type ();
} }
@@ -2732,19 +2733,17 @@ basic_lookup_transparent_type_quick (struct objfile *objfile,
static struct type * static struct type *
basic_lookup_transparent_type_1 (struct objfile *objfile, basic_lookup_transparent_type_1 (struct objfile *objfile,
enum block_enum block_index, enum block_enum block_index,
const char *name) const lookup_name_info &name)
{ {
const struct blockvector *bv; const struct blockvector *bv;
const struct block *block; const struct block *block;
const struct symbol *sym; const struct symbol *sym;
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
for (compunit_symtab *cust : objfile->compunits ()) for (compunit_symtab *cust : objfile->compunits ())
{ {
bv = cust->blockvector (); bv = cust->blockvector ();
block = bv->block (block_index); block = bv->block (block_index);
sym = block_find_symbol (block, lookup_name, SEARCH_STRUCT_DOMAIN, sym = block_find_symbol (block, name, SEARCH_STRUCT_DOMAIN, nullptr);
nullptr);
if (sym != nullptr) if (sym != nullptr)
{ {
gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); gdb_assert (!TYPE_IS_OPAQUE (sym->type ()));
@@ -2766,6 +2765,8 @@ basic_lookup_transparent_type (const char *name)
{ {
struct type *t; struct type *t;
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
/* Now search all the global symbols. Do the symtab's first, then /* Now search all the global symbols. Do the symtab's first, then
check the psymtab's. If a psymtab indicates the existence check the psymtab's. If a psymtab indicates the existence
of the desired name as a global, then do psymtab-to-symtab of the desired name as a global, then do psymtab-to-symtab
@@ -2773,14 +2774,16 @@ basic_lookup_transparent_type (const char *name)
for (objfile *objfile : current_program_space->objfiles ()) for (objfile *objfile : current_program_space->objfiles ())
{ {
t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name); t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK,
lookup_name);
if (t) if (t)
return t; return t;
} }
for (objfile *objfile : current_program_space->objfiles ()) for (objfile *objfile : current_program_space->objfiles ())
{ {
t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, name); t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK,
lookup_name);
if (t) if (t)
return t; return t;
} }
@@ -2794,14 +2797,16 @@ basic_lookup_transparent_type (const char *name)
for (objfile *objfile : current_program_space->objfiles ()) for (objfile *objfile : current_program_space->objfiles ())
{ {
t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name); t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK,
lookup_name);
if (t) if (t)
return t; return t;
} }
for (objfile *objfile : current_program_space->objfiles ()) for (objfile *objfile : current_program_space->objfiles ())
{ {
t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, name); t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK,
lookup_name);
if (t) if (t)
return t; return t;
} }