annotate gcc/ipa-predicate.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* IPA predicates.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Jan Hubicka
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* Representation of inline parameters that do depend on context function is
kono
parents:
diff changeset
22 inlined into (i.e. known constant values of function parameters.
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 Conditions that are interesting for function body are collected into CONDS
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
25 vector. They are of simple as kind of a mathematical transformation on
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
26 function parameter, T(function_param), in which the parameter occurs only
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
27 once, and other operands are IPA invariant. The conditions are then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
28 referred by predicates. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
29
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
30
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
31 /* A simplified representation of tree node, for unary, binary and ternary
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
32 operation. Computations on parameter are decomposed to a series of this
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
33 kind of structure. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
34 struct GTY(()) expr_eval_op
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
35 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
36 /* Result type of expression. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
37 tree type;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
38 /* Constant operands in expression, there are at most two. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
39 tree val[2];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
40 /* Index of parameter operand in expression. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
41 unsigned index : 2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
42 /* Operation code of expression. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
43 ENUM_BITFIELD(tree_code) code : 16;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
44 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
45
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
46 typedef vec<expr_eval_op, va_gc> *expr_eval_ops;
111
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 struct GTY(()) condition
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 /* If agg_contents is set, this is the offset from which the used data was
kono
parents:
diff changeset
51 loaded. */
kono
parents:
diff changeset
52 HOST_WIDE_INT offset;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
53 /* Type of the access reading the data (or the PARM_DECL SSA_NAME). */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
54 tree type;
111
kono
parents:
diff changeset
55 tree val;
kono
parents:
diff changeset
56 int operand_num;
kono
parents:
diff changeset
57 ENUM_BITFIELD(tree_code) code : 16;
kono
parents:
diff changeset
58 /* Set if the used data were loaded from an aggregate parameter or from
kono
parents:
diff changeset
59 data received by reference. */
kono
parents:
diff changeset
60 unsigned agg_contents : 1;
kono
parents:
diff changeset
61 /* If agg_contents is set, this differentiates between loads from data
kono
parents:
diff changeset
62 passed by reference and by value. */
kono
parents:
diff changeset
63 unsigned by_ref : 1;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
64 /* A set of sequential operations on the parameter, which can be seen as
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
65 a mathematical function on the parameter. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
66 expr_eval_ops param_ops;
111
kono
parents:
diff changeset
67 };
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 /* Information kept about parameter of call site. */
kono
parents:
diff changeset
70 struct inline_param_summary
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 /* REG_BR_PROB_BASE based probability that parameter will change in between
kono
parents:
diff changeset
73 two invocation of the calls.
kono
parents:
diff changeset
74 I.e. loop invariant parameters
kono
parents:
diff changeset
75 REG_BR_PROB_BASE/estimated_iterations and regular
kono
parents:
diff changeset
76 parameters REG_BR_PROB_BASE.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 Value 0 is reserved for compile time invariants. */
kono
parents:
diff changeset
79 int change_prob;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
80 bool equal_to (const inline_param_summary &other) const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
81 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
82 return change_prob == other.change_prob;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
83 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
84 bool useless_p (void) const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
85 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
86 return change_prob == REG_BR_PROB_BASE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
87 }
111
kono
parents:
diff changeset
88 };
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 typedef vec<condition, va_gc> *conditions;
kono
parents:
diff changeset
91
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
92 /* Predicates are used to represent function parameters (such as runtime)
111
kono
parents:
diff changeset
93 which depend on a context function is called in.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 Predicates are logical formulas in conjunctive-disjunctive form consisting
kono
parents:
diff changeset
96 of clauses which are bitmaps specifying a set of condition that must
kono
parents:
diff changeset
97 be true for a clause to be satisfied. Physically they are represented as
kono
parents:
diff changeset
98 array of clauses terminated by 0.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 In order to make predicate (possibly) true, all of its clauses must
kono
parents:
diff changeset
101 be (possibly) true. To make clause (possibly) true, one of conditions
kono
parents:
diff changeset
102 it mentions must be (possibly) true.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 There are fixed bounds on number of clauses and conditions and all the
kono
parents:
diff changeset
105 manipulation functions are conservative in positive direction. I.e. we
kono
parents:
diff changeset
106 may lose precision by thinking that predicate may be true even when it
kono
parents:
diff changeset
107 is not. */
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 typedef uint32_t clause_t;
kono
parents:
diff changeset
110 class predicate
kono
parents:
diff changeset
111 {
kono
parents:
diff changeset
112 public:
kono
parents:
diff changeset
113 enum predicate_conditions
kono
parents:
diff changeset
114 {
kono
parents:
diff changeset
115 false_condition = 0,
kono
parents:
diff changeset
116 not_inlined_condition = 1,
kono
parents:
diff changeset
117 first_dynamic_condition = 2
kono
parents:
diff changeset
118 };
kono
parents:
diff changeset
119
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
120 /* Maximal number of conditions predicate can refer to. This is limited
111
kono
parents:
diff changeset
121 by using clause_t to be 32bit. */
kono
parents:
diff changeset
122 static const int num_conditions = 32;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 /* Special condition code we use to represent test that operand is compile
kono
parents:
diff changeset
125 time constant. */
kono
parents:
diff changeset
126 static const tree_code is_not_constant = ERROR_MARK;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* Special condition code we use to represent test that operand is not changed
kono
parents:
diff changeset
129 across invocation of the function. When operand IS_NOT_CONSTANT it is
kono
parents:
diff changeset
130 always CHANGED, however i.e. loop invariants can be NOT_CHANGED given
kono
parents:
diff changeset
131 percentage of executions even when they are not compile time constants. */
kono
parents:
diff changeset
132 static const tree_code changed = IDENTIFIER_NODE;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 /* Initialize predicate either to true of false depending on P. */
kono
parents:
diff changeset
137 inline predicate (bool p = true)
kono
parents:
diff changeset
138 {
kono
parents:
diff changeset
139 if (p)
kono
parents:
diff changeset
140 /* True predicate. */
kono
parents:
diff changeset
141 m_clause[0] = 0;
kono
parents:
diff changeset
142 else
kono
parents:
diff changeset
143 /* False predicate. */
kono
parents:
diff changeset
144 set_to_cond (false_condition);
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 /* Sanity check that we do not mix pointers to predicates with predicates. */
kono
parents:
diff changeset
148 inline predicate (predicate *)
kono
parents:
diff changeset
149 {
kono
parents:
diff changeset
150 gcc_unreachable ();
kono
parents:
diff changeset
151 }
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 /* Return predicate testing condition I. */
kono
parents:
diff changeset
154 static inline predicate predicate_testing_cond (int i)
kono
parents:
diff changeset
155 {
kono
parents:
diff changeset
156 class predicate p;
kono
parents:
diff changeset
157 p.set_to_cond (i + first_dynamic_condition);
kono
parents:
diff changeset
158 return p;
kono
parents:
diff changeset
159 }
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /* Return predicate testing that function was not inlined. */
kono
parents:
diff changeset
162 static predicate not_inlined (void)
kono
parents:
diff changeset
163 {
kono
parents:
diff changeset
164 class predicate p;
kono
parents:
diff changeset
165 p.set_to_cond (not_inlined_condition);
kono
parents:
diff changeset
166 return p;
kono
parents:
diff changeset
167 }
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 /* Compute logical and of predicates. */
kono
parents:
diff changeset
170 predicate & operator &= (const predicate &);
kono
parents:
diff changeset
171 inline predicate operator &(const predicate &p) const
kono
parents:
diff changeset
172 {
kono
parents:
diff changeset
173 predicate ret = *this;
kono
parents:
diff changeset
174 ret &= p;
kono
parents:
diff changeset
175 return ret;
kono
parents:
diff changeset
176 }
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 /* Compute logical or of predicates. This is not operator because
kono
parents:
diff changeset
179 extra parameter CONDITIONS is needed */
kono
parents:
diff changeset
180 predicate or_with (conditions, const predicate &) const;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 /* Return true if predicates are known to be equal. */
kono
parents:
diff changeset
183 inline bool operator==(const predicate &p2) const
kono
parents:
diff changeset
184 {
kono
parents:
diff changeset
185 int i;
kono
parents:
diff changeset
186 for (i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
187 {
kono
parents:
diff changeset
188 gcc_checking_assert (i < max_clauses);
kono
parents:
diff changeset
189 gcc_checking_assert (m_clause[i] > m_clause[i + 1]);
kono
parents:
diff changeset
190 gcc_checking_assert (!p2.m_clause[i]
kono
parents:
diff changeset
191 || p2.m_clause[i] > p2.m_clause[i + 1]);
kono
parents:
diff changeset
192 if (m_clause[i] != p2.m_clause[i])
kono
parents:
diff changeset
193 return false;
kono
parents:
diff changeset
194 }
kono
parents:
diff changeset
195 return !p2.m_clause[i];
kono
parents:
diff changeset
196 }
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 /* Return true if predicates are known to be true or false depending
kono
parents:
diff changeset
199 on COND. */
kono
parents:
diff changeset
200 inline bool operator==(const bool cond) const
kono
parents:
diff changeset
201 {
kono
parents:
diff changeset
202 if (cond)
kono
parents:
diff changeset
203 return !m_clause[0];
kono
parents:
diff changeset
204 if (m_clause[0] == (1 << false_condition))
kono
parents:
diff changeset
205 {
kono
parents:
diff changeset
206 gcc_checking_assert (!m_clause[1]
kono
parents:
diff changeset
207 && m_clause[0] == 1
kono
parents:
diff changeset
208 << false_condition);
kono
parents:
diff changeset
209 return true;
kono
parents:
diff changeset
210 }
kono
parents:
diff changeset
211 return false;
kono
parents:
diff changeset
212 }
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 inline bool operator!=(const predicate &p2) const
kono
parents:
diff changeset
215 {
kono
parents:
diff changeset
216 return !(*this == p2);
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 inline bool operator!=(const bool cond) const
kono
parents:
diff changeset
220 {
kono
parents:
diff changeset
221 return !(*this == cond);
kono
parents:
diff changeset
222 }
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 /* Evaluate if predicate is known to be false given the clause of possible
kono
parents:
diff changeset
225 truths. */
kono
parents:
diff changeset
226 bool evaluate (clause_t) const;
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 /* Estimate probability that predicate will be true in a given context. */
kono
parents:
diff changeset
229 int probability (conditions, clause_t, vec<inline_param_summary>) const;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 /* Dump predicate to F. Output newline if nl. */
kono
parents:
diff changeset
232 void dump (FILE *f, conditions, bool nl=true) const;
kono
parents:
diff changeset
233 void DEBUG_FUNCTION debug (conditions) const;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* Return predicate equal to THIS after duplication. */
kono
parents:
diff changeset
236 predicate remap_after_duplication (clause_t);
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 /* Return predicate equal to THIS after inlining. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
239 predicate remap_after_inlining (class ipa_fn_summary *,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
240 class ipa_node_params *params_summary,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
241 class ipa_fn_summary *,
111
kono
parents:
diff changeset
242 vec<int>, vec<int>, clause_t, const predicate &);
kono
parents:
diff changeset
243
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
244 void stream_in (class lto_input_block *);
111
kono
parents:
diff changeset
245 void stream_out (struct output_block *);
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 private:
kono
parents:
diff changeset
248 static const int max_clauses = 8;
kono
parents:
diff changeset
249 clause_t m_clause[max_clauses + 1];
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 /* Initialize predicate to one testing single condition number COND. */
kono
parents:
diff changeset
252 inline void set_to_cond (int cond)
kono
parents:
diff changeset
253 {
kono
parents:
diff changeset
254 m_clause[0] = 1 << cond;
kono
parents:
diff changeset
255 m_clause[1] = 0;
kono
parents:
diff changeset
256 }
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 void add_clause (conditions conditions, clause_t);
kono
parents:
diff changeset
259 };
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 void dump_condition (FILE *f, conditions conditions, int cond);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
262 predicate add_condition (class ipa_fn_summary *summary,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
263 class ipa_node_params *params_summary,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
264 int operand_num,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
265 tree type, struct agg_position_info *aggpos,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
266 enum tree_code code, tree val,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
267 expr_eval_ops param_ops = NULL);