diff options
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. */ |