expmed.c (store_bit_field_1): Be prepared for movstrict expander to fail.
[gcc.git] / gcc / predict.c
1 /* Branch prediction routines for the GNU compiler.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 /* References:
22
23 [1] "Branch Prediction for Free"
24 Ball and Larus; PLDI '93.
25 [2] "Static Branch Frequency and Program Profile Analysis"
26 Wu and Larus; MICRO-27.
27 [3] "Corpus-based Static Branch Prediction"
28 Calder, Grunwald, Lindsay, Martin, Mozer, and Zorn; PLDI '95. */
29
30
31 #include "config.h"
32 #include "system.h"
33 #include "coretypes.h"
34 #include "tm.h"
35 #include "tree.h"
36 #include "rtl.h"
37 #include "tm_p.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "insn-config.h"
41 #include "regs.h"
42 #include "flags.h"
43 #include "output.h"
44 #include "function.h"
45 #include "except.h"
46 #include "toplev.h"
47 #include "recog.h"
48 #include "expr.h"
49 #include "predict.h"
50 #include "coverage.h"
51 #include "sreal.h"
52 #include "params.h"
53 #include "target.h"
54 #include "cfgloop.h"
55 #include "tree-flow.h"
56 #include "ggc.h"
57 #include "tree-dump.h"
58 #include "tree-pass.h"
59 #include "timevar.h"
60 #include "tree-scalar-evolution.h"
61 #include "cfgloop.h"
62 #include "pointer-set.h"
63
64 /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
65 1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX. */
66 static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
67 real_inv_br_prob_base, real_one_half, real_bb_freq_max;
68
69 /* Random guesstimation given names. */
70 #define PROB_VERY_UNLIKELY (REG_BR_PROB_BASE / 100 - 1)
71 #define PROB_EVEN (REG_BR_PROB_BASE / 2)
72 #define PROB_VERY_LIKELY (REG_BR_PROB_BASE - PROB_VERY_UNLIKELY)
73 #define PROB_ALWAYS (REG_BR_PROB_BASE)
74
75 static void combine_predictions_for_insn (rtx, basic_block);
76 static void dump_prediction (FILE *, enum br_predictor, int, basic_block, int);
77 static void predict_paths_leading_to (basic_block, enum br_predictor, enum prediction);
78 static void compute_function_frequency (void);
79 static void choose_function_section (void);
80 static bool can_predict_insn_p (const_rtx);
81
82 /* Information we hold about each branch predictor.
83 Filled using information from predict.def. */
84
85 struct predictor_info
86 {
87 const char *const name; /* Name used in the debugging dumps. */
88 const int hitrate; /* Expected hitrate used by
89 predict_insn_def call. */
90 const int flags;
91 };
92
93 /* Use given predictor without Dempster-Shaffer theory if it matches
94 using first_match heuristics. */
95 #define PRED_FLAG_FIRST_MATCH 1
96
97 /* Recompute hitrate in percent to our representation. */
98
99 #define HITRATE(VAL) ((int) ((VAL) * REG_BR_PROB_BASE + 50) / 100)
100
101 #define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) {NAME, HITRATE, FLAGS},
102 static const struct predictor_info predictor_info[]= {
103 #include "predict.def"
104
105 /* Upper bound on predictors. */
106 {NULL, 0, 0}
107 };
108 #undef DEF_PREDICTOR
109
110 /* Return TRUE if frequency FREQ is considered to be hot. */
111 static bool
112 maybe_hot_frequency_p (int freq)
113 {
114 if (!profile_info || !flag_branch_probabilities)
115 {
116 if (cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
117 return false;
118 if (cfun->function_frequency == FUNCTION_FREQUENCY_HOT)
119 return true;
120 }
121 if (profile_status == PROFILE_ABSENT)
122 return true;
123 if (freq < BB_FREQ_MAX / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION))
124 return false;
125 return true;
126 }
127
128 /* Return true in case BB can be CPU intensive and should be optimized
129 for maximal performance. */
130
131 bool
132 maybe_hot_bb_p (const_basic_block bb)
133 {
134 if (profile_info && flag_branch_probabilities
135 && (bb->count
136 < profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
137 return false;
138 return maybe_hot_frequency_p (bb->frequency);
139 }
140
141 /* Return true in case BB can be CPU intensive and should be optimized
142 for maximal performance. */
143
144 bool
145 maybe_hot_edge_p (edge e)
146 {
147 if (profile_info && flag_branch_probabilities
148 && (e->count
149 < profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
150 return false;
151 return maybe_hot_frequency_p (EDGE_FREQUENCY (e));
152 }
153
154 /* Return true in case BB is cold and should be optimized for size. */
155
156 bool
157 probably_cold_bb_p (const_basic_block bb)
158 {
159 if (profile_info && flag_branch_probabilities
160 && (bb->count
161 < profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
162 return true;
163 if ((!profile_info || !flag_branch_probabilities)
164 && cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
165 return true;
166 if (bb->frequency < BB_FREQ_MAX / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION))
167 return true;
168 return false;
169 }
170
171 /* Return true in case BB is probably never executed. */
172 bool
173 probably_never_executed_bb_p (const_basic_block bb)
174 {
175 if (profile_info && flag_branch_probabilities)
176 return ((bb->count + profile_info->runs / 2) / profile_info->runs) == 0;
177 if ((!profile_info || !flag_branch_probabilities)
178 && cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
179 return true;
180 return false;
181 }
182
183 /* Return true when current function should always be optimized for size. */
184
185 bool
186 optimize_function_for_size_p (struct function *fun)
187 {
188 return (optimize_size
189 || fun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED);
190 }
191
192 /* Return true when current function should always be optimized for speed. */
193
194 bool
195 optimize_function_for_speed_p (struct function *fun)
196 {
197 return !optimize_function_for_size_p (fun);
198 }
199
200 /* Return TRUE when BB should be optimized for size. */
201
202 bool
203 optimize_bb_for_size_p (basic_block bb)
204 {
205 return optimize_function_for_size_p (cfun) || !maybe_hot_bb_p (bb);
206 }
207
208 /* Return TRUE when BB should be optimized for speed. */
209
210 bool
211 optimize_bb_for_speed_p (basic_block bb)
212 {
213 return !optimize_bb_for_size_p (bb);
214 }
215
216 /* Return TRUE when BB should be optimized for size. */
217
218 bool
219 optimize_edge_for_size_p (edge e)
220 {
221 return optimize_function_for_size_p (cfun) || !maybe_hot_edge_p (e);
222 }
223
224 /* Return TRUE when BB should be optimized for speed. */
225
226 bool
227 optimize_edge_for_speed_p (edge e)
228 {
229 return !optimize_edge_for_size_p (e);
230 }
231
232 /* Return TRUE when BB should be optimized for size. */
233
234 bool
235 optimize_insn_for_size_p (void)
236 {
237 return optimize_function_for_size_p (cfun) || !crtl->maybe_hot_insn_p;
238 }
239
240 /* Return TRUE when BB should be optimized for speed. */
241
242 bool
243 optimize_insn_for_speed_p (void)
244 {
245 return !optimize_insn_for_size_p ();
246 }
247
248 /* Set RTL expansion for BB profile. */
249
250 void
251 rtl_profile_for_bb (basic_block bb)
252 {
253 crtl->maybe_hot_insn_p = maybe_hot_bb_p (bb);
254 }
255
256 /* Set RTL expansion for edge profile. */
257
258 void
259 rtl_profile_for_edge (edge e)
260 {
261 crtl->maybe_hot_insn_p = maybe_hot_edge_p (e);
262 }
263
264 /* Set RTL expansion to default mode (i.e. when profile info is not known). */
265 void
266 default_rtl_profile (void)
267 {
268 crtl->maybe_hot_insn_p = true;
269 }
270
271 /* Return true if the one of outgoing edges is already predicted by
272 PREDICTOR. */
273
274 bool
275 rtl_predicted_by_p (const_basic_block bb, enum br_predictor predictor)
276 {
277 rtx note;
278 if (!INSN_P (BB_END (bb)))
279 return false;
280 for (note = REG_NOTES (BB_END (bb)); note; note = XEXP (note, 1))
281 if (REG_NOTE_KIND (note) == REG_BR_PRED
282 && INTVAL (XEXP (XEXP (note, 0), 0)) == (int)predictor)
283 return true;
284 return false;
285 }
286
287 /* This map contains for a basic block the list of predictions for the
288 outgoing edges. */
289
290 static struct pointer_map_t *bb_predictions;
291
292 /* Return true if the one of outgoing edges is already predicted by
293 PREDICTOR. */
294
295 bool
296 gimple_predicted_by_p (const_basic_block bb, enum br_predictor predictor)
297 {
298 struct edge_prediction *i;
299 void **preds = pointer_map_contains (bb_predictions, bb);
300
301 if (!preds)
302 return false;
303
304 for (i = (struct edge_prediction *) *preds; i; i = i->ep_next)
305 if (i->ep_predictor == predictor)
306 return true;
307 return false;
308 }
309
310 /* Return true when the probability of edge is reliable.
311
312 The profile guessing code is good at predicting branch outcome (ie.
313 taken/not taken), that is predicted right slightly over 75% of time.
314 It is however notoriously poor on predicting the probability itself.
315 In general the profile appear a lot flatter (with probabilities closer
316 to 50%) than the reality so it is bad idea to use it to drive optimization
317 such as those disabling dynamic branch prediction for well predictable
318 branches.
319
320 There are two exceptions - edges leading to noreturn edges and edges
321 predicted by number of iterations heuristics are predicted well. This macro
322 should be able to distinguish those, but at the moment it simply check for
323 noreturn heuristic that is only one giving probability over 99% or bellow
324 1%. In future we might want to propagate reliability information across the
325 CFG if we find this information useful on multiple places. */
326 static bool
327 probability_reliable_p (int prob)
328 {
329 return (profile_status == PROFILE_READ
330 || (profile_status == PROFILE_GUESSED
331 && (prob <= HITRATE (1) || prob >= HITRATE (99))));
332 }
333
334 /* Same predicate as above, working on edges. */
335 bool
336 edge_probability_reliable_p (const_edge e)
337 {
338 return probability_reliable_p (e->probability);
339 }
340
341 /* Same predicate as edge_probability_reliable_p, working on notes. */
342 bool
343 br_prob_note_reliable_p (const_rtx note)
344 {
345 gcc_assert (REG_NOTE_KIND (note) == REG_BR_PROB);
346 return probability_reliable_p (INTVAL (XEXP (note, 0)));
347 }
348
349 static void
350 predict_insn (rtx insn, enum br_predictor predictor, int probability)
351 {
352 gcc_assert (any_condjump_p (insn));
353 if (!flag_guess_branch_prob)
354 return;
355
356 add_reg_note (insn, REG_BR_PRED,
357 gen_rtx_CONCAT (VOIDmode,
358 GEN_INT ((int) predictor),
359 GEN_INT ((int) probability)));
360 }
361
362 /* Predict insn by given predictor. */
363
364 void
365 predict_insn_def (rtx insn, enum br_predictor predictor,
366 enum prediction taken)
367 {
368 int probability = predictor_info[(int) predictor].hitrate;
369
370 if (taken != TAKEN)
371 probability = REG_BR_PROB_BASE - probability;
372
373 predict_insn (insn, predictor, probability);
374 }
375
376 /* Predict edge E with given probability if possible. */
377
378 void
379 rtl_predict_edge (edge e, enum br_predictor predictor, int probability)
380 {
381 rtx last_insn;
382 last_insn = BB_END (e->src);
383
384 /* We can store the branch prediction information only about
385 conditional jumps. */
386 if (!any_condjump_p (last_insn))
387 return;
388
389 /* We always store probability of branching. */
390 if (e->flags & EDGE_FALLTHRU)
391 probability = REG_BR_PROB_BASE - probability;
392
393 predict_insn (last_insn, predictor, probability);
394 }
395
396 /* Predict edge E with the given PROBABILITY. */
397 void
398 gimple_predict_edge (edge e, enum br_predictor predictor, int probability)
399 {
400 gcc_assert (profile_status != PROFILE_GUESSED);
401 if ((e->src != ENTRY_BLOCK_PTR && EDGE_COUNT (e->src->succs) > 1)
402 && flag_guess_branch_prob && optimize)
403 {
404 struct edge_prediction *i = XNEW (struct edge_prediction);
405 void **preds = pointer_map_insert (bb_predictions, e->src);
406
407 i->ep_next = (struct edge_prediction *) *preds;
408 *preds = i;
409 i->ep_probability = probability;
410 i->ep_predictor = predictor;
411 i->ep_edge = e;
412 }
413 }
414
415 /* Remove all predictions on given basic block that are attached
416 to edge E. */
417 void
418 remove_predictions_associated_with_edge (edge e)
419 {
420 void **preds;
421
422 if (!bb_predictions)
423 return;
424
425 preds = pointer_map_contains (bb_predictions, e->src);
426
427 if (preds)
428 {
429 struct edge_prediction **prediction = (struct edge_prediction **) preds;
430 struct edge_prediction *next;
431
432 while (*prediction)
433 {
434 if ((*prediction)->ep_edge == e)
435 {
436 next = (*prediction)->ep_next;
437 free (*prediction);
438 *prediction = next;
439 }
440 else
441 prediction = &((*prediction)->ep_next);
442 }
443 }
444 }
445
446 /* Clears the list of predictions stored for BB. */
447
448 static void
449 clear_bb_predictions (basic_block bb)
450 {
451 void **preds = pointer_map_contains (bb_predictions, bb);
452 struct edge_prediction *pred, *next;
453
454 if (!preds)
455 return;
456
457 for (pred = (struct edge_prediction *) *preds; pred; pred = next)
458 {
459 next = pred->ep_next;
460 free (pred);
461 }
462 *preds = NULL;
463 }
464
465 /* Return true when we can store prediction on insn INSN.
466 At the moment we represent predictions only on conditional
467 jumps, not at computed jump or other complicated cases. */
468 static bool
469 can_predict_insn_p (const_rtx insn)
470 {
471 return (JUMP_P (insn)
472 && any_condjump_p (insn)
473 && EDGE_COUNT (BLOCK_FOR_INSN (insn)->succs) >= 2);
474 }
475
476 /* Predict edge E by given predictor if possible. */
477
478 void
479 predict_edge_def (edge e, enum br_predictor predictor,
480 enum prediction taken)
481 {
482 int probability = predictor_info[(int) predictor].hitrate;
483
484 if (taken != TAKEN)
485 probability = REG_BR_PROB_BASE - probability;
486
487 predict_edge (e, predictor, probability);
488 }
489
490 /* Invert all branch predictions or probability notes in the INSN. This needs
491 to be done each time we invert the condition used by the jump. */
492
493 void
494 invert_br_probabilities (rtx insn)
495 {
496 rtx note;
497
498 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
499 if (REG_NOTE_KIND (note) == REG_BR_PROB)
500 XEXP (note, 0) = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (note, 0)));
501 else if (REG_NOTE_KIND (note) == REG_BR_PRED)
502 XEXP (XEXP (note, 0), 1)
503 = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (XEXP (note, 0), 1)));
504 }
505
506 /* Dump information about the branch prediction to the output file. */
507
508 static void
509 dump_prediction (FILE *file, enum br_predictor predictor, int probability,
510 basic_block bb, int used)
511 {
512 edge e;
513 edge_iterator ei;
514
515 if (!file)
516 return;
517
518 FOR_EACH_EDGE (e, ei, bb->succs)
519 if (! (e->flags & EDGE_FALLTHRU))
520 break;
521
522 fprintf (file, " %s heuristics%s: %.1f%%",
523 predictor_info[predictor].name,
524 used ? "" : " (ignored)", probability * 100.0 / REG_BR_PROB_BASE);
525
526 if (bb->count)
527 {
528 fprintf (file, " exec ");
529 fprintf (file, HOST_WIDEST_INT_PRINT_DEC, bb->count);
530 if (e)
531 {
532 fprintf (file, " hit ");
533 fprintf (file, HOST_WIDEST_INT_PRINT_DEC, e->count);
534 fprintf (file, " (%.1f%%)", e->count * 100.0 / bb->count);
535 }
536 }
537
538 fprintf (file, "\n");
539 }
540
541 /* We can not predict the probabilities of outgoing edges of bb. Set them
542 evenly and hope for the best. */
543 static void
544 set_even_probabilities (basic_block bb)
545 {
546 int nedges = 0;
547 edge e;
548 edge_iterator ei;
549
550 FOR_EACH_EDGE (e, ei, bb->succs)
551 if (!(e->flags & (EDGE_EH | EDGE_FAKE)))
552 nedges ++;
553 FOR_EACH_EDGE (e, ei, bb->succs)
554 if (!(e->flags & (EDGE_EH | EDGE_FAKE)))
555 e->probability = (REG_BR_PROB_BASE + nedges / 2) / nedges;
556 else
557 e->probability = 0;
558 }
559
560 /* Combine all REG_BR_PRED notes into single probability and attach REG_BR_PROB
561 note if not already present. Remove now useless REG_BR_PRED notes. */
562
563 static void
564 combine_predictions_for_insn (rtx insn, basic_block bb)
565 {
566 rtx prob_note;
567 rtx *pnote;
568 rtx note;
569 int best_probability = PROB_EVEN;
570 int best_predictor = END_PREDICTORS;
571 int combined_probability = REG_BR_PROB_BASE / 2;
572 int d;
573 bool first_match = false;
574 bool found = false;
575
576 if (!can_predict_insn_p (insn))
577 {
578 set_even_probabilities (bb);
579 return;
580 }
581
582 prob_note = find_reg_note (insn, REG_BR_PROB, 0);
583 pnote = &REG_NOTES (insn);
584 if (dump_file)
585 fprintf (dump_file, "Predictions for insn %i bb %i\n", INSN_UID (insn),
586 bb->index);
587
588 /* We implement "first match" heuristics and use probability guessed
589 by predictor with smallest index. */
590 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
591 if (REG_NOTE_KIND (note) == REG_BR_PRED)
592 {
593 int predictor = INTVAL (XEXP (XEXP (note, 0), 0));
594 int probability = INTVAL (XEXP (XEXP (note, 0), 1));
595
596 found = true;
597 if (best_predictor > predictor)
598 best_probability = probability, best_predictor = predictor;
599
600 d = (combined_probability * probability
601 + (REG_BR_PROB_BASE - combined_probability)
602 * (REG_BR_PROB_BASE - probability));
603
604 /* Use FP math to avoid overflows of 32bit integers. */
605 if (d == 0)
606 /* If one probability is 0% and one 100%, avoid division by zero. */
607 combined_probability = REG_BR_PROB_BASE / 2;
608 else
609 combined_probability = (((double) combined_probability) * probability
610 * REG_BR_PROB_BASE / d + 0.5);
611 }
612
613 /* Decide which heuristic to use. In case we didn't match anything,
614 use no_prediction heuristic, in case we did match, use either
615 first match or Dempster-Shaffer theory depending on the flags. */
616
617 if (predictor_info [best_predictor].flags & PRED_FLAG_FIRST_MATCH)
618 first_match = true;
619
620 if (!found)
621 dump_prediction (dump_file, PRED_NO_PREDICTION,
622 combined_probability, bb, true);
623 else
624 {
625 dump_prediction (dump_file, PRED_DS_THEORY, combined_probability,
626 bb, !first_match);
627 dump_prediction (dump_file, PRED_FIRST_MATCH, best_probability,
628 bb, first_match);
629 }
630
631 if (first_match)
632 combined_probability = best_probability;
633 dump_prediction (dump_file, PRED_COMBINED, combined_probability, bb, true);
634
635 while (*pnote)
636 {
637 if (REG_NOTE_KIND (*pnote) == REG_BR_PRED)
638 {
639 int predictor = INTVAL (XEXP (XEXP (*pnote, 0), 0));
640 int probability = INTVAL (XEXP (XEXP (*pnote, 0), 1));
641
642 dump_prediction (dump_file, predictor, probability, bb,
643 !first_match || best_predictor == predictor);
644 *pnote = XEXP (*pnote, 1);
645 }
646 else
647 pnote = &XEXP (*pnote, 1);
648 }
649
650 if (!prob_note)
651 {
652 add_reg_note (insn, REG_BR_PROB, GEN_INT (combined_probability));
653
654 /* Save the prediction into CFG in case we are seeing non-degenerated
655 conditional jump. */
656 if (!single_succ_p (bb))
657 {
658 BRANCH_EDGE (bb)->probability = combined_probability;
659 FALLTHRU_EDGE (bb)->probability
660 = REG_BR_PROB_BASE - combined_probability;
661 }
662 }
663 else if (!single_succ_p (bb))
664 {
665 int prob = INTVAL (XEXP (prob_note, 0));
666
667 BRANCH_EDGE (bb)->probability = prob;
668 FALLTHRU_EDGE (bb)->probability = REG_BR_PROB_BASE - prob;
669 }
670 else
671 single_succ_edge (bb)->probability = REG_BR_PROB_BASE;
672 }
673
674 /* Combine predictions into single probability and store them into CFG.
675 Remove now useless prediction entries. */
676
677 static void
678 combine_predictions_for_bb (basic_block bb)
679 {
680 int best_probability = PROB_EVEN;
681 int best_predictor = END_PREDICTORS;
682 int combined_probability = REG_BR_PROB_BASE / 2;
683 int d;
684 bool first_match = false;
685 bool found = false;
686 struct edge_prediction *pred;
687 int nedges = 0;
688 edge e, first = NULL, second = NULL;
689 edge_iterator ei;
690 void **preds;
691
692 FOR_EACH_EDGE (e, ei, bb->succs)
693 if (!(e->flags & (EDGE_EH | EDGE_FAKE)))
694 {
695 nedges ++;
696 if (first && !second)
697 second = e;
698 if (!first)
699 first = e;
700 }
701
702 /* When there is no successor or only one choice, prediction is easy.
703
704 We are lazy for now and predict only basic blocks with two outgoing
705 edges. It is possible to predict generic case too, but we have to
706 ignore first match heuristics and do more involved combining. Implement
707 this later. */
708 if (nedges != 2)
709 {
710 if (!bb->count)
711 set_even_probabilities (bb);
712 clear_bb_predictions (bb);
713 if (dump_file)
714 fprintf (dump_file, "%i edges in bb %i predicted to even probabilities\n",
715 nedges, bb->index);
716 return;
717 }
718
719 if (dump_file)
720 fprintf (dump_file, "Predictions for bb %i\n", bb->index);
721
722 preds = pointer_map_contains (bb_predictions, bb);
723 if (preds)
724 {
725 /* We implement "first match" heuristics and use probability guessed
726 by predictor with smallest index. */
727 for (pred = (struct edge_prediction *) *preds; pred; pred = pred->ep_next)
728 {
729 int predictor = pred->ep_predictor;
730 int probability = pred->ep_probability;
731
732 if (pred->ep_edge != first)
733 probability = REG_BR_PROB_BASE - probability;
734
735 found = true;
736 if (best_predictor > predictor)
737 best_probability = probability, best_predictor = predictor;
738
739 d = (combined_probability * probability
740 + (REG_BR_PROB_BASE - combined_probability)
741 * (REG_BR_PROB_BASE - probability));
742
743 /* Use FP math to avoid overflows of 32bit integers. */
744 if (d == 0)
745 /* If one probability is 0% and one 100%, avoid division by zero. */
746 combined_probability = REG_BR_PROB_BASE / 2;
747 else
748 combined_probability = (((double) combined_probability)
749 * probability
750 * REG_BR_PROB_BASE / d + 0.5);
751 }
752 }
753
754 /* Decide which heuristic to use. In case we didn't match anything,
755 use no_prediction heuristic, in case we did match, use either
756 first match or Dempster-Shaffer theory depending on the flags. */
757
758 if (predictor_info [best_predictor].flags & PRED_FLAG_FIRST_MATCH)
759 first_match = true;
760
761 if (!found)
762 dump_prediction (dump_file, PRED_NO_PREDICTION, combined_probability, bb, true);
763 else
764 {
765 dump_prediction (dump_file, PRED_DS_THEORY, combined_probability, bb,
766 !first_match);
767 dump_prediction (dump_file, PRED_FIRST_MATCH, best_probability, bb,
768 first_match);
769 }
770
771 if (first_match)
772 combined_probability = best_probability;
773 dump_prediction (dump_file, PRED_COMBINED, combined_probability, bb, true);
774
775 if (preds)
776 {
777 for (pred = (struct edge_prediction *) *preds; pred; pred = pred->ep_next)
778 {
779 int predictor = pred->ep_predictor;
780 int probability = pred->ep_probability;
781
782 if (pred->ep_edge != EDGE_SUCC (bb, 0))
783 probability = REG_BR_PROB_BASE - probability;
784 dump_prediction (dump_file, predictor, probability, bb,
785 !first_match || best_predictor == predictor);
786 }
787 }
788 clear_bb_predictions (bb);
789
790 if (!bb->count)
791 {
792 first->probability = combined_probability;
793 second->probability = REG_BR_PROB_BASE - combined_probability;
794 }
795 }
796
797 /* Predict edge probabilities by exploiting loop structure. */
798
799 static void
800 predict_loops (void)
801 {
802 loop_iterator li;
803 struct loop *loop;
804
805 scev_initialize ();
806
807 /* Try to predict out blocks in a loop that are not part of a
808 natural loop. */
809 FOR_EACH_LOOP (li, loop, 0)
810 {
811 basic_block bb, *bbs;
812 unsigned j, n_exits;
813 VEC (edge, heap) *exits;
814 struct tree_niter_desc niter_desc;
815 edge ex;
816
817 exits = get_loop_exit_edges (loop);
818 n_exits = VEC_length (edge, exits);
819
820 for (j = 0; VEC_iterate (edge, exits, j, ex); j++)
821 {
822 tree niter = NULL;
823 HOST_WIDE_INT nitercst;
824 int max = PARAM_VALUE (PARAM_MAX_PREDICTED_ITERATIONS);
825 int probability;
826 enum br_predictor predictor;
827
828 if (number_of_iterations_exit (loop, ex, &niter_desc, false))
829 niter = niter_desc.niter;
830 if (!niter || TREE_CODE (niter_desc.niter) != INTEGER_CST)
831 niter = loop_niter_by_eval (loop, ex);
832
833 if (TREE_CODE (niter) == INTEGER_CST)
834 {
835 if (host_integerp (niter, 1)
836 && compare_tree_int (niter, max-1) == -1)
837 nitercst = tree_low_cst (niter, 1) + 1;
838 else
839 nitercst = max;
840 predictor = PRED_LOOP_ITERATIONS;
841 }
842 /* If we have just one exit and we can derive some information about
843 the number of iterations of the loop from the statements inside
844 the loop, use it to predict this exit. */
845 else if (n_exits == 1)
846 {
847 nitercst = estimated_loop_iterations_int (loop, false);
848 if (nitercst < 0)
849 continue;
850 if (nitercst > max)
851 nitercst = max;
852
853 predictor = PRED_LOOP_ITERATIONS_GUESSED;
854 }
855 else
856 continue;
857
858 probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst);
859 predict_edge (ex, predictor, probability);
860 }
861 VEC_free (edge, heap, exits);
862
863 bbs = get_loop_body (loop);
864
865 for (j = 0; j < loop->num_nodes; j++)
866 {
867 int header_found = 0;
868 edge e;
869 edge_iterator ei;
870
871 bb = bbs[j];
872
873 /* Bypass loop heuristics on continue statement. These
874 statements construct loops via "non-loop" constructs
875 in the source language and are better to be handled
876 separately. */
877 if (predicted_by_p (bb, PRED_CONTINUE))
878 continue;
879
880 /* Loop branch heuristics - predict an edge back to a
881 loop's head as taken. */
882 if (bb == loop->latch)
883 {
884 e = find_edge (loop->latch, loop->header);
885 if (e)
886 {
887 header_found = 1;
888 predict_edge_def (e, PRED_LOOP_BRANCH, TAKEN);
889 }
890 }
891
892 /* Loop exit heuristics - predict an edge exiting the loop if the
893 conditional has no loop header successors as not taken. */
894 if (!header_found
895 /* If we already used more reliable loop exit predictors, do not
896 bother with PRED_LOOP_EXIT. */
897 && !predicted_by_p (bb, PRED_LOOP_ITERATIONS_GUESSED)
898 && !predicted_by_p (bb, PRED_LOOP_ITERATIONS))
899 {
900 /* For loop with many exits we don't want to predict all exits
901 with the pretty large probability, because if all exits are
902 considered in row, the loop would be predicted to iterate
903 almost never. The code to divide probability by number of
904 exits is very rough. It should compute the number of exits
905 taken in each patch through function (not the overall number
906 of exits that might be a lot higher for loops with wide switch
907 statements in them) and compute n-th square root.
908
909 We limit the minimal probability by 2% to avoid
910 EDGE_PROBABILITY_RELIABLE from trusting the branch prediction
911 as this was causing regression in perl benchmark containing such
912 a wide loop. */
913
914 int probability = ((REG_BR_PROB_BASE
915 - predictor_info [(int) PRED_LOOP_EXIT].hitrate)
916 / n_exits);
917 if (probability < HITRATE (2))
918 probability = HITRATE (2);
919 FOR_EACH_EDGE (e, ei, bb->succs)
920 if (e->dest->index < NUM_FIXED_BLOCKS
921 || !flow_bb_inside_loop_p (loop, e->dest))
922 predict_edge (e, PRED_LOOP_EXIT, probability);
923 }
924 }
925
926 /* Free basic blocks from get_loop_body. */
927 free (bbs);
928 }
929
930 scev_finalize ();
931 }
932
933 /* Attempt to predict probabilities of BB outgoing edges using local
934 properties. */
935 static void
936 bb_estimate_probability_locally (basic_block bb)
937 {
938 rtx last_insn = BB_END (bb);
939 rtx cond;
940
941 if (! can_predict_insn_p (last_insn))
942 return;
943 cond = get_condition (last_insn, NULL, false, false);
944 if (! cond)
945 return;
946
947 /* Try "pointer heuristic."
948 A comparison ptr == 0 is predicted as false.
949 Similarly, a comparison ptr1 == ptr2 is predicted as false. */
950 if (COMPARISON_P (cond)
951 && ((REG_P (XEXP (cond, 0)) && REG_POINTER (XEXP (cond, 0)))
952 || (REG_P (XEXP (cond, 1)) && REG_POINTER (XEXP (cond, 1)))))
953 {
954 if (GET_CODE (cond) == EQ)
955 predict_insn_def (last_insn, PRED_POINTER, NOT_TAKEN);
956 else if (GET_CODE (cond) == NE)
957 predict_insn_def (last_insn, PRED_POINTER, TAKEN);
958 }
959 else
960
961 /* Try "opcode heuristic."
962 EQ tests are usually false and NE tests are usually true. Also,
963 most quantities are positive, so we can make the appropriate guesses
964 about signed comparisons against zero. */
965 switch (GET_CODE (cond))
966 {
967 case CONST_INT:
968 /* Unconditional branch. */
969 predict_insn_def (last_insn, PRED_UNCONDITIONAL,
970 cond == const0_rtx ? NOT_TAKEN : TAKEN);
971 break;
972
973 case EQ:
974 case UNEQ:
975 /* Floating point comparisons appears to behave in a very
976 unpredictable way because of special role of = tests in
977 FP code. */
978 if (FLOAT_MODE_P (GET_MODE (XEXP (cond, 0))))
979 ;
980 /* Comparisons with 0 are often used for booleans and there is
981 nothing useful to predict about them. */
982 else if (XEXP (cond, 1) == const0_rtx
983 || XEXP (cond, 0) == const0_rtx)
984 ;
985 else
986 predict_insn_def (last_insn, PRED_OPCODE_NONEQUAL, NOT_TAKEN);
987 break;
988
989 case NE:
990 case LTGT:
991 /* Floating point comparisons appears to behave in a very
992 unpredictable way because of special role of = tests in
993 FP code. */
994 if (FLOAT_MODE_P (GET_MODE (XEXP (cond, 0))))
995 ;
996 /* Comparisons with 0 are often used for booleans and there is
997 nothing useful to predict about them. */
998 else if (XEXP (cond, 1) == const0_rtx
999 || XEXP (cond, 0) == const0_rtx)
1000 ;
1001 else
1002 predict_insn_def (last_insn, PRED_OPCODE_NONEQUAL, TAKEN);
1003 break;
1004
1005 case ORDERED:
1006 predict_insn_def (last_insn, PRED_FPOPCODE, TAKEN);
1007 break;
1008
1009 case UNORDERED:
1010 predict_insn_def (last_insn, PRED_FPOPCODE, NOT_TAKEN);
1011 break;
1012
1013 case LE:
1014 case LT:
1015 if (XEXP (cond, 1) == const0_rtx || XEXP (cond, 1) == const1_rtx
1016 || XEXP (cond, 1) == constm1_rtx)
1017 predict_insn_def (last_insn, PRED_OPCODE_POSITIVE, NOT_TAKEN);
1018 break;
1019
1020 case GE:
1021 case GT:
1022 if (XEXP (cond, 1) == const0_rtx || XEXP (cond, 1) == const1_rtx
1023 || XEXP (cond, 1) == constm1_rtx)
1024 predict_insn_def (last_insn, PRED_OPCODE_POSITIVE, TAKEN);
1025 break;
1026
1027 default:
1028 break;
1029 }
1030 }
1031
1032 /* Set edge->probability for each successor edge of BB. */
1033 void
1034 guess_outgoing_edge_probabilities (basic_block bb)
1035 {
1036 bb_estimate_probability_locally (bb);
1037 combine_predictions_for_insn (BB_END (bb), bb);
1038 }
1039 \f
1040 static tree expr_expected_value (tree, bitmap);
1041
1042 /* Helper function for expr_expected_value. */
1043
1044 static tree
1045 expr_expected_value_1 (tree type, tree op0, enum tree_code code, tree op1, bitmap visited)
1046 {
1047 gimple def;
1048
1049 if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)
1050 {
1051 if (TREE_CONSTANT (op0))
1052 return op0;
1053
1054 if (code != SSA_NAME)
1055 return NULL_TREE;
1056
1057 def = SSA_NAME_DEF_STMT (op0);
1058
1059 /* If we were already here, break the infinite cycle. */
1060 if (bitmap_bit_p (visited, SSA_NAME_VERSION (op0)))
1061 return NULL;
1062 bitmap_set_bit (visited, SSA_NAME_VERSION (op0));
1063
1064 if (gimple_code (def) == GIMPLE_PHI)
1065 {
1066 /* All the arguments of the PHI node must have the same constant
1067 length. */
1068 int i, n = gimple_phi_num_args (def);
1069 tree val = NULL, new_val;
1070
1071 for (i = 0; i < n; i++)
1072 {
1073 tree arg = PHI_ARG_DEF (def, i);
1074
1075 /* If this PHI has itself as an argument, we cannot
1076 determine the string length of this argument. However,
1077 if we can find an expected constant value for the other
1078 PHI args then we can still be sure that this is
1079 likely a constant. So be optimistic and just
1080 continue with the next argument. */
1081 if (arg == PHI_RESULT (def))
1082 continue;
1083
1084 new_val = expr_expected_value (arg, visited);
1085 if (!new_val)
1086 return NULL;
1087 if (!val)
1088 val = new_val;
1089 else if (!operand_equal_p (val, new_val, false))
1090 return NULL;
1091 }
1092 return val;
1093 }
1094 if (is_gimple_assign (def))
1095 {
1096 if (gimple_assign_lhs (def) != op0)
1097 return NULL;
1098
1099 return expr_expected_value_1 (TREE_TYPE (gimple_assign_lhs (def)),
1100 gimple_assign_rhs1 (def),
1101 gimple_assign_rhs_code (def),
1102 gimple_assign_rhs2 (def),
1103 visited);
1104 }
1105
1106 if (is_gimple_call (def))
1107 {
1108 tree decl = gimple_call_fndecl (def);
1109 if (!decl)
1110 return NULL;
1111 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1112 && DECL_FUNCTION_CODE (decl) == BUILT_IN_EXPECT)
1113 {
1114 tree val;
1115
1116 if (gimple_call_num_args (def) != 2)
1117 return NULL;
1118 val = gimple_call_arg (def, 0);
1119 if (TREE_CONSTANT (val))
1120 return val;
1121 return gimple_call_arg (def, 1);
1122 }
1123 }
1124
1125 return NULL;
1126 }
1127
1128 if (get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS)
1129 {
1130 tree res;
1131 op0 = expr_expected_value (op0, visited);
1132 if (!op0)
1133 return NULL;
1134 op1 = expr_expected_value (op1, visited);
1135 if (!op1)
1136 return NULL;
1137 res = fold_build2 (code, type, op0, op1);
1138 if (TREE_CONSTANT (res))
1139 return res;
1140 return NULL;
1141 }
1142 if (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS)
1143 {
1144 tree res;
1145 op0 = expr_expected_value (op0, visited);
1146 if (!op0)
1147 return NULL;
1148 res = fold_build1 (code, type, op0);
1149 if (TREE_CONSTANT (res))
1150 return res;
1151 return NULL;
1152 }
1153 return NULL;
1154 }
1155
1156 /* Return constant EXPR will likely have at execution time, NULL if unknown.
1157 The function is used by builtin_expect branch predictor so the evidence
1158 must come from this construct and additional possible constant folding.
1159
1160 We may want to implement more involved value guess (such as value range
1161 propagation based prediction), but such tricks shall go to new
1162 implementation. */
1163
1164 static tree
1165 expr_expected_value (tree expr, bitmap visited)
1166 {
1167 enum tree_code code;
1168 tree op0, op1;
1169
1170 if (TREE_CONSTANT (expr))
1171 return expr;
1172
1173 extract_ops_from_tree (expr, &code, &op0, &op1);
1174 return expr_expected_value_1 (TREE_TYPE (expr),
1175 op0, code, op1, visited);
1176 }
1177
1178 \f
1179 /* Get rid of all builtin_expect calls we no longer need. */
1180 static void
1181 strip_builtin_expect (void)
1182 {
1183 basic_block bb;
1184 gimple ass_stmt;
1185 tree var;
1186
1187 FOR_EACH_BB (bb)
1188 {
1189 gimple_stmt_iterator bi;
1190 for (bi = gsi_start_bb (bb); !gsi_end_p (bi); gsi_next (&bi))
1191 {
1192 gimple stmt = gsi_stmt (bi);
1193 tree fndecl;
1194
1195 if (gimple_code (stmt) != GIMPLE_CALL)
1196 continue;
1197
1198 fndecl = gimple_call_fndecl (stmt);
1199
1200 if (fndecl
1201 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
1202 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_EXPECT
1203 && gimple_call_num_args (stmt) == 2)
1204 {
1205 var = gimple_call_lhs (stmt);
1206 ass_stmt = gimple_build_assign (var, gimple_call_arg (stmt, 0));
1207
1208 gsi_replace (&bi, ass_stmt, true);
1209 }
1210 }
1211 }
1212 }
1213 \f
1214 /* Predict using opcode of the last statement in basic block. */
1215 static void
1216 tree_predict_by_opcode (basic_block bb)
1217 {
1218 gimple stmt = last_stmt (bb);
1219 edge then_edge;
1220 tree op0, op1;
1221 tree type;
1222 tree val;
1223 enum tree_code cmp;
1224 bitmap visited;
1225 edge_iterator ei;
1226
1227 if (!stmt || gimple_code (stmt) != GIMPLE_COND)
1228 return;
1229 FOR_EACH_EDGE (then_edge, ei, bb->succs)
1230 if (then_edge->flags & EDGE_TRUE_VALUE)
1231 break;
1232 op0 = gimple_cond_lhs (stmt);
1233 op1 = gimple_cond_rhs (stmt);
1234 cmp = gimple_cond_code (stmt);
1235 type = TREE_TYPE (op0);
1236 visited = BITMAP_ALLOC (NULL);
1237 val = expr_expected_value_1 (boolean_type_node, op0, cmp, op1, visited);
1238 BITMAP_FREE (visited);
1239 if (val)
1240 {
1241 if (integer_zerop (val))
1242 predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, NOT_TAKEN);
1243 else
1244 predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, TAKEN);
1245 return;
1246 }
1247 /* Try "pointer heuristic."
1248 A comparison ptr == 0 is predicted as false.
1249 Similarly, a comparison ptr1 == ptr2 is predicted as false. */
1250 if (POINTER_TYPE_P (type))
1251 {
1252 if (cmp == EQ_EXPR)
1253 predict_edge_def (then_edge, PRED_TREE_POINTER, NOT_TAKEN);
1254 else if (cmp == NE_EXPR)
1255 predict_edge_def (then_edge, PRED_TREE_POINTER, TAKEN);
1256 }
1257 else
1258
1259 /* Try "opcode heuristic."
1260 EQ tests are usually false and NE tests are usually true. Also,
1261 most quantities are positive, so we can make the appropriate guesses
1262 about signed comparisons against zero. */
1263 switch (cmp)
1264 {
1265 case EQ_EXPR:
1266 case UNEQ_EXPR:
1267 /* Floating point comparisons appears to behave in a very
1268 unpredictable way because of special role of = tests in
1269 FP code. */
1270 if (FLOAT_TYPE_P (type))
1271 ;
1272 /* Comparisons with 0 are often used for booleans and there is
1273 nothing useful to predict about them. */
1274 else if (integer_zerop (op0) || integer_zerop (op1))
1275 ;
1276 else
1277 predict_edge_def (then_edge, PRED_TREE_OPCODE_NONEQUAL, NOT_TAKEN);
1278 break;
1279
1280 case NE_EXPR:
1281 case LTGT_EXPR:
1282 /* Floating point comparisons appears to behave in a very
1283 unpredictable way because of special role of = tests in
1284 FP code. */
1285 if (FLOAT_TYPE_P (type))
1286 ;
1287 /* Comparisons with 0 are often used for booleans and there is
1288 nothing useful to predict about them. */
1289 else if (integer_zerop (op0)
1290 || integer_zerop (op1))
1291 ;
1292 else
1293 predict_edge_def (then_edge, PRED_TREE_OPCODE_NONEQUAL, TAKEN);
1294 break;
1295
1296 case ORDERED_EXPR:
1297 predict_edge_def (then_edge, PRED_TREE_FPOPCODE, TAKEN);
1298 break;
1299
1300 case UNORDERED_EXPR:
1301 predict_edge_def (then_edge, PRED_TREE_FPOPCODE, NOT_TAKEN);
1302 break;
1303
1304 case LE_EXPR:
1305 case LT_EXPR:
1306 if (integer_zerop (op1)
1307 || integer_onep (op1)
1308 || integer_all_onesp (op1)
1309 || real_zerop (op1)
1310 || real_onep (op1)
1311 || real_minus_onep (op1))
1312 predict_edge_def (then_edge, PRED_TREE_OPCODE_POSITIVE, NOT_TAKEN);
1313 break;
1314
1315 case GE_EXPR:
1316 case GT_EXPR:
1317 if (integer_zerop (op1)
1318 || integer_onep (op1)
1319 || integer_all_onesp (op1)
1320 || real_zerop (op1)
1321 || real_onep (op1)
1322 || real_minus_onep (op1))
1323 predict_edge_def (then_edge, PRED_TREE_OPCODE_POSITIVE, TAKEN);
1324 break;
1325
1326 default:
1327 break;
1328 }
1329 }
1330
1331 /* Try to guess whether the value of return means error code. */
1332
1333 static enum br_predictor
1334 return_prediction (tree val, enum prediction *prediction)
1335 {
1336 /* VOID. */
1337 if (!val)
1338 return PRED_NO_PREDICTION;
1339 /* Different heuristics for pointers and scalars. */
1340 if (POINTER_TYPE_P (TREE_TYPE (val)))
1341 {
1342 /* NULL is usually not returned. */
1343 if (integer_zerop (val))
1344 {
1345 *prediction = NOT_TAKEN;
1346 return PRED_NULL_RETURN;
1347 }
1348 }
1349 else if (INTEGRAL_TYPE_P (TREE_TYPE (val)))
1350 {
1351 /* Negative return values are often used to indicate
1352 errors. */
1353 if (TREE_CODE (val) == INTEGER_CST
1354 && tree_int_cst_sgn (val) < 0)
1355 {
1356 *prediction = NOT_TAKEN;
1357 return PRED_NEGATIVE_RETURN;
1358 }
1359 /* Constant return values seems to be commonly taken.
1360 Zero/one often represent booleans so exclude them from the
1361 heuristics. */
1362 if (TREE_CONSTANT (val)
1363 && (!integer_zerop (val) && !integer_onep (val)))
1364 {
1365 *prediction = TAKEN;
1366 return PRED_CONST_RETURN;
1367 }
1368 }
1369 return PRED_NO_PREDICTION;
1370 }
1371
1372 /* Find the basic block with return expression and look up for possible
1373 return value trying to apply RETURN_PREDICTION heuristics. */
1374 static void
1375 apply_return_prediction (void)
1376 {
1377 gimple return_stmt = NULL;
1378 tree return_val;
1379 edge e;
1380 gimple phi;
1381 int phi_num_args, i;
1382 enum br_predictor pred;
1383 enum prediction direction;
1384 edge_iterator ei;
1385
1386 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
1387 {
1388 return_stmt = last_stmt (e->src);
1389 if (return_stmt
1390 && gimple_code (return_stmt) == GIMPLE_RETURN)
1391 break;
1392 }
1393 if (!e)
1394 return;
1395 return_val = gimple_return_retval (return_stmt);
1396 if (!return_val)
1397 return;
1398 if (TREE_CODE (return_val) != SSA_NAME
1399 || !SSA_NAME_DEF_STMT (return_val)
1400 || gimple_code (SSA_NAME_DEF_STMT (return_val)) != GIMPLE_PHI)
1401 return;
1402 phi = SSA_NAME_DEF_STMT (return_val);
1403 phi_num_args = gimple_phi_num_args (phi);
1404 pred = return_prediction (PHI_ARG_DEF (phi, 0), &direction);
1405
1406 /* Avoid the degenerate case where all return values form the function
1407 belongs to same category (ie they are all positive constants)
1408 so we can hardly say something about them. */
1409 for (i = 1; i < phi_num_args; i++)
1410 if (pred != return_prediction (PHI_ARG_DEF (phi, i), &direction))
1411 break;
1412 if (i != phi_num_args)
1413 for (i = 0; i < phi_num_args; i++)
1414 {
1415 pred = return_prediction (PHI_ARG_DEF (phi, i), &direction);
1416 if (pred != PRED_NO_PREDICTION)
1417 predict_paths_leading_to (gimple_phi_arg_edge (phi, i)->src, pred,
1418 direction);
1419 }
1420 }
1421
1422 /* Look for basic block that contains unlikely to happen events
1423 (such as noreturn calls) and mark all paths leading to execution
1424 of this basic blocks as unlikely. */
1425
1426 static void
1427 tree_bb_level_predictions (void)
1428 {
1429 basic_block bb;
1430
1431 apply_return_prediction ();
1432
1433 FOR_EACH_BB (bb)
1434 {
1435 gimple_stmt_iterator gsi;
1436
1437 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
1438 {
1439 gimple stmt = gsi_stmt (gsi);
1440 tree decl;
1441
1442 if (is_gimple_call (stmt))
1443 {
1444 if (gimple_call_flags (stmt) & ECF_NORETURN)
1445 predict_paths_leading_to (bb, PRED_NORETURN,
1446 NOT_TAKEN);
1447 decl = gimple_call_fndecl (stmt);
1448 if (decl
1449 && lookup_attribute ("cold",
1450 DECL_ATTRIBUTES (decl)))
1451 predict_paths_leading_to (bb, PRED_COLD_FUNCTION,
1452 NOT_TAKEN);
1453 }
1454 else if (gimple_code (stmt) == GIMPLE_PREDICT)
1455 {
1456 predict_paths_leading_to (bb, gimple_predict_predictor (stmt),
1457 gimple_predict_outcome (stmt));
1458 gsi_remove (&gsi, true);
1459 continue;
1460 }
1461
1462 gsi_next (&gsi);
1463 }
1464 }
1465 }
1466
1467 #ifdef ENABLE_CHECKING
1468
1469 /* Callback for pointer_map_traverse, asserts that the pointer map is
1470 empty. */
1471
1472 static bool
1473 assert_is_empty (const void *key ATTRIBUTE_UNUSED, void **value,
1474 void *data ATTRIBUTE_UNUSED)
1475 {
1476 gcc_assert (!*value);
1477 return false;
1478 }
1479 #endif
1480
1481 /* Predict branch probabilities and estimate profile of the tree CFG. */
1482 static unsigned int
1483 tree_estimate_probability (void)
1484 {
1485 basic_block bb;
1486
1487 loop_optimizer_init (0);
1488 if (dump_file && (dump_flags & TDF_DETAILS))
1489 flow_loops_dump (dump_file, NULL, 0);
1490
1491 add_noreturn_fake_exit_edges ();
1492 connect_infinite_loops_to_exit ();
1493 /* We use loop_niter_by_eval, which requires that the loops have
1494 preheaders. */
1495 create_preheaders (CP_SIMPLE_PREHEADERS);
1496 calculate_dominance_info (CDI_POST_DOMINATORS);
1497
1498 bb_predictions = pointer_map_create ();
1499 tree_bb_level_predictions ();
1500
1501 mark_irreducible_loops ();
1502 record_loop_exits ();
1503 if (number_of_loops () > 1)
1504 predict_loops ();
1505
1506 FOR_EACH_BB (bb)
1507 {
1508 edge e;
1509 edge_iterator ei;
1510
1511 FOR_EACH_EDGE (e, ei, bb->succs)
1512 {
1513 /* Predict early returns to be probable, as we've already taken
1514 care for error returns and other cases are often used for
1515 fast paths through function.
1516
1517 Since we've already removed the return statements, we are
1518 looking for CFG like:
1519
1520 if (conditional)
1521 {
1522 ..
1523 goto return_block
1524 }
1525 some other blocks
1526 return_block:
1527 return_stmt. */
1528 if (e->dest != bb->next_bb
1529 && e->dest != EXIT_BLOCK_PTR
1530 && single_succ_p (e->dest)
1531 && single_succ_edge (e->dest)->dest == EXIT_BLOCK_PTR
1532 && gimple_code (last_stmt (e->dest)) == GIMPLE_RETURN)
1533 {
1534 edge e1;
1535 edge_iterator ei1;
1536
1537 if (single_succ_p (bb))
1538 {
1539 FOR_EACH_EDGE (e1, ei1, bb->preds)
1540 if (!predicted_by_p (e1->src, PRED_NULL_RETURN)
1541 && !predicted_by_p (e1->src, PRED_CONST_RETURN)
1542 && !predicted_by_p (e1->src, PRED_NEGATIVE_RETURN))
1543 predict_edge_def (e1, PRED_TREE_EARLY_RETURN, NOT_TAKEN);
1544 }
1545 else
1546 if (!predicted_by_p (e->src, PRED_NULL_RETURN)
1547 && !predicted_by_p (e->src, PRED_CONST_RETURN)
1548 && !predicted_by_p (e->src, PRED_NEGATIVE_RETURN))
1549 predict_edge_def (e, PRED_TREE_EARLY_RETURN, NOT_TAKEN);
1550 }
1551
1552 /* Look for block we are guarding (ie we dominate it,
1553 but it doesn't postdominate us). */
1554 if (e->dest != EXIT_BLOCK_PTR && e->dest != bb
1555 && dominated_by_p (CDI_DOMINATORS, e->dest, e->src)
1556 && !dominated_by_p (CDI_POST_DOMINATORS, e->src, e->dest))
1557 {
1558 gimple_stmt_iterator bi;
1559
1560 /* The call heuristic claims that a guarded function call
1561 is improbable. This is because such calls are often used
1562 to signal exceptional situations such as printing error
1563 messages. */
1564 for (bi = gsi_start_bb (e->dest); !gsi_end_p (bi);
1565 gsi_next (&bi))
1566 {
1567 gimple stmt = gsi_stmt (bi);
1568 if (is_gimple_call (stmt)
1569 /* Constant and pure calls are hardly used to signalize
1570 something exceptional. */
1571 && gimple_has_side_effects (stmt))
1572 {
1573 predict_edge_def (e, PRED_CALL, NOT_TAKEN);
1574 break;
1575 }
1576 }
1577 }
1578 }
1579 tree_predict_by_opcode (bb);
1580 }
1581 FOR_EACH_BB (bb)
1582 combine_predictions_for_bb (bb);
1583
1584 #ifdef ENABLE_CHECKING
1585 pointer_map_traverse (bb_predictions, assert_is_empty, NULL);
1586 #endif
1587 pointer_map_destroy (bb_predictions);
1588 bb_predictions = NULL;
1589
1590 strip_builtin_expect ();
1591 estimate_bb_frequencies ();
1592 free_dominance_info (CDI_POST_DOMINATORS);
1593 remove_fake_exit_edges ();
1594 loop_optimizer_finalize ();
1595 if (dump_file && (dump_flags & TDF_DETAILS))
1596 gimple_dump_cfg (dump_file, dump_flags);
1597 if (profile_status == PROFILE_ABSENT)
1598 profile_status = PROFILE_GUESSED;
1599 return 0;
1600 }
1601 \f
1602 /* Predict edges to successors of CUR whose sources are not postdominated by
1603 BB by PRED and recurse to all postdominators. */
1604
1605 static void
1606 predict_paths_for_bb (basic_block cur, basic_block bb,
1607 enum br_predictor pred,
1608 enum prediction taken)
1609 {
1610 edge e;
1611 edge_iterator ei;
1612 basic_block son;
1613
1614 /* We are looking for all edges forming edge cut induced by
1615 set of all blocks postdominated by BB. */
1616 FOR_EACH_EDGE (e, ei, cur->preds)
1617 if (e->src->index >= NUM_FIXED_BLOCKS
1618 && !dominated_by_p (CDI_POST_DOMINATORS, e->src, bb))
1619 {
1620 gcc_assert (bb == cur || dominated_by_p (CDI_POST_DOMINATORS, cur, bb));
1621 predict_edge_def (e, pred, taken);
1622 }
1623 for (son = first_dom_son (CDI_POST_DOMINATORS, cur);
1624 son;
1625 son = next_dom_son (CDI_POST_DOMINATORS, son))
1626 predict_paths_for_bb (son, bb, pred, taken);
1627 }
1628
1629 /* Sets branch probabilities according to PREDiction and
1630 FLAGS. */
1631
1632 static void
1633 predict_paths_leading_to (basic_block bb, enum br_predictor pred,
1634 enum prediction taken)
1635 {
1636 predict_paths_for_bb (bb, bb, pred, taken);
1637 }
1638 \f
1639 /* This is used to carry information about basic blocks. It is
1640 attached to the AUX field of the standard CFG block. */
1641
1642 typedef struct block_info_def
1643 {
1644 /* Estimated frequency of execution of basic_block. */
1645 sreal frequency;
1646
1647 /* To keep queue of basic blocks to process. */
1648 basic_block next;
1649
1650 /* Number of predecessors we need to visit first. */
1651 int npredecessors;
1652 } *block_info;
1653
1654 /* Similar information for edges. */
1655 typedef struct edge_info_def
1656 {
1657 /* In case edge is a loopback edge, the probability edge will be reached
1658 in case header is. Estimated number of iterations of the loop can be
1659 then computed as 1 / (1 - back_edge_prob). */
1660 sreal back_edge_prob;
1661 /* True if the edge is a loopback edge in the natural loop. */
1662 unsigned int back_edge:1;
1663 } *edge_info;
1664
1665 #define BLOCK_INFO(B) ((block_info) (B)->aux)
1666 #define EDGE_INFO(E) ((edge_info) (E)->aux)
1667
1668 /* Helper function for estimate_bb_frequencies.
1669 Propagate the frequencies in blocks marked in
1670 TOVISIT, starting in HEAD. */
1671
1672 static void
1673 propagate_freq (basic_block head, bitmap tovisit)
1674 {
1675 basic_block bb;
1676 basic_block last;
1677 unsigned i;
1678 edge e;
1679 basic_block nextbb;
1680 bitmap_iterator bi;
1681
1682 /* For each basic block we need to visit count number of his predecessors
1683 we need to visit first. */
1684 EXECUTE_IF_SET_IN_BITMAP (tovisit, 0, i, bi)
1685 {
1686 edge_iterator ei;
1687 int count = 0;
1688
1689 /* The outermost "loop" includes the exit block, which we can not
1690 look up via BASIC_BLOCK. Detect this and use EXIT_BLOCK_PTR
1691 directly. Do the same for the entry block. */
1692 bb = BASIC_BLOCK (i);
1693
1694 FOR_EACH_EDGE (e, ei, bb->preds)
1695 {
1696 bool visit = bitmap_bit_p (tovisit, e->src->index);
1697
1698 if (visit && !(e->flags & EDGE_DFS_BACK))
1699 count++;
1700 else if (visit && dump_file && !EDGE_INFO (e)->back_edge)
1701 fprintf (dump_file,
1702 "Irreducible region hit, ignoring edge to %i->%i\n",
1703 e->src->index, bb->index);
1704 }
1705 BLOCK_INFO (bb)->npredecessors = count;
1706 }
1707
1708 memcpy (&BLOCK_INFO (head)->frequency, &real_one, sizeof (real_one));
1709 last = head;
1710 for (bb = head; bb; bb = nextbb)
1711 {
1712 edge_iterator ei;
1713 sreal cyclic_probability, frequency;
1714
1715 memcpy (&cyclic_probability, &real_zero, sizeof (real_zero));
1716 memcpy (&frequency, &real_zero, sizeof (real_zero));
1717
1718 nextbb = BLOCK_INFO (bb)->next;
1719 BLOCK_INFO (bb)->next = NULL;
1720
1721 /* Compute frequency of basic block. */
1722 if (bb != head)
1723 {
1724 #ifdef ENABLE_CHECKING
1725 FOR_EACH_EDGE (e, ei, bb->preds)
1726 gcc_assert (!bitmap_bit_p (tovisit, e->src->index)
1727 || (e->flags & EDGE_DFS_BACK));
1728 #endif
1729
1730 FOR_EACH_EDGE (e, ei, bb->preds)
1731 if (EDGE_INFO (e)->back_edge)
1732 {
1733 sreal_add (&cyclic_probability, &cyclic_probability,
1734 &EDGE_INFO (e)->back_edge_prob);
1735 }
1736 else if (!(e->flags & EDGE_DFS_BACK))
1737 {
1738 sreal tmp;
1739
1740 /* frequency += (e->probability
1741 * BLOCK_INFO (e->src)->frequency /
1742 REG_BR_PROB_BASE); */
1743
1744 sreal_init (&tmp, e->probability, 0);
1745 sreal_mul (&tmp, &tmp, &BLOCK_INFO (e->src)->frequency);
1746 sreal_mul (&tmp, &tmp, &real_inv_br_prob_base);
1747 sreal_add (&frequency, &frequency, &tmp);
1748 }
1749
1750 if (sreal_compare (&cyclic_probability, &real_zero) == 0)
1751 {
1752 memcpy (&BLOCK_INFO (bb)->frequency, &frequency,
1753 sizeof (frequency));
1754 }
1755 else
1756 {
1757 if (sreal_compare (&cyclic_probability, &real_almost_one) > 0)
1758 {
1759 memcpy (&cyclic_probability, &real_almost_one,
1760 sizeof (real_almost_one));
1761 }
1762
1763 /* BLOCK_INFO (bb)->frequency = frequency
1764 / (1 - cyclic_probability) */
1765
1766 sreal_sub (&cyclic_probability, &real_one, &cyclic_probability);
1767 sreal_div (&BLOCK_INFO (bb)->frequency,
1768 &frequency, &cyclic_probability);
1769 }
1770 }
1771
1772 bitmap_clear_bit (tovisit, bb->index);
1773
1774 e = find_edge (bb, head);
1775 if (e)
1776 {
1777 sreal tmp;
1778
1779 /* EDGE_INFO (e)->back_edge_prob
1780 = ((e->probability * BLOCK_INFO (bb)->frequency)
1781 / REG_BR_PROB_BASE); */
1782
1783 sreal_init (&tmp, e->probability, 0);
1784 sreal_mul (&tmp, &tmp, &BLOCK_INFO (bb)->frequency);
1785 sreal_mul (&EDGE_INFO (e)->back_edge_prob,
1786 &tmp, &real_inv_br_prob_base);
1787 }
1788
1789 /* Propagate to successor blocks. */
1790 FOR_EACH_EDGE (e, ei, bb->succs)
1791 if (!(e->flags & EDGE_DFS_BACK)
1792 && BLOCK_INFO (e->dest)->npredecessors)
1793 {
1794 BLOCK_INFO (e->dest)->npredecessors--;
1795 if (!BLOCK_INFO (e->dest)->npredecessors)
1796 {
1797 if (!nextbb)
1798 nextbb = e->dest;
1799 else
1800 BLOCK_INFO (last)->next = e->dest;
1801
1802 last = e->dest;
1803 }
1804 }
1805 }
1806 }
1807
1808 /* Estimate probabilities of loopback edges in loops at same nest level. */
1809
1810 static void
1811 estimate_loops_at_level (struct loop *first_loop)
1812 {
1813 struct loop *loop;
1814
1815 for (loop = first_loop; loop; loop = loop->next)
1816 {
1817 edge e;
1818 basic_block *bbs;
1819 unsigned i;
1820 bitmap tovisit = BITMAP_ALLOC (NULL);
1821
1822 estimate_loops_at_level (loop->inner);
1823
1824 /* Find current loop back edge and mark it. */
1825 e = loop_latch_edge (loop);
1826 EDGE_INFO (e)->back_edge = 1;
1827
1828 bbs = get_loop_body (loop);
1829 for (i = 0; i < loop->num_nodes; i++)
1830 bitmap_set_bit (tovisit, bbs[i]->index);
1831 free (bbs);
1832 propagate_freq (loop->header, tovisit);
1833 BITMAP_FREE (tovisit);
1834 }
1835 }
1836
1837 /* Propagates frequencies through structure of loops. */
1838
1839 static void
1840 estimate_loops (void)
1841 {
1842 bitmap tovisit = BITMAP_ALLOC (NULL);
1843 basic_block bb;
1844
1845 /* Start by estimating the frequencies in the loops. */
1846 if (number_of_loops () > 1)
1847 estimate_loops_at_level (current_loops->tree_root->inner);
1848
1849 /* Now propagate the frequencies through all the blocks. */
1850 FOR_ALL_BB (bb)
1851 {
1852 bitmap_set_bit (tovisit, bb->index);
1853 }
1854 propagate_freq (ENTRY_BLOCK_PTR, tovisit);
1855 BITMAP_FREE (tovisit);
1856 }
1857
1858 /* Convert counts measured by profile driven feedback to frequencies.
1859 Return nonzero iff there was any nonzero execution count. */
1860
1861 int
1862 counts_to_freqs (void)
1863 {
1864 gcov_type count_max, true_count_max = 0;
1865 basic_block bb;
1866
1867 FOR_EACH_BB (bb)
1868 true_count_max = MAX (bb->count, true_count_max);
1869
1870 count_max = MAX (true_count_max, 1);
1871 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
1872 bb->frequency = (bb->count * BB_FREQ_MAX + count_max / 2) / count_max;
1873
1874 return true_count_max;
1875 }
1876
1877 /* Return true if function is likely to be expensive, so there is no point to
1878 optimize performance of prologue, epilogue or do inlining at the expense
1879 of code size growth. THRESHOLD is the limit of number of instructions
1880 function can execute at average to be still considered not expensive. */
1881
1882 bool
1883 expensive_function_p (int threshold)
1884 {
1885 unsigned int sum = 0;
1886 basic_block bb;
1887 unsigned int limit;
1888
1889 /* We can not compute accurately for large thresholds due to scaled
1890 frequencies. */
1891 gcc_assert (threshold <= BB_FREQ_MAX);
1892
1893 /* Frequencies are out of range. This either means that function contains
1894 internal loop executing more than BB_FREQ_MAX times or profile feedback
1895 is available and function has not been executed at all. */
1896 if (ENTRY_BLOCK_PTR->frequency == 0)
1897 return true;
1898
1899 /* Maximally BB_FREQ_MAX^2 so overflow won't happen. */
1900 limit = ENTRY_BLOCK_PTR->frequency * threshold;
1901 FOR_EACH_BB (bb)
1902 {
1903 rtx insn;
1904
1905 for (insn = BB_HEAD (bb); insn != NEXT_INSN (BB_END (bb));
1906 insn = NEXT_INSN (insn))
1907 if (active_insn_p (insn))
1908 {
1909 sum += bb->frequency;
1910 if (sum > limit)
1911 return true;
1912 }
1913 }
1914
1915 return false;
1916 }
1917
1918 /* Estimate basic blocks frequency by given branch probabilities. */
1919
1920 void
1921 estimate_bb_frequencies (void)
1922 {
1923 basic_block bb;
1924 sreal freq_max;
1925
1926 if (!flag_branch_probabilities || !counts_to_freqs ())
1927 {
1928 static int real_values_initialized = 0;
1929
1930 if (!real_values_initialized)
1931 {
1932 real_values_initialized = 1;
1933 sreal_init (&real_zero, 0, 0);
1934 sreal_init (&real_one, 1, 0);
1935 sreal_init (&real_br_prob_base, REG_BR_PROB_BASE, 0);
1936 sreal_init (&real_bb_freq_max, BB_FREQ_MAX, 0);
1937 sreal_init (&real_one_half, 1, -1);
1938 sreal_div (&real_inv_br_prob_base, &real_one, &real_br_prob_base);
1939 sreal_sub (&real_almost_one, &real_one, &real_inv_br_prob_base);
1940 }
1941
1942 mark_dfs_back_edges ();
1943
1944 single_succ_edge (ENTRY_BLOCK_PTR)->probability = REG_BR_PROB_BASE;
1945
1946 /* Set up block info for each basic block. */
1947 alloc_aux_for_blocks (sizeof (struct block_info_def));
1948 alloc_aux_for_edges (sizeof (struct edge_info_def));
1949 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
1950 {
1951 edge e;
1952 edge_iterator ei;
1953
1954 FOR_EACH_EDGE (e, ei, bb->succs)
1955 {
1956 sreal_init (&EDGE_INFO (e)->back_edge_prob, e->probability, 0);
1957 sreal_mul (&EDGE_INFO (e)->back_edge_prob,
1958 &EDGE_INFO (e)->back_edge_prob,
1959 &real_inv_br_prob_base);
1960 }
1961 }
1962
1963 /* First compute probabilities locally for each loop from innermost
1964 to outermost to examine probabilities for back edges. */
1965 estimate_loops ();
1966
1967 memcpy (&freq_max, &real_zero, sizeof (real_zero));
1968 FOR_EACH_BB (bb)
1969 if (sreal_compare (&freq_max, &BLOCK_INFO (bb)->frequency) < 0)
1970 memcpy (&freq_max, &BLOCK_INFO (bb)->frequency, sizeof (freq_max));
1971
1972 sreal_div (&freq_max, &real_bb_freq_max, &freq_max);
1973 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
1974 {
1975 sreal tmp;
1976
1977 sreal_mul (&tmp, &BLOCK_INFO (bb)->frequency, &freq_max);
1978 sreal_add (&tmp, &tmp, &real_one_half);
1979 bb->frequency = sreal_to_int (&tmp);
1980 }
1981
1982 free_aux_for_blocks ();
1983 free_aux_for_edges ();
1984 }
1985 compute_function_frequency ();
1986 if (flag_reorder_functions)
1987 choose_function_section ();
1988 }
1989
1990 /* Decide whether function is hot, cold or unlikely executed. */
1991 static void
1992 compute_function_frequency (void)
1993 {
1994 basic_block bb;
1995
1996 if (!profile_info || !flag_branch_probabilities)
1997 {
1998 if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
1999 != NULL)
2000 cfun->function_frequency = FUNCTION_FREQUENCY_UNLIKELY_EXECUTED;
2001 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl))
2002 != NULL)
2003 cfun->function_frequency = FUNCTION_FREQUENCY_HOT;
2004 return;
2005 }
2006 cfun->function_frequency = FUNCTION_FREQUENCY_UNLIKELY_EXECUTED;
2007 FOR_EACH_BB (bb)
2008 {
2009 if (maybe_hot_bb_p (bb))
2010 {
2011 cfun->function_frequency = FUNCTION_FREQUENCY_HOT;
2012 return;
2013 }
2014 if (!probably_never_executed_bb_p (bb))
2015 cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
2016 }
2017 }
2018
2019 /* Choose appropriate section for the function. */
2020 static void
2021 choose_function_section (void)
2022 {
2023 if (DECL_SECTION_NAME (current_function_decl)
2024 || !targetm.have_named_sections
2025 /* Theoretically we can split the gnu.linkonce text section too,
2026 but this requires more work as the frequency needs to match
2027 for all generated objects so we need to merge the frequency
2028 of all instances. For now just never set frequency for these. */
2029 || DECL_ONE_ONLY (current_function_decl))
2030 return;
2031
2032 /* If we are doing the partitioning optimization, let the optimization
2033 choose the correct section into which to put things. */
2034
2035 if (flag_reorder_blocks_and_partition)
2036 return;
2037
2038 if (cfun->function_frequency == FUNCTION_FREQUENCY_HOT)
2039 DECL_SECTION_NAME (current_function_decl) =
2040 build_string (strlen (HOT_TEXT_SECTION_NAME), HOT_TEXT_SECTION_NAME);
2041 if (cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
2042 DECL_SECTION_NAME (current_function_decl) =
2043 build_string (strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME),
2044 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
2045 }
2046
2047 static bool
2048 gate_estimate_probability (void)
2049 {
2050 return flag_guess_branch_prob;
2051 }
2052
2053 /* Build PREDICT_EXPR. */
2054 tree
2055 build_predict_expr (enum br_predictor predictor, enum prediction taken)
2056 {
2057 tree t = build1 (PREDICT_EXPR, void_type_node,
2058 build_int_cst (NULL, predictor));
2059 PREDICT_EXPR_OUTCOME (t) = taken;
2060 return t;
2061 }
2062
2063 const char *
2064 predictor_name (enum br_predictor predictor)
2065 {
2066 return predictor_info[predictor].name;
2067 }
2068
2069 struct gimple_opt_pass pass_profile =
2070 {
2071 {
2072 GIMPLE_PASS,
2073 "profile", /* name */
2074 gate_estimate_probability, /* gate */
2075 tree_estimate_probability, /* execute */
2076 NULL, /* sub */
2077 NULL, /* next */
2078 0, /* static_pass_number */
2079 TV_BRANCH_PROB, /* tv_id */
2080 PROP_cfg, /* properties_required */
2081 0, /* properties_provided */
2082 0, /* properties_destroyed */
2083 0, /* todo_flags_start */
2084 TODO_ggc_collect | TODO_verify_ssa /* todo_flags_finish */
2085 }
2086 };