diff options
author | Richard Biener <rguenther@suse.de> | 2022-08-24 11:22:55 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-08-24 11:47:05 +0200 |
commit | cd1216d581b44f14b93a427bf2e95ee37e394b8b (patch) | |
tree | 620bc5dcb99245da71c9ea66c33c2c19af2ec329 /gcc/gimple-predicate-analysis.h | |
parent | 9e50aebc813477655e0090b7de6578a7b11816ba (diff) | |
download | gcc-cd1216d581b44f14b93a427bf2e95ee37e394b8b.zip gcc-cd1216d581b44f14b93a427bf2e95ee37e394b8b.tar.gz gcc-cd1216d581b44f14b93a427bf2e95ee37e394b8b.tar.bz2 |
Split uninit analysis from predicate analysis
This splits the API collected in gimple-predicate-analysis.h into
what I'd call a predicate and assorted functionality plus utility
used by the uninit pass that happens to use that. I've tried to
be minimalistic with refactoring, there's still recursive
instantiation of uninit_analysis, the new class encapsulating a
series of uninit analysis queries from the uninit pass. But it
at least should make the predicate part actually reusable and
what predicate is dealt with is a little bit more clear in the
uninit_analysis part.
I will followup with moving the predicate implementation bits
together in the gimple-predicate-analysis.cc file.
* gimple-predicate-analysis.h (predicate): Split out
non-predicate related functionality into ..
(uninit_analysis): .. this new class.
* gimple-predicate-analysis.cc: Refactor into two classes.
* tree-ssa-uninit.cc (find_uninit_use): Use uninit_analysis.
Diffstat (limited to 'gcc/gimple-predicate-analysis.h')
-rw-r--r-- | gcc/gimple-predicate-analysis.h | 101 |
1 files changed, 59 insertions, 42 deletions
diff --git a/gcc/gimple-predicate-analysis.h b/gcc/gimple-predicate-analysis.h index 7767229..b4aa5de 100644 --- a/gcc/gimple-predicate-analysis.h +++ b/gcc/gimple-predicate-analysis.h @@ -44,37 +44,11 @@ typedef vec<pred_chain, va_heap, vl_ptr> pred_chain_union; class predicate { public: - /* Base function object type used to determine whether an expression - is of interest. */ - struct func_t - { - typedef unsigned phi_arg_set_t; - - /* Return true if the argument is an expression of interest. */ - virtual bool operator()(tree) = 0; - /* Return a bitset of PHI arguments of interest. By default returns - bitset with a bit set for each argument. Should be called in - the overriden function first and, if nonzero, the result then - refined as appropriate. */ - virtual phi_arg_set_t phi_arg_set (gphi *); - - /* Maximum number of PHI arguments supported by phi_arg_set(). */ - static constexpr unsigned max_phi_args = - sizeof (phi_arg_set_t) * CHAR_BIT; - }; - /* Construct with the specified EVAL object. */ - predicate (func_t &eval) - : m_preds (vNULL), m_eval (eval) { } + predicate () : m_preds (vNULL) { } /* Copy. */ - predicate (const predicate &rhs) - : m_preds (vNULL), m_eval (rhs.m_eval) - { - *this = rhs; - } - - predicate (basic_block, basic_block, func_t &); + predicate (const predicate &rhs) : m_preds (vNULL) { *this = rhs; } ~predicate (); @@ -91,10 +65,6 @@ class predicate return m_preds; } - /* Return true if the use by a statement in the basic block of - a PHI operand is ruled out (i.e., guarded) by *THIS. */ - bool is_use_guarded (gimple *, basic_block, gphi *, unsigned); - void init_from_control_deps (const vec<edge> *, unsigned); void dump (gimple *, const char *) const; @@ -102,23 +72,16 @@ class predicate void normalize (gimple * = NULL, bool = false); void simplify (gimple * = NULL, bool = false); - bool is_use_guarded (gimple *, basic_block, gphi *, unsigned, - hash_set<gphi *> *); - -private: - bool includes (const pred_chain &) const; bool superset_of (const predicate &) const; - bool overlap (gphi *, unsigned, hash_set<gphi *> *); - bool use_cannot_happen (gphi *, unsigned); - bool init_from_phi_def (gphi *); +private: + bool includes (const pred_chain &) const; void push_pred (const pred_info &); /* Normalization functions. */ void normalize (pred_chain *, pred_info, tree_code, pred_chain *, hash_set<tree> *); - void normalize (const pred_info &); void normalize (const pred_chain &); @@ -127,9 +90,63 @@ private: bool simplify_3 (); bool simplify_4 (); -private: /* Representation of the predicate expression(s). */ pred_chain_union m_preds; +}; + +/* Represents a complex Boolean predicate expression. */ +class uninit_analysis +{ + public: + /* Base function object type used to determine whether an expression + is of interest. */ + struct func_t + { + typedef unsigned phi_arg_set_t; + + /* Return true if the argument is an expression of interest. */ + virtual bool operator()(tree) = 0; + /* Return a bitset of PHI arguments of interest. By default returns + bitset with a bit set for each argument. Should be called in + the overriden function first and, if nonzero, the result then + refined as appropriate. */ + virtual phi_arg_set_t phi_arg_set (gphi *); + + /* Maximum number of PHI arguments supported by phi_arg_set(). */ + static constexpr unsigned max_phi_args = + sizeof (phi_arg_set_t) * CHAR_BIT; + }; + + /* Construct with the specified EVAL object. */ + uninit_analysis (func_t &eval) + : m_phi_def_preds (), m_eval (eval) { } + + /* Copy. */ + uninit_analysis (const uninit_analysis &rhs) = delete; + + /* Assign. */ + uninit_analysis& operator= (const uninit_analysis&) = delete; + + /* Return true if the use by a statement in the basic block of + a PHI operand is ruled out (i.e., guarded) by *THIS. */ + bool is_use_guarded (gimple *, basic_block, gphi *, unsigned); + +private: + bool is_use_guarded (gimple *, basic_block, gphi *, unsigned, + hash_set<gphi *> *); + bool prune_phi_opnds (gphi *, unsigned, gphi *, tree, tree_code, + hash_set<gphi *> *, bitmap *); + bool overlap (gphi *, unsigned, hash_set<gphi *> *, const predicate &); + bool use_cannot_happen (gphi *, unsigned, const predicate &); + + void collect_phi_def_edges (gphi *, basic_block, vec<edge> *, + hash_set<gimple *> *); + bool init_from_phi_def (gphi *); + bool init_use_preds (predicate &, basic_block, basic_block); + + + /* Representation of the predicate expression(s). */ + predicate m_phi_def_preds; /* Callback to evaluate an operand. Return true if it's interesting. */ func_t &m_eval; }; |