From 619641397a558bf65c24b99a4c52878bd940fcbe Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Sun, 16 Jul 2023 12:46:00 -0400 Subject: [PATCH] Remove value_query, push into sub&fold class * tree-ssa-propagate.cc (substitute_and_fold_engine::value_on_edge): Move from value-query.cc. (substitute_and_fold_engine::value_of_stmt): Ditto. (substitute_and_fold_engine::range_of_expr): New. * tree-ssa-propagate.h (substitute_and_fold_engine): Inherit from range_query. New prototypes. * value-query.cc (value_query::value_on_edge): Relocate. (value_query::value_of_stmt): Ditto. * value-query.h (class value_query): Remove. (class range_query): Remove base class. Adjust prototypes. --- gcc/tree-ssa-propagate.cc | 28 ++++++++++++++++++++++++++++ gcc/tree-ssa-propagate.h | 8 +++++++- gcc/value-query.cc | 21 --------------------- gcc/value-query.h | 30 ++++-------------------------- 4 files changed, 39 insertions(+), 48 deletions(-) diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc index 174d19890f9..cb68b419b8c 100644 --- a/gcc/tree-ssa-propagate.cc +++ b/gcc/tree-ssa-propagate.cc @@ -532,6 +532,34 @@ struct prop_stats_d static struct prop_stats_d prop_stats; +// range_query default methods to drive from a value_of_expr() ranther than +// range_of_expr. + +tree +substitute_and_fold_engine::value_on_edge (edge, tree expr) +{ + return value_of_expr (expr); +} + +tree +substitute_and_fold_engine::value_of_stmt (gimple *stmt, tree name) +{ + if (!name) + name = gimple_get_lhs (stmt); + + gcc_checking_assert (!name || name == gimple_get_lhs (stmt)); + + if (name) + return value_of_expr (name); + return NULL_TREE; +} + +bool +substitute_and_fold_engine::range_of_expr (vrange &, tree, gimple *) +{ + return false; +} + /* Replace USE references in statement STMT with the values stored in PROP_VALUE. Return true if at least one reference was replaced. */ diff --git a/gcc/tree-ssa-propagate.h b/gcc/tree-ssa-propagate.h index be4cb457873..29bde37add9 100644 --- a/gcc/tree-ssa-propagate.h +++ b/gcc/tree-ssa-propagate.h @@ -96,11 +96,17 @@ class ssa_propagation_engine void simulate_block (basic_block); }; -class substitute_and_fold_engine : public value_query +class substitute_and_fold_engine : public range_query { public: substitute_and_fold_engine (bool fold_all_stmts = false) : fold_all_stmts (fold_all_stmts) { } + + virtual tree value_of_expr (tree expr, gimple * = NULL) = 0; + virtual tree value_on_edge (edge, tree expr) override; + virtual tree value_of_stmt (gimple *, tree name = NULL) override; + virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL); + virtual ~substitute_and_fold_engine (void) { } virtual bool fold_stmt (gimple_stmt_iterator *) { return false; } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index adef93415b7..0870d6c60a6 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -33,27 +33,6 @@ along with GCC; see the file COPYING3. If not see #include "gimple-range.h" #include "value-range-storage.h" -// value_query default methods. - -tree -value_query::value_on_edge (edge, tree expr) -{ - return value_of_expr (expr); -} - -tree -value_query::value_of_stmt (gimple *stmt, tree name) -{ - if (!name) - name = gimple_get_lhs (stmt); - - gcc_checking_assert (!name || name == gimple_get_lhs (stmt)); - - if (name) - return value_of_expr (name); - return NULL_TREE; -} - // range_query default methods. bool diff --git a/gcc/value-query.h b/gcc/value-query.h index d10c3eac1e2..429446b32eb 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -37,28 +37,6 @@ along with GCC; see the file COPYING3. If not see // Proper usage of the correct query in passes will enable other // valuation mechanisms to produce more precise results. -class value_query -{ -public: - value_query () { } - // Return the singleton expression for EXPR at a gimple statement, - // or NULL if none found. - virtual tree value_of_expr (tree expr, gimple * = NULL) = 0; - // Return the singleton expression for EXPR at an edge, or NULL if - // none found. - virtual tree value_on_edge (edge, tree expr); - // Return the singleton expression for the LHS of a gimple - // statement, assuming an (optional) initial value of NAME. Returns - // NULL if none found. - // - // Note that this method calculates the range the LHS would have - // *after* the statement has executed. - virtual tree value_of_stmt (gimple *, tree name = NULL); - -private: - DISABLE_COPY_AND_ASSIGN (value_query); -}; - // The range_query class is used by optimization passes which are // range aware. // @@ -73,15 +51,15 @@ private: // The get_value_range method is currently provided for compatibility // with vr-values. It will be deprecated when possible. -class range_query : public value_query +class range_query { public: range_query (); virtual ~range_query (); - virtual tree value_of_expr (tree expr, gimple * = NULL) override; - virtual tree value_on_edge (edge, tree expr) override; - virtual tree value_of_stmt (gimple *, tree name = NULL) override; + virtual tree value_of_expr (tree expr, gimple * = NULL); + virtual tree value_on_edge (edge, tree expr); + virtual tree value_of_stmt (gimple *, tree name = NULL); // These are the range equivalents of the value_* methods. Instead // of returning a singleton, they calculate a range and return it in -- 2.11.4.GIT