> 
> Honza reports high CPU usage from lookup_external_ref at LTRANS time.
> This is likely because build_abbrev_table calls it on all DIEs
> rather than just type DIEs which we populate the ref table with.
> So we end up calling it for all the DIEs refering to early debug,
> possibly many distinct ones with the same die.symbol (but usually
> different die_offset).  That will end up with loads of hashtable
> collisions.
> 
> The following patch restricts the build_abbrev_table lookups to
> type DIEs.
> 
> We might consider optimizing the refs to decrease the number of
> relocations the link editor has to process but I guess it's not
> worth it and the rest of the optimize_external_refs isn't prepared
> for the LTO case anyways.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> Honza has yet to confirm the patch helps, once he does I plan to
> install it.

Before patch I got about 5% of lookup_external_ref while building
cc1 and after patch the function is off the profile :)

Honza

> 
> Richard.
> 
> 2018-10-31  Richard Biener  <rguent...@suse.de>
> 
>       * dwarf2out.c (build_abbrev_table): Guard lookup_external_ref call
>       with is_type_die.
> 
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 30bbfee9052..8b478aa265f 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -9023,8 +9023,9 @@ build_abbrev_table (dw_die_ref die, 
> external_ref_hash_type *extern_map)
>       struct external_ref *ref_p;
>       gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
>  
> -     ref_p = lookup_external_ref (extern_map, c);
> -     if (ref_p->stub && ref_p->stub != die)
> +     if (is_type_die (c)
> +         && (ref_p = lookup_external_ref (extern_map, c))
> +         && ref_p->stub && ref_p->stub != die)
>         change_AT_die_ref (a, ref_p->stub);
>       else
>         /* We aren't changing this reference, so mark it external.  */

Reply via email to