From 321b7c23c7ca128297f3346c867d0adb8f8852c0 Mon Sep 17 00:00:00 2001 From: amker Date: Tue, 5 Dec 2017 15:42:58 +0000 Subject: [PATCH] * tree-ssa-dce.c (simple_dce_from_worklist): Move and rename from tree-ssa-pre.c::remove_dead_inserted_code. * tree-ssa-dce.h: New file. * tree-ssa-pre.c (tree-ssa-dce.h): Include new header file. (remove_dead_inserted_code): Move and rename to function tree-ssa-dce.c::simple_dce_from_worklist. (pass_pre::execute): Update use. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255426 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 10 +++++++++ gcc/tree-ssa-dce.c | 52 +++++++++++++++++++++++++++++++++++++++++++ gcc/tree-ssa-dce.h | 22 ++++++++++++++++++ gcc/tree-ssa-pre.c | 65 +++++------------------------------------------------- 4 files changed, 90 insertions(+), 59 deletions(-) create mode 100644 gcc/tree-ssa-dce.h diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cfda6b3c691..4d58c0f9aec 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2017-12-05 Bin Cheng + + * tree-ssa-dce.c (simple_dce_from_worklist): Move and rename from + tree-ssa-pre.c::remove_dead_inserted_code. + * tree-ssa-dce.h: New file. + * tree-ssa-pre.c (tree-ssa-dce.h): Include new header file. + (remove_dead_inserted_code): Move and rename to function + tree-ssa-dce.c::simple_dce_from_worklist. + (pass_pre::execute): Update use. + 2017-12-05 Richard Biener PR tree-optimization/83277 diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index a5f0edf7893..8595decc702 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -1723,3 +1723,55 @@ make_pass_cd_dce (gcc::context *ctxt) { 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); + } + } +} diff --git a/gcc/tree-ssa-dce.h b/gcc/tree-ssa-dce.h new file mode 100644 index 00000000000..2adb0860ab0 --- /dev/null +++ b/gcc/tree-ssa-dce.h @@ -0,0 +1,22 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3, or (at your option) any +later version. + +GCC is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef TREE_SSA_DCE_H +#define TREE_SSA_DCE_H +extern void simple_dce_from_worklist (bitmap); +#endif diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index a9dcd5edd50..999b881becd 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see #include "dbgcnt.h" #include "domwalk.h" #include "tree-ssa-propagate.h" +#include "tree-ssa-dce.h" #include "tree-cfgcleanup.h" #include "alias.h" @@ -3995,64 +3996,6 @@ compute_avail (void) free (worklist); } -/* Cheap DCE of a known set of possibly dead stmts. - - Because we don't follow exactly the standard PRE algorithm, and decide not - to insert PHI nodes sometimes, and because value numbering of casts isn't - perfect, we sometimes end up inserting dead code. This simple DCE-like - pass removes any insertions we made that weren't actually used. */ - -static void -remove_dead_inserted_code (void) -{ - /* ??? Re-use inserted_exprs as worklist not only as initial set. - This may end up removing non-inserted code as well. If we - keep inserted_exprs unchanged we could restrict new worklist - elements to members of inserted_exprs. */ - bitmap worklist = inserted_exprs; - 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 unnecessary insertion:"); - 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); - } - } -} - /* Initialize data structures used by PRE. */ @@ -4188,7 +4131,11 @@ pass_pre::execute (function *fun) /* Remove all the redundant expressions. */ todo |= vn_eliminate (inserted_exprs); - remove_dead_inserted_code (); + /* Because we don't follow exactly the standard PRE algorithm, and decide not + to insert PHI nodes sometimes, and because value numbering of casts isn't + perfect, we sometimes end up inserting dead code. This simple DCE-like + pass removes any insertions we made that weren't actually used. */ + simple_dce_from_worklist (inserted_exprs); fini_pre (); -- 2.11.4.GIT