comparison gcc/cgraphbuild.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Callgraph construction. 1 /* Callgraph construction.
2 Copyright (C) 2003-2017 Free Software Foundation, Inc. 2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka 3 Contributed by Jan Hubicka
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
188 /* Computes the frequency of the call statement so that it can be stored in 188 /* Computes the frequency of the call statement so that it can be stored in
189 cgraph_edge. BB is the basic block of the call statement. */ 189 cgraph_edge. BB is the basic block of the call statement. */
190 int 190 int
191 compute_call_stmt_bb_frequency (tree decl, basic_block bb) 191 compute_call_stmt_bb_frequency (tree decl, basic_block bb)
192 { 192 {
193 int entry_freq = ENTRY_BLOCK_PTR_FOR_FN 193 return bb->count.to_cgraph_frequency
194 (DECL_STRUCT_FUNCTION (decl))->frequency; 194 (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count);
195 int freq = bb->frequency;
196
197 if (profile_status_for_fn (DECL_STRUCT_FUNCTION (decl)) == PROFILE_ABSENT)
198 return CGRAPH_FREQ_BASE;
199
200 if (!entry_freq)
201 entry_freq = 1, freq++;
202
203 freq = freq * CGRAPH_FREQ_BASE / entry_freq;
204 if (freq > CGRAPH_FREQ_MAX)
205 freq = CGRAPH_FREQ_MAX;
206
207 return freq;
208 } 195 }
209 196
210 /* Mark address taken in STMT. */ 197 /* Mark address taken in STMT. */
211 198
212 static bool 199 static bool
328 if (is_gimple_debug (stmt)) 315 if (is_gimple_debug (stmt))
329 continue; 316 continue;
330 317
331 if (gcall *call_stmt = dyn_cast <gcall *> (stmt)) 318 if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
332 { 319 {
333 int freq = compute_call_stmt_bb_frequency (current_function_decl,
334 bb);
335 decl = gimple_call_fndecl (call_stmt); 320 decl = gimple_call_fndecl (call_stmt);
336 if (decl) 321 if (decl)
337 node->create_edge (cgraph_node::get_create (decl), call_stmt, bb->count, freq); 322 node->create_edge (cgraph_node::get_create (decl), call_stmt, bb->count);
338 else if (gimple_call_internal_p (call_stmt)) 323 else if (gimple_call_internal_p (call_stmt))
339 ; 324 ;
340 else 325 else
341 node->create_indirect_edge (call_stmt, 326 node->create_indirect_edge (call_stmt,
342 gimple_call_flags (call_stmt), 327 gimple_call_flags (call_stmt),
343 bb->count, freq); 328 bb->count);
344 } 329 }
345 node->record_stmt_references (stmt); 330 node->record_stmt_references (stmt);
346 if (gomp_parallel *omp_par_stmt = dyn_cast <gomp_parallel *> (stmt)) 331 if (gomp_parallel *omp_par_stmt = dyn_cast <gomp_parallel *> (stmt))
347 { 332 {
348 tree fn = gimple_omp_parallel_child_fn (omp_par_stmt); 333 tree fn = gimple_omp_parallel_child_fn (omp_par_stmt);
424 gimple *stmt = gsi_stmt (gsi); 409 gimple *stmt = gsi_stmt (gsi);
425 tree decl; 410 tree decl;
426 411
427 if (gcall *call_stmt = dyn_cast <gcall *> (stmt)) 412 if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
428 { 413 {
429 int freq = compute_call_stmt_bb_frequency (current_function_decl,
430 bb);
431 decl = gimple_call_fndecl (call_stmt); 414 decl = gimple_call_fndecl (call_stmt);
432 if (decl) 415 if (decl)
433 node->create_edge (cgraph_node::get_create (decl), call_stmt, 416 node->create_edge (cgraph_node::get_create (decl), call_stmt,
434 bb->count, freq); 417 bb->count);
435 else if (gimple_call_internal_p (call_stmt)) 418 else if (gimple_call_internal_p (call_stmt))
436 ; 419 ;
437 else 420 else
438 node->create_indirect_edge (call_stmt, 421 node->create_indirect_edge (call_stmt,
439 gimple_call_flags (call_stmt), 422 gimple_call_flags (call_stmt),
440 bb->count, freq); 423 bb->count);
441 } 424 }
442 node->record_stmt_references (stmt); 425 node->record_stmt_references (stmt);
443 } 426 }
444 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 427 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
445 node->record_stmt_references (gsi_stmt (gsi)); 428 node->record_stmt_references (gsi_stmt (gsi));
446 } 429 }
447 record_eh_tables (node, cfun); 430 record_eh_tables (node, cfun);
448 gcc_assert (!node->global.inlined_to); 431 gcc_assert (!node->global.inlined_to);
449
450 if (node->instrumented_version
451 && !node->instrumentation_clone)
452 node->create_reference (node->instrumented_version, IPA_REF_CHKP, NULL);
453
454 return 0; 432 return 0;
455 } 433 }
456 434
457 /* Rebuild cgraph references for current function node. This needs to be run 435 /* Rebuild cgraph references for current function node. This needs to be run
458 after passes that don't update the cgraph. */ 436 after passes that don't update the cgraph. */
479 node->record_stmt_references (gsi_stmt (gsi)); 457 node->record_stmt_references (gsi_stmt (gsi));
480 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 458 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
481 node->record_stmt_references (gsi_stmt (gsi)); 459 node->record_stmt_references (gsi_stmt (gsi));
482 } 460 }
483 record_eh_tables (node, cfun); 461 record_eh_tables (node, cfun);
484
485 if (node->instrumented_version
486 && !node->instrumentation_clone)
487 node->create_reference (node->instrumented_version, IPA_REF_CHKP, NULL);
488 } 462 }
489 463
490 namespace { 464 namespace {
491 465
492 const pass_data pass_data_rebuild_cgraph_edges = 466 const pass_data pass_data_rebuild_cgraph_edges =