Advertisement
Guest User

Untitled

a guest
Jun 28th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. diff --git a/gcc/Makefile.in b/gcc/Makefile.in
  2. index 89eda96..81bcfe8 100644
  3. --- a/gcc/Makefile.in
  4. +++ b/gcc/Makefile.in
  5. @@ -1445,6 +1445,7 @@ OBJS = \
  6. tree-ssa-dce.o \
  7. tree-ssa-dom.o \
  8. tree-ssa-dse.o \
  9. + tree-ssa-remove-temps.o \
  10. tree-ssa-forwprop.o \
  11. tree-ssa-ifcombine.o \
  12. tree-ssa-live.o \
  13. diff --git a/gcc/passes.def b/gcc/passes.def
  14. index 9ced655..1e01dbc 100644
  15. --- a/gcc/passes.def
  16. +++ b/gcc/passes.def
  17. @@ -354,6 +354,7 @@ along with GCC; see the file COPYING3. If not see
  18. NEXT_PASS (pass_cleanup_eh);
  19. NEXT_PASS (pass_lower_resx);
  20. NEXT_PASS (pass_nrv);
  21. + NEXT_PASS (pass_remove_temps);
  22. NEXT_PASS (pass_cleanup_cfg_post_optimizing);
  23. NEXT_PASS (pass_warn_function_noreturn);
  24.  
  25. diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
  26. index 4545556..3228ba9 100644
  27. --- a/gcc/tree-pass.h
  28. +++ b/gcc/tree-pass.h
  29. @@ -422,6 +422,7 @@ extern gimple_opt_pass *make_pass_forwprop (gcc::context *ctxt);
  30. extern gimple_opt_pass *make_pass_phiprop (gcc::context *ctxt);
  31. extern gimple_opt_pass *make_pass_tree_ifcombine (gcc::context *ctxt);
  32. extern gimple_opt_pass *make_pass_dse (gcc::context *ctxt);
  33. +extern gimple_opt_pass *make_pass_remove_temps (gcc::context *ctxt);
  34. extern gimple_opt_pass *make_pass_nrv (gcc::context *ctxt);
  35. extern gimple_opt_pass *make_pass_rename_ssa_copies (gcc::context *ctxt);
  36. extern gimple_opt_pass *make_pass_sink_code (gcc::context *ctxt);
  37. diff --git a/gcc/tree-ssa-remove-temps.c b/gcc/tree-ssa-remove-temps.c
  38. new file mode 100644
  39. index 0000000..23bc40f
  40. --- /dev/null
  41. +++ b/gcc/tree-ssa-remove-temps.c
  42. @@ -0,0 +1,173 @@
  43. +/*
  44. + Copyright (C) 2004-2015 Free Software Foundation, Inc.
  45. +
  46. +This file is part of GCC.
  47. +
  48. +GCC is free software; you can redistribute it and/or modify
  49. +it under the terms of the GNU General Public License as published by
  50. +the Free Software Foundation; either version 3, or (at your option)
  51. +any later version.
  52. +
  53. +GCC is distributed in the hope that it will be useful,
  54. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  55. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  56. +GNU General Public License for more details.
  57. +
  58. +You should have received a copy of the GNU General Public License
  59. +along with GCC; see the file COPYING3. If not see
  60. +<http://www.gnu.org/licenses/>. */
  61. +
  62. +#include "config.h"
  63. +#include "system.h"
  64. +#include "coretypes.h"
  65. +#include "tm.h"
  66. +#include "alias.h"
  67. +#include "symtab.h"
  68. +#include "tree.h"
  69. +#include "fold-const.h"
  70. +#include "stor-layout.h"
  71. +#include "tm_p.h"
  72. +#include "predict.h"
  73. +#include "hard-reg-set.h"
  74. +#include "function.h"
  75. +#include "dominance.h"
  76. +#include "cfg.h"
  77. +#include "basic-block.h"
  78. +#include "gimple-pretty-print.h"
  79. +#include "tree-ssa-alias.h"
  80. +#include "internal-fn.h"
  81. +#include "gimple-fold.h"
  82. +#include "tree-eh.h"
  83. +#include "gimple-expr.h"
  84. +#include "gimple.h"
  85. +#include "gimplify.h"
  86. +#include "gimple-iterator.h"
  87. +#include "gimplify-me.h"
  88. +#include "gimple-ssa.h"
  89. +#include "tree-cfg.h"
  90. +#include "tree-phinodes.h"
  91. +#include "ssa-iterators.h"
  92. +#include "stringpool.h"
  93. +#include "tree-ssanames.h"
  94. +#include "rtl.h"
  95. +#include "flags.h"
  96. +#include "insn-config.h"
  97. +#include "expmed.h"
  98. +#include "dojump.h"
  99. +#include "explow.h"
  100. +#include "calls.h"
  101. +#include "emit-rtl.h"
  102. +#include "varasm.h"
  103. +#include "stmt.h"
  104. +#include "expr.h"
  105. +#include "tree-dfa.h"
  106. +#include "tree-pass.h"
  107. +#include "langhooks.h"
  108. +#include "diagnostic.h"
  109. +#include "cfgloop.h"
  110. +#include "insn-codes.h"
  111. +#include "optabs.h"
  112. +#include "tree-ssa-propagate.h"
  113. +#include "tree-ssa-dom.h"
  114. +#include "builtins.h"
  115. +#include "tree-cfgcleanup.h"
  116. +#include "tree-into-ssa.h"
  117. +#include "cfganal.h"
  118. +
  119. +namespace {
  120. +
  121. +const pass_data pass_data_remove_temps =
  122. +{
  123. + GIMPLE_PASS, /* type */
  124. + "remove-temps", /* name */
  125. + OPTGROUP_NONE, /* optinfo_flags */
  126. + TV_NONE, /* tv_id */
  127. + ( PROP_cfg | PROP_ssa ), /* properties_required */
  128. + 0, /* properties_provided */
  129. + 0, /* properties_destroyed */
  130. + 0, /* todo_flags_start */
  131. + TODO_update_ssa, /* todo_flags_finish */
  132. +};
  133. +
  134. +class pass_remove_temps: public gimple_opt_pass
  135. +{
  136. +public:
  137. + pass_remove_temps (gcc::context *ctxt)
  138. + : gimple_opt_pass (pass_data_remove_temps, ctxt)
  139. + {}
  140. +
  141. + /* opt_pass methods: */
  142. + opt_pass * clone () { return new pass_remove_temps (m_ctxt); }
  143. + virtual bool gate (function *) { return 1; }
  144. + virtual unsigned int execute (function *);
  145. +
  146. +}; // class pass_remove_temps
  147. +
  148. +unsigned int
  149. +pass_remove_temps::execute (function *fun)
  150. +{
  151. + int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (fun));
  152. + int postorder_num = inverted_post_order_compute (postorder);
  153. + int todoflags = 0;
  154. + bool cfg_changed = false;
  155. +
  156. + for (int i = 0; i < postorder_num; ++i)
  157. + {
  158. + gimple_stmt_iterator gsi;
  159. + basic_block bb = BASIC_BLOCK_FOR_FN (fun, postorder[i]);
  160. +
  161. + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
  162. + {
  163. + gimple stmt = gsi_stmt (gsi);
  164. + if (!stmt) /* Is this check required in general or it's safe to assume stmt can never be NULL ? */
  165. + continue;
  166. +
  167. + /* Trasnform
  168. + * if (temp != 0)
  169. + * to
  170. + * temp1 = SSA_NAME_DEF_STMT (temp)
  171. + * if (temp1 != 0)
  172. + */
  173. + if (gimple_code (stmt) == GIMPLE_COND)
  174. + {
  175. + gcond *cond = as_a<gcond *> (stmt);
  176. + tree lhs = gimple_cond_lhs (cond);
  177. + tree rhs = gimple_cond_rhs (cond);
  178. + enum tree_code code = gimple_cond_code (cond);
  179. +
  180. + if (code == NE_EXPR
  181. + && SSA_VAR_P (lhs) && is_gimple_reg (lhs)
  182. + && integer_zerop (rhs))
  183. + {
  184. + tree new_ssa_var = make_ssa_name (TREE_TYPE (lhs));
  185. + gimple def_stmt = SSA_NAME_DEF_STMT (lhs);
  186. +
  187. + /* Is there better way to build gimple_assign from another gimple stmt ? */
  188. + gimple g = gimple_build_assign (new_ssa_var,
  189. + gimple_assign_rhs_code (def_stmt),
  190. + gimple_assign_rhs1 (def_stmt),
  191. + gimple_assign_rhs2 (def_stmt),
  192. + gimple_assign_rhs3 (def_stmt));
  193. +
  194. + gsi_insert_before (&gsi, g, GSI_SAME_STMT);
  195. + gimple_cond_set_lhs ((gcond *) cond, new_ssa_var);
  196. + update_stmt (cond);
  197. + }
  198. + }
  199. + }
  200. + }
  201. +
  202. +
  203. + if (cfg_changed)
  204. + todoflags |= TODO_cleanup_cfg;
  205. +
  206. + return todoflags;
  207. +}
  208. +
  209. +} // anon namespace
  210. +
  211. +gimple_opt_pass *
  212. +make_pass_remove_temps (gcc::context *ctxt)
  213. +{
  214. + return new pass_remove_temps (ctxt);
  215. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement