1 /* Calculate branch probabilities, and basic block execution counts.
2 Copyright (C) 1990-2014 Free Software Foundation, Inc.
3 Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
4 based on some ideas from Dain Samples of UC Berkeley.
5 Further mangling by Bob Manson, Cygnus Support.
6 Converted to use trees by Dale Johannesen, Apple Computer.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* Generate basic block profile instrumentation and auxiliary files.
25 Tree-based version. See profile.c for overview. */
29 #include "coretypes.h"
36 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "diagnostic-core.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "gimple-expr.h"
49 #include "tree-nested.h"
51 #include "gimple-iterator.h"
52 #include "gimplify-me.h"
53 #include "gimple-ssa.h"
56 #include "stringpool.h"
57 #include "tree-ssanames.h"
58 #include "tree-into-ssa.h"
59 #include "tree-pass.h"
60 #include "value-prof.h"
63 #include "tree-cfgcleanup.h"
64 #include "tree-nested.h"
67 static GTY(()) tree gcov_type_node
;
68 static GTY(()) tree tree_interval_profiler_fn
;
69 static GTY(()) tree tree_pow2_profiler_fn
;
70 static GTY(()) tree tree_one_value_profiler_fn
;
71 static GTY(()) tree tree_indirect_call_profiler_fn
;
72 static GTY(()) tree tree_time_profiler_fn
;
73 static GTY(()) tree tree_average_profiler_fn
;
74 static GTY(()) tree tree_ior_profiler_fn
;
77 static GTY(()) tree ic_void_ptr_var
;
78 static GTY(()) tree ic_gcov_type_ptr_var
;
79 static GTY(()) tree ptr_void
;
81 /* Do initialization work for the edge profiler. */
84 __thread gcov* __gcov_indirect_call_counters; // pointer to actual counter
85 __thread void* __gcov_indirect_call_callee; // actual callee address
86 __thread int __gcov_function_counter; // time profiler function counter
89 init_ic_make_global_vars (void)
93 ptr_void
= build_pointer_type (void_type_node
);
95 /* Workaround for binutils bug 14342. Once it is fixed, remove lto path. */
99 = build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
100 get_identifier ("__gcov_indirect_call_callee_ltopriv"),
102 TREE_PUBLIC (ic_void_ptr_var
) = 1;
103 DECL_COMMON (ic_void_ptr_var
) = 1;
104 DECL_VISIBILITY (ic_void_ptr_var
) = VISIBILITY_HIDDEN
;
105 DECL_VISIBILITY_SPECIFIED (ic_void_ptr_var
) = true;
110 = build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
112 (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE
) ?
113 "__gcov_indirect_call_topn_callee" :
114 "__gcov_indirect_call_callee")),
116 TREE_PUBLIC (ic_void_ptr_var
) = 1;
117 DECL_EXTERNAL (ic_void_ptr_var
) = 1;
119 TREE_STATIC (ic_void_ptr_var
) = 1;
120 DECL_ARTIFICIAL (ic_void_ptr_var
) = 1;
121 DECL_INITIAL (ic_void_ptr_var
) = NULL
;
122 if (targetm
.have_tls
)
123 set_decl_tls_model (ic_void_ptr_var
, decl_default_tls_model (ic_void_ptr_var
));
125 varpool_node::finalize_decl (ic_void_ptr_var
);
127 gcov_type_ptr
= build_pointer_type (get_gcov_type ());
128 /* Workaround for binutils bug 14342. Once it is fixed, remove lto path. */
132 = build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
133 get_identifier ("__gcov_indirect_call_counters_ltopriv"),
135 TREE_PUBLIC (ic_gcov_type_ptr_var
) = 1;
136 DECL_COMMON (ic_gcov_type_ptr_var
) = 1;
137 DECL_VISIBILITY (ic_gcov_type_ptr_var
) = VISIBILITY_HIDDEN
;
138 DECL_VISIBILITY_SPECIFIED (ic_gcov_type_ptr_var
) = true;
143 = build_decl (UNKNOWN_LOCATION
, VAR_DECL
,
145 (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE
) ?
146 "__gcov_indirect_call_topn_counters" :
147 "__gcov_indirect_call_counters")),
149 TREE_PUBLIC (ic_gcov_type_ptr_var
) = 1;
150 DECL_EXTERNAL (ic_gcov_type_ptr_var
) = 1;
152 TREE_STATIC (ic_gcov_type_ptr_var
) = 1;
153 DECL_ARTIFICIAL (ic_gcov_type_ptr_var
) = 1;
154 DECL_INITIAL (ic_gcov_type_ptr_var
) = NULL
;
155 if (targetm
.have_tls
)
156 set_decl_tls_model (ic_gcov_type_ptr_var
, decl_default_tls_model (ic_gcov_type_ptr_var
));
158 varpool_node::finalize_decl (ic_gcov_type_ptr_var
);
161 /* Create the type and function decls for the interface with gcov. */
164 gimple_init_edge_profiler (void)
166 tree interval_profiler_fn_type
;
167 tree pow2_profiler_fn_type
;
168 tree one_value_profiler_fn_type
;
170 tree ic_profiler_fn_type
;
171 tree average_profiler_fn_type
;
172 tree time_profiler_fn_type
;
176 gcov_type_node
= get_gcov_type ();
177 gcov_type_ptr
= build_pointer_type (gcov_type_node
);
179 /* void (*) (gcov_type *, gcov_type, int, unsigned) */
180 interval_profiler_fn_type
181 = build_function_type_list (void_type_node
,
182 gcov_type_ptr
, gcov_type_node
,
184 unsigned_type_node
, NULL_TREE
);
185 tree_interval_profiler_fn
186 = build_fn_decl ("__gcov_interval_profiler",
187 interval_profiler_fn_type
);
188 TREE_NOTHROW (tree_interval_profiler_fn
) = 1;
189 DECL_ATTRIBUTES (tree_interval_profiler_fn
)
190 = tree_cons (get_identifier ("leaf"), NULL
,
191 DECL_ATTRIBUTES (tree_interval_profiler_fn
));
193 /* void (*) (gcov_type *, gcov_type) */
194 pow2_profiler_fn_type
195 = build_function_type_list (void_type_node
,
196 gcov_type_ptr
, gcov_type_node
,
198 tree_pow2_profiler_fn
= build_fn_decl ("__gcov_pow2_profiler",
199 pow2_profiler_fn_type
);
200 TREE_NOTHROW (tree_pow2_profiler_fn
) = 1;
201 DECL_ATTRIBUTES (tree_pow2_profiler_fn
)
202 = tree_cons (get_identifier ("leaf"), NULL
,
203 DECL_ATTRIBUTES (tree_pow2_profiler_fn
));
205 /* void (*) (gcov_type *, gcov_type) */
206 one_value_profiler_fn_type
207 = build_function_type_list (void_type_node
,
208 gcov_type_ptr
, gcov_type_node
,
210 tree_one_value_profiler_fn
211 = build_fn_decl ("__gcov_one_value_profiler",
212 one_value_profiler_fn_type
);
213 TREE_NOTHROW (tree_one_value_profiler_fn
) = 1;
214 DECL_ATTRIBUTES (tree_one_value_profiler_fn
)
215 = tree_cons (get_identifier ("leaf"), NULL
,
216 DECL_ATTRIBUTES (tree_one_value_profiler_fn
));
218 init_ic_make_global_vars ();
220 /* Workaround for binutils bug 14342. Once it is fixed, remove lto path. */
223 /* void (*) (gcov_type, void *) */
225 = build_function_type_list (void_type_node
,
226 gcov_type_ptr
, gcov_type_node
,
229 tree_indirect_call_profiler_fn
230 = build_fn_decl ("__gcov_indirect_call_profiler",
231 ic_profiler_fn_type
);
235 /* void (*) (gcov_type, void *) */
237 = build_function_type_list (void_type_node
,
241 tree_indirect_call_profiler_fn
242 = build_fn_decl ( (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE
) ?
243 "__gcov_indirect_call_topn_profiler":
244 "__gcov_indirect_call_profiler_v2"),
245 ic_profiler_fn_type
);
247 TREE_NOTHROW (tree_indirect_call_profiler_fn
) = 1;
248 DECL_ATTRIBUTES (tree_indirect_call_profiler_fn
)
249 = tree_cons (get_identifier ("leaf"), NULL
,
250 DECL_ATTRIBUTES (tree_indirect_call_profiler_fn
));
252 /* void (*) (gcov_type *, gcov_type, void *) */
253 time_profiler_fn_type
254 = build_function_type_list (void_type_node
,
255 gcov_type_ptr
, NULL_TREE
);
256 tree_time_profiler_fn
257 = build_fn_decl ("__gcov_time_profiler",
258 time_profiler_fn_type
);
259 TREE_NOTHROW (tree_time_profiler_fn
) = 1;
260 DECL_ATTRIBUTES (tree_time_profiler_fn
)
261 = tree_cons (get_identifier ("leaf"), NULL
,
262 DECL_ATTRIBUTES (tree_time_profiler_fn
));
264 /* void (*) (gcov_type *, gcov_type) */
265 average_profiler_fn_type
266 = build_function_type_list (void_type_node
,
267 gcov_type_ptr
, gcov_type_node
, NULL_TREE
);
268 tree_average_profiler_fn
269 = build_fn_decl ("__gcov_average_profiler",
270 average_profiler_fn_type
);
271 TREE_NOTHROW (tree_average_profiler_fn
) = 1;
272 DECL_ATTRIBUTES (tree_average_profiler_fn
)
273 = tree_cons (get_identifier ("leaf"), NULL
,
274 DECL_ATTRIBUTES (tree_average_profiler_fn
));
276 = build_fn_decl ("__gcov_ior_profiler",
277 average_profiler_fn_type
);
278 TREE_NOTHROW (tree_ior_profiler_fn
) = 1;
279 DECL_ATTRIBUTES (tree_ior_profiler_fn
)
280 = tree_cons (get_identifier ("leaf"), NULL
,
281 DECL_ATTRIBUTES (tree_ior_profiler_fn
));
283 /* LTO streamer needs assembler names. Because we create these decls
284 late, we need to initialize them by hand. */
285 DECL_ASSEMBLER_NAME (tree_interval_profiler_fn
);
286 DECL_ASSEMBLER_NAME (tree_pow2_profiler_fn
);
287 DECL_ASSEMBLER_NAME (tree_one_value_profiler_fn
);
288 DECL_ASSEMBLER_NAME (tree_indirect_call_profiler_fn
);
289 DECL_ASSEMBLER_NAME (tree_time_profiler_fn
);
290 DECL_ASSEMBLER_NAME (tree_average_profiler_fn
);
291 DECL_ASSEMBLER_NAME (tree_ior_profiler_fn
);
295 /* Output instructions as GIMPLE trees to increment the edge
296 execution count, and insert them on E. We rely on
297 gsi_insert_on_edge to preserve the order. */
300 gimple_gen_edge_profiler (int edgeno
, edge e
)
302 tree ref
, one
, gcov_type_tmp_var
;
303 gimple stmt1
, stmt2
, stmt3
;
305 ref
= tree_coverage_counter_ref (GCOV_COUNTER_ARCS
, edgeno
);
306 one
= build_int_cst (gcov_type_node
, 1);
307 gcov_type_tmp_var
= make_temp_ssa_name (gcov_type_node
,
308 NULL
, "PROF_edge_counter");
309 stmt1
= gimple_build_assign (gcov_type_tmp_var
, ref
);
310 gcov_type_tmp_var
= make_temp_ssa_name (gcov_type_node
,
311 NULL
, "PROF_edge_counter");
312 stmt2
= gimple_build_assign_with_ops (PLUS_EXPR
, gcov_type_tmp_var
,
313 gimple_assign_lhs (stmt1
), one
);
314 stmt3
= gimple_build_assign (unshare_expr (ref
), gimple_assign_lhs (stmt2
));
315 gsi_insert_on_edge (e
, stmt1
);
316 gsi_insert_on_edge (e
, stmt2
);
317 gsi_insert_on_edge (e
, stmt3
);
320 /* Emits code to get VALUE to instrument at GSI, and returns the
321 variable containing the value. */
324 prepare_instrumented_value (gimple_stmt_iterator
*gsi
, histogram_value value
)
326 tree val
= value
->hvalue
.value
;
327 if (POINTER_TYPE_P (TREE_TYPE (val
)))
328 val
= fold_convert (build_nonstandard_integer_type
329 (TYPE_PRECISION (TREE_TYPE (val
)), 1), val
);
330 return force_gimple_operand_gsi (gsi
, fold_convert (gcov_type_node
, val
),
331 true, NULL_TREE
, true, GSI_SAME_STMT
);
334 /* Output instructions as GIMPLE trees to increment the interval histogram
335 counter. VALUE is the expression whose value is profiled. TAG is the
336 tag of the section for counters, BASE is offset of the counter position. */
339 gimple_gen_interval_profiler (histogram_value value
, unsigned tag
, unsigned base
)
341 gimple stmt
= value
->hvalue
.stmt
;
342 gimple_stmt_iterator gsi
= gsi_for_stmt (stmt
);
343 tree ref
= tree_coverage_counter_ref (tag
, base
), ref_ptr
;
346 tree start
= build_int_cst_type (integer_type_node
,
347 value
->hdata
.intvl
.int_start
);
348 tree steps
= build_int_cst_type (unsigned_type_node
,
349 value
->hdata
.intvl
.steps
);
351 ref_ptr
= force_gimple_operand_gsi (&gsi
,
352 build_addr (ref
, current_function_decl
),
353 true, NULL_TREE
, true, GSI_SAME_STMT
);
354 val
= prepare_instrumented_value (&gsi
, value
);
355 call
= gimple_build_call (tree_interval_profiler_fn
, 4,
356 ref_ptr
, val
, start
, steps
);
357 gsi_insert_before (&gsi
, call
, GSI_NEW_STMT
);
360 /* Output instructions as GIMPLE trees to increment the power of two histogram
361 counter. VALUE is the expression whose value is profiled. TAG is the tag
362 of the section for counters, BASE is offset of the counter position. */
365 gimple_gen_pow2_profiler (histogram_value value
, unsigned tag
, unsigned base
)
367 gimple stmt
= value
->hvalue
.stmt
;
368 gimple_stmt_iterator gsi
= gsi_for_stmt (stmt
);
369 tree ref_ptr
= tree_coverage_counter_addr (tag
, base
);
373 ref_ptr
= force_gimple_operand_gsi (&gsi
, ref_ptr
,
374 true, NULL_TREE
, true, GSI_SAME_STMT
);
375 val
= prepare_instrumented_value (&gsi
, value
);
376 call
= gimple_build_call (tree_pow2_profiler_fn
, 2, ref_ptr
, val
);
377 gsi_insert_before (&gsi
, call
, GSI_NEW_STMT
);
380 /* Output instructions as GIMPLE trees for code to find the most common value.
381 VALUE is the expression whose value is profiled. TAG is the tag of the
382 section for counters, BASE is offset of the counter position. */
385 gimple_gen_one_value_profiler (histogram_value value
, unsigned tag
, unsigned base
)
387 gimple stmt
= value
->hvalue
.stmt
;
388 gimple_stmt_iterator gsi
= gsi_for_stmt (stmt
);
389 tree ref_ptr
= tree_coverage_counter_addr (tag
, base
);
393 ref_ptr
= force_gimple_operand_gsi (&gsi
, ref_ptr
,
394 true, NULL_TREE
, true, GSI_SAME_STMT
);
395 val
= prepare_instrumented_value (&gsi
, value
);
396 call
= gimple_build_call (tree_one_value_profiler_fn
, 2, ref_ptr
, val
);
397 gsi_insert_before (&gsi
, call
, GSI_NEW_STMT
);
401 /* Output instructions as GIMPLE trees for code to find the most
402 common called function in indirect call.
403 VALUE is the call expression whose indirect callee is profiled.
404 TAG is the tag of the section for counters, BASE is offset of the
408 gimple_gen_ic_profiler (histogram_value value
, unsigned tag
, unsigned base
)
411 gimple stmt1
, stmt2
, stmt3
;
412 gimple stmt
= value
->hvalue
.stmt
;
413 gimple_stmt_iterator gsi
= gsi_for_stmt (stmt
);
414 tree ref_ptr
= tree_coverage_counter_addr (tag
, base
);
416 if ( (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE
) &&
417 tag
== GCOV_COUNTER_V_INDIR
) ||
418 (!PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE
) &&
419 tag
== GCOV_COUNTER_ICALL_TOPNV
))
422 ref_ptr
= force_gimple_operand_gsi (&gsi
, ref_ptr
,
423 true, NULL_TREE
, true, GSI_SAME_STMT
);
427 stmt1: __gcov_indirect_call_counters = get_relevant_counter_ptr ();
428 stmt2: tmp1 = (void *) (indirect call argument value)
429 stmt3: __gcov_indirect_call_callee = tmp1;
432 stmt1
= gimple_build_assign (ic_gcov_type_ptr_var
, ref_ptr
);
433 tmp1
= make_temp_ssa_name (ptr_void
, NULL
, "PROF");
434 stmt2
= gimple_build_assign (tmp1
, unshare_expr (value
->hvalue
.value
));
435 stmt3
= gimple_build_assign (ic_void_ptr_var
, gimple_assign_lhs (stmt2
));
437 gsi_insert_before (&gsi
, stmt1
, GSI_SAME_STMT
);
438 gsi_insert_before (&gsi
, stmt2
, GSI_SAME_STMT
);
439 gsi_insert_before (&gsi
, stmt3
, GSI_SAME_STMT
);
443 /* Output instructions as GIMPLE trees for code to find the most
444 common called function in indirect call. Insert instructions at the
445 beginning of every possible called function.
449 gimple_gen_ic_func_profiler (void)
451 struct cgraph_node
* c_node
= cgraph_node::get (current_function_decl
);
452 gimple_stmt_iterator gsi
;
454 tree tree_uid
, cur_func
, void0
;
456 if (c_node
->only_called_directly_p ())
459 gimple_init_edge_profiler ();
463 stmt1: __gcov_indirect_call_profiler_v2 (profile_id,
464 ¤t_function_decl)
466 gsi
= gsi_after_labels (split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
))));
468 cur_func
= force_gimple_operand_gsi (&gsi
,
469 build_addr (current_function_decl
,
470 current_function_decl
),
472 true, GSI_SAME_STMT
);
473 tree_uid
= build_int_cst
474 (gcov_type_node
, cgraph_node::get (current_function_decl
)->profile_id
);
475 /* Workaround for binutils bug 14342. Once it is fixed, remove lto path. */
478 tree counter_ptr
, ptr_var
;
479 counter_ptr
= force_gimple_operand_gsi (&gsi
, ic_gcov_type_ptr_var
,
480 true, NULL_TREE
, true,
482 ptr_var
= force_gimple_operand_gsi (&gsi
, ic_void_ptr_var
,
483 true, NULL_TREE
, true,
486 stmt1
= gimple_build_call (tree_indirect_call_profiler_fn
, 4,
487 counter_ptr
, tree_uid
, cur_func
, ptr_var
);
491 stmt1
= gimple_build_call (tree_indirect_call_profiler_fn
, 2,
494 gsi_insert_before (&gsi
, stmt1
, GSI_SAME_STMT
);
496 /* Set __gcov_indirect_call_callee to 0,
497 so that calls from other modules won't get misattributed
498 to the last caller of the current callee. */
499 void0
= build_int_cst (build_pointer_type (void_type_node
), 0);
500 stmt2
= gimple_build_assign (ic_void_ptr_var
, void0
);
501 gsi_insert_before (&gsi
, stmt2
, GSI_SAME_STMT
);
504 /* Output instructions as GIMPLE tree at the beginning for each function.
505 TAG is the tag of the section for counters, BASE is offset of the
506 counter position and GSI is the iterator we place the counter. */
509 gimple_gen_time_profiler (unsigned tag
, unsigned base
,
510 gimple_stmt_iterator
&gsi
)
512 tree ref_ptr
= tree_coverage_counter_addr (tag
, base
);
515 ref_ptr
= force_gimple_operand_gsi (&gsi
, ref_ptr
,
516 true, NULL_TREE
, true, GSI_SAME_STMT
);
517 call
= gimple_build_call (tree_time_profiler_fn
, 1, ref_ptr
);
518 gsi_insert_before (&gsi
, call
, GSI_NEW_STMT
);
521 /* Output instructions as GIMPLE trees for code to find the most common value
522 of a difference between two evaluations of an expression.
523 VALUE is the expression whose value is profiled. TAG is the tag of the
524 section for counters, BASE is offset of the counter position. */
527 gimple_gen_const_delta_profiler (histogram_value value ATTRIBUTE_UNUSED
,
528 unsigned tag ATTRIBUTE_UNUSED
,
529 unsigned base ATTRIBUTE_UNUSED
)
531 /* FIXME implement this. */
532 #ifdef ENABLE_CHECKING
533 internal_error ("unimplemented functionality");
538 /* Output instructions as GIMPLE trees to increment the average histogram
539 counter. VALUE is the expression whose value is profiled. TAG is the
540 tag of the section for counters, BASE is offset of the counter position. */
543 gimple_gen_average_profiler (histogram_value value
, unsigned tag
, unsigned base
)
545 gimple stmt
= value
->hvalue
.stmt
;
546 gimple_stmt_iterator gsi
= gsi_for_stmt (stmt
);
547 tree ref_ptr
= tree_coverage_counter_addr (tag
, base
);
551 ref_ptr
= force_gimple_operand_gsi (&gsi
, ref_ptr
,
553 true, GSI_SAME_STMT
);
554 val
= prepare_instrumented_value (&gsi
, value
);
555 call
= gimple_build_call (tree_average_profiler_fn
, 2, ref_ptr
, val
);
556 gsi_insert_before (&gsi
, call
, GSI_NEW_STMT
);
559 /* Output instructions as GIMPLE trees to increment the ior histogram
560 counter. VALUE is the expression whose value is profiled. TAG is the
561 tag of the section for counters, BASE is offset of the counter position. */
564 gimple_gen_ior_profiler (histogram_value value
, unsigned tag
, unsigned base
)
566 gimple stmt
= value
->hvalue
.stmt
;
567 gimple_stmt_iterator gsi
= gsi_for_stmt (stmt
);
568 tree ref_ptr
= tree_coverage_counter_addr (tag
, base
);
572 ref_ptr
= force_gimple_operand_gsi (&gsi
, ref_ptr
,
573 true, NULL_TREE
, true, GSI_SAME_STMT
);
574 val
= prepare_instrumented_value (&gsi
, value
);
575 call
= gimple_build_call (tree_ior_profiler_fn
, 2, ref_ptr
, val
);
576 gsi_insert_before (&gsi
, call
, GSI_NEW_STMT
);
579 /* Profile all functions in the callgraph. */
582 tree_profiling (void)
584 struct cgraph_node
*node
;
586 /* This is a small-ipa pass that gets called only once, from
587 cgraphunit.c:ipa_passes(). */
588 gcc_assert (symtab
->state
== IPA_SSA
);
590 init_node_map (true);
592 FOR_EACH_DEFINED_FUNCTION (node
)
594 if (!gimple_has_body_p (node
->decl
))
597 /* Don't profile functions produced for builtin stuff. */
598 if (DECL_SOURCE_LOCATION (node
->decl
) == BUILTINS_LOCATION
)
601 /* Do not instrument extern inline functions when testing coverage.
602 While this is not perfectly consistent (early inlined extern inlines
603 will get acocunted), testsuite expects that. */
604 if (DECL_EXTERNAL (node
->decl
)
605 && flag_test_coverage
)
608 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
610 /* Local pure-const may imply need to fixup the cfg. */
611 if (execute_fixup_cfg () & TODO_cleanup_cfg
)
616 if (! flag_branch_probabilities
617 && flag_profile_values
)
618 gimple_gen_ic_func_profiler ();
620 if (flag_branch_probabilities
621 && flag_profile_values
622 && flag_value_profile_transformations
)
623 gimple_value_profile_transformations ();
625 /* The above could hose dominator info. Currently there is
626 none coming in, this is a safety valve. It should be
627 easy to adjust it, if and when there is some. */
628 free_dominance_info (CDI_DOMINATORS
);
629 free_dominance_info (CDI_POST_DOMINATORS
);
633 /* Drop pure/const flags from instrumented functions. */
634 FOR_EACH_DEFINED_FUNCTION (node
)
636 if (!gimple_has_body_p (node
->decl
)
638 || node
->decl
!= node
->clone_of
->decl
))
641 /* Don't profile functions produced for builtin stuff. */
642 if (DECL_SOURCE_LOCATION (node
->decl
) == BUILTINS_LOCATION
)
645 node
->set_const_flag (false, false);
646 node
->set_pure_flag (false, false);
649 /* Update call statements and rebuild the cgraph. */
650 FOR_EACH_DEFINED_FUNCTION (node
)
654 if (!gimple_has_body_p (node
->decl
)
656 || node
->decl
!= node
->clone_of
->decl
))
659 /* Don't profile functions produced for builtin stuff. */
660 if (DECL_SOURCE_LOCATION (node
->decl
) == BUILTINS_LOCATION
)
663 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
665 FOR_EACH_BB_FN (bb
, cfun
)
667 gimple_stmt_iterator gsi
;
668 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
670 gimple stmt
= gsi_stmt (gsi
);
671 if (is_gimple_call (stmt
))
676 /* re-merge split blocks. */
678 update_ssa (TODO_update_ssa
);
680 cgraph_edge::rebuild_edges ();
685 handle_missing_profiles ();
693 const pass_data pass_data_ipa_tree_profile
=
695 SIMPLE_IPA_PASS
, /* type */
696 "profile", /* name */
697 OPTGROUP_NONE
, /* optinfo_flags */
698 TV_IPA_PROFILE
, /* tv_id */
699 0, /* properties_required */
700 0, /* properties_provided */
701 0, /* properties_destroyed */
702 0, /* todo_flags_start */
703 0, /* todo_flags_finish */
706 class pass_ipa_tree_profile
: public simple_ipa_opt_pass
709 pass_ipa_tree_profile (gcc::context
*ctxt
)
710 : simple_ipa_opt_pass (pass_data_ipa_tree_profile
, ctxt
)
713 /* opt_pass methods: */
714 virtual bool gate (function
*);
715 virtual unsigned int execute (function
*) { return tree_profiling (); }
717 }; // class pass_ipa_tree_profile
720 pass_ipa_tree_profile::gate (function
*)
722 /* When profile instrumentation, use or test coverage shall be performed.
723 But for AutoFDO, this there is no instrumentation, thus this pass is
725 return (!in_lto_p
&& !flag_auto_profile
726 && (flag_branch_probabilities
|| flag_test_coverage
727 || profile_arc_flag
));
732 simple_ipa_opt_pass
*
733 make_pass_ipa_tree_profile (gcc::context
*ctxt
)
735 return new pass_ipa_tree_profile (ctxt
);
738 #include "gt-tree-profile.h"