This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pruning unused debugging types (enums/PR23336)


On Sat, Feb 18, 2006 at 07:23:30AM -0400, Aldy Hernandez wrote:

Ping.

(http://gcc.gnu.org/ml/gcc-patches/2006-02/msg01506.html)

> On Fri, Feb 17, 2006 at 03:52:09PM -0800, Richard Henderson wrote:
> 
> [moving this to gcc-patches]
> 
> > > +  htab_t GTY ((param_is (union tree_node))) used_types_hash;
> > 
> > Should be "tree" not the union.  You're storing a pointer, 
> > not the union itself.
> 
> Are you sure, because I got the above incantation from doc/gty.texi?:
> 
> @smallexample
>   static htab_t GTY ((param_is (union tree_node))) ict;
> @end smallexample
> 
> Otherwise, by just using "tree", I get the following from gengtype:
> 
> /source/svn/trunk/unused-types/gcc/../include/hashtab.h:142: field `(*x).entries[i0]' is pointer to unimplemented type
> 
> Everything else fixed in the patch below.
> 
> 	* function.h (struct function): Add used_types_hash field.
> 	Include hashtab.h.
> 	(used_types_insert): Protoize.
> 	* function.c (used_types_insert): New.
> 	* c-parser.c (c_parser_cast_expression): Call used_types_insert.
> 	* dwarf2out.c (struct die_struct): Add die_perennial_p field.
> 	(premark_used_types_helper): New.
> 	(premark_used_types): New.
> 	(gen_subprogram_die): Call premark_used_types.
> 	(prune_unused_types_walk): Do not mark perennial types.
> 	* Makefile.in (FUNCTION_H): Depend on HASHTAB_H.
> 
> Index: function.h
> ===================================================================
> --- function.h	(revision 110692)
> +++ function.h	(working copy)
> @@ -23,6 +23,7 @@ Software Foundation, 51 Franklin Street,
>  #define GCC_FUNCTION_H
>  
>  #include "tree.h"
> +#include "hashtab.h"
>  
>  struct var_refs_queue GTY(())
>  {
> @@ -312,6 +313,9 @@ struct function GTY(())
>    /* Language-specific code can use this to store whatever it likes.  */
>    struct language_function * language;
>  
> +  /* Used types hash table.  */
> +  htab_t GTY ((param_is (union tree_node))) used_types_hash;
> +
>    /* For reorg.  */
>  
>    /* If some insns can be deferred to the delay slots of the epilogue, the
> @@ -562,4 +566,6 @@ extern bool pass_by_reference (CUMULATIV
>  extern bool reference_callee_copied (CUMULATIVE_ARGS *, enum machine_mode,
>  				     tree, bool);
>  
> +extern void used_types_insert (tree, struct function *);
> +
>  #endif  /* GCC_FUNCTION_H */
> Index: function.c
> ===================================================================
> --- function.c	(revision 110692)
> +++ function.c	(working copy)
> @@ -5569,6 +5569,23 @@ rest_of_handle_check_leaf_regs (void)
>  #endif
>  }
>  
> +/* Insert a type into the used types hash table.  */
> +void
> +used_types_insert (tree t, struct function *func)
> +{
> +  if (t != NULL)
> +    {
> +      void **slot;
> +
> +      if (func->used_types_hash == NULL)
> +	func->used_types_hash = htab_create (37, htab_hash_pointer,
> +					     htab_eq_pointer, NULL);
> +      slot = htab_find_slot (func->used_types_hash, t, INSERT);
> +      if (*slot == NULL)
> +	*slot = t;
> +    }
> +}
> +
>  struct tree_opt_pass pass_leaf_regs =
>  {
>    NULL,                                 /* name */
> Index: c-parser.c
> ===================================================================
> --- c-parser.c	(revision 110692)
> +++ c-parser.c	(working copy)
> @@ -4660,6 +4660,10 @@ c_parser_cast_expression (c_parser *pars
>  	  ret.original_code = ERROR_MARK;
>  	  return ret;
>  	}
> +
> +      /* Save casted types in the function's used types hash table.  */
> +      used_types_insert (TREE_TYPE (groktypename (type_name)), cfun);
> +
>        if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
>  	return c_parser_postfix_expression_after_paren_type (parser,
>  							     type_name);
> Index: dwarf2out.c
> ===================================================================
> --- dwarf2out.c	(revision 110692)
> +++ dwarf2out.c	(working copy)
> @@ -3677,6 +3677,8 @@ typedef struct die_struct GTY(())
>    dw_offset die_offset;
>    unsigned long die_abbrev;
>    int die_mark;
> +  /* Die is used and must not be pruned as unused.  */
> +  int die_perennial_p;
>    unsigned int decl_id;
>  }
>  die_node;
> @@ -11477,6 +11479,30 @@ dwarf2out_abstract_function (tree decl)
>    current_function_decl = save_fn;
>  }
>  
> +/* Helper function of premark_used_types() which gets called through
> +   htab_traverse_resize().
> +
> +   Marks the DIE of a given type in *SLOT as perennial, so it never gets
> +   marked as unused by prune_unused_types.  */
> +static int
> +premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
> +{
> +  tree type;
> +  dw_die_ref die;
> +
> +  type = *slot;
> +  die = lookup_type_die (type);
> +  die->die_perennial_p = 1;
> +  return 1;
> +}
> +
> +/* Mark all members of used_types_hash as perennial.  */
> +static
> +void premark_used_types ()
> +{
> +  htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
> +}
> +
>  /* Generate a DIE to represent a declared function (either file-scope or
>     block-local).  */
>  
> @@ -11492,6 +11518,8 @@ gen_subprogram_die (tree decl, dw_die_re
>    int declaration = (current_function_decl != decl
>  		     || class_or_namespace_scope_p (context_die));
>  
> +  premark_used_types();
> +
>    /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
>       started to generate the abstract instance of an inline, decided to output
>       its containing class, and proceeded to emit the declaration of the inline
> @@ -13968,6 +13996,9 @@ prune_unused_types_walk (dw_die_ref die)
>    case DW_TAG_subrange_type:
>    case DW_TAG_ptr_to_member_type:
>    case DW_TAG_file_type:
> +    if (die->die_perennial_p)
> +      break;
> +
>      /* It's a type node --- don't mark it.  */
>      return;
>  
> Index: Makefile.in
> ===================================================================
> --- Makefile.in	(revision 110692)
> +++ Makefile.in	(working copy)
> @@ -750,7 +750,7 @@ RECOG_H = recog.h
>  ALIAS_H = alias.h
>  EMIT_RTL_H = emit-rtl.h
>  FLAGS_H = flags.h options.h
> -FUNCTION_H = function.h $(TREE_H)
> +FUNCTION_H = function.h $(TREE_H) $(HASHTAB_H)
>  EXPR_H = expr.h insn-config.h $(FUNCTION_H) $(RTL_H) $(FLAGS_H) $(TREE_H) $(MACHMODE_H) $(EMIT_RTL_H)
>  OPTABS_H = optabs.h insn-codes.h
>  REGS_H = regs.h varray.h $(MACHMODE_H) $(OBSTACK_H) $(BASIC_BLOCK_H) $(FUNCTION_H)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]