This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] tree-vrp: add "const" qualifier to various value_range pointers


Adding "const" to these indicates to both humans and the compiler in which
direction information is intended to flow.  For example, compare:
  extract_range_from_binary_expr_1, which takes two vr and modifies a third
with:
  ranges_from_anti_range, which takes one and modifies two others.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
	* tree-vrp.c (copy_value_range): Convert param "from" from
	"value_range *" to "const value_range *".
	(range_is_nonnull): Likewise for param "vr".
	(range_is_null): Likewise.
	(range_int_cst_p): Likewise.
	(range_int_cst_singleton_p): Likewise.
	(symbolic_range_p): Likewise.
	(value_ranges_intersect_p): Likewise for both params.
	(value_range_nonnegative_p): Likewise for param "vr".
	(value_range_constant_singleton): Likewise.
	(vrp_set_zero_nonzero_bits): Likewise for param "ar".
	(extract_range_into_wide_ints): Likewise for param "vr".
	(extract_range_from_multiplicative_op): Likewise for params "vr0"
	and "vr1".
	(vrp_can_optimize_bit_op): Likewise.
	(extract_range_from_binary_expr_1): Likewise for params "vr0_" and
	"vr1_".
	(extract_range_from_unary_expr): Likewise.
	(debug_value_range): Likewise for param "vr".
	(value_range::dump): Add "const" qualifier.
	(vrp_prop::check_array_ref): Convert local "vr" from
	"value_range *" to "const value_range *".
	(vrp_prop::check_mem_ref): Likewise.
	(vrp_prop::visit_stmt): Likewise for local "old_vr".
	(vrp_intersect_ranges_1): Likewise for param "vr_1".
	(vrp_intersect_ranges): Likewise.
	(simplify_stmt_for_jump_threading): Likewise for local "vr".
	(vrp_prop::vrp_finalize): Likewise.
	* tree-vrp.h (value_range::dump): Add "const" qualifier.
	(vrp_intersect_ranges): Add "const" qualifier to params as above.
	(extract_range_from_unary_expr): Likewise.
	(range_is_nonnull): Likewise.
	(value_range_constant_singleton): Likewise.
	(symbolic_range_p): Likewise.
	(copy_value_range): Likewise.
	(extract_range_from_binary_expr_1): Likewise.
	(range_int_cst_p): Likewise.
	(vrp_set_zero_nonzero_bits): Likewise.
	(range_int_cst_singleton_p): Likewise.
---
 gcc/tree-vrp.c | 54 ++++++++++++++++++++++++++++--------------------------
 gcc/tree-vrp.h | 24 ++++++++++++------------
 2 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index ead19f1..09cc3ae 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -442,7 +442,7 @@ set_and_canonicalize_value_range (value_range *vr, enum value_range_type t,
 /* Copy value range FROM into value range TO.  */
 
 void
-copy_value_range (value_range *to, value_range *from)
+copy_value_range (value_range *to, const value_range *from)
 {
   set_value_range (to, from->type, from->min, from->max, from->equiv);
 }
@@ -541,7 +541,7 @@ vrp_bitmap_equal_p (const_bitmap b1, const_bitmap b2)
 /* Return true if VR is ~[0, 0].  */
 
 bool
-range_is_nonnull (value_range *vr)
+range_is_nonnull (const value_range *vr)
 {
   return vr->type == VR_ANTI_RANGE
 	 && integer_zerop (vr->min)
@@ -552,7 +552,7 @@ range_is_nonnull (value_range *vr)
 /* Return true if VR is [0, 0].  */
 
 static inline bool
-range_is_null (value_range *vr)
+range_is_null (const value_range *vr)
 {
   return vr->type == VR_RANGE
 	 && integer_zerop (vr->min)
@@ -563,7 +563,7 @@ range_is_null (value_range *vr)
    a singleton.  */
 
 bool
-range_int_cst_p (value_range *vr)
+range_int_cst_p (const value_range *vr)
 {
   return (vr->type == VR_RANGE
 	  && TREE_CODE (vr->max) == INTEGER_CST
@@ -573,7 +573,7 @@ range_int_cst_p (value_range *vr)
 /* Return true if VR is a INTEGER_CST singleton.  */
 
 bool
-range_int_cst_singleton_p (value_range *vr)
+range_int_cst_singleton_p (const value_range *vr)
 {
   return (range_int_cst_p (vr)
 	  && tree_int_cst_equal (vr->min, vr->max));
@@ -582,7 +582,7 @@ range_int_cst_singleton_p (value_range *vr)
 /* Return true if value range VR involves at least one symbol.  */
 
 bool
-symbolic_range_p (value_range *vr)
+symbolic_range_p (const value_range *vr)
 {
   return (!is_gimple_min_invariant (vr->min)
           || !is_gimple_min_invariant (vr->max));
@@ -903,7 +903,7 @@ value_inside_range (tree val, tree min, tree max)
    */
 
 static inline bool
-value_ranges_intersect_p (value_range *vr0, value_range *vr1)
+value_ranges_intersect_p (const value_range *vr0, const value_range *vr1)
 {
   /* The value ranges do not intersect if the maximum of the first range is
      less than the minimum of the second range or vice versa.
@@ -929,7 +929,7 @@ range_includes_zero_p (tree min, tree max)
 /* Return true if *VR is know to only contain nonnegative values.  */
 
 static inline bool
-value_range_nonnegative_p (value_range *vr)
+value_range_nonnegative_p (const value_range *vr)
 {
   /* Testing for VR_ANTI_RANGE is not useful here as any anti-range
      which would return a useful value should be encoded as a 
@@ -947,7 +947,7 @@ value_range_nonnegative_p (value_range *vr)
    otherwise return NULL_TREE.  */
 
 tree
-value_range_constant_singleton (value_range *vr)
+value_range_constant_singleton (const value_range *vr)
 {
   if (vr->type == VR_RANGE
       && vrp_operand_equal_p (vr->min, vr->max)
@@ -966,7 +966,7 @@ value_range_constant_singleton (value_range *vr)
 
 bool
 vrp_set_zero_nonzero_bits (const tree expr_type,
-			   value_range *vr,
+			   const value_range *vr,
 			   wide_int *may_be_nonzero,
 			   wide_int *must_be_nonzero)
 {
@@ -989,7 +989,7 @@ vrp_set_zero_nonzero_bits (const tree expr_type,
    *VR1 will be VR_UNDEFINED.  */
 
 static bool
-ranges_from_anti_range (value_range *ar,
+ranges_from_anti_range (const value_range *ar,
 			value_range *vr0, value_range *vr1)
 {
   tree type = TREE_TYPE (ar->min);
@@ -1032,7 +1032,7 @@ ranges_from_anti_range (value_range *ar,
    resulting wide ints are set to [-MIN, +MAX] for the type.  */
 
 static void inline
-extract_range_into_wide_ints (value_range *vr,
+extract_range_into_wide_ints (const value_range *vr,
 			      signop sign, unsigned prec,
 			      wide_int *wmin, wide_int *wmax)
 {
@@ -1066,7 +1066,8 @@ vrp_shift_undefined_p (const value_range &shifter, unsigned prec)
 static void
 extract_range_from_multiplicative_op (value_range *vr,
 				      enum tree_code code,
-				      value_range *vr0, value_range *vr1)
+				      const value_range *vr0,
+				      const value_range *vr1)
 {
   gcc_assert (code == MULT_EXPR
 	      || code == TRUNC_DIV_EXPR
@@ -1106,7 +1107,7 @@ extract_range_from_multiplicative_op (value_range *vr,
 
 static bool
 vrp_can_optimize_bit_op (value_range *vr, enum tree_code code,
-			 value_range *vr0, value_range *vr1)
+			 const value_range *vr0, const value_range *vr1)
 {
   tree lower_bound, upper_bound, mask;
   if (code != BIT_AND_EXPR && code != BIT_IOR_EXPR)
@@ -1315,7 +1316,8 @@ set_value_range_with_overflow (value_range &vr,
 void
 extract_range_from_binary_expr_1 (value_range *vr,
 				  enum tree_code code, tree expr_type,
-				  value_range *vr0_, value_range *vr1_)
+				  const value_range *vr0_,
+				  const value_range *vr1_)
 {
   signop sign = TYPE_SIGN (expr_type);
   unsigned int prec = TYPE_PRECISION (expr_type);
@@ -1900,7 +1902,7 @@ extract_range_from_binary_expr_1 (value_range *vr,
 void
 extract_range_from_unary_expr (value_range *vr,
 			       enum tree_code code, tree type,
-			       value_range *vr0_, tree op0_type)
+			       const value_range *vr0_, tree op0_type)
 {
   signop sign = TYPE_SIGN (type);
   unsigned int prec = TYPE_PRECISION (type);
@@ -2052,7 +2054,7 @@ extract_range_from_unary_expr (value_range *vr,
 /* Debugging dumps.  */
 
 void dump_value_range (FILE *, const value_range *);
-void debug_value_range (value_range *);
+void debug_value_range (const value_range *);
 void dump_all_value_ranges (FILE *);
 void dump_vr_equiv (FILE *, bitmap);
 void debug_vr_equiv (bitmap);
@@ -2117,14 +2119,14 @@ dump_value_range (FILE *file, const value_range *vr)
 /* Dump value range VR to stderr.  */
 
 DEBUG_FUNCTION void
-debug_value_range (value_range *vr)
+debug_value_range (const value_range *vr)
 {
   dump_value_range (stderr, vr);
   fprintf (stderr, "\n");
 }
 
 void
-value_range::dump ()
+value_range::dump () const
 {
   debug_value_range (this);
 }
@@ -4304,7 +4306,7 @@ void
 vrp_prop::check_array_ref (location_t location, tree ref,
 			   bool ignore_off_by_one)
 {
-  value_range *vr = NULL;
+  const value_range *vr = NULL;
   tree low_sub, up_sub;
   tree low_bound, up_bound, up_bound_p1;
 
@@ -4473,7 +4475,7 @@ vrp_prop::check_mem_ref (location_t location, tree ref,
   /* The range of the byte offset into the reference.  */
   offset_int offrange[2] = { 0, 0 };
 
-  value_range *vr = NULL;
+  const value_range *vr = NULL;
 
   /* Determine the offsets and increment OFFRANGE for the bounds of each.
      The loop computes the the range of the final offset for expressions
@@ -5363,7 +5365,7 @@ vrp_prop::visit_stmt (gimple *stmt, edge *taken_edge_p, tree *output_p)
 		   return SSA_PROP_VARYING.  */
 		value_range new_vr = VR_INITIALIZER;
 		extract_range_basic (&new_vr, use_stmt);
-		value_range *old_vr = get_value_range (use_lhs);
+		const value_range *old_vr = get_value_range (use_lhs);
 		if (old_vr->type != new_vr.type
 		    || !vrp_operand_equal_p (old_vr->min, new_vr.min)
 		    || !vrp_operand_equal_p (old_vr->max, new_vr.max)
@@ -5991,7 +5993,7 @@ intersect_ranges (enum value_range_type *vr0type,
    in *VR0.  This may not be the smallest possible such range.  */
 
 static void
-vrp_intersect_ranges_1 (value_range *vr0, value_range *vr1)
+vrp_intersect_ranges_1 (value_range *vr0, const value_range *vr1)
 {
   value_range saved;
 
@@ -6048,7 +6050,7 @@ vrp_intersect_ranges_1 (value_range *vr0, value_range *vr1)
 }
 
 void
-vrp_intersect_ranges (value_range *vr0, value_range *vr1)
+vrp_intersect_ranges (value_range *vr0, const value_range *vr1)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
@@ -6369,7 +6371,7 @@ simplify_stmt_for_jump_threading (gimple *stmt, gimple *within_stmt,
 
       op = lhs_of_dominating_assert (op, bb, stmt);
 
-      value_range *vr = vr_values->get_value_range (op);
+      const value_range *vr = vr_values->get_value_range (op);
       if ((vr->type != VR_RANGE && vr->type != VR_ANTI_RANGE)
 	  || symbolic_range_p (vr))
 	return NULL_TREE;
@@ -6618,7 +6620,7 @@ vrp_prop::vrp_finalize (bool warn_array_bounds_p)
       if (!name)
 	continue;
 
-      value_range *vr = get_value_range (name);
+      const value_range *vr = get_value_range (name);
       if (!name
 	  || (vr->type == VR_VARYING)
 	  || (vr->type == VR_UNDEFINED)
diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h
index 0c1fb36..65513f3 100644
--- a/gcc/tree-vrp.h
+++ b/gcc/tree-vrp.h
@@ -51,16 +51,16 @@ struct GTY((for_user)) value_range
   bitmap equiv;
 
   /* Dump value range to stderr.  */
-  void dump ();
+  void dump () const;
 };
 
-extern void vrp_intersect_ranges (value_range *vr0, value_range *vr1);
+extern void vrp_intersect_ranges (value_range *vr0, const value_range *vr1);
 extern void vrp_meet (value_range *vr0, const value_range *vr1);
 extern void dump_value_range (FILE *, const value_range *);
 extern void extract_range_from_unary_expr (value_range *vr,
 					   enum tree_code code,
 					   tree type,
-					   value_range *vr0_,
+					   const value_range *vr0_,
 					   tree op0_type);
 
 extern bool vrp_operand_equal_p (const_tree, const_tree);
@@ -96,29 +96,29 @@ extern void set_and_canonicalize_value_range (value_range *,
 					      enum value_range_type,
 					      tree, tree, bitmap);
 extern bool vrp_bitmap_equal_p (const_bitmap, const_bitmap);
-extern bool range_is_nonnull (value_range *);
-extern tree value_range_constant_singleton (value_range *);
-extern bool symbolic_range_p (value_range *);
+extern bool range_is_nonnull (const value_range *);
+extern tree value_range_constant_singleton (const value_range *);
+extern bool symbolic_range_p (const value_range *);
 extern int compare_values (tree, tree);
 extern int compare_values_warnv (tree, tree, bool *);
 extern bool vrp_val_is_min (const_tree);
 extern bool vrp_val_is_max (const_tree);
-extern void copy_value_range (value_range *, value_range *);
+extern void copy_value_range (value_range *, const value_range *);
 extern void set_value_range_to_value (value_range *, tree, bitmap);
 extern void extract_range_from_binary_expr_1 (value_range *, enum tree_code,
-					      tree, value_range *,
-					      value_range *);
+					      tree, const value_range *,
+					      const value_range *);
 extern tree vrp_val_min (const_tree);
 extern tree vrp_val_max (const_tree);
 extern void set_value_range_to_null (value_range *, tree);
-extern bool range_int_cst_p (value_range *);
+extern bool range_int_cst_p (const value_range *);
 extern int operand_less_p (tree, tree);
 extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *);
 extern bool find_case_label_index (gswitch *, size_t, tree, size_t *);
-extern bool vrp_set_zero_nonzero_bits (const tree, value_range *,
+extern bool vrp_set_zero_nonzero_bits (const tree, const value_range *,
 				       wide_int *, wide_int *);
 extern bool overflow_comparison_p (tree_code, tree, tree, bool, tree *);
-extern bool range_int_cst_singleton_p (value_range *);
+extern bool range_int_cst_singleton_p (const value_range *);
 extern int value_inside_range (tree, tree, tree);
 extern tree get_single_symbol (tree, bool *, tree *);
 extern void maybe_set_nonzero_bits (edge, tree);
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]