On Thu, Oct 13, 2016 at 09:16:07AM +0200, Richard Biener wrote:
> 
> This merges a few more bits guarding stuff with ! early_dwarf, mostly
> to avoid creating locations that involve addresses of decls early
> but also to avoid wasting work for BLOCK_NONLOCALIZED_VARs.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, gdb testsuite
> tested on the same arch (from the gdb 7.12 branch), applied to trunk.
> 
> Richard.
> 
> 2016-10-13  Richard Biener  <rguent...@suse.de>
> 
>       * dwarf2out.c (tree_add_const_value_attribute): Do not try
>       rtl_for_decl_init during early phase.
>       (gen_variable_die): Do not create locations during early phase.
>       (gen_label_die): Likewise.
>       (decls_for_scope): Do not waste time handling BLOCK_NONLOCALIZED_VARs
>       twice.

As Martin reported, this has very undesirable effect on the size of DWARF
debug info.

The problem is that add_const_value_attribute has lots of smarts to handle
various kinds of constants, which the
  if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
      && initializer_constant_valid_p (init, type))
block doesn't implement, it relies on all the smarts to be done earlier.
One option is to duplicate that all on trees, another option is
to use the rtl_for_decl_init + add_const_value_attribute way
even for early_dwarf for constants, something like:

-  if (! early_dwarf)
+  if (! early_dwarf || CONSTANT_CLASS_P (init))
     {
       rtl = rtl_for_decl_init (init, type);
       if (rtl)
        return add_const_value_attribute (die, rtl);
     }
   if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
       && initializer_constant_valid_p (init, type))

For the duplicate on trees, some cases might not be that hard, like
handling of INTEGER_CSTs, just see if they are negative and fit into shwi,
(then add_AT_int), or fit into uhwi (then add_AT_unsigned); maybe that
would be enough for now.

> --- gcc/dwarf2out.c   (revision 241022)
> +++ gcc/dwarf2out.c   (working copy)
> @@ -17958,12 +17958,15 @@ tree_add_const_value_attribute (dw_die_r
>    init = t;
>    gcc_assert (!DECL_P (init));
>  
> -  rtl = rtl_for_decl_init (init, type);
> -  if (rtl)
> -    return add_const_value_attribute (die, rtl);
> +  if (! early_dwarf)
> +    {
> +      rtl = rtl_for_decl_init (init, type);
> +      if (rtl)
> +     return add_const_value_attribute (die, rtl);
> +    }
>    /* If the host and target are sane, try harder.  */
> -  else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
> -        && initializer_constant_valid_p (init, type))
> +  if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
> +      && initializer_constant_valid_p (init, type))
>      {
>        HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
>        if (size > 0 && (int) size == size)

        Jakub

Reply via email to