diff mbox

[patchv3,2/2] Accelerate lookup_symbol_aux_objfile 85x

Message ID 20141129121124.GA21606@host2.jankratochvil.net
State New
Headers show

Commit Message

Jan Kratochvil Nov. 29, 2014, 12:11 p.m. UTC
On Fri, 24 Oct 2014 09:16:01 +0200, Doug Evans wrote:
> This breaks an abstraction boundary, IWBN to preserve it.
> [IOW, I look at dict_* as being an implementation detail of blocks.]
> 
> If we were to go this route (and apologies for the delay), can you
> write a routine like lookup_block_symbol which does the above and call
> that here instead?
> 
> lookup_block_symbol should live in block.c, not symtab.c.
> That's where this new routine should go too.

Done.

For the 'slow.C' test the performance gain is even higher; but I have not
re-benchmarked the 'non-trivial app':
	Command execution time: 26.540344 (cpu), 26.575254 (wall)
	->
	Command execution time: 0.310607 (cpu), 0.311062 (wall)
	 = 85x

OK for check-in?

No regressions on {x86_64,x86_64-m32,i686}-fedora21-linux-gnu native and in
DWZ and in -fdebug-types-section modes.


Thanks,
Jan
gdb/
2014-11-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* block.c (block_lookup_symbol_primary): New function.
	* block.h (block_lookup_symbol_primary): New declaration.
	* symtab.c (lookup_symbol_in_objfile_symtabs): Assert BLOCK_INDEX.
	Call block_lookup_symbol_primary.

Comments

Doug Evans Dec. 2, 2014, 3:06 a.m. UTC | #1
Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> On Fri, 24 Oct 2014 09:16:01 +0200, Doug Evans wrote:
>> This breaks an abstraction boundary, IWBN to preserve it.
>> [IOW, I look at dict_* as being an implementation detail of blocks.]
>> 
>> If we were to go this route (and apologies for the delay), can you
>> write a routine like lookup_block_symbol which does the above and call
>> that here instead?
>> 
>> lookup_block_symbol should live in block.c, not symtab.c.
>> That's where this new routine should go too.
>
> Done.
>
> For the 'slow.C' test the performance gain is even higher; but I have not
> re-benchmarked the 'non-trivial app':
> 	Command execution time: 26.540344 (cpu), 26.575254 (wall)
> 	->
> 	Command execution time: 0.310607 (cpu), 0.311062 (wall)
> 	 = 85x
>
> OK for check-in?
>
> No regressions on {x86_64,x86_64-m32,i686}-fedora21-linux-gnu native and in
> DWZ and in -fdebug-types-section modes.
>
>
> Thanks,
> Jan
> gdb/
> 2014-11-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
> 	* block.c (block_lookup_symbol_primary): New function.
> 	* block.h (block_lookup_symbol_primary): New declaration.
> 	* symtab.c (lookup_symbol_in_objfile_symtabs): Assert BLOCK_INDEX.
> 	Call block_lookup_symbol_primary.

Hi.

I was reviewing all the callers of lookup_symbol_in_objfile_symtabs.

This patch assumes we're looping over all objfiles,
but some callers aren't.  e.g., lookup_symbol_in_objfile_from_linkage_name.
It seems like we'll need to make a copy of lookup_symbol_in_objfile_symtabs
and call that in lookup_symbol_in_objfile (plus I'd add some comments
to lookup_symbol_in_objfile warning the reader that included symtabs
are not searched).

I could be missing something though.
Jan Kratochvil Dec. 3, 2014, 6:05 p.m. UTC | #2
On Tue, 02 Dec 2014 04:06:28 +0100, Doug Evans wrote:
> I was reviewing all the callers of lookup_symbol_in_objfile_symtabs.

I do not see why, see below.


> This patch assumes we're looping over all objfiles,

No.  each objfile is considered completely independent wrt various kinds of
symbol tables and their inter-refefences.

Function block_lookup_symbol_primary() assumes we're looping over all
'compunit_symtabs's (of an objfile).  This is satisfied by the current only
caller of block_lookup_symbol_primary()
(which is lookup_symbol_in_objfile_symtabs()).


> but some callers aren't.  e.g., lookup_symbol_in_objfile_from_linkage_name.
> It seems like we'll need to make a copy of lookup_symbol_in_objfile_symtabs
> and call that in lookup_symbol_in_objfile (plus I'd add some comments
> to lookup_symbol_in_objfile warning the reader that included symtabs
> are not searched).
> 
> I could be missing something though.

I also can be missing something but I do not see why
block_lookup_symbol_primary() should have any dependencies on other objfiles
than the one that is passed to it.


Thanks,
Jan
Doug Evans Dec. 4, 2014, 6:21 a.m. UTC | #3
On Wed, Dec 3, 2014 at 10:05 AM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> Function block_lookup_symbol_primary() assumes we're looping over all
> 'compunit_symtabs's (of an objfile).

Ah, righto.

LGTM
Jan Kratochvil Dec. 4, 2014, 7:27 a.m. UTC | #4
On Thu, 04 Dec 2014 07:21:15 +0100, Doug Evans wrote:
> On Wed, Dec 3, 2014 at 10:05 AM, Jan Kratochvil
> <jan.kratochvil@redhat.com> wrote:
> > Function block_lookup_symbol_primary() assumes we're looping over all
> > 'compunit_symtabs's (of an objfile).
> 
> Ah, righto.
> 
> LGTM

Checked in:
	ba715d7fe49c8a59660fbd571b935b29eb7cfbdb


Thanks,
Jan
diff mbox

Patch

diff --git a/gdb/block.c b/gdb/block.c
index 597d143..e791c73 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -746,3 +746,28 @@  block_lookup_symbol (const struct block *block, const char *name,
       return (sym_found);	/* Will be NULL if not found.  */
     }
 }
+
+/* See block.h.  */
+
+struct symbol *
+block_lookup_symbol_primary (const struct block *block, const char *name,
+			     const domain_enum domain)
+{
+  struct symbol *sym;
+  struct dict_iterator dict_iter;
+
+  /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
+  gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
+	      || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
+
+  for (sym = dict_iter_name_first (block->dict, name, &dict_iter);
+       sym != NULL;
+       sym = dict_iter_name_next (name, &dict_iter))
+    {
+      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+				 SYMBOL_DOMAIN (sym), domain))
+	return sym;
+    }
+
+  return NULL;
+}
diff --git a/gdb/block.h b/gdb/block.h
index bd358d6..409a5c7 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -276,6 +276,14 @@  extern struct symbol *block_lookup_symbol (const struct block *block,
 					   const char *name,
 					   const domain_enum domain);
 
+/* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of
+   BLOCK.  BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK.  Function is useful if
+   one iterates all global/static blocks of an objfile.  */
+
+extern struct symbol *block_lookup_symbol_primary (const struct block *block,
+						   const char *name,
+						   const domain_enum domain);
+
 /* Macro to loop through all symbols in BLOCK, in no particular
    order.  ITER helps keep track of the iteration, and must be a
    struct block_iterator.  SYM points to the current symbol.  */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 345c20d..fd93fb8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1618,6 +1618,8 @@  lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
 {
   struct compunit_symtab *cust;
 
+  gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
+
   ALL_OBJFILE_COMPUNITS (objfile, cust)
     {
       const struct blockvector *bv;
@@ -1626,7 +1628,7 @@  lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
 
       bv = COMPUNIT_BLOCKVECTOR (cust);
       block = BLOCKVECTOR_BLOCK (bv, block_index);
-      sym = block_lookup_symbol (block, name, domain);
+      sym = block_lookup_symbol_primary (block, name, domain);
       if (sym)
 	{
 	  block_found = block;