public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1087] Move global range code to value-query.cc.
@ 2021-05-27  8:41 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-05-27  8:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:13dbaefefbab04d5137e718262d4b81cb9035784

commit r12-1087-g13dbaefefbab04d5137e718262d4b81cb9035784
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed May 26 08:25:36 2021 +0200

    Move global range code to value-query.cc.
    
    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.
    
    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.

Diff:
---
 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.
 #define DEBUG_RANGE_CACHE (dump_file && (param_evrp_mode & EVRP_MODE_DEBUG))
 
-// Global ranges for SSA names using SSA_NAME_RANGE_INFO.
-
-class global_range_query : public range_query
-{
-public:
-  bool range_of_expr (irange &r, tree expr, gimple * = NULL) OVERRIDE;
-};
-
-extern global_range_query global_ranges;
-extern value_range gimple_range_global (tree name);
-
 extern gimple_ranger *enable_ranger (struct function *);
 extern void disable_ranger (struct function *);
 
diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c
index 5329c0a4187..2165ad71cf3 100644
--- a/gcc/tree-ssanames.c
+++ b/gcc/tree-ssanames.c
@@ -423,31 +423,6 @@ set_range_info (tree name, const value_range &vr)
   set_range_info (name, vr.kind (), min, max);
 }
 
-/* Gets range information corresponding to ssa_name NAME and stores it
-   in a value_range VR.  Returns the value_range_kind.  */
-
-enum value_range_kind
-get_range_info (const_tree name, irange &vr)
-{
-  tree type = TREE_TYPE (name);
-  gcc_checking_assert (!POINTER_TYPE_P (type));
-  gcc_checking_assert (TREE_CODE (name) == SSA_NAME);
-
-  range_info_def *ri = SSA_NAME_RANGE_INFO (name);
-
-  /* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
-     with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision.  */
-  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (name)))
-	      > 2 * HOST_BITS_PER_WIDE_INT))
-    vr.set_varying (type);
-  else
-    vr.set (wide_int_to_tree (type, ri->get_min ()),
-	    wide_int_to_tree (type, ri->get_max ()),
-	    SSA_NAME_RANGE_TYPE (name));
-
-  return vr.kind ();
-}
-
 /* Set nonnull attribute to pointer NAME.  */
 
 void
@@ -458,25 +433,6 @@ set_ptr_nonnull (tree name)
   pi->pt.null = 0;
 }
 
-/* Return nonnull attribute of pointer NAME.  */
-bool
-get_ptr_nonnull (const_tree name)
-{
-  gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
-  struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
-  if (pi == NULL)
-    return false;
-  /* TODO Now pt->null is conservatively set to true in PTA
-     analysis. vrp is the only pass (including ipa-vrp)
-     that clears pt.null via set_ptr_nonull when it knows
-     for sure. PTA will preserves the pt.null value set by VRP.
-
-     When PTA analysis is improved, pt.anything, pt.nonlocal
-     and pt.escaped may also has to be considered before
-     deciding that pointer cannot point to NULL.  */
-  return !pi->pt.null;
-}
-
 /* Change non-zero bits bitmask of NAME.  */
 
 void
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index 166f921f04c..ac880f3a67a 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -70,8 +70,6 @@ struct GTY ((variable_size)) range_info_def {
 extern void set_range_info (tree, enum value_range_kind, const wide_int_ref &,
 			    const wide_int_ref &);
 extern void set_range_info (tree, const value_range &);
-/* Gets the value range from SSA.  */
-extern enum value_range_kind get_range_info (const_tree, irange &);
 extern void set_nonzero_bits (tree, const wide_int_ref &);
 extern wide_int get_nonzero_bits (const_tree);
 extern bool ssa_name_has_boolean_range (tree);
@@ -90,7 +88,6 @@ extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int,
 extern void adjust_ptr_info_misalignment (struct ptr_info_def *, poly_uint64);
 extern struct ptr_info_def *get_ptr_info (tree);
 extern void set_ptr_nonnull (tree);
-extern bool get_ptr_nonnull (const_tree);
 
 extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
 extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index 509d2d33cc5..f8b457d362c 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "value-range-equiv.h"
 #include "value-query.h"
 #include "alloc-pool.h"
+#include "gimple-range.h"
 
 // value_query default methods.
 
@@ -180,3 +181,149 @@ range_query::~range_query ()
   equiv_alloc->release ();
   delete equiv_alloc;
 }
+
+// Return the range for NAME from SSA_NAME_RANGE_INFO.
+
+static inline void
+get_ssa_name_range_info (irange &r, const_tree name)
+{
+  tree type = TREE_TYPE (name);
+  gcc_checking_assert (!POINTER_TYPE_P (type));
+  gcc_checking_assert (TREE_CODE (name) == SSA_NAME);
+
+  range_info_def *ri = SSA_NAME_RANGE_INFO (name);
+
+  // Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
+  // with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision.
+  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (name)))
+	      > 2 * HOST_BITS_PER_WIDE_INT))
+    r.set_varying (type);
+  else
+    r.set (wide_int_to_tree (type, ri->get_min ()),
+	   wide_int_to_tree (type, ri->get_max ()),
+	   SSA_NAME_RANGE_TYPE (name));
+}
+
+// Return nonnull attribute of pointer NAME from SSA_NAME_PTR_INFO.
+
+static inline bool
+get_ssa_name_ptr_info_nonnull (const_tree name)
+{
+  gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
+  struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
+  if (pi == NULL)
+    return false;
+  /* TODO Now pt->null is conservatively set to true in PTA
+     analysis. vrp is the only pass (including ipa-vrp)
+     that clears pt.null via set_ptr_nonull when it knows
+     for sure. PTA will preserves the pt.null value set by VRP.
+
+     When PTA analysis is improved, pt.anything, pt.nonlocal
+     and pt.escaped may also has to be considered before
+     deciding that pointer cannot point to NULL.  */
+  return !pi->pt.null;
+}
+
+// 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_ssa_name_ptr_info_nonnull (name)))
+	    r.set_nonzero (type);
+	  else if (INTEGRAL_TYPE_P (type))
+	    {
+	      get_ssa_name_range_info (r, name);
+	      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_ssa_name_range_info (r, name);
+      if (r.undefined_p ())
+	r.set_varying (type);
+    }
+  else if (POINTER_TYPE_P (type) && SSA_NAME_PTR_INFO (name))
+    {
+      if (get_ssa_name_ptr_info_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;
+}
diff --git a/gcc/value-query.h b/gcc/value-query.h
index 5eff9317ed5..97da6637747 100644
--- a/gcc/value-query.h
+++ b/gcc/value-query.h
@@ -105,4 +105,15 @@ private:
   class equiv_allocator *equiv_alloc;
 };
 
+// Global ranges for SSA names using SSA_NAME_RANGE_INFO.
+
+class global_range_query : public range_query
+{
+public:
+  bool range_of_expr (irange &r, tree expr, gimple * = NULL) OVERRIDE;
+};
+
+extern global_range_query global_ranges;
+extern value_range gimple_range_global (tree name);
+
 #endif // GCC_QUERY_H


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-27  8:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27  8:41 [gcc r12-1087] Move global range code to value-query.cc Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).