From b7cff112b4a3ee950b22abaa2218485140e945bd Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 17 Jun 2024 16:07:16 -0400
Subject: [PATCH 3/5] Print "Global Exported" to dump_file from set_range_info.
* gimple-range.cc (gimple_ranger::register_inferred_ranges): Do not
dump global range info after set_range_info.
(gimple_ranger::register_transitive_inferred_ranges): Likewise.
(dom_ranger::range_of_stmt): Likewise.
* tree-ssanames.cc (set_range_info): If global range info
changes, maybe print new range to dump_file.
* tree-vrp.cc (remove_unreachable::handle_early): Do not
dump global range info after set_range_info.
(remove_unreachable::remove): Likewise.
(remove_unreachable::remove_and_update_globals): Likewise.
(pass_assumptions::execute): Likewise.
---
gcc/gimple-range.cc | 60 ++++++++++++--------------------------------
gcc/tree-ssanames.cc | 42 ++++++++++++++++++++-----------
gcc/tree-vrp.cc | 43 +++----------------------------
3 files changed, 47 insertions(+), 98 deletions(-)
@@ -495,15 +495,8 @@ gimple_ranger::register_inferred_ranges (gimple *s)
if (lhs)
{
value_range tmp (TREE_TYPE (lhs));
- if (range_of_stmt (tmp, s, lhs) && !tmp.varying_p ()
- && set_range_info (lhs, tmp) && dump_file)
- {
- fprintf (dump_file, "Global Exported: ");
- print_generic_expr (dump_file, lhs, TDF_SLIM);
- fprintf (dump_file, " = ");
- tmp.dump (dump_file);
- fputc ('\n', dump_file);
- }
+ if (range_of_stmt (tmp, s, lhs) && !tmp.varying_p ())
+ set_range_info (lhs, tmp);
}
m_cache.apply_inferred_ranges (s);
}
@@ -562,38 +555,25 @@ gimple_ranger::register_transitive_inferred_ranges (basic_block bb)
void
gimple_ranger::export_global_ranges ()
{
- /* Cleared after the table header has been printed. */
- bool print_header = true;
+ if (dump_file)
+ {
+ /* Print the header only when there's something else
+ to print below. */
+ fprintf (dump_file, "Exporting new global ranges:\n");
+ fprintf (dump_file, "============================\n");
+ }
for (unsigned x = 1; x < num_ssa_names; x++)
{
tree name = ssa_name (x);
if (!name)
continue;
value_range r (TREE_TYPE (name));
- if (name && !SSA_NAME_IN_FREE_LIST (name)
- && gimple_range_ssa_p (name)
- && m_cache.get_global_range (r, name)
- && !r.varying_p())
- {
- bool updated = set_range_info (name, r);
- if (!updated || !dump_file)
- continue;
-
- if (print_header)
- {
- /* Print the header only when there's something else
- to print below. */
- fprintf (dump_file, "Exported global range table:\n");
- fprintf (dump_file, "============================\n");
- print_header = false;
- }
-
- print_generic_expr (dump_file, name , TDF_SLIM);
- fprintf (dump_file, " : ");
- r.dump (dump_file);
- fprintf (dump_file, "\n");
- }
+ if (name && !SSA_NAME_IN_FREE_LIST (name) && gimple_range_ssa_p (name)
+ && m_cache.get_global_range (r, name) && !r.varying_p())
+ set_range_info (name, r);
}
+ if (dump_file)
+ fprintf (dump_file, "========= Done =============\n");
}
// Print the known table values to file F.
@@ -1069,16 +1049,8 @@ dom_ranger::range_of_stmt (vrange &r, gimple *s, tree name)
// If there is a new calculated range and it is not varying, set
// a global range.
if (ret && name && m_global.merge_range (name, r) && !r.varying_p ())
- {
- if (set_range_info (name, r) && dump_file)
- {
- fprintf (dump_file, "Global Exported: ");
- print_generic_expr (dump_file, name, TDF_SLIM);
- fprintf (dump_file, " = ");
- r.dump (dump_file);
- fputc ('\n', dump_file);
- }
- }
+ set_range_info (name, r);
+
if (idx)
tracer.trailer (idx, " ", ret, name, r);
return ret;
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimple.h"
#include "tree-pass.h"
#include "ssa.h"
+#include "gimple-pretty-print.h"
#include "gimple-iterator.h"
#include "stor-layout.h"
#include "tree-into-ssa.h"
@@ -425,23 +426,34 @@ set_range_info (tree name, const vrange &r)
struct ptr_info_def *pi = get_ptr_info (name);
// If R is nonnull and pi is not, set nonnull.
if (r.nonzero_p () && (!pi || pi->pt.null))
- {
- set_ptr_nonnull (name);
- return true;
- }
- return false;
+ set_ptr_nonnull (name);
+ else
+ return false;
}
-
- value_range tmp (type);
- if (range_info_p (name))
- range_info_get_range (name, tmp);
else
- tmp.set_varying (type);
- // If the result doesn't change, or is undefined, return false.
- if (!tmp.intersect (r) || tmp.undefined_p ())
- return false;
-
- return range_info_set_range (name, tmp);
+ {
+ value_range tmp (type);
+ if (range_info_p (name))
+ range_info_get_range (name, tmp);
+ else
+ tmp.set_varying (type);
+ // If the result doesn't change, or is undefined, return false.
+ if (!tmp.intersect (r) || tmp.undefined_p ())
+ return false;
+ if (!range_info_set_range (name, tmp))
+ return false;
+ }
+ if (dump_file)
+ {
+ value_range tmp (type);
+ fprintf (dump_file, "Global Exported: ");
+ print_generic_expr (dump_file, name, TDF_SLIM);
+ fprintf (dump_file, " = ");
+ gimple_range_global (tmp, name);
+ tmp.dump (dump_file);
+ fputc ('\n', dump_file);
+ }
+ return true;
}
/* Set nonnull attribute to pointer NAME. */
@@ -228,15 +228,6 @@ remove_unreachable::handle_early (gimple *s, edge e)
// Nothing at this late stage we can do if the write fails.
if (!set_range_info (name, r))
continue;
- if (dump_file)
- {
- fprintf (dump_file, "Global Exported (via early unreachable): ");
- print_generic_expr (dump_file, name, TDF_SLIM);
- fprintf (dump_file, " = ");
- gimple_range_global (r, name);
- r.dump (dump_file);
- fputc ('\n', dump_file);
- }
}
tree ssa = lhs_p ? gimple_cond_lhs (s) : gimple_cond_rhs (s);
@@ -287,16 +278,8 @@ remove_unreachable::remove ()
if (name && fully_replaceable (name, src))
{
value_range r (TREE_TYPE (name));
- if (gori_name_on_edge (r, name, e, &m_ranger)
- && set_range_info (name, r) &&(dump_file))
- {
- fprintf (dump_file, "Global Exported (via unreachable): ");
- print_generic_expr (dump_file, name, TDF_SLIM);
- fprintf (dump_file, " = ");
- gimple_range_global (r, name);
- r.dump (dump_file);
- fputc ('\n', dump_file);
- }
+ if (gori_name_on_edge (r, name, e, &m_ranger))
+ set_range_info (name, r);
}
change = true;
@@ -419,15 +402,6 @@ remove_unreachable::remove_and_update_globals ()
if (!set_range_info (name, r))
continue;
change = true;
- if (dump_file)
- {
- fprintf (dump_file, "Global Exported (via unreachable): ");
- print_generic_expr (dump_file, name, TDF_SLIM);
- fprintf (dump_file, " = ");
- gimple_range_global (r, name);
- r.dump (dump_file);
- fputc ('\n', dump_file);
- }
}
return change;
}
@@ -1404,18 +1378,9 @@ public:
if (!value_range::supports_type_p (type))
continue;
value_range assume_range (type);
+ // Set the global range of NAME to anything calculated.
if (query.assume_range_p (assume_range, name))
- {
- // Set the global range of NAME to anything calculated.
- set_range_info (name, assume_range);
- if (dump_file)
- {
- print_generic_expr (dump_file, name, TDF_SLIM);
- fprintf (dump_file, " -> ");
- assume_range.dump (dump_file);
- fputc ('\n', dump_file);
- }
- }
+ set_range_info (name, assume_range);
}
if (dump_file)
{
--
2.45.0