GCC Middle and Back End API Reference
gimple-predicate-analysis.h
Go to the documentation of this file.
1/* Support for simple predicate analysis.
2
3 Copyright (C) 2021-2026 Free Software Foundation, Inc.
4 Contributed by Martin Sebor <msebor@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22#ifndef GIMPLE_PREDICATE_ANALYSIS_H_INCLUDED
23#define GIMPLE_PREDICATE_ANALYSIS_H_INCLUDED
24
25
26/* Represents a simple Boolean predicate. */
34
35/* The type to represent a sequence of predicates grouped
36 with .AND. operation. */
38
39/* The type to represent a sequence of pred_chains grouped
40 with .OR. operation. */
42
43/* Represents a complex Boolean predicate expression. */
44class predicate
45{
46 public:
47 /* Construct with the specified EVAL object. */
49
50 /* Copy. */
51 predicate (const predicate &rhs) : m_preds (vNULL) { *this = rhs; }
52
53 ~predicate ();
54
55 /* Assign. */
57
58 bool is_empty () const
59 {
60 return m_preds.is_empty ();
61 }
62
63 bool is_true () const
64 {
65 return is_empty () && m_cval;
66 }
67
68 bool is_false () const
69 {
70 return is_empty () && !m_cval;
71 }
72
73 bool empty_val () const
74 {
75 return m_cval;
76 }
77
78 const pred_chain_union chain () const
79 {
80 return m_preds;
81 }
82
83 void init_from_control_deps (const vec<edge> *, unsigned, bool);
84
85 void dump (FILE *) const;
86 void dump (FILE *, gimple *, const char *) const;
87 void debug () const;
88
89 void normalize (gimple * = NULL, bool = false);
90 void simplify (gimple * = NULL, bool = false);
91
92 bool superset_of (const predicate &) const;
93
95
96private:
97
98 bool includes (const pred_chain &) const;
99 void push_pred (const pred_info &);
100
101 /* Normalization functions. */
104 void normalize (const pred_info &);
105 void normalize (const pred_chain &);
106
107 /* Simplification functions. */
108 bool simplify_2 ();
109 bool simplify_3 ();
110 bool simplify_4 ();
111
112 /* Representation of the predicate expression(s). The predicate is
113 m_cval || m_preds[0] || ... */
115 bool m_cval;
116};
117
118/* Represents a complex Boolean predicate expression. */
120{
121 public:
122 /* Base function object type used to determine whether an expression
123 is of interest. */
124 struct func_t
125 {
126 typedef unsigned phi_arg_set_t;
127
128 /* Return a bitset of PHI arguments of interest. By default returns
129 bitset with a bit set for each argument. Should be called in
130 the overridden function first and, if nonzero, the result then
131 refined as appropriate. */
132 virtual phi_arg_set_t phi_arg_set (gphi *);
133
134 /* Maximum number of PHI arguments supported by phi_arg_set(). */
135 static constexpr unsigned max_phi_args =
136 sizeof (phi_arg_set_t) * CHAR_BIT;
137 };
138
139 /* Construct with the specified EVAL object. */
141 : m_phi_def_preds (false), m_eval (eval) { }
142
143 /* Copy. */
144 uninit_analysis (const uninit_analysis &rhs) = delete;
145
146 /* Assign. */
148
149 /* Return true if the use by a statement in the basic block of
150 a PHI operand is ruled out (i.e., guarded) by *THIS. */
151 bool is_use_guarded (gimple *, basic_block, gphi *, unsigned);
152
153private:
154 bool is_use_guarded (gimple *, basic_block, gphi *, unsigned,
156 bool prune_phi_opnds (gphi *, unsigned, gphi *, tree, tree_code,
157 hash_set<gphi *> *, bitmap *, unsigned &);
158 bool overlap (gphi *, unsigned, hash_set<gphi *> *, const predicate &);
159
162 bool init_from_phi_def (gphi *);
164
165
166 /* Representation of the predicate expression(s). */
168 /* Callback to evaluate an operand. Return true if it's interesting. */
170};
171
172/* Bit mask handling macros. */
173#define MASK_SET_BIT(mask, pos) mask |= (1 << pos)
174#define MASK_TEST_BIT(mask, pos) (mask & (1 << pos))
175#define MASK_EMPTY(mask) (mask == 0)
176
177#endif // GIMPLE_PREDICATE_ANALYSIS_H_INCLUDED
Definition hash-set.h:37
Definition genmatch.cc:1496
bool is_false() const
Definition gimple-predicate-analysis.h:68
pred_chain_union m_preds
Definition gimple-predicate-analysis.h:114
bool superset_of(const predicate &) const
Definition gimple-predicate-analysis.cc:820
const pred_chain_union chain() const
Definition gimple-predicate-analysis.h:78
bool simplify_3()
Definition gimple-predicate-analysis.cc:1419
bool simplify_4()
Definition gimple-predicate-analysis.cc:1467
bool includes(const pred_chain &) const
Definition gimple-predicate-analysis.cc:801
predicate(const predicate &rhs)
Definition gimple-predicate-analysis.h:51
void debug() const
Definition gimple-predicate-analysis.cc:2009
void push_pred(const pred_info &)
Definition gimple-predicate-analysis.cc:1976
bool is_empty() const
Definition gimple-predicate-analysis.h:58
bool m_cval
Definition gimple-predicate-analysis.h:115
void simplify(gimple *=NULL, bool=false)
Definition gimple-predicate-analysis.cc:1537
void dump(FILE *) const
Definition gimple-predicate-analysis.cc:1986
predicate(predicate_id *p_, location_t loc)
Definition genmatch.cc:1498
predicate(bool empty_val)
Definition gimple-predicate-analysis.h:48
bool simplify_2()
Definition gimple-predicate-analysis.cc:1360
~predicate()
Definition gimple-predicate-analysis.cc:2106
void normalize(gimple *=NULL, bool=false)
Definition gimple-predicate-analysis.cc:1781
bool is_true() const
Definition gimple-predicate-analysis.h:63
predicate & operator=(const predicate &)
Definition gimple-predicate-analysis.cc:2117
void init_from_control_deps(const vec< edge > *, unsigned, bool)
Definition gimple-predicate-analysis.cc:1817
bool empty_val() const
Definition gimple-predicate-analysis.h:73
bool drop_conjuncts_implied_by(const vec< pred_info > &)
Definition gimple-predicate-analysis.cc:834
bool init_use_preds(predicate &, basic_block, basic_block)
Definition gimple-predicate-analysis.cc:2035
bool init_from_phi_def(gphi *)
Definition gimple-predicate-analysis.cc:2144
void collect_phi_def_edges(gphi *, basic_block, vec< edge > *, hash_set< gimple * > *)
Definition gimple-predicate-analysis.cc:484
predicate m_phi_def_preds
Definition gimple-predicate-analysis.h:167
bool is_use_guarded(gimple *, basic_block, gphi *, unsigned)
Definition gimple-predicate-analysis.cc:2337
bool prune_phi_opnds(gphi *, unsigned, gphi *, tree, tree_code, hash_set< gphi * > *, bitmap *, unsigned &)
Definition gimple-predicate-analysis.cc:385
bool overlap(gphi *, unsigned, hash_set< gphi * > *, const predicate &)
Definition gimple-predicate-analysis.cc:624
uninit_analysis & operator=(const uninit_analysis &)=delete
uninit_analysis(func_t &eval)
Definition gimple-predicate-analysis.h:140
func_t & m_eval
Definition gimple-predicate-analysis.h:169
uninit_analysis(const uninit_analysis &rhs)=delete
struct basic_block_def * basic_block
Definition coretypes.h:351
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
#define CHAR_BIT
Definition genautomata.cc:120
tree_code
Definition genmatch.cc:1002
vec< pred_info, va_heap, vl_ptr > pred_chain
Definition gimple-predicate-analysis.h:37
vec< pred_chain, va_heap, vl_ptr > pred_chain_union
Definition gimple-predicate-analysis.h:41
Definition gimple.h:224
Definition gimple.h:464
Definition gimple-predicate-analysis.h:28
bool invert
Definition gimple-predicate-analysis.h:32
tree pred_lhs
Definition gimple-predicate-analysis.h:29
enum tree_code cond_code
Definition gimple-predicate-analysis.h:31
tree pred_rhs
Definition gimple-predicate-analysis.h:30
Definition gimple-predicate-analysis.h:125
virtual phi_arg_set_t phi_arg_set(gphi *)
Definition gimple-predicate-analysis.cc:541
unsigned phi_arg_set_t
Definition gimple-predicate-analysis.h:126
static constexpr unsigned max_phi_args
Definition gimple-predicate-analysis.h:135
Definition vec.h:450
#define NULL
Definition system.h:50
#define false
Definition system.h:894
constexpr vnull vNULL
Definition vec.h:569