Re: [PATCH] Move global range code to value-query.cc.

2021-05-28 Thread Jeff Law via Gcc-patches




On 5/27/2021 2:39 AM, Aldy Hernandez via Gcc-patches wrote:

As discussed...

This patch moves all the global range code from gimple-range.cc into
value-query.cc.  It also moves get_range_info and get_ptr_nonnull from
tree-ssanames.c into their only uses, and removes external access to them.

No functional changes.

Pushed.

gcc/ChangeLog:

* gimple-range.cc (get_range_global): Move to value-query.cc.
(gimple_range_global): Same.
(get_global_range_query): Same.
(global_range_query::range_of_expr): Same.
* gimple-range.h (class global_range_query): Move to
value-query.h.
(gimple_range_global): Same.
* tree-ssanames.c (get_range_info): Move to value-query.cc.
(get_ptr_nonnull): Same.
* tree-ssanames.h (get_range_info): Remove.
(get_ptr_nonnull): Remove.
* value-query.cc (get_ssa_name_range_info): Move from
tree-ssanames.c.
(get_ssa_name_ptr_info_nonnull): Same.
(get_range_global): Move from gimple-range.cc.
(gimple_range_global): Same.
(get_global_range_query): Same.
(global_range_query::range_of_expr): Same.
* value-query.h (class global_range_query): Move from
gimple-range.h.
(gimple_range_global): Same.

OK
jeff



[PATCH] Move global range code to value-query.cc.

2021-05-27 Thread Aldy Hernandez via Gcc-patches
As discussed...

This patch moves all the global range code from gimple-range.cc into
value-query.cc.  It also moves get_range_info and get_ptr_nonnull from
tree-ssanames.c into their only uses, and removes external access to them.

No functional changes.

Pushed.

gcc/ChangeLog:

* gimple-range.cc (get_range_global): Move to value-query.cc.
(gimple_range_global): Same.
(get_global_range_query): Same.
(global_range_query::range_of_expr): Same.
* gimple-range.h (class global_range_query): Move to
value-query.h.
(gimple_range_global): Same.
* tree-ssanames.c (get_range_info): Move to value-query.cc.
(get_ptr_nonnull): Same.
* tree-ssanames.h (get_range_info): Remove.
(get_ptr_nonnull): Remove.
* value-query.cc (get_ssa_name_range_info): Move from
tree-ssanames.c.
(get_ssa_name_ptr_info_nonnull): Same.
(get_range_global): Move from gimple-range.cc.
(gimple_range_global): Same.
(get_global_range_query): Same.
(global_range_query::range_of_expr): Same.
* value-query.h (class global_range_query): Move from
gimple-range.h.
(gimple_range_global): Same.
---
 gcc/gimple-range.cc | 103 ---
 gcc/gimple-range.h  |  11 
 gcc/tree-ssanames.c |  44 -
 gcc/tree-ssanames.h |   3 -
 gcc/value-query.cc  | 147 
 gcc/value-query.h   |  11 
 6 files changed, 158 insertions(+), 161 deletions(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index e351a841583..b4dfaa92168 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -1441,109 +1441,6 @@ trace_ranger::range_of_expr (irange &r, tree name, 
gimple *s)
   return trailer (idx, "range_of_expr", res, name, r);
 }
 
-// Return the legacy global range for NAME if it has one, otherwise
-// return VARYING.
-
-static void
-get_range_global (irange &r, tree name)
-{
-  tree type = TREE_TYPE (name);
-
-  if (SSA_NAME_IS_DEFAULT_DEF (name))
-{
-  tree sym = SSA_NAME_VAR (name);
-  // Adapted from vr_values::get_lattice_entry().
-  // Use a range from an SSA_NAME's available range.
-  if (TREE_CODE (sym) == PARM_DECL)
-   {
- // Try to use the "nonnull" attribute to create ~[0, 0]
- // anti-ranges for pointers.  Note that this is only valid with
- // default definitions of PARM_DECLs.
- if (POINTER_TYPE_P (type)
- && ((cfun && nonnull_arg_p (sym)) || get_ptr_nonnull (name)))
-   r.set_nonzero (type);
- else if (INTEGRAL_TYPE_P (type))
-   {
- get_range_info (name, r);
- if (r.undefined_p ())
-   r.set_varying (type);
-   }
- else
-   r.set_varying (type);
-   }
-  // If this is a local automatic with no definition, use undefined.
-  else if (TREE_CODE (sym) != RESULT_DECL)
-   r.set_undefined ();
-  else
-   r.set_varying (type);
-   }
-  else if (!POINTER_TYPE_P (type) && SSA_NAME_RANGE_INFO (name))
-{
-  get_range_info (name, r);
-  if (r.undefined_p ())
-   r.set_varying (type);
-}
-  else if (POINTER_TYPE_P (type) && SSA_NAME_PTR_INFO (name))
-{
-  if (get_ptr_nonnull (name))
-   r.set_nonzero (type);
-  else
-   r.set_varying (type);
-}
-  else
-r.set_varying (type);
-}
-
-// ?? Like above, but only for default definitions of NAME.  This is
-// so VRP passes using ranger do not start with known ranges,
-// otherwise we'd eliminate builtin_unreachables too early because of
-// inlining.
-//
-// Without this restriction, the test in g++.dg/tree-ssa/pr61034.C has
-// all of its unreachable calls removed too early.  We should
-// investigate whether we should just adjust the test above.
-
-value_range
-gimple_range_global (tree name)
-{
-  gcc_checking_assert (gimple_range_ssa_p (name));
-  tree type = TREE_TYPE (name);
-
-  if (SSA_NAME_IS_DEFAULT_DEF (name))
-{
-  value_range vr;
-  get_range_global (vr, name);
-  return vr;
-}
-  return value_range (type);
-}
-
-// --
-// global_range_query implementation.
-
-global_range_query global_ranges;
-
-// Like get_range_query, but for accessing global ranges.
-
-range_query *
-get_global_range_query ()
-{
-  return &global_ranges;
-}
-
-bool
-global_range_query::range_of_expr (irange &r, tree expr, gimple *)
-{
-  tree type = TREE_TYPE (expr);
-
-  if (!irange::supports_type_p (type) || !gimple_range_ssa_p (expr))
-return get_tree_range (r, expr);
-
-  get_range_global (r, expr);
-
-  return true;
-}
-
 gimple_ranger *
 enable_ranger (struct function *fun)
 {
diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h
index 23734c6e226..ecd332a3c54 100644
--- a/gcc/gimple-range.h
+++ b/gcc/gimple-range.h
@@ -252,17 +252,6 @@ private:
 // Flag to enable debugging the various internal Caches