annotate gcc/ipa-predicate.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* IPA predicates.
kono
parents:
diff changeset
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
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 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "backend.h"
kono
parents:
diff changeset
25 #include "tree.h"
kono
parents:
diff changeset
26 #include "cgraph.h"
kono
parents:
diff changeset
27 #include "tree-vrp.h"
kono
parents:
diff changeset
28 #include "symbol-summary.h"
kono
parents:
diff changeset
29 #include "alloc-pool.h"
kono
parents:
diff changeset
30 #include "ipa-prop.h"
kono
parents:
diff changeset
31 #include "ipa-fnsummary.h"
kono
parents:
diff changeset
32 #include "real.h"
kono
parents:
diff changeset
33 #include "fold-const.h"
kono
parents:
diff changeset
34 #include "tree-pretty-print.h"
kono
parents:
diff changeset
35 #include "gimple.h"
kono
parents:
diff changeset
36 #include "data-streamer.h"
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 /* Add clause CLAUSE into the predicate P.
kono
parents:
diff changeset
40 When CONDITIONS is NULL do not perform checking whether NEW_CLAUSE
kono
parents:
diff changeset
41 is obviously true. This is useful only when NEW_CLAUSE is known to be
kono
parents:
diff changeset
42 sane. */
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 void
kono
parents:
diff changeset
45 predicate::add_clause (conditions conditions, clause_t new_clause)
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 int i;
kono
parents:
diff changeset
48 int i2;
kono
parents:
diff changeset
49 int insert_here = -1;
kono
parents:
diff changeset
50 int c1, c2;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* True clause. */
kono
parents:
diff changeset
53 if (!new_clause)
kono
parents:
diff changeset
54 return;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* False clause makes the whole predicate false. Kill the other variants. */
kono
parents:
diff changeset
57 if (new_clause == (1 << predicate::false_condition))
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 *this = false;
kono
parents:
diff changeset
60 return;
kono
parents:
diff changeset
61 }
kono
parents:
diff changeset
62 if (*this == false)
kono
parents:
diff changeset
63 return;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 /* No one should be silly enough to add false into nontrivial clauses. */
kono
parents:
diff changeset
66 gcc_checking_assert (!(new_clause & (1 << predicate::false_condition)));
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Look where to insert the new_clause. At the same time prune out
kono
parents:
diff changeset
69 new_clauses of P that are implied by the new new_clause and thus
kono
parents:
diff changeset
70 redundant. */
kono
parents:
diff changeset
71 for (i = 0, i2 = 0; i <= max_clauses; i++)
kono
parents:
diff changeset
72 {
kono
parents:
diff changeset
73 m_clause[i2] = m_clause[i];
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 if (!m_clause[i])
kono
parents:
diff changeset
76 break;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 /* If m_clause[i] implies new_clause, there is nothing to add. */
kono
parents:
diff changeset
79 if ((m_clause[i] & new_clause) == m_clause[i])
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 /* We had nothing to add, none of clauses should've become
kono
parents:
diff changeset
82 redundant. */
kono
parents:
diff changeset
83 gcc_checking_assert (i == i2);
kono
parents:
diff changeset
84 return;
kono
parents:
diff changeset
85 }
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 if (m_clause[i] < new_clause && insert_here < 0)
kono
parents:
diff changeset
88 insert_here = i2;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* If new_clause implies clause[i], then clause[i] becomes redundant.
kono
parents:
diff changeset
91 Otherwise the clause[i] has to stay. */
kono
parents:
diff changeset
92 if ((m_clause[i] & new_clause) != new_clause)
kono
parents:
diff changeset
93 i2++;
kono
parents:
diff changeset
94 }
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 /* Look for clauses that are obviously true. I.e.
kono
parents:
diff changeset
97 op0 == 5 || op0 != 5. */
kono
parents:
diff changeset
98 if (conditions)
kono
parents:
diff changeset
99 for (c1 = predicate::first_dynamic_condition;
kono
parents:
diff changeset
100 c1 < num_conditions; c1++)
kono
parents:
diff changeset
101 {
kono
parents:
diff changeset
102 condition *cc1;
kono
parents:
diff changeset
103 if (!(new_clause & (1 << c1)))
kono
parents:
diff changeset
104 continue;
kono
parents:
diff changeset
105 cc1 = &(*conditions)[c1 - predicate::first_dynamic_condition];
kono
parents:
diff changeset
106 /* We have no way to represent !changed and !is_not_constant
kono
parents:
diff changeset
107 and thus there is no point for looking for them. */
kono
parents:
diff changeset
108 if (cc1->code == changed || cc1->code == is_not_constant)
kono
parents:
diff changeset
109 continue;
kono
parents:
diff changeset
110 for (c2 = c1 + 1; c2 < num_conditions; c2++)
kono
parents:
diff changeset
111 if (new_clause & (1 << c2))
kono
parents:
diff changeset
112 {
kono
parents:
diff changeset
113 condition *cc1 =
kono
parents:
diff changeset
114 &(*conditions)[c1 - predicate::first_dynamic_condition];
kono
parents:
diff changeset
115 condition *cc2 =
kono
parents:
diff changeset
116 &(*conditions)[c2 - predicate::first_dynamic_condition];
kono
parents:
diff changeset
117 if (cc1->operand_num == cc2->operand_num
kono
parents:
diff changeset
118 && cc1->val == cc2->val
kono
parents:
diff changeset
119 && cc2->code != is_not_constant
kono
parents:
diff changeset
120 && cc2->code != predicate::changed
kono
parents:
diff changeset
121 && cc1->code == invert_tree_comparison (cc2->code,
kono
parents:
diff changeset
122 HONOR_NANS (cc1->val)))
kono
parents:
diff changeset
123 return;
kono
parents:
diff changeset
124 }
kono
parents:
diff changeset
125 }
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* We run out of variants. Be conservative in positive direction. */
kono
parents:
diff changeset
129 if (i2 == max_clauses)
kono
parents:
diff changeset
130 return;
kono
parents:
diff changeset
131 /* Keep clauses in decreasing order. This makes equivalence testing easy. */
kono
parents:
diff changeset
132 m_clause[i2 + 1] = 0;
kono
parents:
diff changeset
133 if (insert_here >= 0)
kono
parents:
diff changeset
134 for (; i2 > insert_here; i2--)
kono
parents:
diff changeset
135 m_clause[i2] = m_clause[i2 - 1];
kono
parents:
diff changeset
136 else
kono
parents:
diff changeset
137 insert_here = i2;
kono
parents:
diff changeset
138 m_clause[insert_here] = new_clause;
kono
parents:
diff changeset
139 }
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 /* Do THIS &= P. */
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 predicate &
kono
parents:
diff changeset
145 predicate::operator &= (const predicate &p)
kono
parents:
diff changeset
146 {
kono
parents:
diff changeset
147 /* Avoid busy work. */
kono
parents:
diff changeset
148 if (p == false || *this == true)
kono
parents:
diff changeset
149 {
kono
parents:
diff changeset
150 *this = p;
kono
parents:
diff changeset
151 return *this;
kono
parents:
diff changeset
152 }
kono
parents:
diff changeset
153 if (*this == false || p == true || this == &p)
kono
parents:
diff changeset
154 return *this;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 int i;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 /* See how far predicates match. */
kono
parents:
diff changeset
159 for (i = 0; m_clause[i] && m_clause[i] == p.m_clause[i]; i++)
kono
parents:
diff changeset
160 {
kono
parents:
diff changeset
161 gcc_checking_assert (i < max_clauses);
kono
parents:
diff changeset
162 }
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 /* Combine the predicates rest. */
kono
parents:
diff changeset
165 for (; p.m_clause[i]; i++)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 gcc_checking_assert (i < max_clauses);
kono
parents:
diff changeset
168 add_clause (NULL, p.m_clause[i]);
kono
parents:
diff changeset
169 }
kono
parents:
diff changeset
170 return *this;
kono
parents:
diff changeset
171 }
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 /* Return THIS | P2. */
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 predicate
kono
parents:
diff changeset
178 predicate::or_with (conditions conditions,
kono
parents:
diff changeset
179 const predicate &p) const
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 /* Avoid busy work. */
kono
parents:
diff changeset
182 if (p == false || *this == true || *this == p)
kono
parents:
diff changeset
183 return *this;
kono
parents:
diff changeset
184 if (*this == false || p == true)
kono
parents:
diff changeset
185 return p;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 /* OK, combine the predicates. */
kono
parents:
diff changeset
188 predicate out = true;
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 for (int i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
191 for (int j = 0; p.m_clause[j]; j++)
kono
parents:
diff changeset
192 {
kono
parents:
diff changeset
193 gcc_checking_assert (i < max_clauses && j < max_clauses);
kono
parents:
diff changeset
194 out.add_clause (conditions, m_clause[i] | p.m_clause[j]);
kono
parents:
diff changeset
195 }
kono
parents:
diff changeset
196 return out;
kono
parents:
diff changeset
197 }
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 /* Having partial truth assignment in POSSIBLE_TRUTHS, return false
kono
parents:
diff changeset
201 if predicate P is known to be false. */
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 bool
kono
parents:
diff changeset
204 predicate::evaluate (clause_t possible_truths) const
kono
parents:
diff changeset
205 {
kono
parents:
diff changeset
206 int i;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 /* True remains true. */
kono
parents:
diff changeset
209 if (*this == true)
kono
parents:
diff changeset
210 return true;
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 gcc_assert (!(possible_truths & (1 << predicate::false_condition)));
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 /* See if we can find clause we can disprove. */
kono
parents:
diff changeset
215 for (i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
216 {
kono
parents:
diff changeset
217 gcc_checking_assert (i < max_clauses);
kono
parents:
diff changeset
218 if (!(m_clause[i] & possible_truths))
kono
parents:
diff changeset
219 return false;
kono
parents:
diff changeset
220 }
kono
parents:
diff changeset
221 return true;
kono
parents:
diff changeset
222 }
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 /* Return the probability in range 0...REG_BR_PROB_BASE that the predicated
kono
parents:
diff changeset
225 instruction will be recomputed per invocation of the inlined call. */
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 int
kono
parents:
diff changeset
228 predicate::probability (conditions conds,
kono
parents:
diff changeset
229 clause_t possible_truths,
kono
parents:
diff changeset
230 vec<inline_param_summary> inline_param_summary) const
kono
parents:
diff changeset
231 {
kono
parents:
diff changeset
232 int i;
kono
parents:
diff changeset
233 int combined_prob = REG_BR_PROB_BASE;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* True remains true. */
kono
parents:
diff changeset
236 if (*this == true)
kono
parents:
diff changeset
237 return REG_BR_PROB_BASE;
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 if (*this == false)
kono
parents:
diff changeset
240 return 0;
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 gcc_assert (!(possible_truths & (1 << predicate::false_condition)));
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 /* See if we can find clause we can disprove. */
kono
parents:
diff changeset
245 for (i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
246 {
kono
parents:
diff changeset
247 gcc_checking_assert (i < max_clauses);
kono
parents:
diff changeset
248 if (!(m_clause[i] & possible_truths))
kono
parents:
diff changeset
249 return 0;
kono
parents:
diff changeset
250 else
kono
parents:
diff changeset
251 {
kono
parents:
diff changeset
252 int this_prob = 0;
kono
parents:
diff changeset
253 int i2;
kono
parents:
diff changeset
254 if (!inline_param_summary.exists ())
kono
parents:
diff changeset
255 return REG_BR_PROB_BASE;
kono
parents:
diff changeset
256 for (i2 = 0; i2 < num_conditions; i2++)
kono
parents:
diff changeset
257 if ((m_clause[i] & possible_truths) & (1 << i2))
kono
parents:
diff changeset
258 {
kono
parents:
diff changeset
259 if (i2 >= predicate::first_dynamic_condition)
kono
parents:
diff changeset
260 {
kono
parents:
diff changeset
261 condition *c =
kono
parents:
diff changeset
262 &(*conds)[i2 - predicate::first_dynamic_condition];
kono
parents:
diff changeset
263 if (c->code == predicate::changed
kono
parents:
diff changeset
264 && (c->operand_num <
kono
parents:
diff changeset
265 (int) inline_param_summary.length ()))
kono
parents:
diff changeset
266 {
kono
parents:
diff changeset
267 int iprob =
kono
parents:
diff changeset
268 inline_param_summary[c->operand_num].change_prob;
kono
parents:
diff changeset
269 this_prob = MAX (this_prob, iprob);
kono
parents:
diff changeset
270 }
kono
parents:
diff changeset
271 else
kono
parents:
diff changeset
272 this_prob = REG_BR_PROB_BASE;
kono
parents:
diff changeset
273 }
kono
parents:
diff changeset
274 else
kono
parents:
diff changeset
275 this_prob = REG_BR_PROB_BASE;
kono
parents:
diff changeset
276 }
kono
parents:
diff changeset
277 combined_prob = MIN (this_prob, combined_prob);
kono
parents:
diff changeset
278 if (!combined_prob)
kono
parents:
diff changeset
279 return 0;
kono
parents:
diff changeset
280 }
kono
parents:
diff changeset
281 }
kono
parents:
diff changeset
282 return combined_prob;
kono
parents:
diff changeset
283 }
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 /* Dump conditional COND. */
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 void
kono
parents:
diff changeset
289 dump_condition (FILE *f, conditions conditions, int cond)
kono
parents:
diff changeset
290 {
kono
parents:
diff changeset
291 condition *c;
kono
parents:
diff changeset
292 if (cond == predicate::false_condition)
kono
parents:
diff changeset
293 fprintf (f, "false");
kono
parents:
diff changeset
294 else if (cond == predicate::not_inlined_condition)
kono
parents:
diff changeset
295 fprintf (f, "not inlined");
kono
parents:
diff changeset
296 else
kono
parents:
diff changeset
297 {
kono
parents:
diff changeset
298 c = &(*conditions)[cond - predicate::first_dynamic_condition];
kono
parents:
diff changeset
299 fprintf (f, "op%i", c->operand_num);
kono
parents:
diff changeset
300 if (c->agg_contents)
kono
parents:
diff changeset
301 fprintf (f, "[%soffset: " HOST_WIDE_INT_PRINT_DEC "]",
kono
parents:
diff changeset
302 c->by_ref ? "ref " : "", c->offset);
kono
parents:
diff changeset
303 if (c->code == predicate::is_not_constant)
kono
parents:
diff changeset
304 {
kono
parents:
diff changeset
305 fprintf (f, " not constant");
kono
parents:
diff changeset
306 return;
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308 if (c->code == predicate::changed)
kono
parents:
diff changeset
309 {
kono
parents:
diff changeset
310 fprintf (f, " changed");
kono
parents:
diff changeset
311 return;
kono
parents:
diff changeset
312 }
kono
parents:
diff changeset
313 fprintf (f, " %s ", op_symbol_code (c->code));
kono
parents:
diff changeset
314 print_generic_expr (f, c->val);
kono
parents:
diff changeset
315 }
kono
parents:
diff changeset
316 }
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 /* Dump clause CLAUSE. */
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 static void
kono
parents:
diff changeset
322 dump_clause (FILE *f, conditions conds, clause_t clause)
kono
parents:
diff changeset
323 {
kono
parents:
diff changeset
324 int i;
kono
parents:
diff changeset
325 bool found = false;
kono
parents:
diff changeset
326 fprintf (f, "(");
kono
parents:
diff changeset
327 if (!clause)
kono
parents:
diff changeset
328 fprintf (f, "true");
kono
parents:
diff changeset
329 for (i = 0; i < predicate::num_conditions; i++)
kono
parents:
diff changeset
330 if (clause & (1 << i))
kono
parents:
diff changeset
331 {
kono
parents:
diff changeset
332 if (found)
kono
parents:
diff changeset
333 fprintf (f, " || ");
kono
parents:
diff changeset
334 found = true;
kono
parents:
diff changeset
335 dump_condition (f, conds, i);
kono
parents:
diff changeset
336 }
kono
parents:
diff changeset
337 fprintf (f, ")");
kono
parents:
diff changeset
338 }
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 /* Dump THIS to F. CONDS a vector of conditions used when evauating
kono
parents:
diff changeset
342 predicats. When NL is true new line is output at the end of dump. */
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 void
kono
parents:
diff changeset
345 predicate::dump (FILE *f, conditions conds, bool nl) const
kono
parents:
diff changeset
346 {
kono
parents:
diff changeset
347 int i;
kono
parents:
diff changeset
348 if (*this == true)
kono
parents:
diff changeset
349 dump_clause (f, conds, 0);
kono
parents:
diff changeset
350 else
kono
parents:
diff changeset
351 for (i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
352 {
kono
parents:
diff changeset
353 if (i)
kono
parents:
diff changeset
354 fprintf (f, " && ");
kono
parents:
diff changeset
355 dump_clause (f, conds, m_clause[i]);
kono
parents:
diff changeset
356 }
kono
parents:
diff changeset
357 if (nl)
kono
parents:
diff changeset
358 fprintf (f, "\n");
kono
parents:
diff changeset
359 }
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 void
kono
parents:
diff changeset
363 predicate::debug (conditions conds) const
kono
parents:
diff changeset
364 {
kono
parents:
diff changeset
365 dump (stderr, conds);
kono
parents:
diff changeset
366 }
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 /* Remap predicate THIS of former function to be predicate of duplicated function.
kono
parents:
diff changeset
370 POSSIBLE_TRUTHS is clause of possible truths in the duplicated node,
kono
parents:
diff changeset
371 INFO is inline summary of the duplicated node. */
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 predicate
kono
parents:
diff changeset
374 predicate::remap_after_duplication (clause_t possible_truths)
kono
parents:
diff changeset
375 {
kono
parents:
diff changeset
376 int j;
kono
parents:
diff changeset
377 predicate out = true;
kono
parents:
diff changeset
378 for (j = 0; m_clause[j]; j++)
kono
parents:
diff changeset
379 if (!(possible_truths & m_clause[j]))
kono
parents:
diff changeset
380 return false;
kono
parents:
diff changeset
381 else
kono
parents:
diff changeset
382 out.add_clause (NULL, possible_truths & m_clause[j]);
kono
parents:
diff changeset
383 return out;
kono
parents:
diff changeset
384 }
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 /* Translate all conditions from callee representation into caller
kono
parents:
diff changeset
388 representation and symbolically evaluate predicate THIS into new predicate.
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 INFO is ipa_fn_summary of function we are adding predicate into, CALLEE_INFO
kono
parents:
diff changeset
391 is summary of function predicate P is from. OPERAND_MAP is array giving
kono
parents:
diff changeset
392 callee formal IDs the caller formal IDs. POSSSIBLE_TRUTHS is clausule of all
kono
parents:
diff changeset
393 callee conditions that may be true in caller context. TOPLEV_PREDICATE is
kono
parents:
diff changeset
394 predicate under which callee is executed. OFFSET_MAP is an array of of
kono
parents:
diff changeset
395 offsets that need to be added to conditions, negative offset means that
kono
parents:
diff changeset
396 conditions relying on values passed by reference have to be discarded
kono
parents:
diff changeset
397 because they might not be preserved (and should be considered offset zero
kono
parents:
diff changeset
398 for other purposes). */
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 predicate
kono
parents:
diff changeset
401 predicate::remap_after_inlining (struct ipa_fn_summary *info,
kono
parents:
diff changeset
402 struct ipa_fn_summary *callee_info,
kono
parents:
diff changeset
403 vec<int> operand_map,
kono
parents:
diff changeset
404 vec<int> offset_map,
kono
parents:
diff changeset
405 clause_t possible_truths,
kono
parents:
diff changeset
406 const predicate &toplev_predicate)
kono
parents:
diff changeset
407 {
kono
parents:
diff changeset
408 int i;
kono
parents:
diff changeset
409 predicate out = true;
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 /* True predicate is easy. */
kono
parents:
diff changeset
412 if (*this == true)
kono
parents:
diff changeset
413 return toplev_predicate;
kono
parents:
diff changeset
414 for (i = 0; m_clause[i]; i++)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 clause_t clause = m_clause[i];
kono
parents:
diff changeset
417 int cond;
kono
parents:
diff changeset
418 predicate clause_predicate = false;
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 gcc_assert (i < max_clauses);
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 for (cond = 0; cond < num_conditions; cond++)
kono
parents:
diff changeset
423 /* Do we have condition we can't disprove? */
kono
parents:
diff changeset
424 if (clause & possible_truths & (1 << cond))
kono
parents:
diff changeset
425 {
kono
parents:
diff changeset
426 predicate cond_predicate;
kono
parents:
diff changeset
427 /* Work out if the condition can translate to predicate in the
kono
parents:
diff changeset
428 inlined function. */
kono
parents:
diff changeset
429 if (cond >= predicate::first_dynamic_condition)
kono
parents:
diff changeset
430 {
kono
parents:
diff changeset
431 struct condition *c;
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 c = &(*callee_info->conds)[cond
kono
parents:
diff changeset
434 -
kono
parents:
diff changeset
435 predicate::first_dynamic_condition];
kono
parents:
diff changeset
436 /* See if we can remap condition operand to caller's operand.
kono
parents:
diff changeset
437 Otherwise give up. */
kono
parents:
diff changeset
438 if (!operand_map.exists ()
kono
parents:
diff changeset
439 || (int) operand_map.length () <= c->operand_num
kono
parents:
diff changeset
440 || operand_map[c->operand_num] == -1
kono
parents:
diff changeset
441 /* TODO: For non-aggregate conditions, adding an offset is
kono
parents:
diff changeset
442 basically an arithmetic jump function processing which
kono
parents:
diff changeset
443 we should support in future. */
kono
parents:
diff changeset
444 || ((!c->agg_contents || !c->by_ref)
kono
parents:
diff changeset
445 && offset_map[c->operand_num] > 0)
kono
parents:
diff changeset
446 || (c->agg_contents && c->by_ref
kono
parents:
diff changeset
447 && offset_map[c->operand_num] < 0))
kono
parents:
diff changeset
448 cond_predicate = true;
kono
parents:
diff changeset
449 else
kono
parents:
diff changeset
450 {
kono
parents:
diff changeset
451 struct agg_position_info ap;
kono
parents:
diff changeset
452 HOST_WIDE_INT offset_delta = offset_map[c->operand_num];
kono
parents:
diff changeset
453 if (offset_delta < 0)
kono
parents:
diff changeset
454 {
kono
parents:
diff changeset
455 gcc_checking_assert (!c->agg_contents || !c->by_ref);
kono
parents:
diff changeset
456 offset_delta = 0;
kono
parents:
diff changeset
457 }
kono
parents:
diff changeset
458 gcc_assert (!c->agg_contents
kono
parents:
diff changeset
459 || c->by_ref || offset_delta == 0);
kono
parents:
diff changeset
460 ap.offset = c->offset + offset_delta;
kono
parents:
diff changeset
461 ap.agg_contents = c->agg_contents;
kono
parents:
diff changeset
462 ap.by_ref = c->by_ref;
kono
parents:
diff changeset
463 cond_predicate = add_condition (info,
kono
parents:
diff changeset
464 operand_map[c->operand_num],
kono
parents:
diff changeset
465 c->size, &ap, c->code,
kono
parents:
diff changeset
466 c->val);
kono
parents:
diff changeset
467 }
kono
parents:
diff changeset
468 }
kono
parents:
diff changeset
469 /* Fixed conditions remains same, construct single
kono
parents:
diff changeset
470 condition predicate. */
kono
parents:
diff changeset
471 else
kono
parents:
diff changeset
472 cond_predicate = predicate::predicate_testing_cond (cond);
kono
parents:
diff changeset
473 clause_predicate = clause_predicate.or_with (info->conds,
kono
parents:
diff changeset
474 cond_predicate);
kono
parents:
diff changeset
475 }
kono
parents:
diff changeset
476 out &= clause_predicate;
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478 out &= toplev_predicate;
kono
parents:
diff changeset
479 return out;
kono
parents:
diff changeset
480 }
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 /* Read predicate from IB. */
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 void
kono
parents:
diff changeset
486 predicate::stream_in (struct lto_input_block *ib)
kono
parents:
diff changeset
487 {
kono
parents:
diff changeset
488 clause_t clause;
kono
parents:
diff changeset
489 int k = 0;
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 do
kono
parents:
diff changeset
492 {
kono
parents:
diff changeset
493 gcc_assert (k <= max_clauses);
kono
parents:
diff changeset
494 clause = m_clause[k++] = streamer_read_uhwi (ib);
kono
parents:
diff changeset
495 }
kono
parents:
diff changeset
496 while (clause);
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 /* Zero-initialize the remaining clauses in OUT. */
kono
parents:
diff changeset
499 while (k <= max_clauses)
kono
parents:
diff changeset
500 m_clause[k++] = 0;
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 /* Write predicate P to OB. */
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 void
kono
parents:
diff changeset
507 predicate::stream_out (struct output_block *ob)
kono
parents:
diff changeset
508 {
kono
parents:
diff changeset
509 int j;
kono
parents:
diff changeset
510 for (j = 0; m_clause[j]; j++)
kono
parents:
diff changeset
511 {
kono
parents:
diff changeset
512 gcc_assert (j < max_clauses);
kono
parents:
diff changeset
513 streamer_write_uhwi (ob, m_clause[j]);
kono
parents:
diff changeset
514 }
kono
parents:
diff changeset
515 streamer_write_uhwi (ob, 0);
kono
parents:
diff changeset
516 }
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 /* Add condition to condition list SUMMARY. OPERAND_NUM, SIZE, CODE and VAL
kono
parents:
diff changeset
520 correspond to fields of condition structure. AGGPOS describes whether the
kono
parents:
diff changeset
521 used operand is loaded from an aggregate and where in the aggregate it is.
kono
parents:
diff changeset
522 It can be NULL, which means this not a load from an aggregate. */
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 predicate
kono
parents:
diff changeset
525 add_condition (struct ipa_fn_summary *summary, int operand_num,
kono
parents:
diff changeset
526 HOST_WIDE_INT size, struct agg_position_info *aggpos,
kono
parents:
diff changeset
527 enum tree_code code, tree val)
kono
parents:
diff changeset
528 {
kono
parents:
diff changeset
529 int i;
kono
parents:
diff changeset
530 struct condition *c;
kono
parents:
diff changeset
531 struct condition new_cond;
kono
parents:
diff changeset
532 HOST_WIDE_INT offset;
kono
parents:
diff changeset
533 bool agg_contents, by_ref;
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 if (aggpos)
kono
parents:
diff changeset
536 {
kono
parents:
diff changeset
537 offset = aggpos->offset;
kono
parents:
diff changeset
538 agg_contents = aggpos->agg_contents;
kono
parents:
diff changeset
539 by_ref = aggpos->by_ref;
kono
parents:
diff changeset
540 }
kono
parents:
diff changeset
541 else
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 offset = 0;
kono
parents:
diff changeset
544 agg_contents = false;
kono
parents:
diff changeset
545 by_ref = false;
kono
parents:
diff changeset
546 }
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 gcc_checking_assert (operand_num >= 0);
kono
parents:
diff changeset
549 for (i = 0; vec_safe_iterate (summary->conds, i, &c); i++)
kono
parents:
diff changeset
550 {
kono
parents:
diff changeset
551 if (c->operand_num == operand_num
kono
parents:
diff changeset
552 && c->size == size
kono
parents:
diff changeset
553 && c->code == code
kono
parents:
diff changeset
554 && c->val == val
kono
parents:
diff changeset
555 && c->agg_contents == agg_contents
kono
parents:
diff changeset
556 && (!agg_contents || (c->offset == offset && c->by_ref == by_ref)))
kono
parents:
diff changeset
557 return predicate::predicate_testing_cond (i);
kono
parents:
diff changeset
558 }
kono
parents:
diff changeset
559 /* Too many conditions. Give up and return constant true. */
kono
parents:
diff changeset
560 if (i == predicate::num_conditions - predicate::first_dynamic_condition)
kono
parents:
diff changeset
561 return true;
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 new_cond.operand_num = operand_num;
kono
parents:
diff changeset
564 new_cond.code = code;
kono
parents:
diff changeset
565 new_cond.val = val;
kono
parents:
diff changeset
566 new_cond.agg_contents = agg_contents;
kono
parents:
diff changeset
567 new_cond.by_ref = by_ref;
kono
parents:
diff changeset
568 new_cond.offset = offset;
kono
parents:
diff changeset
569 new_cond.size = size;
kono
parents:
diff changeset
570 vec_safe_push (summary->conds, new_cond);
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 return predicate::predicate_testing_cond (i);
kono
parents:
diff changeset
573 }