From 47ea02bb862d6be9a200ebccbd5d64b31a003ec2 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 31 May 2021 16:00:16 -0400 Subject: Move Ranger cache to range-query and fur_source model. Flatten and simplify gori-computes. Tweak debug output. range-cache now provides range_of_expr and range_on_edge in the standard formats, but in a "query what you have" mode rather than "go figure out anything that is missing" mode. * gimple-range-cache.cc (ranger_cache::ranger_cache): Adjust for gori_compute being a member rather than base class. dervied call to member call. (ranger_cache::dump): No longer dump gori_map. (ranger_cache::dump_bb): New. (ranger_cache::get_non_stale_global_range): Adjust for gori_compute being a member rather than base class. (ranger_cache::set_global_range): Ditto. (ranger_cache::ssa_range_in_bb): Ditto. (ranger_cache::range_of_expr): New. (ranger_cache::range_on_edge): New. (ranger_cache::block_range): Adjust for gori_computes. Debug changes. (ranger_cache::propagate_cache): Adjust debugging output. (ranger_cache::fill_block_cache): Adjust for gori_computes. Debug output changes. * gimple-range-cache.h (class ranger_cache): Make gori_compute a member, and inherit from range_query instead. (ranger_cache::dump_bb): New. split from dump. * gimple-range-gori.cc (gori_compute::ssa_range_in_bb): Delete. (gori_compute::expr_range_at_stmt): Delete. (gori_compute::compute_name_range_op): Delete. (gori_compute::compute_operand_range_switch): Add fur_source. (gori_compute::compute_operand_range): Add fur_source param, inline old compute_name_range_op and optimize_logical_operands. (struct tf_range): Delete. (gori_compute::logical_combine): Adjust (gori_compute::optimize_logical_operands): Delete. (gori_compute::compute_logical_operands_in_chain): Delete. (gori_compute::compute_logical_operands): Adjust. (gori_compute::compute_operand1_range): Adjust to fur_source. (gori_compute::compute_operand2_range): Ditto. (gori_compute::compute_operand1_and_operand2_range): Ditto. (gori_compute::outgoing_edge_range_p): Add range_query parameter, and adjust to fur_source. * gimple-range-gori.h (class gori_compute): Simplify and adjust to range_query and fur_source. * gimple-range.cc (gimple_ranger::range_on_edge): Query range_on_edge from the ranger_cache.. (gimple_ranger::fold_range_internal): Adjust to base class change of ranger_cache. (gimple_ranger::dump_bb): Adjust dump. * gimple-range.h (gimple_ranger):export gori computes object. --- gcc/gimple-range-cache.cc | 79 ++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 28 deletions(-) (limited to 'gcc/gimple-range-cache.cc') diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index ef3bc04..e776bed 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -583,7 +583,7 @@ ranger_cache::ranger_cache (gimple_ranger &q) : query (q) { basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); if (bb) - exports (bb); + m_gori.exports (bb); } } @@ -599,22 +599,18 @@ ranger_cache::~ranger_cache () // gori map as well. void -ranger_cache::dump (FILE *f, bool gori_dump) +ranger_cache::dump (FILE *f) { m_globals.dump (f); - if (gori_dump) - { - fprintf (f, "\nDUMPING GORI MAP\n"); - gori_compute::dump (f); - } fprintf (f, "\n"); } // Dump the caches for basic block BB to file F. void -ranger_cache::dump (FILE *f, basic_block bb) +ranger_cache::dump_bb (FILE *f, basic_block bb) { + m_gori.gori_map::dump (f, bb, false); m_on_entry.dump (f, bb); } @@ -641,7 +637,8 @@ ranger_cache::get_non_stale_global_range (irange &r, tree name) { // Use this value if the range is constant or current. if (r.singleton_p () - || m_temporal->current_p (name, depend1 (name), depend2 (name))) + || m_temporal->current_p (name, m_gori.depend1 (name), + m_gori.depend2 (name))) return true; } else @@ -681,7 +678,7 @@ ranger_cache::set_global_range (tree name, const irange &r) if (r.singleton_p () || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ())) - set_range_invariant (name); + m_gori.set_range_invariant (name); m_temporal->set_timestamp (name); } @@ -745,7 +742,7 @@ ranger_cache::ssa_range_in_bb (irange &r, tree name, basic_block bb) // If it has no entry but should, then mark this as a poor value. // Its not a poor value if it does not have *any* edge ranges, // Then global range is as good as it gets. - if (has_edge_range_p (name) && push_poor_value (bb, name)) + if (m_gori.has_edge_range_p (name) && push_poor_value (bb, name)) { if (DEBUG_RANGE_CACHE) { @@ -759,7 +756,6 @@ ranger_cache::ssa_range_in_bb (irange &r, tree name, basic_block bb) if (!m_globals.get_global_range (r, name)) r = gimple_range_global (name); } - // Check if pointers have any non-null dereferences. Non-call // exceptions mean we could throw in the middle of the block, so just // punt for now on those. @@ -768,6 +764,29 @@ ranger_cache::ssa_range_in_bb (irange &r, tree name, basic_block bb) r = range_nonzero (TREE_TYPE (name)); } +// Implement range_of_expr. + +bool +ranger_cache::range_of_expr (irange &r, tree expr, gimple *stmt) +{ + if (gimple_range_ssa_p (expr)) + ssa_range_in_bb (r, expr, gimple_bb (stmt)); + else + get_tree_range (r, expr); + return true; +} + +// Implement range_on_edge which returns true ONLY if there is a range +// calculated. + +bool +ranger_cache::range_on_edge (irange &r, edge e, tree expr) +{ + if (gimple_range_ssa_p (expr)) + return m_gori.outgoing_edge_range_p (r, e, expr, *this); + return false; +} + // Return a static range for NAME on entry to basic block BB in R. If // calc is true, fill any cache entries required between BB and the // def block for NAME. Otherwise, return false if the cache is empty. @@ -779,7 +798,7 @@ ranger_cache::block_range (irange &r, basic_block bb, tree name, bool calc) // If there are no range calculations anywhere in the IL, global range // applies everywhere, so don't bother caching it. - if (!has_edge_range_p (name)) + if (!m_gori.has_edge_range_p (name)) return false; if (calc) @@ -842,6 +861,15 @@ ranger_cache::propagate_cache (tree name) gcc_checking_assert (m_on_entry.bb_range_p (name, bb)); m_on_entry.get_bb_range (current_range, name, bb); + if (DEBUG_RANGE_CACHE) + { + fprintf (dump_file, "FWD visiting block %d for ", bb->index); + print_generic_expr (dump_file, name, TDF_SLIM); + fprintf (dump_file, " starting range : "); + current_range.dump (dump_file); + fprintf (dump_file, "\n"); + } + // Calculate the "new" range on entry by unioning the pred edges. new_range.set_undefined (); FOR_EACH_EDGE (e, ei, bb->preds) @@ -849,13 +877,13 @@ ranger_cache::propagate_cache (tree name) if (DEBUG_RANGE_CACHE) fprintf (dump_file, " edge %d->%d :", e->src->index, bb->index); // Get whatever range we can for this edge. - if (!outgoing_edge_range_p (e_range, e, name)) + if (!m_gori.outgoing_edge_range_p (e_range, e, name, *this)) { ssa_range_in_bb (e_range, name, e->src); if (DEBUG_RANGE_CACHE) { fprintf (dump_file, "No outgoing edge range, picked up "); - e_range.dump(dump_file); + e_range.dump (dump_file); fprintf (dump_file, "\n"); } } @@ -864,7 +892,7 @@ ranger_cache::propagate_cache (tree name) if (DEBUG_RANGE_CACHE) { fprintf (dump_file, "outgoing range :"); - e_range.dump(dump_file); + e_range.dump (dump_file); fprintf (dump_file, "\n"); } } @@ -873,15 +901,6 @@ ranger_cache::propagate_cache (tree name) break; } - if (DEBUG_RANGE_CACHE) - { - fprintf (dump_file, "FWD visiting block %d for ", bb->index); - print_generic_expr (dump_file, name, TDF_SLIM); - fprintf (dump_file, " starting range : "); - current_range.dump (dump_file); - fprintf (dump_file, "\n"); - } - // If the range on entry has changed, update it. if (new_range != current_range) { @@ -1042,8 +1061,12 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) if (m_on_entry.get_bb_range (r, name, pred)) { if (DEBUG_RANGE_CACHE) - fprintf (dump_file, "has cache, "); - if (!r.undefined_p () || has_edge_range_p (name, e)) + { + fprintf (dump_file, "has cache, "); + r.dump (dump_file); + fprintf (dump_file, ", "); + } + if (!r.undefined_p () || m_gori.has_edge_range_p (name, e)) { add_to_update (node); if (DEBUG_RANGE_CACHE) @@ -1053,7 +1076,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) } if (DEBUG_RANGE_CACHE) - fprintf (dump_file, "pushing undefined pred block. "); + fprintf (dump_file, "pushing undefined pred block.\n"); // If the pred hasn't been visited (has no range), add it to // the list. gcc_checking_assert (!m_on_entry.bb_range_p (name, pred)); -- cgit v1.1