Mercurial > hg > CbC > CbC_gcc
comparison gcc/value-prof.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
1 /* Transformations based on profile information for values. | 1 /* Transformations based on profile information for values. |
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 | 2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
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 |
43 #include "tree.h" | 43 #include "tree.h" |
44 #include "gcov-io.h" | 44 #include "gcov-io.h" |
45 #include "cgraph.h" | 45 #include "cgraph.h" |
46 #include "timevar.h" | 46 #include "timevar.h" |
47 #include "tree-pass.h" | 47 #include "tree-pass.h" |
48 #include "toplev.h" | |
49 #include "pointer-set.h" | 48 #include "pointer-set.h" |
50 | |
51 static struct value_prof_hooks *value_prof_hooks; | |
52 | 49 |
53 /* In this file value profile based optimizations are placed. Currently the | 50 /* In this file value profile based optimizations are placed. Currently the |
54 following optimizations are implemented (for more detailed descriptions | 51 following optimizations are implemented (for more detailed descriptions |
55 see comments at value_profile_transformations): | 52 see comments at value_profile_transformations): |
56 | 53 |
373 { | 370 { |
374 struct pointer_set_t *visited = (struct pointer_set_t *) data; | 371 struct pointer_set_t *visited = (struct pointer_set_t *) data; |
375 histogram_value hist = *(histogram_value *) slot; | 372 histogram_value hist = *(histogram_value *) slot; |
376 if (!pointer_set_contains (visited, hist)) | 373 if (!pointer_set_contains (visited, hist)) |
377 { | 374 { |
378 error ("Dead histogram"); | 375 error ("dead histogram"); |
379 dump_histogram_value (stderr, hist); | 376 dump_histogram_value (stderr, hist); |
380 debug_gimple_stmt (hist->hvalue.stmt); | 377 debug_gimple_stmt (hist->hvalue.stmt); |
381 error_found = true; | 378 error_found = true; |
382 } | 379 } |
383 return 1; | 380 return 1; |
384 } | 381 } |
385 | 382 |
386 | 383 |
387 /* Verify sanity of the histograms. */ | 384 /* Verify sanity of the histograms. */ |
388 | 385 |
389 void | 386 DEBUG_FUNCTION void |
390 verify_histograms (void) | 387 verify_histograms (void) |
391 { | 388 { |
392 basic_block bb; | 389 basic_block bb; |
393 gimple_stmt_iterator gsi; | 390 gimple_stmt_iterator gsi; |
394 histogram_value hist; | 391 histogram_value hist; |
464 locus = (stmt != NULL) | 461 locus = (stmt != NULL) |
465 ? gimple_location (stmt) | 462 ? gimple_location (stmt) |
466 : DECL_SOURCE_LOCATION (current_function_decl); | 463 : DECL_SOURCE_LOCATION (current_function_decl); |
467 if (flag_profile_correction) | 464 if (flag_profile_correction) |
468 { | 465 { |
469 inform (locus, "Correcting inconsistent value profile: " | 466 inform (locus, "correcting inconsistent value profile: " |
470 "%s profiler overall count (%d) does not match BB count " | 467 "%s profiler overall count (%d) does not match BB count " |
471 "(%d)", name, (int)*all, (int)bb_count); | 468 "(%d)", name, (int)*all, (int)bb_count); |
472 *all = bb_count; | 469 *all = bb_count; |
473 if (*count > *all) | 470 if (*count > *all) |
474 *count = *all; | 471 *count = *all; |
475 return false; | 472 return false; |
476 } | 473 } |
477 else | 474 else |
478 { | 475 { |
479 error_at (locus, "Corrupted value profile: %s " | 476 error_at (locus, "corrupted value profile: %s " |
480 "profiler overall count (%d) does not match BB count (%d)", | 477 "profile counter (%d out of %d) inconsistent with " |
481 name, (int)*all, (int)bb_count); | 478 "basic-block count (%d)", |
479 name, | |
480 (int) *count, | |
481 (int) *all, | |
482 (int) bb_count); | |
482 return true; | 483 return true; |
483 } | 484 } |
484 } | 485 } |
485 | 486 |
486 return false; | 487 return false; |
487 } | 488 } |
488 | 489 |
489 | 490 |
490 /* GIMPLE based transformations. */ | 491 /* GIMPLE based transformations. */ |
491 | 492 |
492 static bool | 493 bool |
493 gimple_value_profile_transformations (void) | 494 gimple_value_profile_transformations (void) |
494 { | 495 { |
495 basic_block bb; | 496 basic_block bb; |
496 gimple_stmt_iterator gsi; | 497 gimple_stmt_iterator gsi; |
497 bool changed = false; | 498 bool changed = false; |
556 static tree | 557 static tree |
557 gimple_divmod_fixed_value (gimple stmt, tree value, int prob, gcov_type count, | 558 gimple_divmod_fixed_value (gimple stmt, tree value, int prob, gcov_type count, |
558 gcov_type all) | 559 gcov_type all) |
559 { | 560 { |
560 gimple stmt1, stmt2, stmt3; | 561 gimple stmt1, stmt2, stmt3; |
561 tree tmp1, tmp2, tmpv; | 562 tree tmp0, tmp1, tmp2, tmpv; |
562 gimple bb1end, bb2end, bb3end; | 563 gimple bb1end, bb2end, bb3end; |
563 basic_block bb, bb2, bb3, bb4; | 564 basic_block bb, bb2, bb3, bb4; |
564 tree optype, op1, op2; | 565 tree optype, op1, op2; |
565 edge e12, e13, e23, e24, e34; | 566 edge e12, e13, e23, e24, e34; |
566 gimple_stmt_iterator gsi; | 567 gimple_stmt_iterator gsi; |
574 op2 = gimple_assign_rhs2 (stmt); | 575 op2 = gimple_assign_rhs2 (stmt); |
575 | 576 |
576 bb = gimple_bb (stmt); | 577 bb = gimple_bb (stmt); |
577 gsi = gsi_for_stmt (stmt); | 578 gsi = gsi_for_stmt (stmt); |
578 | 579 |
579 tmpv = create_tmp_var (optype, "PROF"); | 580 tmpv = create_tmp_reg (optype, "PROF"); |
580 tmp1 = create_tmp_var (optype, "PROF"); | 581 tmp0 = make_ssa_name (tmpv, NULL); |
581 stmt1 = gimple_build_assign (tmpv, fold_convert (optype, value)); | 582 tmp1 = make_ssa_name (tmpv, NULL); |
583 stmt1 = gimple_build_assign (tmp0, fold_convert (optype, value)); | |
584 SSA_NAME_DEF_STMT (tmp0) = stmt1; | |
582 stmt2 = gimple_build_assign (tmp1, op2); | 585 stmt2 = gimple_build_assign (tmp1, op2); |
583 stmt3 = gimple_build_cond (NE_EXPR, tmp1, tmpv, NULL_TREE, NULL_TREE); | 586 SSA_NAME_DEF_STMT (tmp1) = stmt2; |
587 stmt3 = gimple_build_cond (NE_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE); | |
584 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); | 588 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); |
585 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); | 589 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); |
586 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT); | 590 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT); |
587 bb1end = stmt3; | 591 bb1end = stmt3; |
588 | 592 |
589 tmp2 = create_tmp_var (optype, "PROF"); | 593 tmp2 = make_rename_temp (optype, "PROF"); |
590 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), tmp2, | 594 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), tmp2, |
591 op1, tmpv); | 595 op1, tmp0); |
592 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); | 596 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); |
593 bb2end = stmt1; | 597 bb2end = stmt1; |
594 | 598 |
595 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), tmp2, | 599 stmt1 = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), tmp2, |
596 op1, op2); | 600 op1, op2); |
697 fprintf (dump_file, " transformation on insn "); | 701 fprintf (dump_file, " transformation on insn "); |
698 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); | 702 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); |
699 } | 703 } |
700 | 704 |
701 gimple_assign_set_rhs_from_tree (si, result); | 705 gimple_assign_set_rhs_from_tree (si, result); |
706 update_stmt (gsi_stmt (*si)); | |
702 | 707 |
703 return true; | 708 return true; |
704 } | 709 } |
705 | 710 |
706 /* Generate code for transformation 2 (with parent gimple assign STMT and | 711 /* Generate code for transformation 2 (with parent gimple assign STMT and |
709 the temp; it does not replace or alter the original STMT. */ | 714 the temp; it does not replace or alter the original STMT. */ |
710 static tree | 715 static tree |
711 gimple_mod_pow2 (gimple stmt, int prob, gcov_type count, gcov_type all) | 716 gimple_mod_pow2 (gimple stmt, int prob, gcov_type count, gcov_type all) |
712 { | 717 { |
713 gimple stmt1, stmt2, stmt3, stmt4; | 718 gimple stmt1, stmt2, stmt3, stmt4; |
714 tree tmp2, tmp3; | 719 tree tmp2, tmp3, tmpv; |
715 gimple bb1end, bb2end, bb3end; | 720 gimple bb1end, bb2end, bb3end; |
716 basic_block bb, bb2, bb3, bb4; | 721 basic_block bb, bb2, bb3, bb4; |
717 tree optype, op1, op2; | 722 tree optype, op1, op2; |
718 edge e12, e13, e23, e24, e34; | 723 edge e12, e13, e23, e24, e34; |
719 gimple_stmt_iterator gsi; | 724 gimple_stmt_iterator gsi; |
727 op2 = gimple_assign_rhs2 (stmt); | 732 op2 = gimple_assign_rhs2 (stmt); |
728 | 733 |
729 bb = gimple_bb (stmt); | 734 bb = gimple_bb (stmt); |
730 gsi = gsi_for_stmt (stmt); | 735 gsi = gsi_for_stmt (stmt); |
731 | 736 |
732 result = create_tmp_var (optype, "PROF"); | 737 result = make_rename_temp (optype, "PROF"); |
733 tmp2 = create_tmp_var (optype, "PROF"); | 738 tmpv = create_tmp_var (optype, "PROF"); |
734 tmp3 = create_tmp_var (optype, "PROF"); | 739 tmp2 = make_ssa_name (tmpv, NULL); |
740 tmp3 = make_ssa_name (tmpv, NULL); | |
735 stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, tmp2, op2, | 741 stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, tmp2, op2, |
736 build_int_cst (optype, -1)); | 742 build_int_cst (optype, -1)); |
743 SSA_NAME_DEF_STMT (tmp2) = stmt2; | |
737 stmt3 = gimple_build_assign_with_ops (BIT_AND_EXPR, tmp3, tmp2, op2); | 744 stmt3 = gimple_build_assign_with_ops (BIT_AND_EXPR, tmp3, tmp2, op2); |
745 SSA_NAME_DEF_STMT (tmp3) = stmt3; | |
738 stmt4 = gimple_build_cond (NE_EXPR, tmp3, build_int_cst (optype, 0), | 746 stmt4 = gimple_build_cond (NE_EXPR, tmp3, build_int_cst (optype, 0), |
739 NULL_TREE, NULL_TREE); | 747 NULL_TREE, NULL_TREE); |
740 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); | 748 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); |
741 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT); | 749 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT); |
742 gsi_insert_before (&gsi, stmt4, GSI_SAME_STMT); | 750 gsi_insert_before (&gsi, stmt4, GSI_SAME_STMT); |
843 prob = 0; | 851 prob = 0; |
844 | 852 |
845 result = gimple_mod_pow2 (stmt, prob, count, all); | 853 result = gimple_mod_pow2 (stmt, prob, count, all); |
846 | 854 |
847 gimple_assign_set_rhs_from_tree (si, result); | 855 gimple_assign_set_rhs_from_tree (si, result); |
856 update_stmt (gsi_stmt (*si)); | |
848 | 857 |
849 return true; | 858 return true; |
850 } | 859 } |
851 | 860 |
852 /* Generate code for transformations 3 and 4 (with parent gimple assign STMT, and | 861 /* Generate code for transformations 3 and 4 (with parent gimple assign STMT, and |
879 op2 = gimple_assign_rhs2 (stmt); | 888 op2 = gimple_assign_rhs2 (stmt); |
880 | 889 |
881 bb = gimple_bb (stmt); | 890 bb = gimple_bb (stmt); |
882 gsi = gsi_for_stmt (stmt); | 891 gsi = gsi_for_stmt (stmt); |
883 | 892 |
884 result = create_tmp_var (optype, "PROF"); | 893 result = make_rename_temp (optype, "PROF"); |
885 tmp1 = create_tmp_var (optype, "PROF"); | 894 tmp1 = make_ssa_name (create_tmp_var (optype, "PROF"), NULL); |
886 stmt1 = gimple_build_assign (result, op1); | 895 stmt1 = gimple_build_assign (result, op1); |
887 stmt2 = gimple_build_assign (tmp1, op2); | 896 stmt2 = gimple_build_assign (tmp1, op2); |
897 SSA_NAME_DEF_STMT (tmp1) = stmt2; | |
888 stmt3 = gimple_build_cond (LT_EXPR, result, tmp1, NULL_TREE, NULL_TREE); | 898 stmt3 = gimple_build_cond (LT_EXPR, result, tmp1, NULL_TREE, NULL_TREE); |
889 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); | 899 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); |
890 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); | 900 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); |
891 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT); | 901 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT); |
892 bb1end = stmt3; | 902 bb1end = stmt3; |
1042 /* In practice, "steps" is always 2. This interface reflects this, | 1052 /* In practice, "steps" is always 2. This interface reflects this, |
1043 and will need to be changed if "steps" can change. */ | 1053 and will need to be changed if "steps" can change. */ |
1044 result = gimple_mod_subtract (stmt, prob1, prob2, i, count1, count2, all); | 1054 result = gimple_mod_subtract (stmt, prob1, prob2, i, count1, count2, all); |
1045 | 1055 |
1046 gimple_assign_set_rhs_from_tree (si, result); | 1056 gimple_assign_set_rhs_from_tree (si, result); |
1057 update_stmt (gsi_stmt (*si)); | |
1047 | 1058 |
1048 return true; | 1059 return true; |
1049 } | 1060 } |
1050 | 1061 |
1051 static struct cgraph_node** pid_map = NULL; | 1062 static struct cgraph_node** pid_map = NULL; |
1090 static gimple | 1101 static gimple |
1091 gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call, | 1102 gimple_ic (gimple icall_stmt, struct cgraph_node *direct_call, |
1092 int prob, gcov_type count, gcov_type all) | 1103 int prob, gcov_type count, gcov_type all) |
1093 { | 1104 { |
1094 gimple dcall_stmt, load_stmt, cond_stmt; | 1105 gimple dcall_stmt, load_stmt, cond_stmt; |
1095 tree tmp1, tmpv, tmp; | 1106 tree tmp0, tmp1, tmpv, tmp; |
1096 basic_block cond_bb, dcall_bb, icall_bb, join_bb; | 1107 basic_block cond_bb, dcall_bb, icall_bb, join_bb; |
1097 tree optype = build_pointer_type (void_type_node); | 1108 tree optype = build_pointer_type (void_type_node); |
1098 edge e_cd, e_ci, e_di, e_dj, e_ij; | 1109 edge e_cd, e_ci, e_di, e_dj, e_ij; |
1099 gimple_stmt_iterator gsi; | 1110 gimple_stmt_iterator gsi; |
1100 int lp_nr; | 1111 int lp_nr; |
1101 | 1112 |
1102 cond_bb = gimple_bb (icall_stmt); | 1113 cond_bb = gimple_bb (icall_stmt); |
1103 gsi = gsi_for_stmt (icall_stmt); | 1114 gsi = gsi_for_stmt (icall_stmt); |
1104 | 1115 |
1105 tmpv = create_tmp_var (optype, "PROF"); | 1116 tmpv = create_tmp_reg (optype, "PROF"); |
1106 tmp1 = create_tmp_var (optype, "PROF"); | 1117 tmp0 = make_ssa_name (tmpv, NULL); |
1118 tmp1 = make_ssa_name (tmpv, NULL); | |
1107 tmp = unshare_expr (gimple_call_fn (icall_stmt)); | 1119 tmp = unshare_expr (gimple_call_fn (icall_stmt)); |
1108 load_stmt = gimple_build_assign (tmpv, tmp); | 1120 load_stmt = gimple_build_assign (tmp0, tmp); |
1121 SSA_NAME_DEF_STMT (tmp0) = load_stmt; | |
1109 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT); | 1122 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT); |
1110 | 1123 |
1111 tmp = fold_convert (optype, build_addr (direct_call->decl, | 1124 tmp = fold_convert (optype, build_addr (direct_call->decl, |
1112 current_function_decl)); | 1125 current_function_decl)); |
1113 load_stmt = gimple_build_assign (tmp1, tmp); | 1126 load_stmt = gimple_build_assign (tmp1, tmp); |
1127 SSA_NAME_DEF_STMT (tmp1) = load_stmt; | |
1114 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT); | 1128 gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT); |
1115 | 1129 |
1116 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmpv, NULL_TREE, NULL_TREE); | 1130 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE); |
1117 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT); | 1131 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT); |
1118 | 1132 |
1133 gimple_set_vdef (icall_stmt, NULL_TREE); | |
1134 gimple_set_vuse (icall_stmt, NULL_TREE); | |
1135 update_stmt (icall_stmt); | |
1119 dcall_stmt = gimple_copy (icall_stmt); | 1136 dcall_stmt = gimple_copy (icall_stmt); |
1120 gimple_call_set_fndecl (dcall_stmt, direct_call->decl); | 1137 gimple_call_set_fndecl (dcall_stmt, direct_call->decl); |
1121 gsi_insert_before (&gsi, dcall_stmt, GSI_SAME_STMT); | 1138 gsi_insert_before (&gsi, dcall_stmt, GSI_SAME_STMT); |
1122 | 1139 |
1123 /* Fix CFG. */ | 1140 /* Fix CFG. */ |
1128 | 1145 |
1129 e_di = split_block (dcall_bb, dcall_stmt); | 1146 e_di = split_block (dcall_bb, dcall_stmt); |
1130 icall_bb = e_di->dest; | 1147 icall_bb = e_di->dest; |
1131 icall_bb->count = all - count; | 1148 icall_bb->count = all - count; |
1132 | 1149 |
1133 e_ij = split_block (icall_bb, icall_stmt); | 1150 /* Do not disturb existing EH edges from the indirect call. */ |
1151 if (!stmt_ends_bb_p (icall_stmt)) | |
1152 e_ij = split_block (icall_bb, icall_stmt); | |
1153 else | |
1154 { | |
1155 e_ij = find_fallthru_edge (icall_bb->succs); | |
1156 e_ij->probability = REG_BR_PROB_BASE; | |
1157 e_ij->count = all - count; | |
1158 e_ij = single_pred_edge (split_edge (e_ij)); | |
1159 } | |
1134 join_bb = e_ij->dest; | 1160 join_bb = e_ij->dest; |
1135 join_bb->count = all; | 1161 join_bb->count = all; |
1136 | 1162 |
1137 e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE; | 1163 e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE; |
1138 e_cd->probability = prob; | 1164 e_cd->probability = prob; |
1149 e_dj->count = count; | 1175 e_dj->count = count; |
1150 | 1176 |
1151 e_ij->probability = REG_BR_PROB_BASE; | 1177 e_ij->probability = REG_BR_PROB_BASE; |
1152 e_ij->count = all - count; | 1178 e_ij->count = all - count; |
1153 | 1179 |
1154 /* Fix eh edges */ | 1180 /* Insert PHI node for the call result if necessary. */ |
1181 if (gimple_call_lhs (icall_stmt) | |
1182 && TREE_CODE (gimple_call_lhs (icall_stmt)) == SSA_NAME) | |
1183 { | |
1184 tree result = gimple_call_lhs (icall_stmt); | |
1185 gimple phi = create_phi_node (result, join_bb); | |
1186 SSA_NAME_DEF_STMT (result) = phi; | |
1187 gimple_call_set_lhs (icall_stmt, | |
1188 make_ssa_name (SSA_NAME_VAR (result), icall_stmt)); | |
1189 add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); | |
1190 gimple_call_set_lhs (dcall_stmt, | |
1191 make_ssa_name (SSA_NAME_VAR (result), dcall_stmt)); | |
1192 add_phi_arg (phi, gimple_call_lhs (dcall_stmt), e_dj, UNKNOWN_LOCATION); | |
1193 } | |
1194 | |
1195 /* Build an EH edge for the direct call if necessary. */ | |
1155 lp_nr = lookup_stmt_eh_lp (icall_stmt); | 1196 lp_nr = lookup_stmt_eh_lp (icall_stmt); |
1156 if (lp_nr != 0) | 1197 if (lp_nr != 0 |
1157 { | 1198 && stmt_could_throw_p (dcall_stmt)) |
1158 if (stmt_could_throw_p (dcall_stmt)) | 1199 { |
1200 edge e_eh, e; | |
1201 edge_iterator ei; | |
1202 gimple_stmt_iterator psi; | |
1203 | |
1204 add_stmt_to_eh_lp (dcall_stmt, lp_nr); | |
1205 FOR_EACH_EDGE (e_eh, ei, icall_bb->succs) | |
1206 if (e_eh->flags & EDGE_EH) | |
1207 break; | |
1208 e = make_edge (dcall_bb, e_eh->dest, EDGE_EH); | |
1209 for (psi = gsi_start_phis (e_eh->dest); | |
1210 !gsi_end_p (psi); gsi_next (&psi)) | |
1159 { | 1211 { |
1160 add_stmt_to_eh_lp (dcall_stmt, lp_nr); | 1212 gimple phi = gsi_stmt (psi); |
1161 make_eh_edges (dcall_stmt); | 1213 SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, e), |
1214 PHI_ARG_DEF_FROM_EDGE (phi, e_eh)); | |
1162 } | 1215 } |
1163 | |
1164 gcc_assert (stmt_could_throw_p (icall_stmt)); | |
1165 make_eh_edges (icall_stmt); | |
1166 | |
1167 /* The old EH edges are sill on the join BB, purge them. */ | |
1168 gimple_purge_dead_eh_edges (join_bb); | |
1169 } | 1216 } |
1170 | 1217 |
1171 return dcall_stmt; | 1218 return dcall_stmt; |
1172 } | 1219 } |
1173 | 1220 |
1287 static void | 1334 static void |
1288 gimple_stringop_fixed_value (gimple vcall_stmt, tree icall_size, int prob, | 1335 gimple_stringop_fixed_value (gimple vcall_stmt, tree icall_size, int prob, |
1289 gcov_type count, gcov_type all) | 1336 gcov_type count, gcov_type all) |
1290 { | 1337 { |
1291 gimple tmp_stmt, cond_stmt, icall_stmt; | 1338 gimple tmp_stmt, cond_stmt, icall_stmt; |
1292 tree tmp1, tmpv, vcall_size, optype; | 1339 tree tmp0, tmp1, tmpv, vcall_size, optype; |
1293 basic_block cond_bb, icall_bb, vcall_bb, join_bb; | 1340 basic_block cond_bb, icall_bb, vcall_bb, join_bb; |
1294 edge e_ci, e_cv, e_iv, e_ij, e_vj; | 1341 edge e_ci, e_cv, e_iv, e_ij, e_vj; |
1295 gimple_stmt_iterator gsi; | 1342 gimple_stmt_iterator gsi; |
1296 tree fndecl; | 1343 tree fndecl; |
1297 int size_arg; | 1344 int size_arg; |
1305 | 1352 |
1306 vcall_size = gimple_call_arg (vcall_stmt, size_arg); | 1353 vcall_size = gimple_call_arg (vcall_stmt, size_arg); |
1307 optype = TREE_TYPE (vcall_size); | 1354 optype = TREE_TYPE (vcall_size); |
1308 | 1355 |
1309 tmpv = create_tmp_var (optype, "PROF"); | 1356 tmpv = create_tmp_var (optype, "PROF"); |
1310 tmp1 = create_tmp_var (optype, "PROF"); | 1357 tmp0 = make_ssa_name (tmpv, NULL); |
1311 tmp_stmt = gimple_build_assign (tmpv, fold_convert (optype, icall_size)); | 1358 tmp1 = make_ssa_name (tmpv, NULL); |
1359 tmp_stmt = gimple_build_assign (tmp0, fold_convert (optype, icall_size)); | |
1360 SSA_NAME_DEF_STMT (tmp0) = tmp_stmt; | |
1312 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT); | 1361 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT); |
1313 | 1362 |
1314 tmp_stmt = gimple_build_assign (tmp1, vcall_size); | 1363 tmp_stmt = gimple_build_assign (tmp1, vcall_size); |
1364 SSA_NAME_DEF_STMT (tmp1) = tmp_stmt; | |
1315 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT); | 1365 gsi_insert_before (&gsi, tmp_stmt, GSI_SAME_STMT); |
1316 | 1366 |
1317 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmpv, NULL_TREE, NULL_TREE); | 1367 cond_stmt = gimple_build_cond (EQ_EXPR, tmp1, tmp0, NULL_TREE, NULL_TREE); |
1318 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT); | 1368 gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT); |
1319 | 1369 |
1370 gimple_set_vdef (vcall_stmt, NULL); | |
1371 gimple_set_vuse (vcall_stmt, NULL); | |
1372 update_stmt (vcall_stmt); | |
1320 icall_stmt = gimple_copy (vcall_stmt); | 1373 icall_stmt = gimple_copy (vcall_stmt); |
1321 gimple_call_set_arg (icall_stmt, size_arg, icall_size); | 1374 gimple_call_set_arg (icall_stmt, size_arg, icall_size); |
1322 gsi_insert_before (&gsi, icall_stmt, GSI_SAME_STMT); | 1375 gsi_insert_before (&gsi, icall_stmt, GSI_SAME_STMT); |
1323 | 1376 |
1324 /* Fix CFG. */ | 1377 /* Fix CFG. */ |
1349 e_ij->probability = REG_BR_PROB_BASE; | 1402 e_ij->probability = REG_BR_PROB_BASE; |
1350 e_ij->count = count; | 1403 e_ij->count = count; |
1351 | 1404 |
1352 e_vj->probability = REG_BR_PROB_BASE; | 1405 e_vj->probability = REG_BR_PROB_BASE; |
1353 e_vj->count = all - count; | 1406 e_vj->count = all - count; |
1407 | |
1408 /* Insert PHI node for the call result if necessary. */ | |
1409 if (gimple_call_lhs (vcall_stmt) | |
1410 && TREE_CODE (gimple_call_lhs (vcall_stmt)) == SSA_NAME) | |
1411 { | |
1412 tree result = gimple_call_lhs (vcall_stmt); | |
1413 gimple phi = create_phi_node (result, join_bb); | |
1414 SSA_NAME_DEF_STMT (result) = phi; | |
1415 gimple_call_set_lhs (vcall_stmt, | |
1416 make_ssa_name (SSA_NAME_VAR (result), vcall_stmt)); | |
1417 add_phi_arg (phi, gimple_call_lhs (vcall_stmt), e_vj, UNKNOWN_LOCATION); | |
1418 gimple_call_set_lhs (icall_stmt, | |
1419 make_ssa_name (SSA_NAME_VAR (result), icall_stmt)); | |
1420 add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); | |
1421 } | |
1354 | 1422 |
1355 /* Because these are all string op builtins, they're all nothrow. */ | 1423 /* Because these are all string op builtins, they're all nothrow. */ |
1356 gcc_assert (!stmt_could_throw_p (vcall_stmt)); | 1424 gcc_assert (!stmt_could_throw_p (vcall_stmt)); |
1357 gcc_assert (!stmt_could_throw_p (icall_stmt)); | 1425 gcc_assert (!stmt_could_throw_p (icall_stmt)); |
1358 } | 1426 } |
1492 *expected_align = alignment * BITS_PER_UNIT; | 1560 *expected_align = alignment * BITS_PER_UNIT; |
1493 gimple_remove_histogram_value (cfun, stmt, histogram); | 1561 gimple_remove_histogram_value (cfun, stmt, histogram); |
1494 } | 1562 } |
1495 } | 1563 } |
1496 | 1564 |
1497 struct value_prof_hooks { | |
1498 /* Find list of values for which we want to measure histograms. */ | |
1499 void (*find_values_to_profile) (histogram_values *); | |
1500 | |
1501 /* Identify and exploit properties of values that are hard to analyze | |
1502 statically. See value-prof.c for more detail. */ | |
1503 bool (*value_profile_transformations) (void); | |
1504 }; | |
1505 | 1565 |
1506 /* Find values inside STMT for that we want to measure histograms for | 1566 /* Find values inside STMT for that we want to measure histograms for |
1507 division/modulo optimization. */ | 1567 division/modulo optimization. */ |
1508 static void | 1568 static void |
1509 gimple_divmod_values_to_profile (gimple stmt, histogram_values *values) | 1569 gimple_divmod_values_to_profile (gimple stmt, histogram_values *values) |
1633 gimple_stringops_values_to_profile (stmt, values); | 1693 gimple_stringops_values_to_profile (stmt, values); |
1634 gimple_indirect_call_to_profile (stmt, values); | 1694 gimple_indirect_call_to_profile (stmt, values); |
1635 } | 1695 } |
1636 } | 1696 } |
1637 | 1697 |
1638 static void | 1698 void |
1639 gimple_find_values_to_profile (histogram_values *values) | 1699 gimple_find_values_to_profile (histogram_values *values) |
1640 { | 1700 { |
1641 basic_block bb; | 1701 basic_block bb; |
1642 gimple_stmt_iterator gsi; | 1702 gimple_stmt_iterator gsi; |
1643 unsigned i; | 1703 unsigned i; |
1646 *values = NULL; | 1706 *values = NULL; |
1647 FOR_EACH_BB (bb) | 1707 FOR_EACH_BB (bb) |
1648 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 1708 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
1649 gimple_values_to_profile (gsi_stmt (gsi), values); | 1709 gimple_values_to_profile (gsi_stmt (gsi), values); |
1650 | 1710 |
1651 for (i = 0; VEC_iterate (histogram_value, *values, i, hist); i++) | 1711 FOR_EACH_VEC_ELT (histogram_value, *values, i, hist) |
1652 { | 1712 { |
1653 switch (hist->type) | 1713 switch (hist->type) |
1654 { | 1714 { |
1655 case HIST_TYPE_INTERVAL: | 1715 case HIST_TYPE_INTERVAL: |
1656 hist->n_counters = hist->hdata.intvl.steps + 2; | 1716 hist->n_counters = hist->hdata.intvl.steps + 2; |
1690 dump_histogram_value (dump_file, hist); | 1750 dump_histogram_value (dump_file, hist); |
1691 } | 1751 } |
1692 } | 1752 } |
1693 } | 1753 } |
1694 | 1754 |
1695 static struct value_prof_hooks gimple_value_prof_hooks = { | |
1696 gimple_find_values_to_profile, | |
1697 gimple_value_profile_transformations | |
1698 }; | |
1699 | |
1700 void | |
1701 gimple_register_value_prof_hooks (void) | |
1702 { | |
1703 gcc_assert (current_ir_type () == IR_GIMPLE); | |
1704 value_prof_hooks = &gimple_value_prof_hooks; | |
1705 } | |
1706 | |
1707 /* IR-independent entry points. */ | |
1708 void | |
1709 find_values_to_profile (histogram_values *values) | |
1710 { | |
1711 (value_prof_hooks->find_values_to_profile) (values); | |
1712 } | |
1713 | |
1714 bool | |
1715 value_profile_transformations (void) | |
1716 { | |
1717 return (value_prof_hooks->value_profile_transformations) (); | |
1718 } | |
1719 |