Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/gcc/Makefile.in b/gcc/Makefile.in
- index 89eda96..81bcfe8 100644
- --- a/gcc/Makefile.in
- +++ b/gcc/Makefile.in
- @@ -1445,6 +1445,7 @@ OBJS = \
- tree-ssa-dce.o \
- tree-ssa-dom.o \
- tree-ssa-dse.o \
- + tree-ssa-remove-temps.o \
- tree-ssa-forwprop.o \
- tree-ssa-ifcombine.o \
- tree-ssa-live.o \
- diff --git a/gcc/passes.def b/gcc/passes.def
- index 9ced655..1e01dbc 100644
- --- a/gcc/passes.def
- +++ b/gcc/passes.def
- @@ -354,6 +354,7 @@ along with GCC; see the file COPYING3. If not see
- NEXT_PASS (pass_cleanup_eh);
- NEXT_PASS (pass_lower_resx);
- NEXT_PASS (pass_nrv);
- + NEXT_PASS (pass_remove_temps);
- NEXT_PASS (pass_cleanup_cfg_post_optimizing);
- NEXT_PASS (pass_warn_function_noreturn);
- diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
- index 4545556..3228ba9 100644
- --- a/gcc/tree-pass.h
- +++ b/gcc/tree-pass.h
- @@ -422,6 +422,7 @@ extern gimple_opt_pass *make_pass_forwprop (gcc::context *ctxt);
- extern gimple_opt_pass *make_pass_phiprop (gcc::context *ctxt);
- extern gimple_opt_pass *make_pass_tree_ifcombine (gcc::context *ctxt);
- extern gimple_opt_pass *make_pass_dse (gcc::context *ctxt);
- +extern gimple_opt_pass *make_pass_remove_temps (gcc::context *ctxt);
- extern gimple_opt_pass *make_pass_nrv (gcc::context *ctxt);
- extern gimple_opt_pass *make_pass_rename_ssa_copies (gcc::context *ctxt);
- extern gimple_opt_pass *make_pass_sink_code (gcc::context *ctxt);
- diff --git a/gcc/tree-ssa-remove-temps.c b/gcc/tree-ssa-remove-temps.c
- new file mode 100644
- index 0000000..23bc40f
- --- /dev/null
- +++ b/gcc/tree-ssa-remove-temps.c
- @@ -0,0 +1,173 @@
- +/*
- + Copyright (C) 2004-2015 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
- +<http://www.gnu.org/licenses/>. */
- +
- +#include "config.h"
- +#include "system.h"
- +#include "coretypes.h"
- +#include "tm.h"
- +#include "alias.h"
- +#include "symtab.h"
- +#include "tree.h"
- +#include "fold-const.h"
- +#include "stor-layout.h"
- +#include "tm_p.h"
- +#include "predict.h"
- +#include "hard-reg-set.h"
- +#include "function.h"
- +#include "dominance.h"
- +#include "cfg.h"
- +#include "basic-block.h"
- +#include "gimple-pretty-print.h"
- +#include "tree-ssa-alias.h"
- +#include "internal-fn.h"
- +#include "gimple-fold.h"
- +#include "tree-eh.h"
- +#include "gimple-expr.h"
- +#include "gimple.h"
- +#include "gimplify.h"
- +#include "gimple-iterator.h"
- +#include "gimplify-me.h"
- +#include "gimple-ssa.h"
- +#include "tree-cfg.h"
- +#include "tree-phinodes.h"
- +#include "ssa-iterators.h"
- +#include "stringpool.h"
- +#include "tree-ssanames.h"
- +#include "rtl.h"
- +#include "flags.h"
- +#include "insn-config.h"
- +#include "expmed.h"
- +#include "dojump.h"
- +#include "explow.h"
- +#include "calls.h"
- +#include "emit-rtl.h"
- +#include "varasm.h"
- +#include "stmt.h"
- +#include "expr.h"
- +#include "tree-dfa.h"
- +#include "tree-pass.h"
- +#include "langhooks.h"
- +#include "diagnostic.h"
- +#include "cfgloop.h"
- +#include "insn-codes.h"
- +#include "optabs.h"
- +#include "tree-ssa-propagate.h"
- +#include "tree-ssa-dom.h"
- +#include "builtins.h"
- +#include "tree-cfgcleanup.h"
- +#include "tree-into-ssa.h"
- +#include "cfganal.h"
- +
- +namespace {
- +
- +const pass_data pass_data_remove_temps =
- +{
- + GIMPLE_PASS, /* type */
- + "remove-temps", /* name */
- + OPTGROUP_NONE, /* optinfo_flags */
- + TV_NONE, /* tv_id */
- + ( PROP_cfg | PROP_ssa ), /* properties_required */
- + 0, /* properties_provided */
- + 0, /* properties_destroyed */
- + 0, /* todo_flags_start */
- + TODO_update_ssa, /* todo_flags_finish */
- +};
- +
- +class pass_remove_temps: public gimple_opt_pass
- +{
- +public:
- + pass_remove_temps (gcc::context *ctxt)
- + : gimple_opt_pass (pass_data_remove_temps, ctxt)
- + {}
- +
- + /* opt_pass methods: */
- + opt_pass * clone () { return new pass_remove_temps (m_ctxt); }
- + virtual bool gate (function *) { return 1; }
- + virtual unsigned int execute (function *);
- +
- +}; // class pass_remove_temps
- +
- +unsigned int
- +pass_remove_temps::execute (function *fun)
- +{
- + int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (fun));
- + int postorder_num = inverted_post_order_compute (postorder);
- + int todoflags = 0;
- + bool cfg_changed = false;
- +
- + for (int i = 0; i < postorder_num; ++i)
- + {
- + gimple_stmt_iterator gsi;
- + basic_block bb = BASIC_BLOCK_FOR_FN (fun, postorder[i]);
- +
- + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- + {
- + gimple stmt = gsi_stmt (gsi);
- + if (!stmt) /* Is this check required in general or it's safe to assume stmt can never be NULL ? */
- + continue;
- +
- + /* Trasnform
- + * if (temp != 0)
- + * to
- + * temp1 = SSA_NAME_DEF_STMT (temp)
- + * if (temp1 != 0)
- + */
- + if (gimple_code (stmt) == GIMPLE_COND)
- + {
- + gcond *cond = as_a<gcond *> (stmt);
- + tree lhs = gimple_cond_lhs (cond);
- + tree rhs = gimple_cond_rhs (cond);
- + enum tree_code code = gimple_cond_code (cond);
- +
- + if (code == NE_EXPR
- + && SSA_VAR_P (lhs) && is_gimple_reg (lhs)
- + && integer_zerop (rhs))
- + {
- + tree new_ssa_var = make_ssa_name (TREE_TYPE (lhs));
- + gimple def_stmt = SSA_NAME_DEF_STMT (lhs);
- +
- + /* Is there better way to build gimple_assign from another gimple stmt ? */
- + gimple g = gimple_build_assign (new_ssa_var,
- + gimple_assign_rhs_code (def_stmt),
- + gimple_assign_rhs1 (def_stmt),
- + gimple_assign_rhs2 (def_stmt),
- + gimple_assign_rhs3 (def_stmt));
- +
- + gsi_insert_before (&gsi, g, GSI_SAME_STMT);
- + gimple_cond_set_lhs ((gcond *) cond, new_ssa_var);
- + update_stmt (cond);
- + }
- + }
- + }
- + }
- +
- +
- + if (cfg_changed)
- + todoflags |= TODO_cleanup_cfg;
- +
- + return todoflags;
- +}
- +
- +} // anon namespace
- +
- +gimple_opt_pass *
- +make_pass_remove_temps (gcc::context *ctxt)
- +{
- + return new pass_remove_temps (ctxt);
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement