comparison gcc/bb-reorder.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Basic block reordering routines for the GNU compiler. 1 /* Basic block reordering routines for the GNU compiler.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc. 2 Copyright (C) 2000-2020 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 6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by 7 under the terms of the GNU General Public License as published by
103 #include "optabs.h" 103 #include "optabs.h"
104 #include "regs.h" 104 #include "regs.h"
105 #include "emit-rtl.h" 105 #include "emit-rtl.h"
106 #include "output.h" 106 #include "output.h"
107 #include "expr.h" 107 #include "expr.h"
108 #include "params.h"
109 #include "tree-pass.h" 108 #include "tree-pass.h"
110 #include "cfgrtl.h" 109 #include "cfgrtl.h"
111 #include "cfganal.h" 110 #include "cfganal.h"
112 #include "cfgbuild.h" 111 #include "cfgbuild.h"
113 #include "cfgcleanup.h" 112 #include "cfgcleanup.h"
114 #include "bb-reorder.h" 113 #include "bb-reorder.h"
115 #include "except.h" 114 #include "except.h"
115 #include "alloc-pool.h"
116 #include "fibonacci_heap.h" 116 #include "fibonacci_heap.h"
117 #include "stringpool.h" 117 #include "stringpool.h"
118 #include "attribs.h" 118 #include "attribs.h"
119 #include "common/common-target.h" 119 #include "common/common-target.h"
120 120
1030 /* The edge has higher probability than the temporary best edge. */ 1030 /* The edge has higher probability than the temporary best edge. */
1031 is_better_edge = true; 1031 is_better_edge = true;
1032 else if (e->count () < cur_best_edge->count ()) 1032 else if (e->count () < cur_best_edge->count ())
1033 /* The edge has lower probability than the temporary best edge. */ 1033 /* The edge has lower probability than the temporary best edge. */
1034 is_better_edge = false; 1034 is_better_edge = false;
1035 if (e->probability > cur_best_edge->probability) 1035 else if (e->probability > cur_best_edge->probability)
1036 /* The edge has higher probability than the temporary best edge. */ 1036 /* The edge has higher probability than the temporary best edge. */
1037 is_better_edge = true; 1037 is_better_edge = true;
1038 else if (e->probability < cur_best_edge->probability) 1038 else if (e->probability < cur_best_edge->probability)
1039 /* The edge has lower probability than the temporary best edge. */ 1039 /* The edge has lower probability than the temporary best edge. */
1040 is_better_edge = false; 1040 is_better_edge = false;
1355 when code size is allowed to grow by duplication. */ 1355 when code size is allowed to grow by duplication. */
1356 1356
1357 static bool 1357 static bool
1358 copy_bb_p (const_basic_block bb, int code_may_grow) 1358 copy_bb_p (const_basic_block bb, int code_may_grow)
1359 { 1359 {
1360 int size = 0; 1360 unsigned int size = 0;
1361 int max_size = uncond_jump_length; 1361 unsigned int max_size = uncond_jump_length;
1362 rtx_insn *insn; 1362 rtx_insn *insn;
1363 1363
1364 if (EDGE_COUNT (bb->preds) < 2) 1364 if (EDGE_COUNT (bb->preds) < 2)
1365 return false; 1365 return false;
1366 if (!can_duplicate_block_p (bb)) 1366 if (!can_duplicate_block_p (bb))
1369 /* Avoid duplicating blocks which have many successors (PR/13430). */ 1369 /* Avoid duplicating blocks which have many successors (PR/13430). */
1370 if (EDGE_COUNT (bb->succs) > 8) 1370 if (EDGE_COUNT (bb->succs) > 8)
1371 return false; 1371 return false;
1372 1372
1373 if (code_may_grow && optimize_bb_for_speed_p (bb)) 1373 if (code_may_grow && optimize_bb_for_speed_p (bb))
1374 max_size *= PARAM_VALUE (PARAM_MAX_GROW_COPY_BB_INSNS); 1374 max_size *= param_max_grow_copy_bb_insns;
1375 1375
1376 FOR_BB_INSNS (bb, insn) 1376 FOR_BB_INSNS (bb, insn)
1377 { 1377 {
1378 if (INSN_P (insn)) 1378 if (INSN_P (insn))
1379 size += get_attr_min_length (insn); 1379 {
1380 size += get_attr_min_length (insn);
1381 if (size > max_size)
1382 break;
1383 }
1380 } 1384 }
1381 1385
1382 if (size <= max_size) 1386 if (size <= max_size)
1383 return true; 1387 return true;
1384 1388
1385 if (dump_file) 1389 if (dump_file)
1386 { 1390 {
1387 fprintf (dump_file, 1391 fprintf (dump_file,
1388 "Block %d can't be copied because its size = %d.\n", 1392 "Block %d can't be copied because its size = %u.\n",
1389 bb->index, size); 1393 bb->index, size);
1390 } 1394 }
1391 1395
1392 return false; 1396 return false;
1393 } 1397 }
1395 /* Return the length of unconditional jump instruction. */ 1399 /* Return the length of unconditional jump instruction. */
1396 1400
1397 int 1401 int
1398 get_uncond_jump_length (void) 1402 get_uncond_jump_length (void)
1399 { 1403 {
1400 int length; 1404 unsigned int length;
1401 1405
1402 start_sequence (); 1406 start_sequence ();
1403 rtx_code_label *label = emit_label (gen_label_rtx ()); 1407 rtx_code_label *label = emit_label (gen_label_rtx ());
1404 rtx_insn *jump = emit_jump_insn (targetm.gen_jump (label)); 1408 rtx_insn *jump = emit_jump_insn (targetm.gen_jump (label));
1405 length = get_attr_min_length (jump); 1409 length = get_attr_min_length (jump);
1406 end_sequence (); 1410 end_sequence ();
1407 1411
1412 gcc_assert (length < INT_MAX);
1408 return length; 1413 return length;
1409 } 1414 }
1410 1415
1411 /* Create a forwarder block to OLD_BB starting with NEW_LABEL and in the 1416 /* Create a forwarder block to OLD_BB starting with NEW_LABEL and in the
1412 other partition wrt OLD_BB. */ 1417 other partition wrt OLD_BB. */
1661 { 1666 {
1662 bool cold_bb = false; 1667 bool cold_bb = false;
1663 1668
1664 if (probably_never_executed_bb_p (cfun, bb)) 1669 if (probably_never_executed_bb_p (cfun, bb))
1665 { 1670 {
1671 cold_bb = true;
1672
1666 /* Handle profile insanities created by upstream optimizations 1673 /* Handle profile insanities created by upstream optimizations
1667 by also checking the incoming edge weights. If there is a non-cold 1674 by also checking the incoming edge weights. If there is a non-cold
1668 incoming edge, conservatively prevent this block from being split 1675 incoming edge, conservatively prevent this block from being split
1669 into the cold section. */ 1676 into the cold section. */
1670 cold_bb = true; 1677 if (!bb->count.precise_p ())
1671 FOR_EACH_EDGE (e, ei, bb->preds) 1678 FOR_EACH_EDGE (e, ei, bb->preds)
1672 if (!probably_never_executed_edge_p (cfun, e)) 1679 if (!probably_never_executed_edge_p (cfun, e))
1673 { 1680 {
1674 cold_bb = false; 1681 cold_bb = false;
1675 break; 1682 break;
1676 } 1683 }
1677 } 1684 }
1678 if (cold_bb) 1685 if (cold_bb)
1679 { 1686 {
1680 BB_SET_PARTITION (bb, BB_COLD_PARTITION); 1687 BB_SET_PARTITION (bb, BB_COLD_PARTITION);
1681 cold_bb_count++; 1688 cold_bb_count++;
2653 FOR_EACH_BB_FN (bb, fun) 2660 FOR_EACH_BB_FN (bb, fun)
2654 if (bb->next_bb != EXIT_BLOCK_PTR_FOR_FN (fun)) 2661 if (bb->next_bb != EXIT_BLOCK_PTR_FOR_FN (fun))
2655 bb->aux = bb->next_bb; 2662 bb->aux = bb->next_bb;
2656 cfg_layout_finalize (); 2663 cfg_layout_finalize ();
2657 2664
2665 FOR_EACH_BB_FN (bb, fun)
2666 df_recompute_luids (bb);
2658 return 0; 2667 return 0;
2659 } 2668 }
2660 2669
2661 } // anon namespace 2670 } // anon namespace
2662 2671
2742 if (uncond_jump_length == 0) 2751 if (uncond_jump_length == 0)
2743 uncond_jump_length = get_uncond_jump_length (); 2752 uncond_jump_length = get_uncond_jump_length ();
2744 2753
2745 /* Never copy a block larger than this. */ 2754 /* Never copy a block larger than this. */
2746 int max_size 2755 int max_size
2747 = uncond_jump_length * PARAM_VALUE (PARAM_MAX_GOTO_DUPLICATION_INSNS); 2756 = uncond_jump_length * param_max_goto_duplication_insns;
2748 2757
2749 bool changed = false; 2758 bool changed = false;
2750 2759
2751 /* Try to duplicate all blocks that end in a computed jump and that 2760 /* Try to duplicate all blocks that end in a computed jump and that
2752 can be duplicated at all. */ 2761 can be duplicated at all. */