diff options
author | Joern Rennecke <joern.rennecke@embecosm.com> | 2010-07-13 21:55:57 +0000 |
---|---|---|
committer | Joern Rennecke <amylaar@gcc.gnu.org> | 2010-07-13 22:55:57 +0100 |
commit | c31c32f95917cef39e066fd8964abc55c3d5aeac (patch) | |
tree | 78e64b469ad027c41fccce9021395470fd154b69 /gcc/tree-ssa-live.c | |
parent | 5bca11c4efc6271558e920c5a2395bc27ea18e74 (diff) | |
download | gcc-c31c32f95917cef39e066fd8964abc55c3d5aeac.tar.gz |
re PR other/44874 (TDF_NOUID dumps miss information about DECL_UID ordering)
gcc:
PR other/44874
* tree-dump.c (dump_options): Add enumerate_locals entry.
Add TDF_NOID exclusion to all entry.
* tree-dump.h (dump_enumerated_decls): Declare.
* tree-pretty-print.c (dump_generic_node): For TDF_NOID,
Don't display type uid.
(print_declaration): Don't crash on TREE_TYPE (t) == 0.
* tree-pass.h (TDF_ENUMERATE_LOCALS): Define.
* tree-ssa-live.c: Include gimple.h.
(numbered_tree_d): New struct.
(numbered_tree): New typedef.
(DEF_VEC_O (numbered_tree): New.
(DEF_VEC_ALLOC_O (numbered_tree, heap)): Likewise.
(compare_decls_by_uid, dump_enumerated_decls_push): New functions.
(dump_enumerated_decls): Likewise.
* tree-optimize.c (execute_cleanup_cfg_post_optimizing): If comparing
debug info and flag_dump_final_insns, call dump_enumerated_decls.
* tree-cfg.c (dump_function_to_file): Call dump_enumerated_decls.
* Makefile.in (tree-ssa-live.o): Depend on $(GIMPLE_H).
gcc/testsuite:
PR other/44874
PR debug/44832
* c-c++-common/pr44832.c: New test.
From-SVN: r162156
Diffstat (limited to 'gcc/tree-ssa-live.c')
-rw-r--r-- | gcc/tree-ssa-live.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c index ab79d7f327e..fcd277951fb 100644 --- a/gcc/tree-ssa-live.c +++ b/gcc/tree-ssa-live.c @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see #include "toplev.h" #include "debug.h" #include "flags.h" +#include "gimple.h" #ifdef ENABLE_CHECKING static void verify_live_on_entry (tree_live_info_p); @@ -1196,6 +1197,96 @@ dump_live_info (FILE *f, tree_live_info_p live, int flag) } } +struct GTY(()) numbered_tree_d +{ + tree t; + int num; +}; +typedef struct numbered_tree_d numbered_tree; + +DEF_VEC_O (numbered_tree); +DEF_VEC_ALLOC_O (numbered_tree, heap); + +/* Compare two declarations references by their DECL_UID / sequence number. + Called via qsort. */ + +static int +compare_decls_by_uid (const void *pa, const void *pb) +{ + const numbered_tree *nt_a = ((const numbered_tree *)pa); + const numbered_tree *nt_b = ((const numbered_tree *)pb); + + if (DECL_UID (nt_a->t) != DECL_UID (nt_b->t)) + return DECL_UID (nt_a->t) - DECL_UID (nt_b->t); + return nt_a->num - nt_b->num; +} + +/* Called via walk_gimple_stmt / walk_gimple_op by dump_enumerated_decls. */ +static tree +dump_enumerated_decls_push (tree *tp, int *walk_subtrees, void *data) +{ + struct walk_stmt_info *wi = (struct walk_stmt_info *) data; + VEC (numbered_tree, heap) **list = (VEC (numbered_tree, heap) **) &wi->info; + numbered_tree nt; + + if (!DECL_P (*tp)) + return NULL_TREE; + nt.t = *tp; + nt.num = VEC_length (numbered_tree, *list); + VEC_safe_push (numbered_tree, heap, *list, &nt); + *walk_subtrees = 0; + return NULL_TREE; +} + +/* Find all the declarations used by the current function, sort them by uid, + and emit the sorted list. Each declaration is tagged with a sequence + number indicating when it was found during statement / tree walking, + so that TDF_NOUID comparisons of anonymous declarations are still + meaningful. Where a declaration was encountered more than once, we + emit only the sequence number of the first encounter. + FILE is the dump file where to output the list and FLAGS is as in + print_generic_expr. */ +void +dump_enumerated_decls (FILE *file, int flags) +{ + basic_block bb; + struct walk_stmt_info wi; + VEC (numbered_tree, heap) *decl_list = VEC_alloc (numbered_tree, heap, 40); + + wi.info = (void*) decl_list; + wi.pset = NULL; + FOR_EACH_BB (bb) + { + gimple_stmt_iterator gsi; + + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + if (!is_gimple_debug (gsi_stmt (gsi))) + walk_gimple_stmt (&gsi, NULL, dump_enumerated_decls_push, &wi); + } + decl_list = (VEC (numbered_tree, heap) *) wi.info; + qsort (VEC_address (numbered_tree, decl_list), + VEC_length (numbered_tree, decl_list), + sizeof (numbered_tree), compare_decls_by_uid); + if (VEC_length (numbered_tree, decl_list)) + { + unsigned ix; + numbered_tree *ntp; + tree last = NULL_TREE; + + fprintf (file, "Declarations used by %s, sorted by DECL_UID:\n", + current_function_name ()); + for (ix = 0; VEC_iterate (numbered_tree, decl_list, ix, ntp); ix++) + { + if (ntp->t == last) + continue; + fprintf (file, "%d: ", ntp->num); + print_generic_decl (file, ntp->t, flags); + fprintf (file, "\n"); + last = ntp->t; + } + } + VEC_free (numbered_tree, heap, decl_list); +} #ifdef ENABLE_CHECKING /* Verify that SSA_VAR is a non-virtual SSA_NAME. */ |