From 37129f66a59c435afc301ecce1ba9340fdfc9eb2 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Tue, 21 Jun 2016 12:42:44 +1000
Subject: [PATCH 4/7] Refactor vrp
---
gcc/Makefile.in | 1 +
gcc/asan.c | 1 +
gcc/builtins.c | 1 +
gcc/cgraph.c | 1 +
gcc/cgraphunit.c | 1 +
gcc/fold-const.c | 1 +
gcc/gengtype.c | 2 +-
gcc/gimple-builder.c | 1 +
gcc/gimple-laddress.c | 1 +
gcc/hsa-gen.c | 1 +
gcc/internal-fn.c | 1 +
gcc/ipa-cp.c | 1 +
gcc/ipa-devirt.c | 1 +
gcc/ipa-inline-transform.c | 1 +
gcc/ipa-inline.c | 1 +
gcc/ipa-profile.c | 1 +
gcc/ipa-utils.c | 1 +
gcc/ipa.c | 1 +
gcc/lto/lto-partition.c | 1 +
gcc/lto/lto.c | 1 +
gcc/ssa.h | 1 +
gcc/targhooks.c | 1 +
gcc/toplev.c | 1 +
gcc/tree-ssa-address.c | 1 +
gcc/tree-ssanames.h | 5 -----
gcc/tree-vrp.c | 50 +++++++++++-------------------------------
gcc/tree-vrp.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++
27 files changed, 90 insertions(+), 44 deletions(-)
create mode 100644 gcc/tree-vrp.h
@@ -2424,6 +2424,7 @@ GTFILES = $(CPP_ID_DATA_H) $(srcdir)/input.h $(srcdir)/coretypes.h \
$(srcdir)/tree-phinodes.c \
$(srcdir)/tree-ssa-alias.h \
$(srcdir)/tree-ssanames.h \
+ $(srcdir)/tree-vrp.h \
$(srcdir)/ipa-prop.h \
$(srcdir)/trans-mem.c \
$(srcdir)/lto-streamer.h \
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-pass.h"
#include "tm_p.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "optabs.h"
#include "emit-rtl.h"
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "predict.h"
#include "tm_p.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "expmed.h"
#include "optabs.h"
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see
#include "value-prof.h"
#include "ipa-utils.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
#include "cfgloop.h"
@@ -190,6 +190,7 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h"
#include "debug.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "gimple-pretty-print.h"
#include "plugin.h"
@@ -75,6 +75,7 @@ along with GCC; see the file COPYING3. If not see
#include "md5.h"
#include "case-cfn-macros.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "selftest.h"
@@ -1712,7 +1712,7 @@ open_base_files (void)
"explow.h", "calls.h", "cilk.h", "emit-rtl.h", "varasm.h", "stmt.h",
"expr.h", "alloc-pool.h", "cselib.h", "insn-addr.h", "optabs.h",
"libfuncs.h", "debug.h", "internal-fn.h", "gimple-fold.h", "tree-eh.h",
- "gimple-iterator.h", "gimple-ssa.h", "tree-cfg.h",
+ "gimple-iterator.h", "gimple-ssa.h", "tree-cfg.h", "tree-vrp.h",
"tree-phinodes.h", "ssa-iterators.h", "stringpool.h", "tree-ssanames.h",
"tree-ssa-loop.h", "tree-ssa-loop-ivopts.h", "tree-ssa-loop-manip.h",
"tree-ssa-loop-niter.h", "tree-into-ssa.h", "tree-dfa.h",
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "gimple.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "symtab.h"
#include "tree.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "fold-const.h"
#include "gimple-expr.h"
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimple-ssa.h"
#include "tree-phinodes.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "tree-dfa.h"
#include "ssa-iterators.h"
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimple.h"
#include "predict.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "expmed.h"
#include "optabs.h"
@@ -114,6 +114,7 @@ along with GCC; see the file COPYING3. If not see
#include "fold-const.h"
#include "gimple-fold.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "tree-pretty-print.h"
#include "tree-inline.h"
@@ -122,6 +122,7 @@ along with GCC; see the file COPYING3. If not see
#include "ipa-utils.h"
#include "gimple-fold.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
#include "demangle.h"
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "cgraph.h"
#include "tree-cfg.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
#include "tree-inline.h"
@@ -108,6 +108,7 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "profile.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
#include "ipa-utils.h"
@@ -62,6 +62,7 @@ along with GCC; see the file COPYING3. If not see
#include "value-prof.h"
#include "tree-inline.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "splay-tree.h"
#include "ipa-utils.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-iterator.h"
#include "ipa-utils.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
#include "dbgcnt.h"
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "lto-streamer.h"
#include "params.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "ipa-inline.h"
#include "lto-partition.h"
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h"
#include "stor-layout.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "common.h"
#include "debug.h"
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
#include "stringpool.h"
#include "gimple-ssa.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
@@ -57,6 +57,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimple-expr.h"
#include "tm_p.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "optabs.h"
#include "regs.h"
@@ -71,6 +71,7 @@ along with GCC; see the file COPYING3. If not see
#include "dwarf2out.h"
#include "ipa-reference.h"
#include "symbol-summary.h"
+#include "tree-vrp.h"
#include "ipa-prop.h"
#include "gcse.h"
#include "tree-chkp.h"
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "gimple.h"
#include "stringpool.h"
+#include "tree-vrp.h"
#include "tree-ssanames.h"
#include "expmed.h"
#include "insn-config.h"
@@ -62,11 +62,6 @@ struct GTY ((variable_size)) range_info_def {
#define num_ssa_names (vec_safe_length (cfun->gimple_df->ssa_names))
#define ssa_name(i) ((*cfun->gimple_df->ssa_names)[(i)])
-
-/* Type of value ranges. See value_range_d In tree-vrp.c for a
- description of these types. */
-enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING };
-
/* Sets the value range to SSA. */
extern void set_range_info (tree, enum value_range_type, const wide_int_ref &,
const wide_int_ref &);
@@ -59,32 +59,7 @@ along with GCC; see the file COPYING3. If not see
#include "target.h"
#include "case-cfn-macros.h"
#include "alloc-pool.h"
-
-/* Range of values that can be associated with an SSA_NAME after VRP
- has executed. */
-struct value_range
-{
- /* Lattice value represented by this range. */
- enum value_range_type type;
-
- /* Minimum and maximum values represented by this range. These
- values should be interpreted as follows:
-
- - If TYPE is VR_UNDEFINED or VR_VARYING then MIN and MAX must
- be NULL.
-
- - If TYPE == VR_RANGE then MIN holds the minimum value and
- MAX holds the maximum value of the range [MIN, MAX].
-
- - If TYPE == ANTI_RANGE the variable is known to NOT
- take any values in the range [MIN, MAX]. */
- tree min;
- tree max;
-
- /* Set of SSA names whose value ranges are equivalent to this one.
- This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
- bitmap equiv;
-};
+#include "domwalk.h"
#define VR_INITIALIZER { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }
@@ -108,8 +83,6 @@ live_on_edge (edge e, tree name)
/* Local functions. */
static int compare_values (tree val1, tree val2);
static int compare_values_warnv (tree val1, tree val2, bool *);
-static void vrp_meet (value_range *, value_range *);
-static void vrp_intersect_ranges (value_range *, value_range *);
static tree vrp_evaluate_conditional_warnv_with_ops (enum tree_code,
tree, tree, bool, bool *,
bool *);
@@ -4605,7 +4578,7 @@ compare_range_with_value (enum tree_code comp, value_range *vr, tree val,
/* Debugging dumps. */
-void dump_value_range (FILE *, value_range *);
+void dump_value_range (FILE *, const value_range *);
void debug_value_range (value_range *);
void dump_all_value_ranges (FILE *);
void debug_all_value_ranges (void);
@@ -4616,7 +4589,7 @@ void debug_vr_equiv (bitmap);
/* Dump value range VR to FILE. */
void
-dump_value_range (FILE *file, value_range *vr)
+dump_value_range (FILE *file, const value_range *vr)
{
if (vr == NULL)
fprintf (file, "[]");
@@ -8447,7 +8420,7 @@ intersect_ranges (enum value_range_type *vr0type,
/* Intersect the two value-ranges *VR0 and *VR1 and store the result
in *VR0. This may not be the smallest possible such range. */
-static void
+void
vrp_intersect_ranges_1 (value_range *vr0, value_range *vr1)
{
value_range saved;
@@ -8499,7 +8472,7 @@ vrp_intersect_ranges_1 (value_range *vr0, value_range *vr1)
bitmap_copy (vr0->equiv, vr1->equiv);
}
-static void
+void
vrp_intersect_ranges (value_range *vr0, value_range *vr1)
{
if (dump_file && (dump_flags & TDF_DETAILS))
@@ -8524,7 +8497,7 @@ vrp_intersect_ranges (value_range *vr0, value_range *vr1)
may not be the smallest possible such range. */
static void
-vrp_meet_1 (value_range *vr0, value_range *vr1)
+vrp_meet_1 (value_range *vr0, const value_range *vr1)
{
value_range saved;
@@ -8596,8 +8569,8 @@ vrp_meet_1 (value_range *vr0, value_range *vr1)
bitmap_clear (vr0->equiv);
}
-static void
-vrp_meet (value_range *vr0, value_range *vr1)
+void
+vrp_meet (value_range *vr0, const value_range *vr1)
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
@@ -10171,7 +10144,7 @@ finalize_jump_threads (void)
/* Traverse all the blocks folding conditionals with known ranges. */
static void
-vrp_finalize (bool warn_array_bounds_p)
+vrp_finalize (bool jump_thread_p, bool warn_array_bounds_p)
{
size_t i;
@@ -10212,7 +10185,8 @@ vrp_finalize (bool warn_array_bounds_p)
/* We must identify jump threading opportunities before we release
the datastructures built by VRP. */
- identify_jump_threads ();
+ if (jump_thread_p)
+ identify_jump_threads ();
/* Free allocated memory. */
free (vr_value);
@@ -10296,7 +10270,7 @@ execute_vrp (bool warn_array_bounds_p)
vrp_initialize ();
ssa_propagate (vrp_visit_stmt, vrp_visit_phi_node);
- vrp_finalize (warn_array_bounds_p);
+ vrp_finalize (true, warn_array_bounds_p);
free_numbers_of_iterations_estimates (cfun);
new file mode 100644
@@ -0,0 +1,54 @@
+/* Support routines for Value Range Propagation (VRP).
+ Copyright (C) Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+/* Type of value ranges. See value_range_d In tree-vrp.c for a
+ description of these types. */
+enum value_range_type { VR_UNDEFINED, VR_RANGE,
+ VR_ANTI_RANGE, VR_VARYING, VR_LAST };
+
+/* Range of values that can be associated with an SSA_NAME after VRP
+ has executed. */
+struct GTY(()) value_range
+{
+ /* Lattice value represented by this range. */
+ enum value_range_type type;
+
+ /* Minimum and maximum values represented by this range. These
+ values should be interpreted as follows:
+
+ - If TYPE is VR_UNDEFINED or VR_VARYING then MIN and MAX must
+ be NULL.
+
+ - If TYPE == VR_RANGE then MIN holds the minimum value and
+ MAX holds the maximum value of the range [MIN, MAX].
+
+ - If TYPE == ANTI_RANGE the variable is known to NOT
+ take any values in the range [MIN, MAX]. */
+ tree min;
+ tree max;
+
+ /* Set of SSA names whose value ranges are equivalent to this one.
+ This set is only valid when TYPE is VR_RANGE or VR_ANTI_RANGE. */
+ bitmap equiv;
+};
+
+extern void vrp_intersect_ranges (value_range *vr0, value_range *vr1);
+extern void vrp_meet (value_range *vr0, const value_range *vr1);
+extern void dump_value_range (FILE *, const value_range *);
+
--
1.9.1