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]

[tree-ssa] Collect DFA/SSA statistics [patch]


Adds a new 'stats' flag to -ftree-dump to collect and display
statistics for each pass.  So far, the only passes that show
stats are DCE and SSA (-fdump-tree-dce-stats, -fdump-tree-ssa-stats).

It also changes the semantics for tree_annotation().  It used to
create an annotation if the tree didn't have one already.  Dumb.

Bootstrapped and tested on x86.


Diego.

	* Makefile.in (tree-dfa.o): Depend on hashtab.h.
	* c-simplify.c (get_name): Declare extern.
	* tree-cfg.c (tree_dump_cfg): Call it.
	(tree_cfg2dot): Call it.
	* tree-ssa-ccp.c (tree_ssa_ccp): Call get_name.
	* tree-ssa-dce.c (tree_ssa_eliminate_dead_code): Call get_name.
	* tree-ssa-pre.c (tree_perform_ssapre): Call get_name.
	* tree-ssa.c (analyze_rdefs): Call get_name.
	(dump_reaching_defs): Call get_name.
	(dump_tree_ssa): Call get_name.
	* tree.h (get_name): Declare.

	* tree-dfa.c: Include "hashtab.h"
	(struct dfa_stats_d): New.
	(collect_dfa_stats): New local function.
	(collect_dfa_stats_r): New local function.
	(count_tree_refs): New local function.
	(count_ref_list_nodes): New local function.
	(tree_find_refs): Call dump_begin on entry to the function.
	(dump_referenced_vars): Call get_name.
	(SCALE): Declare.
	(LABEL): Declare.
	(dump_dfa_stats): New function.
	(debug_dfa_stats): New function.
	* tree-dump.c (struct dump_option_value_info): Add entry for TDF_STATS.
	* tree-flow.h (has_annotation): Remove.  Update all users.
	(dump_dfa_stats): Declare.
	(debug_dfa_stats): Declare.
	(tree_annotation): Don't create one if the tree doesn't have one
	already.  Update all users to new semantics.
	* tree-ssa-dce.c (print_stats): Dump if dump_flags has TDF_STATS bit
	set.
	* tree-ssa.c (tree_build_ssa): Open dump file on entry.
	Call dump_dfa_stats if dump_flags has TDF_STATS bit set.
	Call dump_tree_ssa if dump_flags has TDF_DETAILS bit set.
	* tree.h (TDF_STATS): Define.
	* doc/invoke.texi: Document 'stats' flag for -fdump-tree.

	* tree-dfa.c (next_tree_ref_id): Change type to unsigned long.
	Update all users.
	tree-flow.h (tree_ref_common): Change type of field 'id' to
	unsigned long.  Update all users.
	(ref_id): Change return type to unsigned long.  Update all users.

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.903.2.31
diff -d -u -p -r1.903.2.31 Makefile.in
--- Makefile.in	20 Sep 2002 13:26:51 -0000	1.903.2.31
+++ Makefile.in	23 Sep 2002 02:58:06 -0000
@@ -1393,7 +1393,7 @@ tree-cfg.o : tree-cfg.c tree-optimize.h 
 tree-dfa.o : tree-dfa.c tree-optimize.h tree-flow.h $(CONFIG_H) $(SYSTEM_H) \
    $(RTL_H) $(TREE_H) $(TM_P_H) $(BASIC_BLOCK_H) $(EXPR_H) \
    $(GGC_H) output.h diagnostic.h errors.h $(C_TREE_H) tree-simple.h \
-   tree-inline.h
+   tree-inline.h $(HASHTAB_H)
 tree-optimize.o : tree-optimize.c tree-optimize.h tree-flow.h $(CONFIG_H) \
    $(SYSTEM_H) $(RTL_H) $(TREE_H) $(TM_P_H) $(BASIC_BLOCK_H) $(EXPR_H) \
    $(GGC_H) output.h diagnostic.h ssa.h errors.h flags.h tree-alias-common.h \
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.24
diff -d -u -p -r1.1.4.24 c-simplify.c
--- c-simplify.c	17 Sep 2002 19:46:20 -0000	1.1.4.24
+++ c-simplify.c	23 Sep 2002 02:58:06 -0000
@@ -85,7 +85,6 @@ static int  stmt_has_effect          PAR
 static int  expr_has_effect          PARAMS ((tree));
 static tree mostly_copy_tree_r       PARAMS ((tree *, int *, void *));
 static inline void remove_suffix     PARAMS ((char *, int));
-static const char *get_name          PARAMS ((tree));
 static int is_last_stmt_of_scope     PARAMS ((tree));
 static tree tail_expression          PARAMS ((tree *, int));
 static tree mark_not_simple_r        PARAMS ((tree *, int *, void *));
@@ -2362,7 +2361,8 @@ create_tmp_alias_var (type, prefix)
 /*  Given a tree, try to return a useful variable name that we can use
     to prefix a temporary that is being assigned the value of the tree. 
     I.E. given  <temp> = &A, return A.  */
-static const char *
+
+const char *
 get_name (t)
      tree t;
 {
@@ -2385,6 +2385,7 @@ get_name (t)
     }
 }
 
+
 /*  Returns a new temporary variable, initialized with VAL.  PRE_P and STMT
     are as in simplify_expr.  */
 
@@ -2693,7 +2694,7 @@ mostly_copy_tree_r (tp, walk_subtrees, d
     *walk_subtrees = 0;
   else
     {
-      enum tree_flags flags = (has_annotation (*tp)) ? tree_flags (*tp) : 0;
+      enum tree_flags flags = tree_flags (*tp);
       copy_tree_r (tp, walk_subtrees, data);
       if (flags)
 	set_tree_flag (*tp, flags);
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.10
diff -d -u -p -r1.1.4.10 tree-cfg.c
--- tree-cfg.c	19 Sep 2002 23:12:05 -0000	1.1.4.10
+++ tree-cfg.c	23 Sep 2002 02:58:07 -0000
@@ -2500,8 +2500,7 @@ tree_dump_cfg (file)
   basic_block bb;
 
   fputc ('\n', file);
-  fprintf (file, ";; Function %s\n\n",
-	   IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
+  fprintf (file, ";; Function %s\n\n", get_name (current_function_decl));
 
   fprintf (file, "\n%d basic blocks, %d edges, last basic block %d.\n",
            n_basic_blocks, n_edges, last_basic_block);
@@ -2523,8 +2522,7 @@ tree_cfg2dot (file)
   basic_block bb;
 
   /* Write the file header.  */
-  fprintf (file, "digraph %s\n{\n",
-	   IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
+  fprintf (file, "digraph %s\n{\n", get_name (current_function_decl));
 
   /* Write blocks and edges.  */
   for (e = ENTRY_BLOCK_PTR->succ; e; e = e->succ_next)
Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.23
diff -d -u -p -r1.1.4.23 tree-dfa.c
--- tree-dfa.c	20 Sep 2002 17:38:10 -0000	1.1.4.23
+++ tree-dfa.c	23 Sep 2002 02:58:07 -0000
@@ -21,6 +21,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
 #include "system.h"
+#include "hashtab.h"
 #include "tree.h"
 #include "rtl.h"
 #include "tm_p.h"
@@ -60,15 +61,37 @@ struct clobber_data_d
 };
 
 
+/* DFA Statistics.  */
+struct dfa_stats_d
+{
+  unsigned long num_tree_refs;
+  unsigned long num_tree_anns;
+  unsigned long num_ref_list_nodes;
+  unsigned long num_defs;
+  unsigned long num_uses;
+  unsigned long num_phis;
+  unsigned long num_phi_args;
+  unsigned long num_fcalls;
+  unsigned long num_ephis;
+  unsigned long num_euses;
+  unsigned long num_ekills;
+};
+
 /* Local functions.  */
-static void find_refs_in_stmt PARAMS ((tree, basic_block));
-static void find_refs_in_expr PARAMS ((tree *, HOST_WIDE_INT, basic_block, tree,
-                                       tree));
-static void add_referenced_var PARAMS ((tree));
-static tree clobber_vars_r PARAMS ((tree *, int *, void *));
-static void add_default_defs PARAMS ((void));
-static void add_call_site_clobbers PARAMS ((void));
-static void add_ptr_may_refs PARAMS ((void));
+static void find_refs_in_stmt		PARAMS ((tree, basic_block));
+static void find_refs_in_expr		PARAMS ((tree *, HOST_WIDE_INT,
+      						 basic_block, tree, tree));
+static void add_referenced_var		PARAMS ((tree));
+static void collect_dfa_stats		PARAMS ((struct dfa_stats_d *));
+static tree collect_dfa_stats_r		PARAMS ((tree *, int *, void *));
+static void count_tree_refs		PARAMS ((struct dfa_stats_d *,
+      						 ref_list));
+static void count_ref_list_nodes	PARAMS ((struct dfa_stats_d *,
+      						 ref_list));
+static tree clobber_vars_r		PARAMS ((tree *, int *, void *));
+static void add_default_defs		PARAMS ((void));
+static void add_call_site_clobbers	PARAMS ((void));
+static void add_ptr_may_refs		PARAMS ((void));
 
 
 /* Global declarations.  */
@@ -81,7 +104,7 @@ varray_type referenced_vars;
 ref_list call_sites;
 
 /* Next unique reference ID to be assigned by create_ref().  */
-HOST_WIDE_INT next_tree_ref_id;
+unsigned long next_tree_ref_id;
 
 /* Reference types.  */
 const HOST_WIDE_INT V_DEF	= 1 << 0;
@@ -110,6 +133,14 @@ tree_find_refs ()
 {
   basic_block bb;
 
+  /* Debugging dumps.  */
+  dump_file = dump_begin (TDI_ssa, &dump_flags);
+  if (dump_file)
+    {
+      fputc ('\n', dump_file);
+      fprintf (dump_file, ";; Function %s\n\n", get_name (current_function_decl));
+    }
+
   next_tree_ref_id = 0;
   call_sites = create_ref_list ();
   pointer_refs = create_ref_list ();
@@ -141,8 +172,6 @@ tree_find_refs ()
   add_call_site_clobbers ();
   add_ptr_may_refs ();
 
-  /* Debugging dumps.  */
-  dump_file = dump_begin (TDI_ssa, &dump_flags);
   if (dump_file)
     {
       if (dump_flags & TDF_REFS)
@@ -1080,9 +1109,7 @@ dump_ref (outf, prefix, ref, indent, det
   else
     fprintf (outf, "nil");
 
-  fprintf (outf, "): line %d, bb %d, id ", lineno, bbix);
-  fprintf (outf, HOST_WIDE_INT_PRINT_DEC, ref_id (ref));
-  fprintf (outf, ", ");
+  fprintf (outf, "): line %d, bb %d, id %lu, ", lineno, bbix, ref_id (ref));
 
   if (ref_expr (ref))
     print_c_node (outf, ref_expr (ref));
@@ -1235,9 +1262,7 @@ dump_referenced_vars (file)
 {
   size_t i;
 
-  fprintf (file, "\n;; Function %s: %lu referenced variables\n\n", 
-	   IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
-	   num_referenced_vars);
+  fprintf (file, "\nReferenced variables: %lu\n\n", num_referenced_vars);
 
   for (i = 0; i < num_referenced_vars; i++)
     {
@@ -1292,6 +1317,218 @@ dump_phi_args (outf, prefix, args, inden
   for (i = 0; i < VARRAY_SIZE (args); i++)
     dump_ref (outf, prefix, phi_arg_def (VARRAY_GENERIC_PTR (args, i)), indent,
 	      details);
+}
+
+
+/* Dump various DFA statistics to FILE.  */
+
+#define SCALE(x) ((unsigned long) ((x) < 1024*10 \
+		  ? (x) \
+		  : ((x) < 1024*1024*10 \
+		     ? (x) / 1024 \
+		     : (x) / (1024*1024))))
+#define LABEL(x) ((x) < 1024*10 ? 'b' : ((x) < 1024*1024*10 ? 'k' : 'M'))
+
+void
+dump_dfa_stats (file)
+     FILE *file;
+{
+  struct dfa_stats_d dfa_stats;
+  unsigned long size;
+  const char * const fmt_str   = "%-30s%-13s%12s\n";
+  const char * const fmt_str_1 = "%-30s%13lu%11lu%c\n";
+  const char * const fmt_str_2 = "%-30s%6lu (%3lu%%)\n";
+
+  collect_dfa_stats (&dfa_stats);
+
+  fprintf (file, "\nDFA Statistics for %s\n\n", get_name (current_function_decl));
+
+  fprintf (file, fmt_str, "", "  Number of  ", "Memory");
+  fprintf (file, fmt_str, "Object", "  instances  ", "used ");
+  fprintf (file, "----------------------------------------------------------\n");
+
+  size = num_referenced_vars * sizeof (tree);
+  fprintf (file, fmt_str_1, "Referenced variables", num_referenced_vars, 
+	   SCALE (size), LABEL (size));
+
+  size = dfa_stats.num_tree_anns * sizeof (struct tree_ann_d);
+  fprintf (file, fmt_str_1, "Trees annotated", dfa_stats.num_tree_anns,
+	   SCALE (size), LABEL (size));
+
+  size = dfa_stats.num_ref_list_nodes * sizeof (struct ref_list_node);
+  fprintf (file, fmt_str_1, "ref_list nodes", dfa_stats.num_ref_list_nodes,
+	   SCALE (size), LABEL (size));
+
+  size = dfa_stats.num_phi_args * sizeof (struct phi_node_arg_d);
+  fprintf (file, fmt_str_1, "PHI arguments", dfa_stats.num_phi_args,
+	   SCALE (size), LABEL (size));
+
+  size = dfa_stats.num_tree_refs * sizeof (union tree_ref_d);
+  fprintf (file, fmt_str_1, "Variable references", dfa_stats.num_tree_refs,
+	   SCALE (size), LABEL (size));
+
+  if (dfa_stats.num_tree_refs == 0)
+    dfa_stats.num_tree_refs = 1;
+
+  if (dfa_stats.num_defs)
+    fprintf (file, fmt_str_2, "    V_DEF", dfa_stats.num_defs,
+	    (dfa_stats.num_defs * 100 / dfa_stats.num_tree_refs));
+
+  if (dfa_stats.num_uses)
+    fprintf (file, fmt_str_2, "    V_USE", dfa_stats.num_uses,
+	    (dfa_stats.num_uses * 100 / dfa_stats.num_tree_refs));
+
+  if (dfa_stats.num_phis)
+    fprintf (file, fmt_str_2, "    V_PHI", dfa_stats.num_phis,
+	    (dfa_stats.num_phis * 100 / dfa_stats.num_tree_refs));
+
+  if (dfa_stats.num_fcalls)
+    fprintf (file, fmt_str_2, "    E_FCALL", dfa_stats.num_fcalls,
+	    (dfa_stats.num_fcalls * 100 / dfa_stats.num_tree_refs));
+
+  if (dfa_stats.num_ephis)
+    fprintf (file, fmt_str_2, "    E_PHI", dfa_stats.num_ephis,
+	    (dfa_stats.num_ephis * 100 / dfa_stats.num_tree_refs));
+
+  if (dfa_stats.num_euses)
+    fprintf (file, fmt_str_2, "    E_USE", dfa_stats.num_euses,
+	    (dfa_stats.num_euses * 100 / dfa_stats.num_tree_refs));
+
+  if (dfa_stats.num_ekills)
+    fprintf (file, fmt_str_2, "    E_KILL", dfa_stats.num_ekills,
+	    (dfa_stats.num_ekills * 100 / dfa_stats.num_tree_refs));
+
+  fprintf (file, "\n");
+
+  if (dfa_stats.num_phis)
+    fprintf (file, "Average number of PHI arguments per PHI node: %.1f\n",
+	    (float) (dfa_stats.num_phi_args) / (float) (dfa_stats.num_phis));
+
+  if (next_tree_ref_id != dfa_stats.num_tree_refs)
+    {
+      fprintf (file, "Number of unaccounted variable references: %ld\n",
+	       labs (next_tree_ref_id - dfa_stats.num_tree_refs));
+      fprintf (file, "\texpected: %lu\n", next_tree_ref_id);
+      fprintf (file, "\tcounted:  %lu\n", dfa_stats.num_tree_refs);
+    }
+
+  fprintf (file, "\n");
+}
+
+
+/* Dump DFA statistics on stderr.  */
+
+void
+debug_dfa_stats ()
+{
+  dump_dfa_stats (stderr);
+}
+
+
+/* Collect DFA statistics into *DFA_STATS_P.  */
+
+static void
+collect_dfa_stats (dfa_stats_p)
+     struct dfa_stats_d *dfa_stats_p;
+{
+  htab_t htab;
+  tree first_stmt;
+  basic_block bb;
+
+  if (dfa_stats_p == NULL)
+    abort ();
+
+  memset ((void *)dfa_stats_p, 0, sizeof (struct dfa_stats_d));
+
+  /* Walk all the trees in the function counting references.  */
+  first_stmt = BASIC_BLOCK (0)->head_tree;
+  htab = htab_create (30, htab_hash_pointer, htab_eq_pointer, NULL);
+  walk_tree (&first_stmt, collect_dfa_stats_r, (void *) dfa_stats_p,
+             (void *) htab);
+
+  FOR_EACH_BB (bb)
+    count_tree_refs (dfa_stats_p, bb_refs (bb));
+}
+
+
+/* Callback for walk_tree to collect DFA statistics for a tree and its
+   children.  */
+
+static tree
+collect_dfa_stats_r (tp, walk_subtrees, data)
+     tree *tp;
+     int *walk_subtrees ATTRIBUTE_UNUSED;
+     void *data;
+{
+  tree_ann ann;
+  tree t = *tp;
+  struct dfa_stats_d *dfa_stats_p = (struct dfa_stats_d *)data;
+
+  ann = tree_annotation (t);
+  if (ann)
+    {
+      dfa_stats_p->num_tree_anns++;
+      count_ref_list_nodes (dfa_stats_p, ann->refs);
+    }
+
+  return NULL;
+}
+
+
+/* Update DFA_STATS_P with the number of tree_ref objects in LIST.  */
+
+static void
+count_tree_refs (dfa_stats_p, list)
+     struct dfa_stats_d *dfa_stats_p;
+     ref_list list;
+{
+  tree_ref ref;
+  struct ref_list_node *tmp;
+
+  FOR_EACH_REF (ref, tmp, list)
+    {
+      dfa_stats_p->num_tree_refs++;
+
+      if (ref_type (ref) & V_DEF)
+	{
+	  dfa_stats_p->num_defs++;
+	  count_ref_list_nodes (dfa_stats_p, imm_uses (ref));
+	  count_ref_list_nodes (dfa_stats_p, reached_uses (ref));
+	}
+      else if (ref_type (ref) & V_USE)
+	{
+	  dfa_stats_p->num_uses++;
+	  count_ref_list_nodes (dfa_stats_p, reaching_defs (ref));
+	}
+      else if (ref_type (ref) & V_PHI)
+	{
+	  dfa_stats_p->num_phis++;
+	  dfa_stats_p->num_phi_args += num_phi_args (ref);
+	}
+      else if (ref_type (ref) & E_FCALL)
+	dfa_stats_p->num_fcalls++;
+      else if (ref_type (ref) & E_PHI)
+	dfa_stats_p->num_ephis++;
+      else if (ref_type (ref) & E_USE)
+	dfa_stats_p->num_euses++;
+      else if (ref_type (ref) & E_KILL)
+	dfa_stats_p->num_ekills++;
+    }
+}
+
+
+/* Count the number of nodes in a ref_list container.  */
+
+static void
+count_ref_list_nodes (dfa_stats_p, list)
+     struct dfa_stats_d *dfa_stats_p;
+     ref_list list;
+{
+  tree_ref ref;
+  struct ref_list_node *tmp;
+
+  FOR_EACH_REF (ref, tmp, list)
+    dfa_stats_p->num_ref_list_nodes++;
 }
 
 
Index: tree-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-dump.c,v
retrieving revision 1.6.2.11
diff -d -u -p -r1.6.2.11 tree-dump.c
--- tree-dump.c	19 Sep 2002 16:30:03 -0000	1.6.2.11
+++ tree-dump.c	23 Sep 2002 02:58:07 -0000
@@ -688,6 +688,7 @@ static const struct dump_option_value_in
   {"details", TDF_DETAILS},
   {"refs", TDF_REFS},
   {"rdefs", TDF_RDEFS},
+  {"stats", TDF_STATS},
   {"all", ~0},
   {NULL, 0}
 };
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.18
diff -d -u -p -r1.1.4.18 tree-flow.h
--- tree-flow.h	19 Sep 2002 23:12:05 -0000	1.1.4.18
+++ tree-flow.h	23 Sep 2002 02:58:07 -0000
@@ -226,7 +226,7 @@ struct tree_ref_common
   basic_block bb;
 
   /* Reference ID.  Unique within a single function.  */
-  HOST_WIDE_INT id;
+  unsigned long id;
 };
 
 /* Generic variable references.  */
@@ -390,7 +390,7 @@ static inline tree ref_var			PARAMS ((tr
 static inline tree ref_stmt			PARAMS ((tree_ref));
 static inline tree ref_expr			PARAMS ((tree_ref));
 static inline basic_block ref_bb		PARAMS ((tree_ref));
-static inline HOST_WIDE_INT ref_id		PARAMS ((tree_ref));
+static inline unsigned long ref_id		PARAMS ((tree_ref));
 static inline void replace_ref_operand_with	PARAMS ((tree_ref, tree));
 static inline void restore_ref_operand		PARAMS ((tree_ref));
 
@@ -499,7 +499,6 @@ struct tree_ann_d
 typedef struct tree_ann_d *tree_ann;
 
 static inline tree_ann tree_annotation	PARAMS ((tree));
-static inline bool has_annotation	PARAMS ((tree));
 static inline basic_block bb_for_stmt	PARAMS ((tree));
 static inline void set_bb_for_stmt	PARAMS ((tree, basic_block));
 static inline tree_ref currdef_for	PARAMS ((tree));
@@ -602,7 +601,7 @@ extern varray_type referenced_vars;
 extern ref_list call_sites;
 
 /* Next unique reference ID to be assigned by create_ref().  */
-extern HOST_WIDE_INT next_tree_ref_id;
+extern unsigned long next_tree_ref_id;
 
 /* Accessors for the referenced_vars array.  */
 extern unsigned long num_referenced_vars;
@@ -678,6 +677,8 @@ extern void dump_ref_array		PARAMS ((FIL
                                                  varray_type, int, int));
 extern void dump_phi_args		PARAMS ((FILE *, const char *,
       						 varray_type, int, int));
+extern void dump_dfa_stats		PARAMS ((FILE *));
+extern void debug_dfa_stats		PARAMS ((void));
 extern void debug_referenced_vars	PARAMS ((void));
 extern void dump_referenced_vars	PARAMS ((FILE *));
 extern int function_may_recurse_p	PARAMS ((void));
@@ -719,7 +720,7 @@ extern void create_alias_vars		PARAMS ((
 				Inline functions
 ---------------------------------------------------------------------------*/
 /* Return the reference ID.  */
-static inline HOST_WIDE_INT
+static inline unsigned long
 ref_id (ref)
      tree_ref ref;
 {
@@ -905,20 +906,7 @@ static inline tree_ann
 tree_annotation (t)
      tree t;
 {
-#if defined ENABLE_CHECKING
-  if (TREE_CODE_CLASS (TREE_CODE (t)) == 'c'
-      || TREE_CODE_CLASS (TREE_CODE (t)) == 't'
-      || TREE_CODE (t) == IDENTIFIER_NODE)
-    abort ();
-#endif
-  return ((t->common.aux) ? (tree_ann)t->common.aux : create_tree_ann (t));
-}
-
-static inline bool
-has_annotation (t)
-     tree t;
-{
-  return (t->common.aux != NULL);
+  return (tree_ann)t->common.aux;
 }
 
 /* Return the basic block containing statement T.  */
@@ -926,7 +914,7 @@ static inline basic_block
 bb_for_stmt (t)
      tree t;
 {
-  return tree_annotation (t)->bb;
+  return tree_annotation (t) ? tree_annotation (t)->bb : NULL;
 }
 
 /* Set the basic block containing statement T.  */
@@ -940,7 +928,7 @@ set_bb_for_stmt (t, bb)
   if (!statement_code_p (TREE_CODE (t)))
     abort ();
 #endif
-  ann = tree_annotation (t);
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
   ann->bb = bb;
 }
 
@@ -950,27 +938,24 @@ static inline tree_ref
 currdef_for (decl)
      tree decl;
 {
-#if defined ENABLE_CHECKING
-  if (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
-    abort ();
-#endif
-  return tree_annotation (decl)->currdef;
+  return tree_annotation (decl) ? tree_annotation (decl)->currdef : NULL;
 }
 
-/* Set the current definition for variable DECL to be DEF.  */
+/* Set the current definition for variable V to be DEF.  */
 static inline void
-set_currdef_for (decl, def)
-     tree decl;
+set_currdef_for (v, def)
+     tree v;
      tree_ref def;
 {
   tree_ann ann;
 #if defined ENABLE_CHECKING
-  if (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
+  if (TREE_CODE_CLASS (TREE_CODE (v)) != 'd')
     abort ();
+
   if (def && !(def->common.type & (V_DEF | V_PHI)))
     abort ();
 #endif
-  ann = tree_annotation (decl);
+  ann = tree_annotation (v) ? tree_annotation (v) : create_tree_ann (v);
   ann->currdef = def;
 }
 
@@ -983,12 +968,7 @@ static inline ref_list
 tree_refs (t)
      tree t;
 {
-#if defined ENABLE_CHECKING
-  if (TREE_CODE_CLASS (TREE_CODE (t)) == 'c'
-      || TREE_CODE_CLASS (TREE_CODE (t)) == 't')
-    abort ();
-#endif
-  return tree_annotation (t)->refs;
+  return tree_annotation (t) ? tree_annotation (t)->refs : NULL;
 }
 
 /* Add REF to the list of referencs for T.  */
@@ -997,12 +977,14 @@ add_tree_ref (t, ref)
      tree t;
      tree_ref ref;
 {
+  tree_ann ann;
 #if defined ENABLE_CHECKING
   if (TREE_CODE_CLASS (TREE_CODE (t)) == 'c'
       || TREE_CODE_CLASS (TREE_CODE (t)) == 't')
     abort ();
 #endif
-  add_ref_to_list_end (tree_refs (t), ref);
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
+  add_ref_to_list_end (ann->refs, ref);
 }
 
 /* Remove REF from the list of references for T.  */
@@ -1023,7 +1005,7 @@ compound_parent (t)
   if (!statement_code_p (TREE_CODE (t)))
     abort ();
 #endif
-  return tree_annotation (t)->compound_parent;
+  return tree_annotation (t) ? tree_annotation (t)->compound_parent : NULL;
 }
 
 /* Set PARENT to be the COMPOUND_STMT enclosing T.  */
@@ -1037,7 +1019,7 @@ set_compound_parent (t, parent)
   if (!statement_code_p (TREE_CODE (t)))
     abort ();
 #endif
-  ann = tree_annotation (t);
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
   ann->compound_parent = parent;
 }
 
@@ -1048,7 +1030,7 @@ static inline tree_ref
 output_ref (t)
      tree t;
 {
-  return tree_annotation (t)->output_ref;
+  return tree_annotation (t) ? tree_annotation (t)->output_ref : NULL;
 }
 
 /* Set the output reference for EXPR to be DEF.  */
@@ -1057,7 +1039,13 @@ set_output_ref (t, def)
      tree t;
      tree_ref def;
 {
-  tree_ann ann = tree_annotation (t);
+  tree_ann ann;
+#if defined ENABLE_CHECKING
+  if (TREE_CODE (t) != MODIFY_EXPR
+      && TREE_CODE (t) != INIT_EXPR)
+    abort ();
+#endif
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
   ann->output_ref = def;
 }
 
@@ -1073,7 +1061,7 @@ set_tree_flag (t, flag)
       || TREE_CODE_CLASS (TREE_CODE (t)) == 't')
     abort ();
 #endif
-  ann = tree_annotation (t);
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
   ann->flags |= flag;
 }
 
@@ -1089,7 +1077,7 @@ clear_tree_flag (t, flag)
       || TREE_CODE_CLASS (TREE_CODE (t)) == 't')
     abort ();
 #endif
-  ann = tree_annotation (t);
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
   ann->flags &= ~flag;
 }
 
@@ -1104,7 +1092,7 @@ reset_tree_flags (t)
       || TREE_CODE_CLASS (TREE_CODE (t)) == 't')
     abort ();
 #endif
-  ann = tree_annotation (t);
+  ann = tree_annotation (t) ? tree_annotation (t) : create_tree_ann (t);
   ann->flags = 0;
 }
 
@@ -1113,12 +1101,7 @@ static inline enum tree_flags
 tree_flags (t)
      tree t;
 {
-#if defined ENABLE_CHECKING
-  if (TREE_CODE_CLASS (TREE_CODE (t)) == 'c'
-      || TREE_CODE_CLASS (TREE_CODE (t)) == 't')
-    abort ();
-#endif
-  return tree_annotation (t)->flags;
+  return tree_annotation (t) ? tree_annotation (t)->flags : 0;
 }
 
 /* Return the annotation for basic block B.  Create a new one if necessary.  */
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.17
diff -d -u -p -r1.1.2.17 tree-ssa-ccp.c
--- tree-ssa-ccp.c	13 Sep 2002 17:46:52 -0000	1.1.2.17
+++ tree-ssa-ccp.c	23 Sep 2002 02:58:07 -0000
@@ -193,7 +193,7 @@ tree_ssa_ccp (fndecl)
   /* Debugging dumps.  */
   if (dump_file)
     {
-      fprintf (dump_file, "%s()\n", IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+      fprintf (dump_file, "%s()\n", get_name (fndecl));
 
       if (dump_flags & TDF_RAW)
 	dump_node (fnbody, TDF_SLIM | dump_flags, dump_file);
@@ -366,7 +366,7 @@ ssa_ccp_substitute_constants ()
       FOR_EACH_REF (ref, tmp, bb_refs (bb))
 	{
 	  tree_ref rdef;
-	  unsigned int id;
+	  unsigned long id;
 	  
 	  /* Notice that we want an unmodified V_USE reference here.  We
 	     don't deal with modifiers like M_PARTIAL or M_VOLATILE.  */
@@ -748,7 +748,7 @@ evaluate_expr (expr)
      UNDEFINED, then the expression is not a constant.  */
   FOR_EACH_REF (r, tmp, refs)
     {
-      unsigned int id;
+      unsigned long id;
       tree_ref rdef;
 
       /* Notice that we want an unmodified V_USE reference here.  We don't
@@ -934,7 +934,7 @@ initialize ()
 
       FOR_EACH_REF (r, tmp, tree_refs (var))
 	{
-	  size_t id = ref_id (r);
+	  unsigned long id = ref_id (r);
 
 	  values[id].lattice_val = UNDEFINED;
 	  values[id].const_value = NULL_TREE;
Index: tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dce.c,v
retrieving revision 1.1.2.1
diff -d -u -p -r1.1.2.1 tree-ssa-dce.c
--- tree-ssa-dce.c	17 Sep 2002 22:04:26 -0000	1.1.2.1
+++ tree-ssa-dce.c	23 Sep 2002 02:58:07 -0000
@@ -115,7 +115,7 @@ mark_control_parent_necessary (bb)
 static void
 print_stats ()
 {
-  if (dump_file && (dump_flags & TDF_DETAILS))
+  if (dump_file && (dump_flags & TDF_STATS))
     {
       float percg;
       percg = ((float) stats.removed / (float) stats.total) * 100;
@@ -129,10 +129,7 @@ static inline bool
 necessary_p (t)
      tree t;
 {
-  if (tree_annotation (t))
-    return (tree_flags (t) & TF_NECESSARY);
-  else
-    return false;
+  return (tree_flags (t) & TF_NECESSARY);
 }
 
 void
@@ -155,8 +152,7 @@ tree_ssa_eliminate_dead_code (fndecl)
   dump_file = dump_begin (TDI_dce, &dump_flags);
   if (dump_file)
     {
-      fprintf (dump_file, "%s\n",
-	       IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+      fprintf (dump_file, "%s\n", get_name (fndecl));
       
       if (dump_flags & TDF_RAW)
 	dump_node (fnbody, TDF_SLIM | dump_flags, dump_file);
Index: tree-ssa-pre.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-pre.c,v
retrieving revision 1.1.4.18
diff -d -u -p -r1.1.4.18 tree-ssa-pre.c
--- tree-ssa-pre.c	19 Sep 2002 19:01:00 -0000	1.1.4.18
+++ tree-ssa-pre.c	23 Sep 2002 02:58:07 -0000
@@ -2250,8 +2250,7 @@ tree_perform_ssapre ()
   /* Debugging dump after SSA PRE */
   if (dump_file)
     {
-      fprintf (dump_file, "%s()\n",
-               IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
+      fprintf (dump_file, "%s()\n", get_name (current_function_decl));
       
       if (dump_flags & TDF_RAW)
         dump_node (fn, TDF_SLIM | dump_flags, dump_file);
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.17
diff -d -u -p -r1.1.4.17 tree-ssa.c
--- tree-ssa.c	17 Sep 2002 19:46:20 -0000	1.1.4.17
+++ tree-ssa.c	23 Sep 2002 02:58:07 -0000
@@ -85,6 +85,9 @@ tree_build_ssa ()
   sbitmap *dfs;
   dominance_info idom;
   
+  /* Debugging dumps.  */
+  dump_file = dump_begin (TDI_ssa, &dump_flags);
+
   /* Compute immediate dominators.  */
   idom = calculate_dominance_info (CDI_DOMINATORS);
 
@@ -99,12 +102,17 @@ tree_build_ssa ()
   sbitmap_vector_free (dfs);
   free_dominance_info (idom);
 
-  /* Debugging dumps.  */
-  dump_file = dump_begin (TDI_ssa, &dump_flags);
-
   if (dump_file)
     {
-      dump_tree_ssa (dump_file);
+      /* FIXME  Default dump should be pretty-printed function with SSA
+	 indices.  */
+
+      if (dump_flags & (TDF_DETAILS))
+	dump_tree_ssa (dump_file);
+
+      if (dump_flags & TDF_STATS)
+	dump_dfa_stats (dump_file);
+
       dump_end (TDI_ssa, dump_file);
     }
 }
@@ -514,10 +522,10 @@ analyze_rdefs ()
 	      prep_stmt (ref_stmt (use));
 	      if (reaching_defs (use)->last == reaching_defs (use)->first)
 		warning ("`%s' is used uninitialized at this point",
-		         IDENTIFIER_POINTER (DECL_NAME (var)));
+		         get_name (var));
 	      else
 		warning ("`%s' may be used uninitialized at this point",
-		         IDENTIFIER_POINTER (DECL_NAME (var)));
+		         get_name (var));
 	    }
 	}
     }
@@ -661,10 +669,8 @@ dump_reaching_defs (dump_file)
 {
   size_t i;
 
-  fprintf (dump_file, ";; Function %s\n\n",
-      IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
-
-  fprintf (dump_file, "Reaching definitions:\n");
+  fprintf (dump_file, "Reaching definitions for %s\n", 
+	   get_name (current_function_decl));
 
   for (i = 0; i < num_referenced_vars; i++)
     {
@@ -707,11 +713,8 @@ dump_tree_ssa (dump_file)
 {
   basic_block bb;
 
-  fputc ('\n', dump_file);
-  fprintf (dump_file, ";; Function %s\n\n",
-      IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
-
-  fputs ("SSA information\n\n", dump_file);
+  fprintf (dump_file, "SSA information for %s\n\n",
+	   get_name (current_function_decl));
 
   FOR_EACH_BB (bb)
     {
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.15
diff -d -u -p -r1.342.2.15 tree.h
--- tree.h	20 Sep 2002 13:27:12 -0000	1.342.2.15
+++ tree.h	23 Sep 2002 02:58:08 -0000
@@ -3097,7 +3097,10 @@ enum tree_dump_index
 #define TDF_ADDRESS	(1 << 0)	/* dump node addresses */
 #define TDF_SLIM	(1 << 1)	/* don't go wild following links */
 #define TDF_RAW  	(1 << 2)	/* unparse the function */
-#define TDF_DETAILS	(1 << 3)	/* show how each statement is simplified */
+#define TDF_DETAILS	(1 << 3)	/* show how each statement is
+					   simplified */
+#define TDF_STATS	(1 << 4)	/* dump various statistics about
+					   each pass */
 #define TDF_REFS	(1 << 0)	/* dump ssa variable refs */
 #define TDF_RDEFS	(1 << 1)	/* dump reaching definitions */
 
@@ -3113,6 +3116,7 @@ extern void dump_enable_all_ssa         
 const char *dump_flag_name	PARAMS ((enum tree_dump_index));
 
 extern int simplify_function_tree      PARAMS ((tree));
+extern const char *get_name            PARAMS ((tree));
 
 /* Redefine abort to report an internal error w/o coredump, and
    reporting the location of the error in the source file.  This logic
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.152.2.18
diff -d -u -p -r1.152.2.18 invoke.texi
--- doc/invoke.texi	20 Sep 2002 13:27:58 -0000	1.152.2.18
+++ doc/invoke.texi	23 Sep 2002 02:58:10 -0000
@@ -3158,6 +3158,9 @@ Print the list of reaching definitions f
 Print a raw representation of the tree.
 @item details
 Enable more detailed dumps (not honored by every dump option).
+@item stats
+Enable dumping various statistics about the pass (not honored by every dump
+option).
 @item all
 Turn on all options.
 @end table


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