comparison gcc/ipa-utils.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 /* Utilities for ipa analysis. 1 /* Utilities for ipa analysis.
2 Copyright (C) 2005-2017 Free Software Foundation, Inc. 2 Copyright (C) 2005-2018 Free Software Foundation, Inc.
3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com> 3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
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
84 struct cgraph_edge *edge; 84 struct cgraph_edge *edge;
85 struct ipa_dfs_info *v_info = (struct ipa_dfs_info *) v->aux; 85 struct ipa_dfs_info *v_info = (struct ipa_dfs_info *) v->aux;
86 86
87 /* mark node as old */ 87 /* mark node as old */
88 v_info->new_node = false; 88 v_info->new_node = false;
89 splay_tree_remove (env->nodes_marked_new, v->uid); 89 splay_tree_remove (env->nodes_marked_new, v->get_uid ());
90 90
91 v_info->dfn_number = env->count; 91 v_info->dfn_number = env->count;
92 v_info->low_link = env->count; 92 v_info->low_link = env->count;
93 env->count++; 93 env->count++;
94 env->stack[(env->stack_size)++] = v; 94 env->stack[(env->stack_size)++] = v;
193 info->on_stack = false; 193 info->on_stack = false;
194 info->next_cycle = NULL; 194 info->next_cycle = NULL;
195 node->aux = info; 195 node->aux = info;
196 196
197 splay_tree_insert (env.nodes_marked_new, 197 splay_tree_insert (env.nodes_marked_new,
198 (splay_tree_key)node->uid, 198 (splay_tree_key)node->get_uid (),
199 (splay_tree_value)node); 199 (splay_tree_value)node);
200 } 200 }
201 else 201 else
202 node->aux = NULL; 202 node->aux = NULL;
203 } 203 }
402 if (src->profile_id && !dst->profile_id) 402 if (src->profile_id && !dst->profile_id)
403 dst->profile_id = src->profile_id; 403 dst->profile_id = src->profile_id;
404 404
405 /* FIXME when we merge in unknown profile, we ought to set counts as 405 /* FIXME when we merge in unknown profile, we ought to set counts as
406 unsafe. */ 406 unsafe. */
407 if (!src->count.initialized_p ()) 407 if (!src->count.initialized_p ()
408 || !(src->count.ipa () == src->count))
408 return; 409 return;
409 if (symtab->dump_file) 410 if (symtab->dump_file)
410 { 411 {
411 fprintf (symtab->dump_file, "Merging profiles of %s to %s\n", 412 fprintf (symtab->dump_file, "Merging profiles of %s to %s\n",
412 src->dump_name (), dst->dump_name ()); 413 src->dump_name (), dst->dump_name ());
413 } 414 }
414 if (dst->count.initialized_p ()) 415 if (dst->count.initialized_p () && dst->count.ipa () == dst->count)
415 dst->count += src->count; 416 dst->count += src->count.ipa ();
416 else 417 else
417 dst->count = src->count; 418 dst->count = src->count.ipa ();
418 419
419 /* This is ugly. We need to get both function bodies into memory. 420 /* This is ugly. We need to get both function bodies into memory.
420 If declaration is merged, we need to duplicate it to be able 421 If declaration is merged, we need to duplicate it to be able
421 to load body that is being replaced. This makes symbol table 422 to load body that is being replaced. This makes symbol table
422 temporarily inconsistent. */ 423 temporarily inconsistent. */
522 FOR_ALL_BB_FN (srcbb, srccfun) 523 FOR_ALL_BB_FN (srcbb, srccfun)
523 { 524 {
524 unsigned int i; 525 unsigned int i;
525 526
526 dstbb = BASIC_BLOCK_FOR_FN (dstcfun, srcbb->index); 527 dstbb = BASIC_BLOCK_FOR_FN (dstcfun, srcbb->index);
527 if (!dstbb->count.initialized_p ()) 528
529 /* Either sum the profiles if both are IPA and not global0, or
530 pick more informative one (that is nonzero IPA if other is
531 uninitialized, guessed or global0). */
532 if (!dstbb->count.ipa ().initialized_p ()
533 || (dstbb->count.ipa () == profile_count::zero ()
534 && (srcbb->count.ipa ().initialized_p ()
535 && !(srcbb->count.ipa () == profile_count::zero ()))))
528 { 536 {
529 dstbb->count = srcbb->count; 537 dstbb->count = srcbb->count;
530 for (i = 0; i < EDGE_COUNT (srcbb->succs); i++) 538 for (i = 0; i < EDGE_COUNT (srcbb->succs); i++)
531 { 539 {
532 edge srce = EDGE_SUCC (srcbb, i); 540 edge srce = EDGE_SUCC (srcbb, i);
533 edge dste = EDGE_SUCC (dstbb, i); 541 edge dste = EDGE_SUCC (dstbb, i);
534 if (srce->probability.initialized_p ()) 542 if (srce->probability.initialized_p ())
535 dste->probability = srce->probability; 543 dste->probability = srce->probability;
536 } 544 }
537 } 545 }
538 else if (srcbb->count.initialized_p ()) 546 else if (srcbb->count.ipa ().initialized_p ()
547 && !(srcbb->count.ipa () == profile_count::zero ()))
539 { 548 {
540 for (i = 0; i < EDGE_COUNT (srcbb->succs); i++) 549 for (i = 0; i < EDGE_COUNT (srcbb->succs); i++)
541 { 550 {
542 edge srce = EDGE_SUCC (srcbb, i); 551 edge srce = EDGE_SUCC (srcbb, i);
543 edge dste = EDGE_SUCC (dstbb, i); 552 edge dste = EDGE_SUCC (dstbb, i);
547 } 556 }
548 dstbb->count += srcbb->count; 557 dstbb->count += srcbb->count;
549 } 558 }
550 } 559 }
551 push_cfun (dstcfun); 560 push_cfun (dstcfun);
552 counts_to_freqs (); 561 update_max_bb_count ();
553 compute_function_frequency (); 562 compute_function_frequency ();
554 pop_cfun (); 563 pop_cfun ();
555 for (e = dst->callees; e; e = e->next_callee) 564 for (e = dst->callees; e; e = e->next_callee)
556 { 565 {
557 if (e->speculative) 566 if (e->speculative)
558 continue; 567 continue;
559 e->count = gimple_bb (e->call_stmt)->count; 568 e->count = gimple_bb (e->call_stmt)->count;
560 e->frequency = compute_call_stmt_bb_frequency
561 (dst->decl,
562 gimple_bb (e->call_stmt));
563 } 569 }
564 for (e = dst->indirect_calls, e2 = src->indirect_calls; e; 570 for (e = dst->indirect_calls, e2 = src->indirect_calls; e;
565 e2 = (e2 ? e2->next_callee : NULL), e = e->next_callee) 571 e2 = (e2 ? e2->next_callee : NULL), e = e->next_callee)
566 { 572 {
567 profile_count count = gimple_bb (e->call_stmt)->count; 573 profile_count count = gimple_bb (e->call_stmt)->count;
568 int freq = compute_call_stmt_bb_frequency
569 (dst->decl,
570 gimple_bb (e->call_stmt));
571 /* When call is speculative, we need to re-distribute probabilities 574 /* When call is speculative, we need to re-distribute probabilities
572 the same way as they was. This is not really correct because 575 the same way as they was. This is not really correct because
573 in the other copy the speculation may differ; but probably it 576 in the other copy the speculation may differ; but probably it
574 is not really worth the effort. */ 577 is not really worth the effort. */
575 if (e->speculative) 578 if (e->speculative)
614 { 617 {
615 direct->count += direct2->count; 618 direct->count += direct2->count;
616 indirect->count += indirect2->count; 619 indirect->count += indirect2->count;
617 } 620 }
618 } 621 }
619 int prob = direct->count.probability_in (direct->count
620 + indirect->count).
621 to_reg_br_prob_base ();
622 direct->frequency = RDIV (freq * prob, REG_BR_PROB_BASE);
623 indirect->frequency = RDIV (freq * (REG_BR_PROB_BASE - prob),
624 REG_BR_PROB_BASE);
625 } 622 }
626 else 623 else
627 /* At the moment we should have only profile feedback based 624 /* At the moment we should have only profile feedback based
628 speculations when merging. */ 625 speculations when merging. */
629 gcc_unreachable (); 626 gcc_unreachable ();
633 cgraph_edge *direct, *indirect; 630 cgraph_edge *direct, *indirect;
634 ipa_ref *ref; 631 ipa_ref *ref;
635 632
636 e2->speculative_call_info (direct, indirect, ref); 633 e2->speculative_call_info (direct, indirect, ref);
637 e->count = count; 634 e->count = count;
638 e->frequency = freq; 635 e->make_speculative (direct->callee, direct->count);
639 int prob = direct->count.probability_in (e->count)
640 .to_reg_br_prob_base ();
641 e->make_speculative (direct->callee, direct->count,
642 RDIV (freq * prob, REG_BR_PROB_BASE));
643 } 636 }
644 else 637 else
645 { 638 e->count = count;
646 e->count = count;
647 e->frequency = freq;
648 }
649 } 639 }
650 if (!preserve_body) 640 if (!preserve_body)
651 src->release_body (); 641 src->release_body ();
652 ipa_update_overall_fn_summary (dst); 642 ipa_update_overall_fn_summary (dst);
653 } 643 }