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]

[tree-ssa] Useless TRY_CATCH and TRY_FINALLY blocks





[ This bounced Friday...  So I'm reposting it. ]

This patch allows the useless statement remover to optimize away unnecessary
TRY_CATCH and TRY_FINALLY blocks.  When building libstdc++ we're able to
zap ~900 of these things.

I removed the code which tried to remove TRY_CATCH and TRY_FINALLY exprs
during gimplification -- it only triggered when I had some code to simplify
empty BIND_EXPRs during gimplification in my tree.

Bootstrapped and regression tested.

	* c-simplify.c (simplify_cleanup): Remove code which optimizes
	TRY_FINALLY and TRY_CATCH.  It doesn't trigger.

	* tree-cfg.c (remove_useless_stmts_and_vars): Optimize away
	TRY_CATCH and TRY_FINALLY blocks when possible.

Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.54
diff -c -3 -p -r1.1.4.54 c-simplify.c
*** c-simplify.c	9 May 2003 13:53:58 -0000	1.1.4.54
- --- c-simplify.c	9 May 2003 19:16:13 -0000
*************** simplify_cleanup (stmt_p, next_p)
*** 437,458 ****
  
    c_simplify_stmt (&body);
  
!   if (IS_EMPTY_STMT (body))
!     {
!       /* If the body of a TRY_FINALLY is empty, then we can just
! 	 emit the handler without the enclosing TRY_FINALLY. 
! 
! 	 If the body of a TRY_CATCH is empty and the handler has
! 	 no reachable code, then we can emit an empty statement
! 	 without the enclosing TRY_CATCH.  */
!       if (code == TRY_FINALLY_EXPR)
! 	*stmt_p = cleanup;
!       else if (! find_reachable_label (cleanup))
! 	*stmt_p = build_empty_stmt ();
!     }
!   else
!     *stmt_p = build (code, void_type_node, body, cleanup);
! 
    *next_p = NULL_TREE;
  }
  
- --- 437,443 ----
  
    c_simplify_stmt (&body);
  
!   *stmt_p = build (code, void_type_node, body, cleanup);
    *next_p = NULL_TREE;
  }
  
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.86
diff -c -3 -p -r1.1.4.86 tree-cfg.c
*** tree-cfg.c	8 May 2003 20:29:29 -0000	1.1.4.86
- --- tree-cfg.c	9 May 2003 19:16:18 -0000
*************** remove_useless_stmts_and_vars (first_p)
*** 1457,1462 ****
- --- 1457,1480 ----
  	{
  	  repeat |= remove_useless_stmts_and_vars (&TREE_OPERAND (*stmt_p, 0));
  	  repeat |= remove_useless_stmts_and_vars (&TREE_OPERAND (*stmt_p, 1));
+ 
+ 	  /* If the body of a TRY_FINALLY is empty, then we can just
+ 	     emit the handler without the enclosing TRY_FINALLY.
+                                                                              

+ 	     If the body of a TRY_CATCH is empty and the handler is
+ 	     empty (it had no reachable code either), then we can
+ 	     emit an empty statement without the enclosing TRY_CATCH.  */
+ 	  if (IS_EMPTY_STMT (TREE_OPERAND (*stmt_p, 0)))
+ 	    {
+ 	      if (code == TRY_FINALLY_EXPR
+ 		  || IS_EMPTY_STMT (TREE_OPERAND (*stmt_p, 1)))
+ 		*stmt_p = TREE_OPERAND (*stmt_p, 1);
+ 
+ 	      /* If we replaced this statement with an empty statement,
+ 		 then we'll need to repeat this optimization.  */
+ 	      if (IS_EMPTY_STMT (*stmt_p))
+ 		repeat = 1;
+ 	    }
  	}
        else if (code == BIND_EXPR)
  	{




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