This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tuples][patch] Remove gimple_seq_has_side_effects, fix gimplifier to correctly wrap the function body into try/finally block, if required


Hi all,

This patch fixes the gimplifier and also removes gimple_seq_has_side_effects.
The first fix is because we were not wrapping the function body
properly within a try block(seen with -finstrument-functions).
The second fix is needed to make the remove_useless_stmts recognise
that if a try consists of a non-empty bind block, it should not wipe
out this block.
Submitting as one patch since both fixes change the behaviour of the
same set of tests. In particular, the gimplifier fix gets rid of an
ICE, while the other one make it passes the execution tests.

Tested on linix-i686, no new regressions.
OK to commit?

2008-03-17  Diego Novillo  <dnovillo@google.com>
            Oleg Ryjkov  <olegr@google.com>

        * gimplify.c (gimplify_body): Copy the block information from
        the tree function body to gimple function body.
        (gimplify_function_tree): Correctly wrap the function body
        into the try/finally block if creating one.
        * gimple.c (gimple_seq_has_side_effects): Removed.
        * gimple.h (gimple_seq_has_side_effects): Removed declaration.
        * tree-cfg.c (remove_useless_stmts_tf, remove_useless_stmts_tc):
        Modified to use gimple_seq_empty_p instead of
        gimple_seq_has_side_effects.
Index: ChangeLog.tuples
===================================================================
--- ChangeLog.tuples	(revision 133298)
+++ ChangeLog.tuples	(working copy)
@@ -1,3 +1,16 @@
+2008-03-17  Diego Novillo  <dnovillo@google.com>
+	    Oleg Ryjkov  <olegr@google.com>
+
+	* gimplify.c (gimplify_body): Copy the block information from
+	the tree function body to gimple function body.
+	(gimplify_function_tree): Correctly wrap the function body
+	into the try/finally block if creating one.
+	* gimple.c (gimple_seq_has_side_effects): Removed.
+	* gimple.h (gimple_seq_has_side_effects): Removed declaration.
+	* tree-cfg.c (remove_useless_stmts_tf, remove_useless_stmts_tc):
+	Modified to use gimple_seq_empty_p instead of
+	gimple_seq_has_side_effects.
+
 2008-03-17  Zdenek Dvorak  <ook@ucw.cz>
 
 	* gimple-iterator.c (gsi_for_stmt): Use gsi_start_phis.
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 133298)
+++ gimplify.c	(working copy)
@@ -6784,6 +6784,9 @@ gimplify_body (tree *body_p, tree fndecl
   else
     outer_bind = gimple_build_bind (NULL_TREE, seq);
 
+  /* Copy the containing block, if body_p had one.  */
+  if (TREE_CODE (*body_p) == BIND_EXPR)
+    gimple_set_block (outer_bind, BIND_EXPR_BLOCK (*body_p));
   *body_p = NULL_TREE;
 
   /* If we had callee-copies statements, insert them at the beginning
@@ -6847,7 +6850,12 @@ gimplify_function_tree (tree fndecl)
     DECL_GIMPLE_REG_P (ret) = 1;
 
   bind = gimplify_body (&DECL_SAVED_TREE (fndecl), fndecl, true);
-  seq = gimple_bind_body (bind);
+
+  /* The tree body of the function is no longer needed, replace it
+     with the new GIMPLE body.  */
+  seq = gimple_seq_alloc ();
+  gimple_seq_add_stmt (&seq, bind);
+  gimple_set_body (fndecl, seq);
 
   /* If we're instrumenting function entry/exit, then prepend the call to
      the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
@@ -6869,13 +6877,14 @@ gimplify_function_tree (tree fndecl)
       gimplify_seq_add_stmt (&body, gimple_build_call (x, 0));
       gimplify_seq_add_stmt (&body, tf);
       bind = gimple_build_bind (NULL, body);
+
+      /* Replace the current function body with the body
+         wrapped in the try/finally TF.  */
+      seq = gimple_seq_alloc ();
+      gimple_seq_add_stmt (&seq, bind);
+      gimple_set_body (fndecl, seq);
     }
 
-  /* The tree body of the function is no longer needed, replace it
-     with the new GIMPLE body.  */
-  seq = gimple_seq_alloc ();
-  gimplify_seq_add_stmt (&seq, bind);
-  gimple_set_body (fndecl, seq);
   DECL_SAVED_TREE (fndecl) = NULL_TREE;
 
   current_function_decl = oldfn;
Index: gimple.c
===================================================================
--- gimple.c	(revision 133298)
+++ gimple.c	(working copy)
@@ -1934,20 +1934,6 @@ gimple_has_side_effects (gimple s)
   return false;
 }
 
-/* Return true if any statement in STMTS has side effects.  */
-
-bool
-gimple_seq_has_side_effects (gimple_seq stmts)
-{
-  gimple_stmt_iterator gsi;
-
-  for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
-    if (gimple_has_side_effects (gsi_stmt (gsi)))
-      return true;
-
-  return false;
-}
-
 /* Return true if statement S can trap.  */
 
 bool
Index: gimple.h
===================================================================
--- gimple.h	(revision 133298)
+++ gimple.h	(working copy)
@@ -572,7 +572,6 @@ void gimple_cond_get_ops_from_tree (tree
 gimple gimple_build_cond_from_tree (tree, tree, tree);
 void gimple_cond_set_condition_from_tree (gimple, tree);
 bool gimple_has_side_effects (gimple);
-bool gimple_seq_has_side_effects (gimple_seq);
 bool gimple_could_trap_p (gimple);
 
 /* FIXME tuples.
Index: tree-cfg.c
===================================================================
--- tree-cfg.c	(revision 133298)
+++ tree-cfg.c	(working copy)
@@ -1642,7 +1642,7 @@ remove_useless_stmts_tf (gimple_stmt_ite
 
   /* If the body is empty, then we can emit the FINALLY block without
      the enclosing TRY_FINALLY_EXPR.  */
-  if (!gimple_seq_has_side_effects (eval_seq))
+  if (gimple_seq_empty_p (eval_seq))
     {
       gsi_insert_seq_before (gsi, cleanup_seq, GSI_SAME_STMT);
       gsi_remove (gsi, false);
@@ -1651,7 +1651,7 @@ remove_useless_stmts_tf (gimple_stmt_ite
 
   /* If the handler is empty, then we can emit the TRY block without
      the enclosing TRY_FINALLY_EXPR.  */
-  else if (!gimple_seq_has_side_effects (cleanup_seq))
+  else if (gimple_seq_empty_p (cleanup_seq))
     {
       gsi_insert_seq_before (gsi, eval_seq, GSI_SAME_STMT);
       gsi_remove (gsi, false);
@@ -1757,7 +1757,7 @@ remove_useless_stmts_tc (gimple_stmt_ite
 
       /* If the cleanup is empty, then we can emit the TRY block without
 	 the enclosing TRY_CATCH_EXPR.  */
-      if (!gimple_seq_has_side_effects (cleanup_seq))
+      if (gimple_seq_empty_p (cleanup_seq))
 	{
           gsi_insert_seq_before (gsi, eval_seq, GSI_SAME_STMT);
           gsi_remove(gsi, false);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]