public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Mark Mitchell <mark@codesourcery.com>
Cc: Richard Henderson <rth@redhat.com>, gcc@gcc.gnu.org, dnovillo@redhat.com
Subject: Re: pruning unused debugging types (enums/PR23336)
Date: Thu, 16 Feb 2006 19:42:00 -0000	[thread overview]
Message-ID: <20060216194057.GA30917@redhat.com> (raw)
In-Reply-To: <43F28D2A.60902@codesourcery.com>

On Tue, Feb 14, 2006 at 06:08:42PM -0800, Mark Mitchell wrote:
> Aldy Hernandez wrote:
> 
> > Do we keep a hash of functions that have been written out somewhere?
> 
> Not to my knowledge.
> 
> > I'd hate to walk the entire hash table each time we write out a function
> > searching for the types that function uses.
> 
> Agreed.

Hi Mark.  Hi folks.

I went through a couple prototypes, some more cumbersome to implement than
others.  I've opted for a hash table of types in struct function.  The
implementation is a lot cleaner.  Perhaps we can optimize it later if
you really hate it :(.

This patch fixes the cast problem.  A similar solution would be in order
for the enums; the infrastructure here would work for that.

Could you take a peek at this, so we can use this as a starting point, and
perhaps then I can start on the C++ front-end?  I've sat on this long enough
:(.

Thanks.
Aldy

	* function.h (struct function): Add used_types_hash field.
	Include hashtab.h.
	* 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.
	* c-decl.c (store_parm_decls): Initialize used_types_hash.
	(used_types_insert): Protoize.
	* 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,18 @@ 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 *cfun)
+{
+  if (t != NULL)
+    {
+      void **slot = htab_find_slot (cfun->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_noresize (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: c-decl.c
===================================================================
--- c-decl.c	(revision 110692)
+++ c-decl.c	(working copy)
@@ -6477,6 +6477,9 @@ store_parm_decls (void)
   /* Initialize the RTL code for the function.  */
   allocate_struct_function (fndecl);
 
+  cfun->used_types_hash = htab_create (37, htab_hash_pointer,
+				       htab_eq_pointer, NULL);
+
   /* Begin the statement tree for this function.  */
   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
 
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)

  reply	other threads:[~2006-02-16 19:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-17 22:08 Aldy Hernandez
2005-11-17 23:09 ` Richard Henderson
2005-11-18  6:24   ` Mark Mitchell
2005-11-18 20:09     ` Aldy Hernandez
2005-11-19  1:03       ` Mark Mitchell
2006-02-10 20:03     ` Aldy Hernandez
2006-02-14  2:11       ` Mark Mitchell
2006-02-14 11:52         ` Aldy Hernandez
2006-02-15  2:08           ` Mark Mitchell
2006-02-16 19:42             ` Aldy Hernandez [this message]
2006-02-17 23:53               ` Richard Henderson
2006-02-15 13:48           ` Diego Novillo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060216194057.GA30917@redhat.com \
    --to=aldyh@redhat.com \
    --cc=dnovillo@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=mark@codesourcery.com \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).