diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2020-04-02 09:27:20 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2020-04-02 11:06:23 +0200 |
commit | d04d67fee0e5bdc38d71345958951d00dd22fd1c (patch) | |
tree | b66705f90ef1090e45258bec973f50ff9189d933 /gcc | |
parent | 9e927c2144e0037708f522df90a7bd58278522cf (diff) | |
download | gcc-d04d67fee0e5bdc38d71345958951d00dd22fd1c.zip gcc-d04d67fee0e5bdc38d71345958951d00dd22fd1c.tar.gz gcc-d04d67fee0e5bdc38d71345958951d00dd22fd1c.tar.bz2 |
More vr_comparison to vr-values.*
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/gimple-ssa-evrp-analyze.c | 178 | ||||
-rw-r--r-- | gcc/value-range.cc | 164 | ||||
-rw-r--r-- | gcc/value-range.h | 24 |
3 files changed, 188 insertions, 178 deletions
diff --git a/gcc/gimple-ssa-evrp-analyze.c b/gcc/gimple-ssa-evrp-analyze.c index 32bead1..43daa72 100644 --- a/gcc/gimple-ssa-evrp-analyze.c +++ b/gcc/gimple-ssa-evrp-analyze.c @@ -331,184 +331,6 @@ trace_vr_gori_interface::refine_range_with_equivalences (irange &r, return trailer (idx, "refine_range_with_equivalences", res, name, r); } -// Class to assert that the new range is at least as good as the old -// one. - -class vr_comparison -{ -public: - vr_comparison (const irange *, const irange *, vr_values *); - void compare (tree name, edge); - void compare (gimple *); -private: - void compare (); - void dump_differences_and_trap () const; - void dump_differences (FILE *) const; - void dump_improvements (FILE *) const; - bool new_range_is_same () const; - bool new_range_is_better () const; - tree m_name; - edge m_edge; - gimple *m_stmt; - const irange *m_old_range; - const irange *m_new_range; - vr_values *m_vr_values; -}; - -vr_comparison::vr_comparison (const irange *old_range, - const irange *new_range, - vr_values *vr) -{ - m_old_range = old_range; - m_new_range = new_range; - m_vr_values = vr; -} - -void -vr_comparison::compare () -{ - if (new_range_is_same ()) - return; - if (new_range_is_better ()) - { - if (dump_file) - dump_improvements (dump_file); - return; - } - dump_differences_and_trap (); -} - -void -vr_comparison::compare (tree name, edge e) -{ - m_name = name; - m_edge = e; - m_stmt = NULL; - compare (); -} - -void -vr_comparison::compare (gimple *stmt) -{ - m_name = get_output_for_vrp (stmt); - m_edge = NULL; - m_stmt = stmt; - compare (); -} - -bool -vr_comparison::new_range_is_same () const -{ - // We may be able to normalize a symbolic to a [MIN,MAX] plus - // or minus the end-points. Don't count that as a win just yet. - if (m_old_range && m_old_range->symbolic_p ()) - return true; - widest_irange old; - if (m_old_range) - old = *m_old_range; - // Treat UNDEFINED and VARYING as interchangeable. - if (old.undefined_p () && m_new_range->varying_p ()) - return true; - if (old.varying_p () && m_new_range->undefined_p ()) - return true; - return old == *m_new_range; -} - -bool -vr_comparison::new_range_is_better () const -{ - if (new_range_is_same ()) - return false; - if (!m_old_range) - return true; - // ?? Sometimes we get an undefined because the ranger determined a - // path was unexecutable. Verify this is actually the case by - // turning this off and analyzing all failures. - if (m_new_range->undefined_p ()) - return true; - if (!range_has_numeric_bounds_p (m_old_range)) - { - gcc_checking_assert (range_has_numeric_bounds_p (m_new_range)); - return true; - } - widest_irange inter (*m_new_range); - inter.intersect (*m_old_range); - return inter == *m_new_range; -} - -void -vr_comparison::dump_differences_and_trap () const -{ - bool dumping = getenv("GORI_DUMP_FILE") != NULL; - if (dumping) - { - const char *filename = getenv("GORI_DUMP_FILE"); - FILE *out = fopen (filename, "a"); - fprintf (out, "=========FILE: %s ========\n", - main_input_filename ? main_input_filename : "UNKNOWN"); - dump_differences (out); - fclose (out); - return; - } - dump_differences (stderr); - gcc_unreachable (); -} - -void -vr_comparison::dump_differences (FILE *out) const -{ - dump_flags_t flags = TDF_NONE; - if (m_stmt) - { - fprintf (out, "Different ranges for stmt: "); - print_gimple_stmt (out, m_stmt, 0, flags); - } - else - { - fprintf (out, "Different ranges on edge (%d -> %d) for SSA: ", - m_edge->src->index, m_edge->dest->index); - print_generic_stmt (out, m_name, flags); - } - fprintf (out, "\told range: "); - m_old_range->dump (out); - fprintf (out, "\n\tnew range: "); - m_new_range->dump (out); - if (m_edge) - { - fprintf (out, "\n\n"); - dump_bb (out, m_edge->src, 0, TDF_NONE); - } - fprintf (out, "\n"); - fprintf (out, "==============================================\n"); - dump_function_to_file (current_function_decl, out, TDF_NONE); - - dump_flags_t save = dump_flags; - dump_flags |= TDF_GORI; - m_vr_values->dump_all_value_ranges (out); - dump_flags = save; -} - -void -vr_comparison::dump_improvements (FILE *out) const -{ - if (m_old_range && !range_has_numeric_bounds_p (m_old_range)) - return; - if (new_range_is_better ()) - { - fprintf (out, "New range improved: "); - if (m_name) - print_generic_expr (out, m_name); - fprintf (out, " from: "); - if (m_old_range) - m_old_range->dump (out); - else - fprintf (out, "UNDEFINED"); - fprintf (out, " to: "); - m_new_range->dump (out); - fprintf (out, "\n"); - } -} - // ?? Eventually overload extract_range_from_stmt instead, since it is // higher level and more comparable to gimple_ranger::range_of_stmt. diff --git a/gcc/value-range.cc b/gcc/value-range.cc index c2290dc..43a8a5b 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -2391,3 +2391,167 @@ DEFINE_INT_RANGX_INSTANCE(1) DEFINE_INT_RANGX_INSTANCE(2) DEFINE_INT_RANGX_INSTANCE(3) DEFINE_INT_RANGX_GC_STUBS(1) + +// Temporary code to compare two ranges for sanity. + +#include "gimple-pretty-print.h" +#include "tree-cfg.h" +#include "alloc-pool.h" +#include "vr-values.h" + +vr_comparison::vr_comparison (const irange *old_range, + const irange *new_range, + vr_values *vr) +{ + m_old_range = old_range; + m_new_range = new_range; + m_vr_values = vr; +} + +void +vr_comparison::compare () +{ + if (new_range_is_same ()) + return; + if (new_range_is_better ()) + { + if (dump_file) + dump_improvements (dump_file); + return; + } + dump_differences_and_trap (); +} + +void +vr_comparison::compare (tree name, edge e) +{ + m_name = name; + m_edge = e; + m_stmt = NULL; + compare (); +} + +void +vr_comparison::compare (gimple *stmt) +{ + m_name = get_output_for_vrp (stmt); + m_edge = NULL; + m_stmt = stmt; + compare (); +} + +bool +vr_comparison::new_range_is_same () const +{ + // We may be able to normalize a symbolic to a [MIN,MAX] plus + // or minus the end-points. Don't count that as a win just yet. + if (m_old_range && m_old_range->symbolic_p ()) + return true; + widest_irange old; + if (m_old_range) + old = *m_old_range; + // Treat UNDEFINED and VARYING as interchangeable. + if (old.undefined_p () && m_new_range->varying_p ()) + return true; + if (old.varying_p () && m_new_range->undefined_p ()) + return true; + return old == *m_new_range; +} + +bool +vr_comparison::new_range_is_better () const +{ + if (new_range_is_same ()) + return false; + if (!m_old_range) + return true; + // ?? Sometimes we get an undefined because the ranger determined a + // path was unexecutable. Verify this is actually the case by + // turning this off and analyzing all failures. + if (m_new_range->undefined_p ()) + return true; + if (!range_has_numeric_bounds_p (m_old_range)) + { + gcc_checking_assert (range_has_numeric_bounds_p (m_new_range)); + return true; + } + widest_irange inter (*m_new_range); + inter.intersect (*m_old_range); + return inter == *m_new_range; +} + +void +vr_comparison::dump_differences_and_trap () const +{ + bool dumping = getenv("GORI_DUMP_FILE") != NULL; + if (dumping) + { + const char *filename = getenv("GORI_DUMP_FILE"); + FILE *out = fopen (filename, "a"); + fprintf (out, "=========FILE: %s ========\n", + main_input_filename ? main_input_filename : "UNKNOWN"); + dump_differences (out); + fclose (out); + return; + } + dump_differences (stderr); + gcc_unreachable (); +} + +void +vr_comparison::dump_differences (FILE *out) const +{ + dump_flags_t flags = TDF_NONE; + if (m_stmt) + { + fprintf (out, "Different ranges for stmt: "); + print_gimple_stmt (out, m_stmt, 0, flags); + } + else + { + fprintf (out, "Different ranges on edge (%d -> %d) for SSA: ", + m_edge->src->index, m_edge->dest->index); + print_generic_stmt (out, m_name, flags); + } + fprintf (out, "\told range: "); + m_old_range->dump (out); + fprintf (out, "\n\tnew range: "); + m_new_range->dump (out); + if (m_edge) + { + fprintf (out, "\n\n"); + dump_bb (out, m_edge->src, 0, TDF_NONE); + } + fprintf (out, "\n"); + fprintf (out, "==============================================\n"); + dump_function_to_file (current_function_decl, out, TDF_NONE); + + if (m_vr_values) + { + dump_flags_t save = dump_flags; + dump_flags |= TDF_GORI; + m_vr_values->dump_all_value_ranges (out); + dump_flags = save; + } +} + +void +vr_comparison::dump_improvements (FILE *out) const +{ + if (m_old_range && !range_has_numeric_bounds_p (m_old_range)) + return; + if (new_range_is_better ()) + { + fprintf (out, "New range improved: "); + if (m_name) + print_generic_expr (out, m_name); + fprintf (out, " from: "); + if (m_old_range) + m_old_range->dump (out); + else + fprintf (out, "UNDEFINED"); + fprintf (out, " to: "); + m_new_range->dump (out); + fprintf (out, "\n"); + } +} diff --git a/gcc/value-range.h b/gcc/value-range.h index 6588086..e158dfe 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -394,4 +394,28 @@ gt_pch_nx (int_range<N> *x, gt_pointer_operator op, void *cookie) } } +// Class to assert that the new range is at least as good as the old +// one. + +class vr_comparison +{ +public: + vr_comparison (const irange *, const irange *, class vr_values * = 0); + void compare (tree name, edge); + void compare (gimple *); +private: + void compare (); + void dump_differences_and_trap () const; + void dump_differences (FILE *) const; + void dump_improvements (FILE *) const; + bool new_range_is_same () const; + bool new_range_is_better () const; + tree m_name; + edge m_edge; + gimple *m_stmt; + const irange *m_old_range; + const irange *m_new_range; + class vr_values *m_vr_values; +}; + #endif // GCC_VALUE_RANGE_H |