* go.test/go-test.exp (go-set-goarch): Enable tests on s390[x].
[official-gcc.git] / gcc / value-prof.c
blob0e4ec8aefc02f9a7933532060d2cdf672fcb8190
1 /* Transformations based on profile information for values.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "tree.h"
25 #include "tree-nested.h"
26 #include "calls.h"
27 #include "rtl.h"
28 #include "expr.h"
29 #include "hard-reg-set.h"
30 #include "predict.h"
31 #include "vec.h"
32 #include "hashtab.h"
33 #include "hash-set.h"
34 #include "machmode.h"
35 #include "input.h"
36 #include "function.h"
37 #include "dominance.h"
38 #include "cfg.h"
39 #include "basic-block.h"
40 #include "value-prof.h"
41 #include "flags.h"
42 #include "insn-config.h"
43 #include "recog.h"
44 #include "insn-codes.h"
45 #include "optabs.h"
46 #include "regs.h"
47 #include "tree-ssa-alias.h"
48 #include "internal-fn.h"
49 #include "tree-eh.h"
50 #include "gimple-expr.h"
51 #include "is-a.h"
52 #include "gimple.h"
53 #include "gimplify.h"
54 #include "gimple-iterator.h"
55 #include "gimple-ssa.h"
56 #include "tree-cfg.h"
57 #include "tree-phinodes.h"
58 #include "ssa-iterators.h"
59 #include "stringpool.h"
60 #include "tree-ssanames.h"
61 #include "diagnostic.h"
62 #include "gimple-pretty-print.h"
63 #include "coverage.h"
64 #include "tree.h"
65 #include "gcov-io.h"
66 #include "timevar.h"
67 #include "dumpfile.h"
68 #include "profile.h"
69 #include "hash-map.h"
70 #include "plugin-api.h"
71 #include "ipa-ref.h"
72 #include "cgraph.h"
73 #include "data-streamer.h"
74 #include "builtins.h"
75 #include "tree-nested.h"
76 #include "params.h"
78 /* In this file value profile based optimizations are placed. Currently the
79 following optimizations are implemented (for more detailed descriptions
80 see comments at value_profile_transformations):
82 1) Division/modulo specialization. Provided that we can determine that the
83 operands of the division have some special properties, we may use it to
84 produce more effective code.
86 2) Indirect/virtual call specialization. If we can determine most
87 common function callee in indirect/virtual call. We can use this
88 information to improve code effectiveness (especially info for
89 the inliner).
91 3) Speculative prefetching. If we are able to determine that the difference
92 between addresses accessed by a memory reference is usually constant, we
93 may add the prefetch instructions.
94 FIXME: This transformation was removed together with RTL based value
95 profiling.
98 Value profiling internals
99 ==========================
101 Every value profiling transformation starts with defining what values
102 to profile. There are different histogram types (see HIST_TYPE_* in
103 value-prof.h) and each transformation can request one or more histogram
104 types per GIMPLE statement. The function gimple_find_values_to_profile()
105 collects the values to profile in a vec, and adds the number of counters
106 required for the different histogram types.
108 For a -fprofile-generate run, the statements for which values should be
109 recorded, are instrumented in instrument_values(). The instrumentation
110 is done by helper functions that can be found in tree-profile.c, where
111 new types of histograms can be added if necessary.
113 After a -fprofile-use, the value profiling data is read back in by
114 compute_value_histograms() that translates the collected data to
115 histograms and attaches them to the profiled statements via
116 gimple_add_histogram_value(). Histograms are stored in a hash table
117 that is attached to every intrumented function, see VALUE_HISTOGRAMS
118 in function.h.
120 The value-profile transformations driver is the function
121 gimple_value_profile_transformations(). It traverses all statements in
122 the to-be-transformed function, and looks for statements with one or
123 more histograms attached to it. If a statement has histograms, the
124 transformation functions are called on the statement.
126 Limitations / FIXME / TODO:
127 * Only one histogram of each type can be associated with a statement.
128 * Currently, HIST_TYPE_CONST_DELTA is not implemented.
129 (This type of histogram was originally used to implement a form of
130 stride profiling based speculative prefetching to improve SPEC2000
131 scores for memory-bound benchmarks, mcf and equake. However, this
132 was an RTL value-profiling transformation, and those have all been
133 removed.)
134 * Some value profile transformations are done in builtins.c (?!)
135 * Updating of histograms needs some TLC.
136 * The value profiling code could be used to record analysis results
137 from non-profiling (e.g. VRP).
138 * Adding new profilers should be simplified, starting with a cleanup
139 of what-happens-where andwith making gimple_find_values_to_profile
140 and gimple_value_profile_transformations table-driven, perhaps...
143 static tree gimple_divmod_fixed_value (gimple, tree, int, gcov_type, gcov_type);
144 static tree gimple_mod_pow2 (gimple, int, gcov_type, gcov_type);
145 static tree gimple_mod_subtract (gimple, int, int, int, gcov_type, gcov_type,
146 gcov_type);
147 static bool gimple_divmod_fixed_value_transform (gimple_stmt_iterator *);
148 static bool gimple_mod_pow2_value_transform (gimple_stmt_iterator *);
149 static bool gimple_mod_subtract_transform (gimple_stmt_iterator *);
150 static bool gimple_stringops_transform (gimple_stmt_iterator *);
151 static bool gimple_ic_transform (gimple_stmt_iterator *);
153 /* Allocate histogram value. */
155 histogram_value
156 gimple_alloc_histogram_value (struct function *fun ATTRIBUTE_UNUSED,
157 enum hist_type type, gimple stmt, tree value)
159 histogram_value hist = (histogram_value) xcalloc (1, sizeof (*hist));
160 hist->hvalue.value = value;
161 hist->hvalue.stmt = stmt;
162 hist->type = type;
163 return hist;
166 /* Hash value for histogram. */
168 static hashval_t
169 histogram_hash (const void *x)
171 return htab_hash_pointer (((const_histogram_value)x)->hvalue.stmt);
174 /* Return nonzero if statement for histogram_value X is Y. */
176 static int
177 histogram_eq (const void *x, const void *y)
179 return ((const_histogram_value) x)->hvalue.stmt == (const_gimple) y;
182 /* Set histogram for STMT. */
184 static void
185 set_histogram_value (struct function *fun, gimple stmt, histogram_value hist)
187 void **loc;
188 if (!hist && !VALUE_HISTOGRAMS (fun))
189 return;
190 if (!VALUE_HISTOGRAMS (fun))
191 VALUE_HISTOGRAMS (fun) = htab_create (1, histogram_hash,
192 histogram_eq, NULL);
193 loc = htab_find_slot_with_hash (VALUE_HISTOGRAMS (fun), stmt,
194 htab_hash_pointer (stmt),
195 hist ? INSERT : NO_INSERT);
196 if (!hist)
198 if (loc)
199 htab_clear_slot (VALUE_HISTOGRAMS (fun), loc);
200 return;
202 *loc = hist;
205 /* Get histogram list for STMT. */
207 histogram_value
208 gimple_histogram_value (struct function *fun, gimple stmt)
210 if (!VALUE_HISTOGRAMS (fun))
211 return NULL;
212 return (histogram_value) htab_find_with_hash (VALUE_HISTOGRAMS (fun), stmt,
213 htab_hash_pointer (stmt));
216 /* Add histogram for STMT. */
218 void
219 gimple_add_histogram_value (struct function *fun, gimple stmt,
220 histogram_value hist)
222 hist->hvalue.next = gimple_histogram_value (fun, stmt);
223 set_histogram_value (fun, stmt, hist);
224 hist->fun = fun;
228 /* Remove histogram HIST from STMT's histogram list. */
230 void
231 gimple_remove_histogram_value (struct function *fun, gimple stmt,
232 histogram_value hist)
234 histogram_value hist2 = gimple_histogram_value (fun, stmt);
235 if (hist == hist2)
237 set_histogram_value (fun, stmt, hist->hvalue.next);
239 else
241 while (hist2->hvalue.next != hist)
242 hist2 = hist2->hvalue.next;
243 hist2->hvalue.next = hist->hvalue.next;
245 free (hist->hvalue.counters);
246 #ifdef ENABLE_CHECKING
247 memset (hist, 0xab, sizeof (*hist));
248 #endif
249 free (hist);
253 /* Lookup histogram of type TYPE in the STMT. */
255 histogram_value
256 gimple_histogram_value_of_type (struct function *fun, gimple stmt,
257 enum hist_type type)
259 histogram_value hist;
260 for (hist = gimple_histogram_value (fun, stmt); hist;
261 hist = hist->hvalue.next)
262 if (hist->type == type)
263 return hist;
264 return NULL;
267 /* Dump information about HIST to DUMP_FILE. */
269 static void
270 dump_histogram_value (FILE *dump_file, histogram_value hist)
272 switch (hist->type)
274 case HIST_TYPE_INTERVAL:
275 fprintf (dump_file, "Interval counter range %d -- %d",
276 hist->hdata.intvl.int_start,
277 (hist->hdata.intvl.int_start
278 + hist->hdata.intvl.steps - 1));
279 if (hist->hvalue.counters)
281 unsigned int i;
282 fprintf (dump_file, " [");
283 for (i = 0; i < hist->hdata.intvl.steps; i++)
284 fprintf (dump_file, " %d:%"PRId64,
285 hist->hdata.intvl.int_start + i,
286 (int64_t) hist->hvalue.counters[i]);
287 fprintf (dump_file, " ] outside range:%"PRId64,
288 (int64_t) hist->hvalue.counters[i]);
290 fprintf (dump_file, ".\n");
291 break;
293 case HIST_TYPE_POW2:
294 fprintf (dump_file, "Pow2 counter ");
295 if (hist->hvalue.counters)
297 fprintf (dump_file, "pow2:%"PRId64
298 " nonpow2:%"PRId64,
299 (int64_t) hist->hvalue.counters[0],
300 (int64_t) hist->hvalue.counters[1]);
302 fprintf (dump_file, ".\n");
303 break;
305 case HIST_TYPE_SINGLE_VALUE:
306 fprintf (dump_file, "Single value ");
307 if (hist->hvalue.counters)
309 fprintf (dump_file, "value:%"PRId64
310 " match:%"PRId64
311 " wrong:%"PRId64,
312 (int64_t) hist->hvalue.counters[0],
313 (int64_t) hist->hvalue.counters[1],
314 (int64_t) hist->hvalue.counters[2]);
316 fprintf (dump_file, ".\n");
317 break;
319 case HIST_TYPE_AVERAGE:
320 fprintf (dump_file, "Average value ");
321 if (hist->hvalue.counters)
323 fprintf (dump_file, "sum:%"PRId64
324 " times:%"PRId64,
325 (int64_t) hist->hvalue.counters[0],
326 (int64_t) hist->hvalue.counters[1]);
328 fprintf (dump_file, ".\n");
329 break;
331 case HIST_TYPE_IOR:
332 fprintf (dump_file, "IOR value ");
333 if (hist->hvalue.counters)
335 fprintf (dump_file, "ior:%"PRId64,
336 (int64_t) hist->hvalue.counters[0]);
338 fprintf (dump_file, ".\n");
339 break;
341 case HIST_TYPE_CONST_DELTA:
342 fprintf (dump_file, "Constant delta ");
343 if (hist->hvalue.counters)
345 fprintf (dump_file, "value:%"PRId64
346 " match:%"PRId64
347 " wrong:%"PRId64,
348 (int64_t) hist->hvalue.counters[0],
349 (int64_t) hist->hvalue.counters[1],
350 (int64_t) hist->hvalue.counters[2]);
352 fprintf (dump_file, ".\n");
353 break;
354 case HIST_TYPE_INDIR_CALL:
355 fprintf (dump_file, "Indirect call ");
356 if (hist->hvalue.counters)
358 fprintf (dump_file, "value:%"PRId64
359 " match:%"PRId64
360 " all:%"PRId64,
361 (int64_t) hist->hvalue.counters[0],
362 (int64_t) hist->hvalue.counters[1],
363 (int64_t) hist->hvalue.counters[2]);
365 fprintf (dump_file, ".\n");
366 break;
367 case HIST_TYPE_TIME_PROFILE:
368 fprintf (dump_file, "Time profile ");
369 if (hist->hvalue.counters)
371 fprintf (dump_file, "time:%"PRId64,
372 (int64_t) hist->hvalue.counters[0]);
374 fprintf (dump_file, ".\n");
375 break;
376 case HIST_TYPE_INDIR_CALL_TOPN:
377 fprintf (dump_file, "Indirect call topn ");
378 if (hist->hvalue.counters)
380 int i;
382 fprintf (dump_file, "accu:%"PRId64, hist->hvalue.counters[0]);
383 for (i = 1; i < (GCOV_ICALL_TOPN_VAL << 2); i += 2)
385 fprintf (dump_file, " target:%"PRId64 " value:%"PRId64,
386 (int64_t) hist->hvalue.counters[i],
387 (int64_t) hist->hvalue.counters[i+1]);
390 fprintf (dump_file, ".\n");
391 break;
392 case HIST_TYPE_MAX:
393 gcc_unreachable ();
397 /* Dump information about HIST to DUMP_FILE. */
399 void
400 stream_out_histogram_value (struct output_block *ob, histogram_value hist)
402 struct bitpack_d bp;
403 unsigned int i;
405 bp = bitpack_create (ob->main_stream);
406 bp_pack_enum (&bp, hist_type, HIST_TYPE_MAX, hist->type);
407 bp_pack_value (&bp, hist->hvalue.next != NULL, 1);
408 streamer_write_bitpack (&bp);
409 switch (hist->type)
411 case HIST_TYPE_INTERVAL:
412 streamer_write_hwi (ob, hist->hdata.intvl.int_start);
413 streamer_write_uhwi (ob, hist->hdata.intvl.steps);
414 break;
415 default:
416 break;
418 for (i = 0; i < hist->n_counters; i++)
419 streamer_write_gcov_count (ob, hist->hvalue.counters[i]);
420 if (hist->hvalue.next)
421 stream_out_histogram_value (ob, hist->hvalue.next);
423 /* Dump information about HIST to DUMP_FILE. */
425 void
426 stream_in_histogram_value (struct lto_input_block *ib, gimple stmt)
428 enum hist_type type;
429 unsigned int ncounters = 0;
430 struct bitpack_d bp;
431 unsigned int i;
432 histogram_value new_val;
433 bool next;
434 histogram_value *next_p = NULL;
438 bp = streamer_read_bitpack (ib);
439 type = bp_unpack_enum (&bp, hist_type, HIST_TYPE_MAX);
440 next = bp_unpack_value (&bp, 1);
441 new_val = gimple_alloc_histogram_value (cfun, type, stmt, NULL);
442 switch (type)
444 case HIST_TYPE_INTERVAL:
445 new_val->hdata.intvl.int_start = streamer_read_hwi (ib);
446 new_val->hdata.intvl.steps = streamer_read_uhwi (ib);
447 ncounters = new_val->hdata.intvl.steps + 2;
448 break;
450 case HIST_TYPE_POW2:
451 case HIST_TYPE_AVERAGE:
452 ncounters = 2;
453 break;
455 case HIST_TYPE_SINGLE_VALUE:
456 case HIST_TYPE_INDIR_CALL:
457 ncounters = 3;
458 break;
460 case HIST_TYPE_CONST_DELTA:
461 ncounters = 4;
462 break;
464 case HIST_TYPE_IOR:
465 case HIST_TYPE_TIME_PROFILE:
466 ncounters = 1;
467 break;
469 case HIST_TYPE_INDIR_CALL_TOPN:
470 ncounters = (GCOV_ICALL_TOPN_VAL << 2) + 1;
471 break;
473 case HIST_TYPE_MAX:
474 gcc_unreachable ();
476 new_val->hvalue.counters = XNEWVAR (gcov_type, sizeof (*new_val->hvalue.counters) * ncounters);
477 new_val->n_counters = ncounters;
478 for (i = 0; i < ncounters; i++)
479 new_val->hvalue.counters[i] = streamer_read_gcov_count (ib);
480 if (!next_p)
481 gimple_add_histogram_value (cfun, stmt, new_val);
482 else
483 *next_p = new_val;
484 next_p = &new_val->hvalue.next;
486 while (next);
489 /* Dump all histograms attached to STMT to DUMP_FILE. */
491 void
492 dump_histograms_for_stmt (struct function *fun, FILE *dump_file, gimple stmt)
494 histogram_value hist;
495 for (hist = gimple_histogram_value (fun, stmt); hist; hist = hist->hvalue.next)
496 dump_histogram_value (dump_file, hist);
499 /* Remove all histograms associated with STMT. */
501 void
502 gimple_remove_stmt_histograms (struct function *fun, gimple stmt)
504 histogram_value val;
505 while ((val = gimple_histogram_value (fun, stmt)) != NULL)
506 gimple_remove_histogram_value (fun, stmt, val);
509 /* Duplicate all histograms associates with OSTMT to STMT. */
511 void
512 gimple_duplicate_stmt_histograms (struct function *fun, gimple stmt,
513 struct function *ofun, gimple ostmt)
515 histogram_value val;
516 for (val = gimple_histogram_value (ofun, ostmt); val != NULL; val = val->hvalue.next)
518 histogram_value new_val = gimple_alloc_histogram_value (fun, val->type, NULL, NULL);
519 memcpy (new_val, val, sizeof (*val));
520 new_val->hvalue.stmt = stmt;
521 new_val->hvalue.counters = XNEWVAR (gcov_type, sizeof (*new_val->hvalue.counters) * new_val->n_counters);
522 memcpy (new_val->hvalue.counters, val->hvalue.counters, sizeof (*new_val->hvalue.counters) * new_val->n_counters);
523 gimple_add_histogram_value (fun, stmt, new_val);
528 /* Move all histograms associated with OSTMT to STMT. */
530 void
531 gimple_move_stmt_histograms (struct function *fun, gimple stmt, gimple ostmt)
533 histogram_value val = gimple_histogram_value (fun, ostmt);
534 if (val)
536 /* The following three statements can't be reordered,
537 because histogram hashtab relies on stmt field value
538 for finding the exact slot. */
539 set_histogram_value (fun, ostmt, NULL);
540 for (; val != NULL; val = val->hvalue.next)
541 val->hvalue.stmt = stmt;
542 set_histogram_value (fun, stmt, val);
546 static bool error_found = false;
548 /* Helper function for verify_histograms. For each histogram reachable via htab
549 walk verify that it was reached via statement walk. */
551 static int
552 visit_hist (void **slot, void *data)
554 hash_set<histogram_value> *visited = (hash_set<histogram_value> *) data;
555 histogram_value hist = *(histogram_value *) slot;
557 if (!visited->contains (hist)
558 && hist->type != HIST_TYPE_TIME_PROFILE)
560 error ("dead histogram");
561 dump_histogram_value (stderr, hist);
562 debug_gimple_stmt (hist->hvalue.stmt);
563 error_found = true;
565 return 1;
569 /* Verify sanity of the histograms. */
571 DEBUG_FUNCTION void
572 verify_histograms (void)
574 basic_block bb;
575 gimple_stmt_iterator gsi;
576 histogram_value hist;
578 error_found = false;
579 hash_set<histogram_value> visited_hists;
580 FOR_EACH_BB_FN (bb, cfun)
581 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
583 gimple stmt = gsi_stmt (gsi);
585 for (hist = gimple_histogram_value (cfun, stmt); hist;
586 hist = hist->hvalue.next)
588 if (hist->hvalue.stmt != stmt)
590 error ("Histogram value statement does not correspond to "
591 "the statement it is associated with");
592 debug_gimple_stmt (stmt);
593 dump_histogram_value (stderr, hist);
594 error_found = true;
596 visited_hists.add (hist);
599 if (VALUE_HISTOGRAMS (cfun))
600 htab_traverse (VALUE_HISTOGRAMS (cfun), visit_hist, &visited_hists);
601 if (error_found)
602 internal_error ("verify_histograms failed");
605 /* Helper function for verify_histograms. For each histogram reachable via htab
606 walk verify that it was reached via statement walk. */
608 static int
609 free_hist (void **slot, void *data ATTRIBUTE_UNUSED)
611 histogram_value hist = *(histogram_value *) slot;
612 free (hist->hvalue.counters);
613 #ifdef ENABLE_CHECKING
614 memset (hist, 0xab, sizeof (*hist));
615 #endif
616 free (hist);
617 return 1;
620 void
621 free_histograms (void)
623 if (VALUE_HISTOGRAMS (cfun))
625 htab_traverse (VALUE_HISTOGRAMS (cfun), free_hist, NULL);
626 htab_delete (VALUE_HISTOGRAMS (cfun));
627 VALUE_HISTOGRAMS (cfun) = NULL;
632 /* The overall number of invocations of the counter should match
633 execution count of basic block. Report it as error rather than
634 internal error as it might mean that user has misused the profile
635 somehow. */
637 static bool
638 check_counter (gimple stmt, const char * name,
639 gcov_type *count, gcov_type *all, gcov_type bb_count)
641 if (*all != bb_count || *count > *all)
643 location_t locus;
644 locus = (stmt != NULL)
645 ? gimple_location (stmt)
646 : DECL_SOURCE_LOCATION (current_function_decl);
647 if (flag_profile_correction)
649 if (dump_enabled_p ())
650 dump_printf_loc (MSG_MISSED_OPTIMIZATION, locus,
651 "correcting inconsistent value profile: %s "
652 "profiler overall count (%d) does not match BB "
653 "count (%d)\n", name, (int)*all, (int)bb_count);
654 *all = bb_count;
655 if (*count > *all)
656 *count = *all;
657 return false;
659 else
661 error_at (locus, "corrupted value profile: %s "
662 "profile counter (%d out of %d) inconsistent with "
663 "basic-block count (%d)",
664 name,
665 (int) *count,
666 (int) *all,
667 (int) bb_count);
668 return true;
672 return false;
676 /* GIMPLE based transformations. */
678 bool
679 gimple_value_profile_transformations (void)
681 basic_block bb;
682 gimple_stmt_iterator gsi;
683 bool changed = false;
685 FOR_EACH_BB_FN (bb, cfun)
687 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
689 gimple stmt = gsi_stmt (gsi);
690 histogram_value th = gimple_histogram_value (cfun, stmt);
691 if (!th)
692 continue;
694 if (dump_file)
696 fprintf (dump_file, "Trying transformations on stmt ");
697 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
698 dump_histograms_for_stmt (cfun, dump_file, stmt);
701 /* Transformations: */
702 /* The order of things in this conditional controls which
703 transformation is used when more than one is applicable. */
704 /* It is expected that any code added by the transformations
705 will be added before the current statement, and that the
706 current statement remain valid (although possibly
707 modified) upon return. */
708 if (gimple_mod_subtract_transform (&gsi)
709 || gimple_divmod_fixed_value_transform (&gsi)
710 || gimple_mod_pow2_value_transform (&gsi)
711 || gimple_stringops_transform (&gsi)
712 || gimple_ic_transform (&gsi))
714 stmt = gsi_stmt (gsi);
715 changed = true;
716 /* Original statement may no longer be in the same block. */
717 if (bb != gimple_bb (stmt))
719 bb = gimple_bb (stmt);
720 gsi = gsi_for_stmt (stmt);
726 if (changed)
728 counts_to_freqs ();
731 return changed;
735 /* Generate code for transformation 1 (with parent gimple assignment
736 STMT and probability of taking the optimal path PROB, which is
737 equivalent to COUNT/ALL within roundoff error). This generates the
738 result into a temp and returns the temp; it does not replace or
739 alter the original STMT. */
741 static tree
742 gimple_divmod_fixed_value (gimple stmt, tree value, int prob, gcov_type count,
743 gcov_type all)
745 gimple stmt1, stmt2, stmt3;
746 tree tmp0, tmp1, tmp2;
747 gimple bb1end, bb2end, bb3end;
748 basic_block bb, bb2, bb3, bb4;
749 tree optype, op1, op2;
750 edge e12, e13, e23, e24, e34;
751 gimple_stmt_iterator gsi;
753 gcc_assert (is_gimple_assign (stmt)
754 && (gimple_assign_rhs_code (stmt) == TRUNC_DIV_EXPR
755 || gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR));
757 optype = TREE_TYPE (gimple_assign_lhs (stmt));
758 op1 = gimple_assign_rhs1 (stmt);
759 op2 = gimple_assign_rhs2 (stmt);
761 bb = gimple_bb (stmt);
762 gsi = gsi_for_stmt (stmt);
764 tmp0 = make_temp_ssa_name (optype, NULL, "PROF");
765 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
766 stmt1 = gimple_build_assign (tmp0, fold_convert (optype, value));
767 stmt2 = gimple_build_assign (tmp1, op2);
768 stmt3 = gimple_build_cond (NE_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE);
769 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
770 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
771 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
772 bb1end = stmt3;
774 tmp2 = create_tmp_reg (optype, "PROF");
775 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), tmp2,
776 op1, tmp0);
777 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
778 bb2end = stmt1;
780 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), tmp2,
781 op1, op2);
782 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
783 bb3end = stmt1;
785 /* Fix CFG. */
786 /* Edge e23 connects bb2 to bb3, etc. */
787 e12 = split_block (bb, bb1end);
788 bb2 = e12->dest;
789 bb2->count = count;
790 e23 = split_block (bb2, bb2end);
791 bb3 = e23->dest;
792 bb3->count = all - count;
793 e34 = split_block (bb3, bb3end);
794 bb4 = e34->dest;
795 bb4->count = all;
797 e12->flags &= ~EDGE_FALLTHRU;
798 e12->flags |= EDGE_FALSE_VALUE;
799 e12->probability = prob;
800 e12->count = count;
802 e13 = make_edge (bb, bb3, EDGE_TRUE_VALUE);
803 e13->probability = REG_BR_PROB_BASE - prob;
804 e13->count = all - count;
806 remove_edge (e23);
808 e24 = make_edge (bb2, bb4, EDGE_FALLTHRU);
809 e24->probability = REG_BR_PROB_BASE;
810 e24->count = count;
812 e34->probability = REG_BR_PROB_BASE;
813 e34->count = all - count;
815 return tmp2;
819 /* Do transform 1) on INSN if applicable. */
821 static bool
822 gimple_divmod_fixed_value_transform (gimple_stmt_iterator *si)
824 histogram_value histogram;
825 enum tree_code code;
826 gcov_type val, count, all;
827 tree result, value, tree_val;
828 gcov_type prob;
829 gimple stmt;
831 stmt = gsi_stmt (*si);
832 if (gimple_code (stmt) != GIMPLE_ASSIGN)
833 return false;
835 if (!INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt))))
836 return false;
838 code = gimple_assign_rhs_code (stmt);
840 if (code != TRUNC_DIV_EXPR && code != TRUNC_MOD_EXPR)
841 return false;
843 histogram = gimple_histogram_value_of_type (cfun, stmt,
844 HIST_TYPE_SINGLE_VALUE);
845 if (!histogram)
846 return false;
848 value = histogram->hvalue.value;
849 val = histogram->hvalue.counters[0];
850 count = histogram->hvalue.counters[1];
851 all = histogram->hvalue.counters[2];
852 gimple_remove_histogram_value (cfun, stmt, histogram);
854 /* We require that count is at least half of all; this means
855 that for the transformation to fire the value must be constant
856 at least 50% of time (and 75% gives the guarantee of usage). */
857 if (simple_cst_equal (gimple_assign_rhs2 (stmt), value) != 1
858 || 2 * count < all
859 || optimize_bb_for_size_p (gimple_bb (stmt)))
860 return false;
862 if (check_counter (stmt, "value", &count, &all, gimple_bb (stmt)->count))
863 return false;
865 /* Compute probability of taking the optimal path. */
866 if (all > 0)
867 prob = GCOV_COMPUTE_SCALE (count, all);
868 else
869 prob = 0;
871 if (sizeof (gcov_type) == sizeof (HOST_WIDE_INT))
872 tree_val = build_int_cst (get_gcov_type (), val);
873 else
875 HOST_WIDE_INT a[2];
876 a[0] = (unsigned HOST_WIDE_INT) val;
877 a[1] = val >> (HOST_BITS_PER_WIDE_INT - 1) >> 1;
879 tree_val = wide_int_to_tree (get_gcov_type (), wide_int::from_array (a, 2,
880 TYPE_PRECISION (get_gcov_type ()), false));
882 result = gimple_divmod_fixed_value (stmt, tree_val, prob, count, all);
884 if (dump_file)
886 fprintf (dump_file, "Div/mod by constant ");
887 print_generic_expr (dump_file, value, TDF_SLIM);
888 fprintf (dump_file, "=");
889 print_generic_expr (dump_file, tree_val, TDF_SLIM);
890 fprintf (dump_file, " transformation on insn ");
891 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
894 gimple_assign_set_rhs_from_tree (si, result);
895 update_stmt (gsi_stmt (*si));
897 return true;
900 /* Generate code for transformation 2 (with parent gimple assign STMT and
901 probability of taking the optimal path PROB, which is equivalent to COUNT/ALL
902 within roundoff error). This generates the result into a temp and returns
903 the temp; it does not replace or alter the original STMT. */
904 static tree
905 gimple_mod_pow2 (gimple stmt, int prob, gcov_type count, gcov_type all)
907 gimple stmt1, stmt2, stmt3, stmt4;
908 tree tmp2, tmp3;
909 gimple bb1end, bb2end, bb3end;
910 basic_block bb, bb2, bb3, bb4;
911 tree optype, op1, op2;
912 edge e12, e13, e23, e24, e34;
913 gimple_stmt_iterator gsi;
914 tree result;
916 gcc_assert (is_gimple_assign (stmt)
917 && gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR);
919 optype = TREE_TYPE (gimple_assign_lhs (stmt));
920 op1 = gimple_assign_rhs1 (stmt);
921 op2 = gimple_assign_rhs2 (stmt);
923 bb = gimple_bb (stmt);
924 gsi = gsi_for_stmt (stmt);
926 result = create_tmp_reg (optype, "PROF");
927 tmp2 = make_temp_ssa_name (optype, NULL, "PROF");
928 tmp3 = make_temp_ssa_name (optype, NULL, "PROF");
929 stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, tmp2, op2,
930 build_int_cst (optype, -1));
931 stmt3 = gimple_build_assign_with_ops (BIT_AND_EXPR, tmp3, tmp2, op2);
932 stmt4 = gimple_build_cond (NE_EXPR, tmp3, build_int_cst (optype, 0),
933 NULL_TREE, NULL_TREE);
934 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
935 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
936 gsi_insert_before (&gsi, stmt4, GSI_SAME_STMT);
937 bb1end = stmt4;
939 /* tmp2 == op2-1 inherited from previous block. */
940 stmt1 = gimple_build_assign_with_ops (BIT_AND_EXPR, result, op1, tmp2);
941 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
942 bb2end = stmt1;
944 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), result,
945 op1, op2);
946 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
947 bb3end = stmt1;
949 /* Fix CFG. */
950 /* Edge e23 connects bb2 to bb3, etc. */
951 e12 = split_block (bb, bb1end);
952 bb2 = e12->dest;
953 bb2->count = count;
954 e23 = split_block (bb2, bb2end);
955 bb3 = e23->dest;
956 bb3->count = all - count;
957 e34 = split_block (bb3, bb3end);
958 bb4 = e34->dest;
959 bb4->count = all;
961 e12->flags &= ~EDGE_FALLTHRU;
962 e12->flags |= EDGE_FALSE_VALUE;
963 e12->probability = prob;
964 e12->count = count;
966 e13 = make_edge (bb, bb3, EDGE_TRUE_VALUE);
967 e13->probability = REG_BR_PROB_BASE - prob;
968 e13->count = all - count;
970 remove_edge (e23);
972 e24 = make_edge (bb2, bb4, EDGE_FALLTHRU);
973 e24->probability = REG_BR_PROB_BASE;
974 e24->count = count;
976 e34->probability = REG_BR_PROB_BASE;
977 e34->count = all - count;
979 return result;
982 /* Do transform 2) on INSN if applicable. */
983 static bool
984 gimple_mod_pow2_value_transform (gimple_stmt_iterator *si)
986 histogram_value histogram;
987 enum tree_code code;
988 gcov_type count, wrong_values, all;
989 tree lhs_type, result, value;
990 gcov_type prob;
991 gimple stmt;
993 stmt = gsi_stmt (*si);
994 if (gimple_code (stmt) != GIMPLE_ASSIGN)
995 return false;
997 lhs_type = TREE_TYPE (gimple_assign_lhs (stmt));
998 if (!INTEGRAL_TYPE_P (lhs_type))
999 return false;
1001 code = gimple_assign_rhs_code (stmt);
1003 if (code != TRUNC_MOD_EXPR || !TYPE_UNSIGNED (lhs_type))
1004 return false;
1006 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_POW2);
1007 if (!histogram)
1008 return false;
1010 value = histogram->hvalue.value;
1011 wrong_values = histogram->hvalue.counters[0];
1012 count = histogram->hvalue.counters[1];
1014 gimple_remove_histogram_value (cfun, stmt, histogram);
1016 /* We require that we hit a power of 2 at least half of all evaluations. */
1017 if (simple_cst_equal (gimple_assign_rhs2 (stmt), value) != 1
1018 || count < wrong_values
1019 || optimize_bb_for_size_p (gimple_bb (stmt)))
1020 return false;
1022 if (dump_file)
1024 fprintf (dump_file, "Mod power of 2 transformation on insn ");
1025 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1028 /* Compute probability of taking the optimal path. */
1029 all = count + wrong_values;
1031 if (check_counter (stmt, "pow2", &count, &all, gimple_bb (stmt)->count))
1032 return false;
1034 if (all > 0)
1035 prob = GCOV_COMPUTE_SCALE (count, all);
1036 else
1037 prob = 0;
1039 result = gimple_mod_pow2 (stmt, prob, count, all);
1041 gimple_assign_set_rhs_from_tree (si, result);
1042 update_stmt (gsi_stmt (*si));
1044 return true;
1047 /* Generate code for transformations 3 and 4 (with parent gimple assign STMT, and
1048 NCOUNTS the number of cases to support. Currently only NCOUNTS==0 or 1 is
1049 supported and this is built into this interface. The probabilities of taking
1050 the optimal paths are PROB1 and PROB2, which are equivalent to COUNT1/ALL and
1051 COUNT2/ALL respectively within roundoff error). This generates the
1052 result into a temp and returns the temp; it does not replace or alter
1053 the original STMT. */
1054 /* FIXME: Generalize the interface to handle NCOUNTS > 1. */
1056 static tree
1057 gimple_mod_subtract (gimple stmt, int prob1, int prob2, int ncounts,
1058 gcov_type count1, gcov_type count2, gcov_type all)
1060 gimple stmt1, stmt2, stmt3;
1061 tree tmp1;
1062 gimple bb1end, bb2end = NULL, bb3end;
1063 basic_block bb, bb2, bb3, bb4;
1064 tree optype, op1, op2;
1065 edge e12, e23 = 0, e24, e34, e14;
1066 gimple_stmt_iterator gsi;
1067 tree result;
1069 gcc_assert (is_gimple_assign (stmt)
1070 && gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR);
1072 optype = TREE_TYPE (gimple_assign_lhs (stmt));
1073 op1 = gimple_assign_rhs1 (stmt);
1074 op2 = gimple_assign_rhs2 (stmt);
1076 bb = gimple_bb (stmt);
1077 gsi = gsi_for_stmt (stmt);
1079 result = create_tmp_reg (optype, "PROF");
1080 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
1081 stmt1 = gimple_build_assign (result, op1);
1082 stmt2 = gimple_build_assign (tmp1, op2);
1083 stmt3 = gimple_build_cond (LT_EXPR, result, tmp1, NULL_TREE, NULL_TREE);
1084 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
1085 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
1086 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
1087 bb1end = stmt3;
1089 if (ncounts) /* Assumed to be 0 or 1 */
1091 stmt1 = gimple_build_assign_with_ops (MINUS_EXPR, result, result, tmp1);
1092 stmt2 = gimple_build_cond (LT_EXPR, result, tmp1, NULL_TREE, NULL_TREE);
1093 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
1094 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
1095 bb2end = stmt2;
1098 /* Fallback case. */
1099 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), result,
1100 result, tmp1);
1101 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
1102 bb3end = stmt1;
1104 /* Fix CFG. */
1105 /* Edge e23 connects bb2 to bb3, etc. */
1106 /* However block 3 is optional; if it is not there, references
1107 to 3 really refer to block 2. */
1108 e12 = split_block (bb, bb1end);
1109 bb2 = e12->dest;
1110 bb2->count = all - count1;
1112 if (ncounts) /* Assumed to be 0 or 1. */
1114 e23 = split_block (bb2, bb2end);
1115 bb3 = e23->dest;
1116 bb3->count = all - count1 - count2;
1119 e34 = split_block (ncounts ? bb3 : bb2, bb3end);
1120 bb4 = e34->dest;
1121 bb4->count = all;
1123 e12->flags &= ~EDGE_FALLTHRU;
1124 e12->flags |= EDGE_FALSE_VALUE;
1125 e12->probability = REG_BR_PROB_BASE - prob1;
1126 e12->count = all - count1;
1128 e14 = make_edge (bb, bb4, EDGE_TRUE_VALUE);
1129 e14->probability = prob1;
1130 e14->count = count1;
1132 if (ncounts) /* Assumed to be 0 or 1. */
1134 e23->flags &= ~EDGE_FALLTHRU;
1135 e23->flags |= EDGE_FALSE_VALUE;
1136 e23->count = all - count1 - count2;
1137 e23->probability = REG_BR_PROB_BASE - prob2;
1139 e24 = make_edge (bb2, bb4, EDGE_TRUE_VALUE);
1140 e24->probability = prob2;
1141 e24->count = count2;
1144 e34->probability = REG_BR_PROB_BASE;
1145 e34->count = all - count1 - count2;
1147 return result;
1151 /* Do transforms 3) and 4) on the statement pointed-to by SI if applicable. */
1153 static bool
1154 gimple_mod_subtract_transform (gimple_stmt_iterator *si)
1156 histogram_value histogram;
1157 enum tree_code code;
1158 gcov_type count, wrong_values, all;
1159 tree lhs_type, result;
1160 gcov_type prob1, prob2;
1161 unsigned int i, steps;
1162 gcov_type count1, count2;
1163 gimple stmt;
1165 stmt = gsi_stmt (*si);
1166 if (gimple_code (stmt) != GIMPLE_ASSIGN)
1167 return false;
1169 lhs_type = TREE_TYPE (gimple_assign_lhs (stmt));
1170 if (!INTEGRAL_TYPE_P (lhs_type))
1171 return false;
1173 code = gimple_assign_rhs_code (stmt);
1175 if (code != TRUNC_MOD_EXPR || !TYPE_UNSIGNED (lhs_type))
1176 return false;
1178 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_INTERVAL);
1179 if (!histogram)
1180 return false;
1182 all = 0;
1183 wrong_values = 0;
1184 for (i = 0; i < histogram->hdata.intvl.steps; i++)
1185 all += histogram->hvalue.counters[i];
1187 wrong_values += histogram->hvalue.counters[i];
1188 wrong_values += histogram->hvalue.counters[i+1];
1189 steps = histogram->hdata.intvl.steps;
1190 all += wrong_values;
1191 count1 = histogram->hvalue.counters[0];
1192 count2 = histogram->hvalue.counters[1];
1194 /* Compute probability of taking the optimal path. */
1195 if (check_counter (stmt, "interval", &count1, &all, gimple_bb (stmt)->count))
1197 gimple_remove_histogram_value (cfun, stmt, histogram);
1198 return false;
1201 if (flag_profile_correction && count1 + count2 > all)
1202 all = count1 + count2;
1204 gcc_assert (count1 + count2 <= all);
1206 /* We require that we use just subtractions in at least 50% of all
1207 evaluations. */
1208 count = 0;
1209 for (i = 0; i < histogram->hdata.intvl.steps; i++)
1211 count += histogram->hvalue.counters[i];
1212 if (count * 2 >= all)
1213 break;
1215 if (i == steps
1216 || optimize_bb_for_size_p (gimple_bb (stmt)))
1217 return false;
1219 gimple_remove_histogram_value (cfun, stmt, histogram);
1220 if (dump_file)
1222 fprintf (dump_file, "Mod subtract transformation on insn ");
1223 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1226 /* Compute probability of taking the optimal path(s). */
1227 if (all > 0)
1229 prob1 = GCOV_COMPUTE_SCALE (count1, all);
1230 prob2 = GCOV_COMPUTE_SCALE (count2, all);
1232 else
1234 prob1 = prob2 = 0;
1237 /* In practice, "steps" is always 2. This interface reflects this,
1238 and will need to be changed if "steps" can change. */
1239 result = gimple_mod_subtract (stmt, prob1, prob2, i, count1, count2, all);
1241 gimple_assign_set_rhs_from_tree (si, result);
1242 update_stmt (gsi_stmt (*si));
1244 return true;
1247 struct profile_id_traits : default_hashmap_traits
1249 template<typename T>
1250 static bool
1251 is_deleted (T &e)
1253 return e.m_key == UINT_MAX;
1256 template<typename T> static bool is_empty (T &e) { return e.m_key == 0; }
1257 template<typename T> static void mark_deleted (T &e) { e.m_key = UINT_MAX; }
1258 template<typename T> static void mark_empty (T &e) { e.m_key = 0; }
1261 static hash_map<unsigned int, cgraph_node *, profile_id_traits> *
1262 cgraph_node_map = 0;
1264 /* Returns true if node graph is initialized. This
1265 is used to test if profile_id has been created
1266 for cgraph_nodes. */
1268 bool
1269 coverage_node_map_initialized_p (void)
1271 return cgraph_node_map != 0;
1274 /* Initialize map from PROFILE_ID to CGRAPH_NODE.
1275 When LOCAL is true, the PROFILE_IDs are computed. when it is false we assume
1276 that the PROFILE_IDs was already assigned. */
1278 void
1279 init_node_map (bool local)
1281 struct cgraph_node *n;
1282 cgraph_node_map
1283 = new hash_map<unsigned int, cgraph_node *, profile_id_traits>;
1285 FOR_EACH_DEFINED_FUNCTION (n)
1286 if (n->has_gimple_body_p ())
1288 cgraph_node **val;
1289 if (local)
1291 n->profile_id = coverage_compute_profile_id (n);
1292 while ((val = cgraph_node_map->get (n->profile_id))
1293 || !n->profile_id)
1295 if (dump_file)
1296 fprintf (dump_file, "Local profile-id %i conflict"
1297 " with nodes %s/%i %s/%i\n",
1298 n->profile_id,
1299 n->name (),
1300 n->order,
1301 (*val)->name (),
1302 (*val)->order);
1303 n->profile_id = (n->profile_id + 1) & 0x7fffffff;
1306 else if (!n->profile_id)
1308 if (dump_file)
1309 fprintf (dump_file,
1310 "Node %s/%i has no profile-id"
1311 " (profile feedback missing?)\n",
1312 n->name (),
1313 n->order);
1314 continue;
1316 else if ((val = cgraph_node_map->get (n->profile_id)))
1318 if (dump_file)
1319 fprintf (dump_file,
1320 "Node %s/%i has IP profile-id %i conflict. "
1321 "Giving up.\n",
1322 n->name (),
1323 n->order,
1324 n->profile_id);
1325 *val = NULL;
1326 continue;
1328 cgraph_node_map->put (n->profile_id, n);
1332 /* Delete the CGRAPH_NODE_MAP. */
1334 void
1335 del_node_map (void)
1337 delete cgraph_node_map;
1340 /* Return cgraph node for function with pid */
1342 struct cgraph_node*
1343 find_func_by_profile_id (int profile_id)
1345 cgraph_node **val = cgraph_node_map->get (profile_id);
1346 if (val)
1347 return *val;
1348 else
1349 return NULL;
1352 /* Perform sanity check on the indirect call target. Due to race conditions,
1353 false function target may be attributed to an indirect call site. If the
1354 call expression type mismatches with the target function's type, expand_call
1355 may ICE. Here we only do very minimal sanity check just to make compiler happy.
1356 Returns true if TARGET is considered ok for call CALL_STMT. */
1358 bool
1359 check_ic_target (gimple call_stmt, struct cgraph_node *target)
1361 location_t locus;
1362 if (gimple_check_call_matching_types (call_stmt, target->decl, true))
1363 return true;
1365 locus = gimple_location (call_stmt);
1366 if (dump_enabled_p ())
1367 dump_printf_loc (MSG_MISSED_OPTIMIZATION, locus,
1368 "Skipping target %s with mismatching types for icall\n",
1369 target->name ());
1370 return false;
1373 /* Do transformation
1375 if (actual_callee_address == address_of_most_common_function/method)
1376 do direct call
1377 else
1378 old call
1381 gimple
1382 gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call,
1383 int prob, gcov_type count, gcov_type all)
1385 gimple dcall_stmt, load_stmt, cond_stmt;
1386 tree tmp0, tmp1, tmp;
1387 basic_block cond_bb, dcall_bb, icall_bb, join_bb = NULL;
1388 tree optype = build_pointer_type (void_type_node);
1389 edge e_cd, e_ci, e_di, e_dj = NULL, e_ij;
1390 gimple_stmt_iterator gsi;
1391 int lp_nr, dflags;
1392 edge e_eh, e;
1393 edge_iterator ei;
1394 gimple_stmt_iterator psi;
1396 cond_bb = gimple_bb (icall_stmt);
1397 gsi = gsi_for_stmt (icall_stmt);
1399 tmp0 = make_temp_ssa_name (optype, NULL, "PROF");
1400 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
1401 tmp = unshare_expr (gimple_call_fn (icall_stmt));
1402 load_stmt = gimple_build_assign (tmp0, tmp);
1403 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT);
1405 tmp = fold_convert (optype, build_addr (direct_call->decl,
1406 current_function_decl));
1407 load_stmt = gimple_build_assign (tmp1, tmp);
1408 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT);
1410 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE);
1411 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
1413 gimple_set_vdef (icall_stmt, NULL_TREE);
1414 gimple_set_vuse (icall_stmt, NULL_TREE);
1415 update_stmt (icall_stmt);
1416 dcall_stmt = gimple_copy (icall_stmt);
1417 gimple_call_set_fndecl (dcall_stmt, direct_call->decl);
1418 dflags = flags_from_decl_or_type (direct_call->decl);
1419 if ((dflags & ECF_NORETURN) != 0)
1420 gimple_call_set_lhs (dcall_stmt, NULL_TREE);
1421 gsi_insert_before (&gsi, dcall_stmt, GSI_SAME_STMT);
1423 /* Fix CFG. */
1424 /* Edge e_cd connects cond_bb to dcall_bb, etc; note the first letters. */
1425 e_cd = split_block (cond_bb, cond_stmt);
1426 dcall_bb = e_cd->dest;
1427 dcall_bb->count = count;
1429 e_di = split_block (dcall_bb, dcall_stmt);
1430 icall_bb = e_di->dest;
1431 icall_bb->count = all - count;
1433 /* Do not disturb existing EH edges from the indirect call. */
1434 if (!stmt_ends_bb_p (icall_stmt))
1435 e_ij = split_block (icall_bb, icall_stmt);
1436 else
1438 e_ij = find_fallthru_edge (icall_bb->succs);
1439 /* The indirect call might be noreturn. */
1440 if (e_ij != NULL)
1442 e_ij->probability = REG_BR_PROB_BASE;
1443 e_ij->count = all - count;
1444 e_ij = single_pred_edge (split_edge (e_ij));
1447 if (e_ij != NULL)
1449 join_bb = e_ij->dest;
1450 join_bb->count = all;
1453 e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;
1454 e_cd->probability = prob;
1455 e_cd->count = count;
1457 e_ci = make_edge (cond_bb, icall_bb, EDGE_FALSE_VALUE);
1458 e_ci->probability = REG_BR_PROB_BASE - prob;
1459 e_ci->count = all - count;
1461 remove_edge (e_di);
1463 if (e_ij != NULL)
1465 if ((dflags & ECF_NORETURN) != 0)
1466 e_ij->count = all;
1467 else
1469 e_dj = make_edge (dcall_bb, join_bb, EDGE_FALLTHRU);
1470 e_dj->probability = REG_BR_PROB_BASE;
1471 e_dj->count = count;
1473 e_ij->count = all - count;
1475 e_ij->probability = REG_BR_PROB_BASE;
1478 /* Insert PHI node for the call result if necessary. */
1479 if (gimple_call_lhs (icall_stmt)
1480 && TREE_CODE (gimple_call_lhs (icall_stmt)) == SSA_NAME
1481 && (dflags & ECF_NORETURN) == 0)
1483 tree result = gimple_call_lhs (icall_stmt);
1484 gimple phi = create_phi_node (result, join_bb);
1485 gimple_call_set_lhs (icall_stmt,
1486 duplicate_ssa_name (result, icall_stmt));
1487 add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION);
1488 gimple_call_set_lhs (dcall_stmt,
1489 duplicate_ssa_name (result, dcall_stmt));
1490 add_phi_arg (phi, gimple_call_lhs (dcall_stmt), e_dj, UNKNOWN_LOCATION);
1493 /* Build an EH edge for the direct call if necessary. */
1494 lp_nr = lookup_stmt_eh_lp (icall_stmt);
1495 if (lp_nr > 0 && stmt_could_throw_p (dcall_stmt))
1497 add_stmt_to_eh_lp (dcall_stmt, lp_nr);
1500 FOR_EACH_EDGE (e_eh, ei, icall_bb->succs)
1501 if (e_eh->flags & (EDGE_EH | EDGE_ABNORMAL))
1503 e = make_edge (dcall_bb, e_eh->dest, e_eh->flags);
1504 for (psi = gsi_start_phis (e_eh->dest);
1505 !gsi_end_p (psi); gsi_next (&psi))
1507 gimple phi = gsi_stmt (psi);
1508 SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e),
1509 PHI_ARG_DEF_FROM_EDGE (phi, e_eh));
1512 return dcall_stmt;
1516 For every checked indirect/virtual call determine if most common pid of
1517 function/class method has probability more than 50%. If yes modify code of
1518 this call to:
1521 static bool
1522 gimple_ic_transform (gimple_stmt_iterator *gsi)
1524 gimple stmt = gsi_stmt (*gsi);
1525 histogram_value histogram;
1526 gcov_type val, count, all, bb_all;
1527 struct cgraph_node *direct_call;
1529 if (gimple_code (stmt) != GIMPLE_CALL)
1530 return false;
1532 if (gimple_call_fndecl (stmt) != NULL_TREE)
1533 return false;
1535 if (gimple_call_internal_p (stmt))
1536 return false;
1538 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_INDIR_CALL);
1539 if (!histogram)
1540 return false;
1542 val = histogram->hvalue.counters [0];
1543 count = histogram->hvalue.counters [1];
1544 all = histogram->hvalue.counters [2];
1546 bb_all = gimple_bb (stmt)->count;
1547 /* The order of CHECK_COUNTER calls is important -
1548 since check_counter can correct the third parameter
1549 and we want to make count <= all <= bb_all. */
1550 if ( check_counter (stmt, "ic", &all, &bb_all, bb_all)
1551 || check_counter (stmt, "ic", &count, &all, all))
1553 gimple_remove_histogram_value (cfun, stmt, histogram);
1554 return false;
1557 if (4 * count <= 3 * all)
1558 return false;
1560 direct_call = find_func_by_profile_id ((int)val);
1562 if (direct_call == NULL)
1564 if (val)
1566 if (dump_file)
1568 fprintf (dump_file, "Indirect call -> direct call from other module");
1569 print_generic_expr (dump_file, gimple_call_fn (stmt), TDF_SLIM);
1570 fprintf (dump_file, "=> %i (will resolve only with LTO)\n", (int)val);
1573 return false;
1576 if (!check_ic_target (stmt, direct_call))
1578 if (dump_file)
1580 fprintf (dump_file, "Indirect call -> direct call ");
1581 print_generic_expr (dump_file, gimple_call_fn (stmt), TDF_SLIM);
1582 fprintf (dump_file, "=> ");
1583 print_generic_expr (dump_file, direct_call->decl, TDF_SLIM);
1584 fprintf (dump_file, " transformation skipped because of type mismatch");
1585 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1587 gimple_remove_histogram_value (cfun, stmt, histogram);
1588 return false;
1591 if (dump_file)
1593 fprintf (dump_file, "Indirect call -> direct call ");
1594 print_generic_expr (dump_file, gimple_call_fn (stmt), TDF_SLIM);
1595 fprintf (dump_file, "=> ");
1596 print_generic_expr (dump_file, direct_call->decl, TDF_SLIM);
1597 fprintf (dump_file, " transformation on insn postponned to ipa-profile");
1598 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1599 fprintf (dump_file, "hist->count %"PRId64
1600 " hist->all %"PRId64"\n", count, all);
1603 return true;
1606 /* Return true if the stringop CALL with FNDECL shall be profiled.
1607 SIZE_ARG be set to the argument index for the size of the string
1608 operation.
1610 static bool
1611 interesting_stringop_to_profile_p (tree fndecl, gimple call, int *size_arg)
1613 enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
1615 if (fcode != BUILT_IN_MEMCPY && fcode != BUILT_IN_MEMPCPY
1616 && fcode != BUILT_IN_MEMSET && fcode != BUILT_IN_BZERO)
1617 return false;
1619 switch (fcode)
1621 case BUILT_IN_MEMCPY:
1622 case BUILT_IN_MEMPCPY:
1623 *size_arg = 2;
1624 return validate_gimple_arglist (call, POINTER_TYPE, POINTER_TYPE,
1625 INTEGER_TYPE, VOID_TYPE);
1626 case BUILT_IN_MEMSET:
1627 *size_arg = 2;
1628 return validate_gimple_arglist (call, POINTER_TYPE, INTEGER_TYPE,
1629 INTEGER_TYPE, VOID_TYPE);
1630 case BUILT_IN_BZERO:
1631 *size_arg = 1;
1632 return validate_gimple_arglist (call, POINTER_TYPE, INTEGER_TYPE,
1633 VOID_TYPE);
1634 default:
1635 gcc_unreachable ();
1639 /* Convert stringop (..., vcall_size)
1640 into
1641 if (vcall_size == icall_size)
1642 stringop (..., icall_size);
1643 else
1644 stringop (..., vcall_size);
1645 assuming we'll propagate a true constant into ICALL_SIZE later. */
1647 static void
1648 gimple_stringop_fixed_value (gimple vcall_stmt, tree icall_size, int prob,
1649 gcov_type count, gcov_type all)
1651 gimple tmp_stmt, cond_stmt, icall_stmt;
1652 tree tmp0, tmp1, vcall_size, optype;
1653 basic_block cond_bb, icall_bb, vcall_bb, join_bb;
1654 edge e_ci, e_cv, e_iv, e_ij, e_vj;
1655 gimple_stmt_iterator gsi;
1656 tree fndecl;
1657 int size_arg;
1659 fndecl = gimple_call_fndecl (vcall_stmt);
1660 if (!interesting_stringop_to_profile_p (fndecl, vcall_stmt, &size_arg))
1661 gcc_unreachable ();
1663 cond_bb = gimple_bb (vcall_stmt);
1664 gsi = gsi_for_stmt (vcall_stmt);
1666 vcall_size = gimple_call_arg (vcall_stmt, size_arg);
1667 optype = TREE_TYPE (vcall_size);
1669 tmp0 = make_temp_ssa_name (optype, NULL, "PROF");
1670 tmp1 = make_temp_ssa_name (optype, NULL, "PROF");
1671 tmp_stmt = gimple_build_assign (tmp0, fold_convert (optype, icall_size));
1672 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT);
1674 tmp_stmt = gimple_build_assign (tmp1, vcall_size);
1675 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT);
1677 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE);
1678 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
1680 gimple_set_vdef (vcall_stmt, NULL);
1681 gimple_set_vuse (vcall_stmt, NULL);
1682 update_stmt (vcall_stmt);
1683 icall_stmt = gimple_copy (vcall_stmt);
1684 gimple_call_set_arg (icall_stmt, size_arg, icall_size);
1685 gsi_insert_before (&gsi, icall_stmt, GSI_SAME_STMT);
1687 /* Fix CFG. */
1688 /* Edge e_ci connects cond_bb to icall_bb, etc. */
1689 e_ci = split_block (cond_bb, cond_stmt);
1690 icall_bb = e_ci->dest;
1691 icall_bb->count = count;
1693 e_iv = split_block (icall_bb, icall_stmt);
1694 vcall_bb = e_iv->dest;
1695 vcall_bb->count = all - count;
1697 e_vj = split_block (vcall_bb, vcall_stmt);
1698 join_bb = e_vj->dest;
1699 join_bb->count = all;
1701 e_ci->flags = (e_ci->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;
1702 e_ci->probability = prob;
1703 e_ci->count = count;
1705 e_cv = make_edge (cond_bb, vcall_bb, EDGE_FALSE_VALUE);
1706 e_cv->probability = REG_BR_PROB_BASE - prob;
1707 e_cv->count = all - count;
1709 remove_edge (e_iv);
1711 e_ij = make_edge (icall_bb, join_bb, EDGE_FALLTHRU);
1712 e_ij->probability = REG_BR_PROB_BASE;
1713 e_ij->count = count;
1715 e_vj->probability = REG_BR_PROB_BASE;
1716 e_vj->count = all - count;
1718 /* Insert PHI node for the call result if necessary. */
1719 if (gimple_call_lhs (vcall_stmt)
1720 && TREE_CODE (gimple_call_lhs (vcall_stmt)) == SSA_NAME)
1722 tree result = gimple_call_lhs (vcall_stmt);
1723 gimple phi = create_phi_node (result, join_bb);
1724 gimple_call_set_lhs (vcall_stmt,
1725 duplicate_ssa_name (result, vcall_stmt));
1726 add_phi_arg (phi, gimple_call_lhs (vcall_stmt), e_vj, UNKNOWN_LOCATION);
1727 gimple_call_set_lhs (icall_stmt,
1728 duplicate_ssa_name (result, icall_stmt));
1729 add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION);
1732 /* Because these are all string op builtins, they're all nothrow. */
1733 gcc_assert (!stmt_could_throw_p (vcall_stmt));
1734 gcc_assert (!stmt_could_throw_p (icall_stmt));
1737 /* Find values inside STMT for that we want to measure histograms for
1738 division/modulo optimization. */
1739 static bool
1740 gimple_stringops_transform (gimple_stmt_iterator *gsi)
1742 gimple stmt = gsi_stmt (*gsi);
1743 tree fndecl;
1744 tree blck_size;
1745 enum built_in_function fcode;
1746 histogram_value histogram;
1747 gcov_type count, all, val;
1748 tree dest, src;
1749 unsigned int dest_align, src_align;
1750 gcov_type prob;
1751 tree tree_val;
1752 int size_arg;
1754 if (gimple_code (stmt) != GIMPLE_CALL)
1755 return false;
1756 fndecl = gimple_call_fndecl (stmt);
1757 if (!fndecl)
1758 return false;
1759 fcode = DECL_FUNCTION_CODE (fndecl);
1760 if (!interesting_stringop_to_profile_p (fndecl, stmt, &size_arg))
1761 return false;
1763 blck_size = gimple_call_arg (stmt, size_arg);
1764 if (TREE_CODE (blck_size) == INTEGER_CST)
1765 return false;
1767 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_SINGLE_VALUE);
1768 if (!histogram)
1769 return false;
1770 val = histogram->hvalue.counters[0];
1771 count = histogram->hvalue.counters[1];
1772 all = histogram->hvalue.counters[2];
1773 gimple_remove_histogram_value (cfun, stmt, histogram);
1774 /* We require that count is at least half of all; this means
1775 that for the transformation to fire the value must be constant
1776 at least 80% of time. */
1777 if ((6 * count / 5) < all || optimize_bb_for_size_p (gimple_bb (stmt)))
1778 return false;
1779 if (check_counter (stmt, "value", &count, &all, gimple_bb (stmt)->count))
1780 return false;
1781 if (all > 0)
1782 prob = GCOV_COMPUTE_SCALE (count, all);
1783 else
1784 prob = 0;
1785 dest = gimple_call_arg (stmt, 0);
1786 dest_align = get_pointer_alignment (dest);
1787 switch (fcode)
1789 case BUILT_IN_MEMCPY:
1790 case BUILT_IN_MEMPCPY:
1791 src = gimple_call_arg (stmt, 1);
1792 src_align = get_pointer_alignment (src);
1793 if (!can_move_by_pieces (val, MIN (dest_align, src_align)))
1794 return false;
1795 break;
1796 case BUILT_IN_MEMSET:
1797 if (!can_store_by_pieces (val, builtin_memset_read_str,
1798 gimple_call_arg (stmt, 1),
1799 dest_align, true))
1800 return false;
1801 break;
1802 case BUILT_IN_BZERO:
1803 if (!can_store_by_pieces (val, builtin_memset_read_str,
1804 integer_zero_node,
1805 dest_align, true))
1806 return false;
1807 break;
1808 default:
1809 gcc_unreachable ();
1811 if (sizeof (gcov_type) == sizeof (HOST_WIDE_INT))
1812 tree_val = build_int_cst (get_gcov_type (), val);
1813 else
1815 HOST_WIDE_INT a[2];
1816 a[0] = (unsigned HOST_WIDE_INT) val;
1817 a[1] = val >> (HOST_BITS_PER_WIDE_INT - 1) >> 1;
1819 tree_val = wide_int_to_tree (get_gcov_type (), wide_int::from_array (a, 2,
1820 TYPE_PRECISION (get_gcov_type ()), false));
1823 if (dump_file)
1825 fprintf (dump_file, "Single value %i stringop transformation on ",
1826 (int)val);
1827 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1829 gimple_stringop_fixed_value (stmt, tree_val, prob, count, all);
1831 return true;
1834 void
1835 stringop_block_profile (gimple stmt, unsigned int *expected_align,
1836 HOST_WIDE_INT *expected_size)
1838 histogram_value histogram;
1839 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_AVERAGE);
1840 if (!histogram)
1841 *expected_size = -1;
1842 else if (!histogram->hvalue.counters[1])
1844 *expected_size = -1;
1845 gimple_remove_histogram_value (cfun, stmt, histogram);
1847 else
1849 gcov_type size;
1850 size = ((histogram->hvalue.counters[0]
1851 + histogram->hvalue.counters[1] / 2)
1852 / histogram->hvalue.counters[1]);
1853 /* Even if we can hold bigger value in SIZE, INT_MAX
1854 is safe "infinity" for code generation strategies. */
1855 if (size > INT_MAX)
1856 size = INT_MAX;
1857 *expected_size = size;
1858 gimple_remove_histogram_value (cfun, stmt, histogram);
1860 histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_IOR);
1861 if (!histogram)
1862 *expected_align = 0;
1863 else if (!histogram->hvalue.counters[0])
1865 gimple_remove_histogram_value (cfun, stmt, histogram);
1866 *expected_align = 0;
1868 else
1870 gcov_type count;
1871 int alignment;
1873 count = histogram->hvalue.counters[0];
1874 alignment = 1;
1875 while (!(count & alignment)
1876 && (alignment * 2 * BITS_PER_UNIT))
1877 alignment <<= 1;
1878 *expected_align = alignment * BITS_PER_UNIT;
1879 gimple_remove_histogram_value (cfun, stmt, histogram);
1884 /* Find values inside STMT for that we want to measure histograms for
1885 division/modulo optimization. */
1886 static void
1887 gimple_divmod_values_to_profile (gimple stmt, histogram_values *values)
1889 tree lhs, divisor, op0, type;
1890 histogram_value hist;
1892 if (gimple_code (stmt) != GIMPLE_ASSIGN)
1893 return;
1895 lhs = gimple_assign_lhs (stmt);
1896 type = TREE_TYPE (lhs);
1897 if (!INTEGRAL_TYPE_P (type))
1898 return;
1900 switch (gimple_assign_rhs_code (stmt))
1902 case TRUNC_DIV_EXPR:
1903 case TRUNC_MOD_EXPR:
1904 divisor = gimple_assign_rhs2 (stmt);
1905 op0 = gimple_assign_rhs1 (stmt);
1907 values->reserve (3);
1909 if (TREE_CODE (divisor) == SSA_NAME)
1910 /* Check for the case where the divisor is the same value most
1911 of the time. */
1912 values->quick_push (gimple_alloc_histogram_value (cfun,
1913 HIST_TYPE_SINGLE_VALUE,
1914 stmt, divisor));
1916 /* For mod, check whether it is not often a noop (or replaceable by
1917 a few subtractions). */
1918 if (gimple_assign_rhs_code (stmt) == TRUNC_MOD_EXPR
1919 && TYPE_UNSIGNED (type))
1921 tree val;
1922 /* Check for a special case where the divisor is power of 2. */
1923 values->quick_push (gimple_alloc_histogram_value (cfun,
1924 HIST_TYPE_POW2,
1925 stmt, divisor));
1927 val = build2 (TRUNC_DIV_EXPR, type, op0, divisor);
1928 hist = gimple_alloc_histogram_value (cfun, HIST_TYPE_INTERVAL,
1929 stmt, val);
1930 hist->hdata.intvl.int_start = 0;
1931 hist->hdata.intvl.steps = 2;
1932 values->quick_push (hist);
1934 return;
1936 default:
1937 return;
1941 /* Find calls inside STMT for that we want to measure histograms for
1942 indirect/virtual call optimization. */
1944 static void
1945 gimple_indirect_call_to_profile (gimple stmt, histogram_values *values)
1947 tree callee;
1949 if (gimple_code (stmt) != GIMPLE_CALL
1950 || gimple_call_internal_p (stmt)
1951 || gimple_call_fndecl (stmt) != NULL_TREE)
1952 return;
1954 callee = gimple_call_fn (stmt);
1956 values->reserve (3);
1958 values->quick_push (gimple_alloc_histogram_value (
1959 cfun,
1960 PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
1961 HIST_TYPE_INDIR_CALL_TOPN :
1962 HIST_TYPE_INDIR_CALL,
1963 stmt, callee));
1965 return;
1968 /* Find values inside STMT for that we want to measure histograms for
1969 string operations. */
1970 static void
1971 gimple_stringops_values_to_profile (gimple stmt, histogram_values *values)
1973 tree fndecl;
1974 tree blck_size;
1975 tree dest;
1976 int size_arg;
1978 if (gimple_code (stmt) != GIMPLE_CALL)
1979 return;
1980 fndecl = gimple_call_fndecl (stmt);
1981 if (!fndecl)
1982 return;
1984 if (!interesting_stringop_to_profile_p (fndecl, stmt, &size_arg))
1985 return;
1987 dest = gimple_call_arg (stmt, 0);
1988 blck_size = gimple_call_arg (stmt, size_arg);
1990 if (TREE_CODE (blck_size) != INTEGER_CST)
1992 values->safe_push (gimple_alloc_histogram_value (cfun,
1993 HIST_TYPE_SINGLE_VALUE,
1994 stmt, blck_size));
1995 values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_AVERAGE,
1996 stmt, blck_size));
1998 if (TREE_CODE (blck_size) != INTEGER_CST)
1999 values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_IOR,
2000 stmt, dest));
2003 /* Find values inside STMT for that we want to measure histograms and adds
2004 them to list VALUES. */
2006 static void
2007 gimple_values_to_profile (gimple stmt, histogram_values *values)
2009 gimple_divmod_values_to_profile (stmt, values);
2010 gimple_stringops_values_to_profile (stmt, values);
2011 gimple_indirect_call_to_profile (stmt, values);
2014 void
2015 gimple_find_values_to_profile (histogram_values *values)
2017 basic_block bb;
2018 gimple_stmt_iterator gsi;
2019 unsigned i;
2020 histogram_value hist = NULL;
2021 values->create (0);
2023 FOR_EACH_BB_FN (bb, cfun)
2024 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2025 gimple_values_to_profile (gsi_stmt (gsi), values);
2027 values->safe_push (gimple_alloc_histogram_value (cfun, HIST_TYPE_TIME_PROFILE, 0, 0));
2029 FOR_EACH_VEC_ELT (*values, i, hist)
2031 switch (hist->type)
2033 case HIST_TYPE_INTERVAL:
2034 hist->n_counters = hist->hdata.intvl.steps + 2;
2035 break;
2037 case HIST_TYPE_POW2:
2038 hist->n_counters = 2;
2039 break;
2041 case HIST_TYPE_SINGLE_VALUE:
2042 hist->n_counters = 3;
2043 break;
2045 case HIST_TYPE_CONST_DELTA:
2046 hist->n_counters = 4;
2047 break;
2049 case HIST_TYPE_INDIR_CALL:
2050 hist->n_counters = 3;
2051 break;
2053 case HIST_TYPE_TIME_PROFILE:
2054 hist->n_counters = 1;
2055 break;
2057 case HIST_TYPE_AVERAGE:
2058 hist->n_counters = 2;
2059 break;
2061 case HIST_TYPE_IOR:
2062 hist->n_counters = 1;
2063 break;
2065 case HIST_TYPE_INDIR_CALL_TOPN:
2066 hist->n_counters = GCOV_ICALL_TOPN_NCOUNTS;
2067 break;
2069 default:
2070 gcc_unreachable ();
2072 if (dump_file)
2074 fprintf (dump_file, "Stmt ");
2075 print_gimple_stmt (dump_file, hist->hvalue.stmt, 0, TDF_SLIM);
2076 dump_histogram_value (dump_file, hist);