These are aids to help in debugging ranger based passes. I find the ability to dump the current ranger knowledge for the function being debugged invaluable during development. Similarly for subsets of the CFG.
Tested with a bootstrap and regtest, as well as countless sessions in gdb :). OK? gcc/ChangeLog: * gimple-range.cc (debug_seed_ranger): New. (dump_ranger): New. (debug_ranger): New. --- gcc/gimple-range.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index b534b8e0a2c..2a0da417708 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -1661,4 +1661,75 @@ disable_ranger (struct function *fun) fun->x_range_query = &global_ranges; } +// ========================================= +// Debugging helpers. +// ========================================= + +// Query all statements in the IL to precalculate computable ranges in RANGER. + +static DEBUG_FUNCTION void +debug_seed_ranger (gimple_ranger &ranger) +{ + // Recalculate SCEV to make sure the dump lists everything. + if (scev_initialized_p ()) + { + scev_finalize (); + scev_initialize (); + } + + basic_block bb; + int_range_max r; + FOR_EACH_BB_FN (bb, cfun) + { + gimple *last = last_stmt (bb); + if (last && gimple_get_lhs (last)) + ranger.range_of_stmt (r, last); + } +} + +// Dump all that ranger knows for the current function. + +DEBUG_FUNCTION void +dump_ranger (FILE *out) +{ + gimple_ranger ranger; + debug_seed_ranger (ranger); + ranger.dump (out); +} + +DEBUG_FUNCTION void +debug_ranger () +{ + dump_ranger (stderr); +} + +// Dump all that ranger knows on a path of BBs. + +DEBUG_FUNCTION void +dump_ranger (FILE *dump_file, const vec<basic_block> &path) +{ + if (path.length () == 0) + { + fprintf (dump_file, "empty\n"); + return; + } + + gimple_ranger ranger; + debug_seed_ranger (ranger); + + unsigned i = path.length (); + do + { + i--; + ranger.dump_bb (dump_file, path[i]); + } + while (i > 0); +} + +DEBUG_FUNCTION void +debug_ranger (const vec<basic_block> &path) +{ + dump_ranger (stderr, path); +} + #include "gimple-range-tests.cc" -- 2.31.1