Mercurial > hg > CbC > CbC_gcc
comparison gcc/gcse.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 /* Partial redundancy elimination / Hoisting for RTL. | 1 /* Partial redundancy elimination / Hoisting for RTL. |
2 Copyright (C) 1997-2018 Free Software Foundation, Inc. | 2 Copyright (C) 1997-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 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 |
152 #include "cfgrtl.h" | 152 #include "cfgrtl.h" |
153 #include "cfganal.h" | 153 #include "cfganal.h" |
154 #include "lcm.h" | 154 #include "lcm.h" |
155 #include "cfgcleanup.h" | 155 #include "cfgcleanup.h" |
156 #include "expr.h" | 156 #include "expr.h" |
157 #include "params.h" | |
158 #include "intl.h" | 157 #include "intl.h" |
159 #include "tree-pass.h" | 158 #include "tree-pass.h" |
160 #include "dbgcnt.h" | 159 #include "dbgcnt.h" |
161 #include "gcse.h" | 160 #include "gcse.h" |
162 #include "gcse-common.h" | 161 #include "gcse-common.h" |
162 #include "function-abi.h" | |
163 | 163 |
164 /* We support GCSE via Partial Redundancy Elimination. PRE optimizations | 164 /* We support GCSE via Partial Redundancy Elimination. PRE optimizations |
165 are a superset of those done by classic GCSE. | 165 are a superset of those done by classic GCSE. |
166 | 166 |
167 Two passes of copy/constant propagation are done around PRE or hoisting | 167 Two passes of copy/constant propagation are done around PRE or hoisting |
796 | 796 |
797 gcc_assert (!optimize_function_for_speed_p (cfun) | 797 gcc_assert (!optimize_function_for_speed_p (cfun) |
798 && optimize_function_for_size_p (cfun)); | 798 && optimize_function_for_size_p (cfun)); |
799 cost = set_src_cost (x, mode, 0); | 799 cost = set_src_cost (x, mode, 0); |
800 | 800 |
801 if (cost < COSTS_N_INSNS (GCSE_UNRESTRICTED_COST)) | 801 if (cost < COSTS_N_INSNS (param_gcse_unrestricted_cost)) |
802 { | 802 { |
803 max_distance | 803 max_distance |
804 = ((HOST_WIDE_INT)GCSE_COST_DISTANCE_RATIO * cost) / 10; | 804 = ((HOST_WIDE_INT)param_gcse_cost_distance_ratio * cost) / 10; |
805 if (max_distance == 0) | 805 if (max_distance == 0) |
806 return 0; | 806 return 0; |
807 | 807 |
808 gcc_assert (max_distance > 0); | 808 gcc_assert (max_distance > 0); |
809 } | 809 } |
1047 | 1047 |
1048 /* SETTER must be an INSN of some kind that sets memory. Call | 1048 /* SETTER must be an INSN of some kind that sets memory. Call |
1049 note_stores to examine each hunk of memory that is modified. */ | 1049 note_stores to examine each hunk of memory that is modified. */ |
1050 mci.mem = x; | 1050 mci.mem = x; |
1051 mci.conflict = false; | 1051 mci.conflict = false; |
1052 note_stores (PATTERN (setter), mems_conflict_for_gcse_p, &mci); | 1052 note_stores (setter, mems_conflict_for_gcse_p, &mci); |
1053 if (mci.conflict) | 1053 if (mci.conflict) |
1054 return 1; | 1054 return 1; |
1055 } | 1055 } |
1056 return 0; | 1056 return 0; |
1057 } | 1057 } |
1526 continue; | 1526 continue; |
1527 | 1527 |
1528 if (CALL_P (insn)) | 1528 if (CALL_P (insn)) |
1529 { | 1529 { |
1530 hard_reg_set_iterator hrsi; | 1530 hard_reg_set_iterator hrsi; |
1531 EXECUTE_IF_SET_IN_HARD_REG_SET (regs_invalidated_by_call, | 1531 |
1532 0, regno, hrsi) | 1532 /* We don't track modes of hard registers, so we need |
1533 to be conservative and assume that partial kills | |
1534 are full kills. */ | |
1535 HARD_REG_SET callee_clobbers | |
1536 = insn_callee_abi (insn).full_and_partial_reg_clobbers (); | |
1537 EXECUTE_IF_SET_IN_HARD_REG_SET (callee_clobbers, 0, regno, hrsi) | |
1533 record_last_reg_set_info (insn, regno); | 1538 record_last_reg_set_info (insn, regno); |
1534 | 1539 |
1535 if (! RTL_CONST_OR_PURE_CALL_P (insn)) | 1540 if (! RTL_CONST_OR_PURE_CALL_P (insn) |
1541 || RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)) | |
1536 record_last_mem_set_info (insn); | 1542 record_last_mem_set_info (insn); |
1537 } | 1543 } |
1538 | 1544 |
1539 note_stores (PATTERN (insn), record_last_set_info, insn); | 1545 note_stores (insn, record_last_set_info, insn); |
1540 } | 1546 } |
1541 | 1547 |
1542 /* The next pass builds the hash table. */ | 1548 /* The next pass builds the hash table. */ |
1543 FOR_BB_INSNS (current_bb, insn) | 1549 FOR_BB_INSNS (current_bb, insn) |
1544 if (NONDEBUG_INSN_P (insn)) | 1550 if (NONDEBUG_INSN_P (insn)) |
1835 hash table and see if any need too many insertions relative to the | 1841 hash table and see if any need too many insertions relative to the |
1836 number of evaluations that can be removed. If so, mark them in | 1842 number of evaluations that can be removed. If so, mark them in |
1837 PRUNE_EXPRS. */ | 1843 PRUNE_EXPRS. */ |
1838 for (j = 0; j < (unsigned) n_elems; j++) | 1844 for (j = 0; j < (unsigned) n_elems; j++) |
1839 if (deletions[j] | 1845 if (deletions[j] |
1840 && ((unsigned) insertions[j] / deletions[j]) > MAX_GCSE_INSERTION_RATIO) | 1846 && (insertions[j] / deletions[j]) > param_max_gcse_insertion_ratio) |
1841 bitmap_set_bit (prune_exprs, j); | 1847 bitmap_set_bit (prune_exprs, j); |
1842 | 1848 |
1843 /* Now prune PRE_INSERT_MAP and PRE_DELETE_MAP based on PRUNE_EXPRS. */ | 1849 /* Now prune PRE_INSERT_MAP and PRE_DELETE_MAP based on PRUNE_EXPRS. */ |
1844 EXECUTE_IF_SET_IN_BITMAP (prune_exprs, 0, j, sbi) | 1850 EXECUTE_IF_SET_IN_BITMAP (prune_exprs, 0, j, sbi) |
1845 { | 1851 { |
1961 | 1967 |
1962 free (visited); | 1968 free (visited); |
1963 return rval; | 1969 return rval; |
1964 } | 1970 } |
1965 | 1971 |
1966 /* Generate RTL to copy an EXPR to its `reaching_reg' and return it. */ | 1972 /* Generate RTL to copy an EXP to REG and return it. */ |
1967 | 1973 |
1968 static rtx_insn * | 1974 rtx_insn * |
1969 process_insert_insn (struct gcse_expr *expr) | 1975 prepare_copy_insn (rtx reg, rtx exp) |
1970 { | 1976 { |
1971 rtx reg = expr->reaching_reg; | |
1972 /* Copy the expression to make sure we don't have any sharing issues. */ | |
1973 rtx exp = copy_rtx (expr->expr); | |
1974 rtx_insn *pat; | 1977 rtx_insn *pat; |
1975 | 1978 |
1976 start_sequence (); | 1979 start_sequence (); |
1977 | 1980 |
1978 /* If the expression is something that's an operand, like a constant, | 1981 /* If the expression is something that's an operand, like a constant, |
1992 | 1995 |
1993 pat = get_insns (); | 1996 pat = get_insns (); |
1994 end_sequence (); | 1997 end_sequence (); |
1995 | 1998 |
1996 return pat; | 1999 return pat; |
2000 } | |
2001 | |
2002 /* Generate RTL to copy an EXPR to its `reaching_reg' and return it. */ | |
2003 | |
2004 static rtx_insn * | |
2005 process_insert_insn (struct gcse_expr *expr) | |
2006 { | |
2007 rtx reg = expr->reaching_reg; | |
2008 /* Copy the expression to make sure we don't have any sharing issues. */ | |
2009 rtx exp = copy_rtx (expr->expr); | |
2010 | |
2011 return prepare_copy_insn (reg, exp); | |
1997 } | 2012 } |
1998 | 2013 |
1999 /* Add EXPR to the end of basic block BB. | 2014 /* Add EXPR to the end of basic block BB. |
2000 | 2015 |
2001 This is used by both the PRE and code hoisting. */ | 2016 This is used by both the PRE and code hoisting. */ |
2403 if (GET_CODE (pattern) == SET) | 2418 if (GET_CODE (pattern) == SET) |
2404 return pattern; | 2419 return pattern; |
2405 | 2420 |
2406 s.insn = insn; | 2421 s.insn = insn; |
2407 s.nsets = 0; | 2422 s.nsets = 0; |
2408 note_stores (pattern, record_set_data, &s); | 2423 note_pattern_stores (pattern, record_set_data, &s); |
2409 | 2424 |
2410 /* Considered invariant insns have exactly one set. */ | 2425 /* Considered invariant insns have exactly one set. */ |
2411 gcc_assert (s.nsets == 1); | 2426 gcc_assert (s.nsets == 1); |
2412 return s.set; | 2427 return s.set; |
2413 } | 2428 } |
3115 | 3130 |
3116 /* Walk over each basic block looking for potentially hoistable | 3131 /* Walk over each basic block looking for potentially hoistable |
3117 expressions, nothing gets hoisted from the entry block. */ | 3132 expressions, nothing gets hoisted from the entry block. */ |
3118 FOR_EACH_VEC_ELT (dom_tree_walk, dom_tree_walk_index, bb) | 3133 FOR_EACH_VEC_ELT (dom_tree_walk, dom_tree_walk_index, bb) |
3119 { | 3134 { |
3120 domby = get_dominated_to_depth (CDI_DOMINATORS, bb, MAX_HOIST_DEPTH); | 3135 domby = get_dominated_to_depth (CDI_DOMINATORS, bb, |
3136 param_max_hoist_depth); | |
3121 | 3137 |
3122 if (domby.length () == 0) | 3138 if (domby.length () == 0) |
3123 continue; | 3139 continue; |
3124 | 3140 |
3125 /* Examine each expression that is very busy at the exit of this | 3141 /* Examine each expression that is very busy at the exit of this |
3964 optimization about to be performed. */ | 3980 optimization about to be performed. */ |
3965 | 3981 |
3966 bool | 3982 bool |
3967 gcse_or_cprop_is_too_expensive (const char *pass) | 3983 gcse_or_cprop_is_too_expensive (const char *pass) |
3968 { | 3984 { |
3969 unsigned int memory_request = (n_basic_blocks_for_fn (cfun) | 3985 int memory_request = (n_basic_blocks_for_fn (cfun) |
3970 * SBITMAP_SET_SIZE (max_reg_num ()) | 3986 * SBITMAP_SET_SIZE (max_reg_num ()) |
3971 * sizeof (SBITMAP_ELT_TYPE)); | 3987 * sizeof (SBITMAP_ELT_TYPE)); |
3972 | 3988 |
3973 /* Trying to perform global optimizations on flow graphs which have | 3989 /* Trying to perform global optimizations on flow graphs which have |
3974 a high connectivity will take a long time and is unlikely to be | 3990 a high connectivity will take a long time and is unlikely to be |
3975 particularly useful. | 3991 particularly useful. |
3976 | 3992 |
3989 return true; | 4005 return true; |
3990 } | 4006 } |
3991 | 4007 |
3992 /* If allocating memory for the dataflow bitmaps would take up too much | 4008 /* If allocating memory for the dataflow bitmaps would take up too much |
3993 storage it's better just to disable the optimization. */ | 4009 storage it's better just to disable the optimization. */ |
3994 if (memory_request > MAX_GCSE_MEMORY) | 4010 if (memory_request > param_max_gcse_memory) |
3995 { | 4011 { |
3996 warning (OPT_Wdisabled_optimization, | 4012 warning (OPT_Wdisabled_optimization, |
3997 "%s: %d basic blocks and %d registers; increase --param max-gcse-memory above %d", | 4013 "%s: %d basic blocks and %d registers; " |
4014 "increase %<--param max-gcse-memory%> above %d", | |
3998 pass, n_basic_blocks_for_fn (cfun), max_reg_num (), | 4015 pass, n_basic_blocks_for_fn (cfun), max_reg_num (), |
3999 memory_request); | 4016 memory_request); |
4000 | 4017 |
4001 return true; | 4018 return true; |
4002 } | 4019 } |