Mercurial > hg > CbC > CbC_gcc
diff gcc/tree-ssa-dce.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
line wrap: on
line diff
--- a/gcc/tree-ssa-dce.c Fri Oct 27 22:46:09 2017 +0900 +++ b/gcc/tree-ssa-dce.c Thu Oct 25 07:37:49 2018 +0900 @@ -1,5 +1,5 @@ /* Dead code elimination pass for the GNU compiler. - Copyright (C) 2002-2017 Free Software Foundation, Inc. + Copyright (C) 2002-2018 Free Software Foundation, Inc. Contributed by Ben Elliston <bje@redhat.com> and Andrew MacLeod <amacleod@redhat.com> Adapted to use control dependence by Steven Bosscher, SUSE Labs. @@ -65,7 +65,6 @@ #include "tree-dfa.h" #include "cfgloop.h" #include "tree-scalar-evolution.h" -#include "tree-chkp.h" #include "tree-ssa-propagate.h" #include "gimple-fold.h" @@ -196,7 +195,7 @@ throw. If a statement could throw, it can be deemed necessary. */ if (cfun->can_throw_non_call_exceptions && !cfun->can_delete_dead_exceptions - && stmt_could_throw_p (stmt)) + && stmt_could_throw_p (cfun, stmt)) { mark_stmt_necessary (stmt, true); return; @@ -225,7 +224,7 @@ { tree callee = gimple_call_fndecl (stmt); if (callee != NULL_TREE - && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL) + && fndecl_built_in_p (callee, BUILT_IN_NORMAL)) switch (DECL_FUNCTION_CODE (callee)) { case BUILT_IN_MALLOC: @@ -256,7 +255,8 @@ easily locate the debug temp bind stmt for a use thereof, would could refrain from marking all debug temps here, and mark them only if they're used. */ - if (!gimple_debug_bind_p (stmt) + if (gimple_debug_nonbind_marker_p (stmt) + || !gimple_debug_bind_p (stmt) || gimple_debug_bind_has_value_p (stmt) || TREE_CODE (gimple_debug_bind_get_var (stmt)) != DEBUG_EXPR_DECL) mark_stmt_necessary (stmt, false); @@ -473,10 +473,10 @@ ??? We only need to care about the RHS throwing. For aggregate assignments or similar calls and non-call exceptions the LHS might throw as well. */ - && !stmt_can_throw_internal (def_stmt)) + && !stmt_can_throw_internal (cfun, def_stmt)) { tree base, lhs = gimple_get_lhs (def_stmt); - HOST_WIDE_INT size, offset, max_size; + poly_int64 size, offset, max_size; bool reverse; ao_ref_base (ref); base @@ -487,13 +487,9 @@ { /* For a must-alias check we need to be able to constrain the accesses properly. */ - if (size != -1 && size == max_size - && ref->max_size != -1) - { - if (offset <= ref->offset - && offset + size >= ref->offset + ref->max_size) - return true; - } + if (known_eq (size, max_size) + && known_subrange_p (ref->offset, ref->max_size, offset, size)) + return true; /* Or they need to be exactly the same. */ else if (ref->ref /* Make sure there is no induction variable involved @@ -569,7 +565,7 @@ { tree callee = gimple_call_fndecl (def_stmt); if (callee != NULL_TREE - && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL) + && fndecl_built_in_p (callee, BUILT_IN_NORMAL)) switch (DECL_FUNCTION_CODE (callee)) { case BUILT_IN_MALLOC: @@ -781,21 +777,7 @@ && (DECL_FUNCTION_CODE (def_callee) == BUILT_IN_ALIGNED_ALLOC || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_MALLOC || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_CALLOC)) - { - gimple *bounds_def_stmt; - tree bounds; - - /* For instrumented calls we should also check used - bounds are returned by the same allocation call. */ - if (!gimple_call_with_bounds_p (stmt) - || ((bounds = gimple_call_arg (stmt, 1)) - && TREE_CODE (bounds) == SSA_NAME - && (bounds_def_stmt = SSA_NAME_DEF_STMT (bounds)) - && chkp_gimple_call_builtin_p (bounds_def_stmt, - BUILT_IN_CHKP_BNDRET) - && gimple_call_arg (bounds_def_stmt, 0) == ptr)) - continue; - } + continue; } FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE) @@ -1081,7 +1063,7 @@ /* If this is a store into a variable that is being optimized away, add a debug bind stmt if possible. */ - if (MAY_HAVE_DEBUG_STMTS + if (MAY_HAVE_DEBUG_BIND_STMTS && gimple_assign_single_p (stmt) && is_gimple_val (gimple_assign_rhs1 (stmt))) { @@ -1279,23 +1261,6 @@ && !gimple_plf (def_stmt, STMT_NECESSARY)) gimple_set_plf (stmt, STMT_NECESSARY, false); } - /* We did not propagate necessity for free calls fed - by allocation function to allow unnecessary - alloc-free sequence elimination. For instrumented - calls it also means we did not mark bounds producer - as necessary and it is time to do it in case free - call is not removed. */ - if (gimple_call_with_bounds_p (stmt)) - { - gimple *bounds_def_stmt; - tree bounds = gimple_call_arg (stmt, 1); - gcc_assert (TREE_CODE (bounds) == SSA_NAME); - bounds_def_stmt = SSA_NAME_DEF_STMT (bounds); - if (bounds_def_stmt - && !gimple_plf (bounds_def_stmt, STMT_NECESSARY)) - gimple_set_plf (bounds_def_stmt, STMT_NECESSARY, - gimple_plf (stmt, STMT_NECESSARY)); - } } /* If GSI is not necessary then remove it. */ @@ -1344,9 +1309,7 @@ && DECL_FUNCTION_CODE (call) != BUILT_IN_MALLOC && DECL_FUNCTION_CODE (call) != BUILT_IN_CALLOC && !ALLOCA_FUNCTION_CODE_P - (DECL_FUNCTION_CODE (call)))) - /* Avoid doing so for bndret calls for the same reason. */ - && !chkp_gimple_call_builtin_p (stmt, BUILT_IN_CHKP_BNDRET)) + (DECL_FUNCTION_CODE (call))))) { something_changed = true; if (dump_file && (dump_flags & TDF_DETAILS)) @@ -1442,8 +1405,7 @@ dominate others. Walking backwards, this should be the common case. ??? Do we need to recompute dominators because of cfg_altered? */ - if (!MAY_HAVE_DEBUG_STMTS - || !first_dom_son (CDI_DOMINATORS, bb)) + if (!first_dom_son (CDI_DOMINATORS, bb)) delete_basic_block (bb); else { @@ -1723,3 +1685,55 @@ { return new pass_cd_dce (ctxt); } + + +/* A cheap DCE interface. WORKLIST is a list of possibly dead stmts and + is consumed by this function. The function has linear complexity in + the number of dead stmts with a constant factor like the average SSA + use operands number. */ + +void +simple_dce_from_worklist (bitmap worklist) +{ + while (! bitmap_empty_p (worklist)) + { + /* Pop item. */ + unsigned i = bitmap_first_set_bit (worklist); + bitmap_clear_bit (worklist, i); + + tree def = ssa_name (i); + /* Removed by somebody else or still in use. */ + if (! def || ! has_zero_uses (def)) + continue; + + gimple *t = SSA_NAME_DEF_STMT (def); + if (gimple_has_side_effects (t)) + continue; + + /* Add uses to the worklist. */ + ssa_op_iter iter; + use_operand_p use_p; + FOR_EACH_PHI_OR_STMT_USE (use_p, t, iter, SSA_OP_USE) + { + tree use = USE_FROM_PTR (use_p); + if (TREE_CODE (use) == SSA_NAME + && ! SSA_NAME_IS_DEFAULT_DEF (use)) + bitmap_set_bit (worklist, SSA_NAME_VERSION (use)); + } + + /* Remove stmt. */ + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Removing dead stmt:"); + print_gimple_stmt (dump_file, t, 0); + } + gimple_stmt_iterator gsi = gsi_for_stmt (t); + if (gimple_code (t) == GIMPLE_PHI) + remove_phi_node (&gsi, true); + else + { + gsi_remove (&gsi, true); + release_defs (t); + } + } +}