Mercurial > hg > CbC > CbC_gcc
comparison gcc/cfgcleanup.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 /* Control flow optimization code for GNU compiler. | 1 /* Control flow optimization code for GNU compiler. |
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1987-2018 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 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 | 7 the terms of the GNU General Public License as published by the Free |
392 { | 392 { |
393 bool changed = false; | 393 bool changed = false; |
394 edge_iterator ei; | 394 edge_iterator ei; |
395 edge e, *threaded_edges = NULL; | 395 edge e, *threaded_edges = NULL; |
396 | 396 |
397 /* If we are partitioning hot/cold basic blocks, we don't want to | |
398 mess up unconditional or indirect jumps that cross between hot | |
399 and cold sections. | |
400 | |
401 Basic block partitioning may result in some jumps that appear to | |
402 be optimizable (or blocks that appear to be mergeable), but which really | |
403 must be left untouched (they are required to make it safely across | |
404 partition boundaries). See the comments at the top of | |
405 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */ | |
406 | |
407 if (JUMP_P (BB_END (b)) && CROSSING_JUMP_P (BB_END (b))) | |
408 return false; | |
409 | |
410 for (ei = ei_start (b->succs); (e = ei_safe_edge (ei)); ) | 397 for (ei = ei_start (b->succs); (e = ei_safe_edge (ei)); ) |
411 { | 398 { |
412 basic_block target, first; | 399 basic_block target, first; |
413 location_t goto_locus; | 400 location_t goto_locus; |
414 int counter; | 401 int counter; |
415 bool threaded = false; | 402 bool threaded = false; |
416 int nthreaded_edges = 0; | 403 int nthreaded_edges = 0; |
417 bool may_thread = first_pass || (b->flags & BB_MODIFIED) != 0; | 404 bool may_thread = first_pass || (b->flags & BB_MODIFIED) != 0; |
405 bool new_target_threaded = false; | |
418 | 406 |
419 /* Skip complex edges because we don't know how to update them. | 407 /* Skip complex edges because we don't know how to update them. |
420 | 408 |
421 Still handle fallthru edges, as we can succeed to forward fallthru | 409 Still handle fallthru edges, as we can succeed to forward fallthru |
422 edge to the same place as the branch edge of conditional branch | 410 edge to the same place as the branch edge of conditional branch |
429 | 417 |
430 target = first = e->dest; | 418 target = first = e->dest; |
431 counter = NUM_FIXED_BLOCKS; | 419 counter = NUM_FIXED_BLOCKS; |
432 goto_locus = e->goto_locus; | 420 goto_locus = e->goto_locus; |
433 | 421 |
434 /* If we are partitioning hot/cold basic_blocks, we don't want to mess | |
435 up jumps that cross between hot/cold sections. | |
436 | |
437 Basic block partitioning may result in some jumps that appear | |
438 to be optimizable (or blocks that appear to be mergeable), but which | |
439 really must be left untouched (they are required to make it safely | |
440 across partition boundaries). See the comments at the top of | |
441 bb-reorder.c:partition_hot_cold_basic_blocks for complete | |
442 details. */ | |
443 | |
444 if (first != EXIT_BLOCK_PTR_FOR_FN (cfun) | |
445 && JUMP_P (BB_END (first)) | |
446 && CROSSING_JUMP_P (BB_END (first))) | |
447 return changed; | |
448 | |
449 while (counter < n_basic_blocks_for_fn (cfun)) | 422 while (counter < n_basic_blocks_for_fn (cfun)) |
450 { | 423 { |
451 basic_block new_target = NULL; | 424 basic_block new_target = NULL; |
452 bool new_target_threaded = false; | |
453 may_thread |= (target->flags & BB_MODIFIED) != 0; | 425 may_thread |= (target->flags & BB_MODIFIED) != 0; |
454 | 426 |
455 if (FORWARDER_BLOCK_P (target) | 427 if (FORWARDER_BLOCK_P (target) |
456 && !(single_succ_edge (target)->flags & EDGE_CROSSING) | |
457 && single_succ (target) != EXIT_BLOCK_PTR_FOR_FN (cfun)) | 428 && single_succ (target) != EXIT_BLOCK_PTR_FOR_FN (cfun)) |
458 { | 429 { |
459 /* Bypass trivial infinite loops. */ | 430 /* Bypass trivial infinite loops. */ |
460 new_target = single_succ (target); | 431 new_target = single_succ (target); |
461 if (target == new_target) | 432 if (target == new_target) |
541 | 512 |
542 if (!new_target) | 513 if (!new_target) |
543 break; | 514 break; |
544 | 515 |
545 counter++; | 516 counter++; |
546 target = new_target; | 517 /* Do not turn non-crossing jump to crossing. Depending on target |
547 threaded |= new_target_threaded; | 518 it may require different instruction pattern. */ |
519 if ((e->flags & EDGE_CROSSING) | |
520 || BB_PARTITION (first) == BB_PARTITION (new_target)) | |
521 { | |
522 target = new_target; | |
523 threaded |= new_target_threaded; | |
524 } | |
548 } | 525 } |
549 | 526 |
550 if (counter >= n_basic_blocks_for_fn (cfun)) | 527 if (counter >= n_basic_blocks_for_fn (cfun)) |
551 { | 528 { |
552 if (dump_file) | 529 if (dump_file) |
557 ; /* We didn't do anything. */ | 534 ; /* We didn't do anything. */ |
558 else | 535 else |
559 { | 536 { |
560 /* Save the values now, as the edge may get removed. */ | 537 /* Save the values now, as the edge may get removed. */ |
561 profile_count edge_count = e->count (); | 538 profile_count edge_count = e->count (); |
562 profile_probability edge_probability = e->probability; | |
563 int edge_frequency; | |
564 int n = 0; | 539 int n = 0; |
565 | 540 |
566 e->goto_locus = goto_locus; | 541 e->goto_locus = goto_locus; |
567 | 542 |
568 /* Don't force if target is exit block. */ | 543 /* Don't force if target is exit block. */ |
583 } | 558 } |
584 | 559 |
585 /* We successfully forwarded the edge. Now update profile | 560 /* We successfully forwarded the edge. Now update profile |
586 data: for each edge we traversed in the chain, remove | 561 data: for each edge we traversed in the chain, remove |
587 the original edge's execution count. */ | 562 the original edge's execution count. */ |
588 edge_frequency = edge_probability.apply (b->frequency); | |
589 | |
590 do | 563 do |
591 { | 564 { |
592 edge t; | 565 edge t; |
593 | 566 |
594 if (!single_succ_p (first)) | 567 if (!single_succ_p (first)) |
595 { | 568 { |
596 gcc_assert (n < nthreaded_edges); | 569 gcc_assert (n < nthreaded_edges); |
597 t = threaded_edges [n++]; | 570 t = threaded_edges [n++]; |
598 gcc_assert (t->src == first); | 571 gcc_assert (t->src == first); |
599 update_bb_profile_for_threading (first, edge_frequency, | 572 update_bb_profile_for_threading (first, edge_count, t); |
600 edge_count, t); | |
601 update_br_prob_note (first); | 573 update_br_prob_note (first); |
602 } | 574 } |
603 else | 575 else |
604 { | 576 { |
605 first->count -= edge_count; | 577 first->count -= edge_count; |
606 first->frequency -= edge_frequency; | |
607 if (first->frequency < 0) | |
608 first->frequency = 0; | |
609 /* It is possible that as the result of | 578 /* It is possible that as the result of |
610 threading we've removed edge as it is | 579 threading we've removed edge as it is |
611 threaded to the fallthru edge. Avoid | 580 threaded to the fallthru edge. Avoid |
612 getting out of sync. */ | 581 getting out of sync. */ |
613 if (n < nthreaded_edges | 582 if (n < nthreaded_edges |
870 MEM_ATTRS (y) = 0; | 839 MEM_ATTRS (y) = 0; |
871 else if (! MEM_ATTRS (y)) | 840 else if (! MEM_ATTRS (y)) |
872 MEM_ATTRS (x) = 0; | 841 MEM_ATTRS (x) = 0; |
873 else | 842 else |
874 { | 843 { |
875 HOST_WIDE_INT mem_size; | |
876 | |
877 if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y)) | 844 if (MEM_ALIAS_SET (x) != MEM_ALIAS_SET (y)) |
878 { | 845 { |
879 set_mem_alias_set (x, 0); | 846 set_mem_alias_set (x, 0); |
880 set_mem_alias_set (y, 0); | 847 set_mem_alias_set (y, 0); |
881 } | 848 } |
887 clear_mem_offset (x); | 854 clear_mem_offset (x); |
888 clear_mem_offset (y); | 855 clear_mem_offset (y); |
889 } | 856 } |
890 else if (MEM_OFFSET_KNOWN_P (x) != MEM_OFFSET_KNOWN_P (y) | 857 else if (MEM_OFFSET_KNOWN_P (x) != MEM_OFFSET_KNOWN_P (y) |
891 || (MEM_OFFSET_KNOWN_P (x) | 858 || (MEM_OFFSET_KNOWN_P (x) |
892 && MEM_OFFSET (x) != MEM_OFFSET (y))) | 859 && maybe_ne (MEM_OFFSET (x), MEM_OFFSET (y)))) |
893 { | 860 { |
894 clear_mem_offset (x); | 861 clear_mem_offset (x); |
895 clear_mem_offset (y); | 862 clear_mem_offset (y); |
896 } | 863 } |
897 | 864 |
898 if (MEM_SIZE_KNOWN_P (x) && MEM_SIZE_KNOWN_P (y)) | 865 if (!MEM_SIZE_KNOWN_P (x)) |
899 { | 866 clear_mem_size (y); |
900 mem_size = MAX (MEM_SIZE (x), MEM_SIZE (y)); | 867 else if (!MEM_SIZE_KNOWN_P (y)) |
901 set_mem_size (x, mem_size); | 868 clear_mem_size (x); |
902 set_mem_size (y, mem_size); | 869 else if (known_le (MEM_SIZE (x), MEM_SIZE (y))) |
903 } | 870 set_mem_size (x, MEM_SIZE (y)); |
871 else if (known_le (MEM_SIZE (y), MEM_SIZE (x))) | |
872 set_mem_size (y, MEM_SIZE (x)); | |
904 else | 873 else |
905 { | 874 { |
875 /* The sizes aren't ordered, so we can't merge them. */ | |
906 clear_mem_size (x); | 876 clear_mem_size (x); |
907 clear_mem_size (y); | 877 clear_mem_size (y); |
908 } | 878 } |
909 | 879 |
910 set_mem_align (x, MIN (MEM_ALIGN (x), MEM_ALIGN (y))); | 880 set_mem_align (x, MIN (MEM_ALIGN (x), MEM_ALIGN (y))); |
1178 return dir_none; | 1148 return dir_none; |
1179 | 1149 |
1180 /* ??? Worse, this adjustment had better be constant lest we | 1150 /* ??? Worse, this adjustment had better be constant lest we |
1181 have differing incoming stack levels. */ | 1151 have differing incoming stack levels. */ |
1182 if (!frame_pointer_needed | 1152 if (!frame_pointer_needed |
1183 && find_args_size_adjust (i1) == HOST_WIDE_INT_MIN) | 1153 && known_eq (find_args_size_adjust (i1), HOST_WIDE_INT_MIN)) |
1184 return dir_none; | 1154 return dir_none; |
1185 } | 1155 } |
1186 else if (p1 || p2) | 1156 else if (p1 || p2) |
1187 return dir_none; | 1157 return dir_none; |
1188 | 1158 |
2107 if (osrc2 == src2) | 2077 if (osrc2 == src2) |
2108 redirect_edges_to = redirect_to; | 2078 redirect_edges_to = redirect_to; |
2109 else | 2079 else |
2110 redirect_edges_to = osrc2; | 2080 redirect_edges_to = osrc2; |
2111 | 2081 |
2112 /* Recompute the frequencies and counts of outgoing edges. */ | 2082 /* Recompute the counts of destinations of outgoing edges. */ |
2113 FOR_EACH_EDGE (s, ei, redirect_edges_to->succs) | 2083 FOR_EACH_EDGE (s, ei, redirect_edges_to->succs) |
2114 { | 2084 { |
2115 edge s2; | 2085 edge s2; |
2116 edge_iterator ei; | 2086 edge_iterator ei; |
2117 basic_block d = s->dest; | 2087 basic_block d = s->dest; |
2130 | 2100 |
2131 /* Take care to update possible forwarder blocks. We verified | 2101 /* Take care to update possible forwarder blocks. We verified |
2132 that there is no more than one in the chain, so we can't run | 2102 that there is no more than one in the chain, so we can't run |
2133 into infinite loop. */ | 2103 into infinite loop. */ |
2134 if (FORWARDER_BLOCK_P (s->dest)) | 2104 if (FORWARDER_BLOCK_P (s->dest)) |
2135 { | 2105 s->dest->count += s->count (); |
2136 s->dest->frequency += EDGE_FREQUENCY (s); | |
2137 } | |
2138 | 2106 |
2139 if (FORWARDER_BLOCK_P (s2->dest)) | 2107 if (FORWARDER_BLOCK_P (s2->dest)) |
2140 { | 2108 s2->dest->count -= s->count (); |
2141 s2->dest->frequency -= EDGE_FREQUENCY (s); | 2109 |
2142 if (s2->dest->frequency < 0) | 2110 s->probability = s->probability.combine_with_count |
2143 s2->dest->frequency = 0; | 2111 (redirect_edges_to->count, |
2144 } | 2112 s2->probability, src1->count); |
2145 | 2113 } |
2146 if (!redirect_edges_to->frequency && !src1->frequency) | 2114 |
2147 s->probability = s->probability.combine_with_freq | 2115 /* Adjust count for the block. An earlier jump |
2148 (redirect_edges_to->frequency, | |
2149 s2->probability, src1->frequency); | |
2150 } | |
2151 | |
2152 /* Adjust count and frequency for the block. An earlier jump | |
2153 threading pass may have left the profile in an inconsistent | 2116 threading pass may have left the profile in an inconsistent |
2154 state (see update_bb_profile_for_threading) so we must be | 2117 state (see update_bb_profile_for_threading) so we must be |
2155 prepared for overflows. */ | 2118 prepared for overflows. */ |
2156 tmp = redirect_to; | 2119 tmp = redirect_to; |
2157 do | 2120 do |
2158 { | 2121 { |
2159 tmp->count += src1->count; | 2122 tmp->count += src1->count; |
2160 tmp->frequency += src1->frequency; | |
2161 if (tmp->frequency > BB_FREQ_MAX) | |
2162 tmp->frequency = BB_FREQ_MAX; | |
2163 if (tmp == redirect_edges_to) | 2123 if (tmp == redirect_edges_to) |
2164 break; | 2124 break; |
2165 tmp = find_fallthru_edge (tmp->succs)->dest; | 2125 tmp = find_fallthru_edge (tmp->succs)->dest; |
2166 } | 2126 } |
2167 while (true); | 2127 while (true); |
2463 || control_flow_insn_p (e0_last_head))) | 2423 || control_flow_insn_p (e0_last_head))) |
2464 { | 2424 { |
2465 max_match--; | 2425 max_match--; |
2466 if (max_match == 0) | 2426 if (max_match == 0) |
2467 return false; | 2427 return false; |
2468 do | 2428 e0_last_head = prev_real_nondebug_insn (e0_last_head); |
2469 e0_last_head = prev_real_insn (e0_last_head); | |
2470 while (DEBUG_INSN_P (e0_last_head)); | |
2471 } | 2429 } |
2472 | 2430 |
2473 if (max_match == 0) | 2431 if (max_match == 0) |
2474 return false; | 2432 return false; |
2475 | 2433 |
3025 by cold blocks. This will cause the verification below to fail, | 2983 by cold blocks. This will cause the verification below to fail, |
3026 and lead to now cold code in the hot section. This is not easy | 2984 and lead to now cold code in the hot section. This is not easy |
3027 to detect and fix during edge forwarding, and in some cases | 2985 to detect and fix during edge forwarding, and in some cases |
3028 is only visible after newly unreachable blocks are deleted, | 2986 is only visible after newly unreachable blocks are deleted, |
3029 which will be done in fixup_partitions. */ | 2987 which will be done in fixup_partitions. */ |
3030 fixup_partitions (); | 2988 if ((mode & CLEANUP_NO_PARTITIONING) == 0) |
3031 checking_verify_flow_info (); | 2989 { |
2990 fixup_partitions (); | |
2991 checking_verify_flow_info (); | |
2992 } | |
3032 } | 2993 } |
3033 | 2994 |
3034 changed_overall |= changed; | 2995 changed_overall |= changed; |
3035 first_pass = false; | 2996 first_pass = false; |
3036 } | 2997 } |
3051 bool changed = false; | 3012 bool changed = false; |
3052 basic_block b, prev_bb; | 3013 basic_block b, prev_bb; |
3053 | 3014 |
3054 find_unreachable_blocks (); | 3015 find_unreachable_blocks (); |
3055 | 3016 |
3056 /* When we're in GIMPLE mode and there may be debug insns, we should | 3017 /* When we're in GIMPLE mode and there may be debug bind insns, we |
3057 delete blocks in reverse dominator order, so as to get a chance | 3018 should delete blocks in reverse dominator order, so as to get a |
3058 to substitute all released DEFs into debug stmts. If we don't | 3019 chance to substitute all released DEFs into debug bind stmts. If |
3059 have dominators information, walking blocks backward gets us a | 3020 we don't have dominators information, walking blocks backward |
3060 better chance of retaining most debug information than | 3021 gets us a better chance of retaining most debug information than |
3061 otherwise. */ | 3022 otherwise. */ |
3062 if (MAY_HAVE_DEBUG_INSNS && current_ir_type () == IR_GIMPLE | 3023 if (MAY_HAVE_DEBUG_BIND_INSNS && current_ir_type () == IR_GIMPLE |
3063 && dom_info_available_p (CDI_DOMINATORS)) | 3024 && dom_info_available_p (CDI_DOMINATORS)) |
3064 { | 3025 { |
3065 for (b = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb; | 3026 for (b = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb; |
3066 b != ENTRY_BLOCK_PTR_FOR_FN (cfun); b = prev_bb) | 3027 b != ENTRY_BLOCK_PTR_FOR_FN (cfun); b = prev_bb) |
3067 { | 3028 { |