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]

[ast-optimizer-branch]: tree-cfg.c insertion fixes


2002-06-03  Daniel Berlin  <dberlin@dberlin.org>

	* tree-cfg.c (insert_before_*):  For insertion into FOR_INIT's, if
	we have an expression statement, transform into a compound
	expression. 
	Pick the right place to insert a statement by iterating until we
	have a first_exec_stmt (first_non_decl_stmt) that is really the
	first executable non decl statement.
	(insert_after_*): Ditto.

Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.2.16
diff -c -3 -p -w -B -b -r1.1.2.16 tree-cfg.c
*** tree-cfg.c	29 May 2002 15:03:29 -0000	1.1.2.16
--- tree-cfg.c	3 Jun 2002 18:50:52 -0000
*************** insert_before_ctrl_stmt (stmt, where, bb
*** 1881,1886 ****
--- 1881,1897 ----
  	{
  	  if (first_exec_stmt (FOR_INIT_STMT (parent)) == NULL)
  	    FOR_INIT_STMT (parent) = stmt;
+ 	  else if (TREE_CODE (stmt) == EXPR_STMT)
+ 	    {
+ 	      tree init_stmt = FOR_INIT_STMT (parent);
+ 	      tree init_stmt_expr = EXPR_STMT_EXPR (init_stmt);
+ 
+ 	      EXPR_STMT_EXPR (init_stmt) = build (COMPOUND_EXPR, 
+ 						  TREE_TYPE (init_stmt_expr),
+ 						  init_stmt_expr, 
+ 						  EXPR_STMT_EXPR (stmt), 
+ 						  init_stmt_expr);
+ 	    }
  	  else
  	    insert_before_normal_stmt (stmt, where, bb);
  	}
*************** insert_before_ctrl_stmt (stmt, where, bb
*** 1891,1901 ****
  	{
  	  tree last_stmt = last_exec_stmt (FOR_INIT_STMT (parent));
  	  if (last_stmt)
! 	    insert_after_normal_stmt (stmt, last_stmt,
! 				      BB_FOR_STMT (last_stmt));
  	  else
  	    FOR_INIT_STMT (parent) = stmt;
- 
  	  last_stmt = last_exec_stmt (FOR_EXPR (parent));
  	  if (last_stmt)
  	    insert_after_normal_stmt (copy_node (stmt), last_stmt,
--- 1902,1919 ----
  	{
  	  tree last_stmt = last_exec_stmt (FOR_INIT_STMT (parent));
  	  if (last_stmt)
! 	    {
! 	      tree init_stmt = FOR_INIT_STMT (parent); 
!               tree init_stmt_expr = EXPR_STMT_EXPR (init_stmt); 
!  
!               EXPR_STMT_EXPR (init_stmt) = build (COMPOUND_EXPR,  
!                                                   TREE_TYPE (init_stmt_expr), 
!                                                   init_stmt_expr,  
!                                                   EXPR_STMT_EXPR (stmt),  
!                                                   init_stmt_expr); 
! 	  }
  	  else
  	    FOR_INIT_STMT (parent) = stmt;
  	  last_stmt = last_exec_stmt (FOR_EXPR (parent));
  	  if (last_stmt)
  	    insert_after_normal_stmt (copy_node (stmt), last_stmt,
*************** insert_after_ctrl_stmt (stmt, bb)
*** 2076,2087 ****
--- 2094,2109 ----
    if (TREE_CODE (parent) == IF_STMT)
      {
        t = first_exec_stmt (first_non_decl_stmt (THEN_CLAUSE (parent)));
+       while (t && (!is_exec_stmt (t)  || first_non_decl_stmt (t) != t))
+         t = first_exec_stmt (first_non_decl_stmt (t));
        if (t == NULL)
  	THEN_CLAUSE (parent) = stmt;
        else
  	insert_before_normal_stmt (stmt, t, BB_FOR_STMT (t));
  
        t = first_exec_stmt (first_non_decl_stmt (ELSE_CLAUSE (parent)));
+       while (t && (!is_exec_stmt (t)  || first_non_decl_stmt (t) != t))
+         t = first_exec_stmt (first_non_decl_stmt (t));
        if (t == NULL)
  	ELSE_CLAUSE (parent) = copy_node (stmt);
        else
*************** insert_after_ctrl_stmt (stmt, bb)
*** 2106,2111 ****
--- 2128,2135 ----
    else if (TREE_CODE (parent) == WHILE_STMT)
      {
        t = first_exec_stmt (first_non_decl_stmt (WHILE_BODY (parent)));
+       while (t && (!is_exec_stmt (t)  || first_non_decl_stmt (t) != t))
+         t = first_exec_stmt (first_non_decl_stmt (t));
        if (t == NULL)
  	WHILE_BODY (parent) = stmt;
        else
*************** insert_after_ctrl_stmt (stmt, bb)
*** 2118,2123 ****
--- 2142,2149 ----
    else if (TREE_CODE (parent) == DO_STMT)
      {
        t = first_exec_stmt (first_non_decl_stmt (DO_BODY (parent)));
+       while (t && (!is_exec_stmt (t)  || first_non_decl_stmt (t) != t))
+         t = first_exec_stmt (first_non_decl_stmt (t));
        if (t == NULL)
  	DO_BODY (parent) = stmt;
        else
*************** insert_after_ctrl_stmt (stmt, bb)
*** 2134,2139 ****
--- 2160,2176 ----
  	  t = last_exec_stmt (FOR_INIT_STMT (parent));
  	  if (t == NULL)
  	    FOR_INIT_STMT (parent) = stmt;
+ 	  else if (TREE_CODE (stmt) == EXPR_STMT)
+ 	    {
+ 	      tree init_stmt = FOR_INIT_STMT (parent); 
+               tree init_stmt_expr = EXPR_STMT_EXPR (init_stmt); 
+  
+               EXPR_STMT_EXPR (init_stmt) = build (COMPOUND_EXPR,  
+                                                   TREE_TYPE (init_stmt_expr), 
+                                                   init_stmt_expr,  
+                                                   EXPR_STMT_EXPR (stmt),  
+                                                   init_stmt_expr); 
+ 	    }
  	  else
  	    insert_after_normal_stmt (stmt, t, bb);
  	}
*************** insert_after_ctrl_stmt (stmt, bb)
*** 2142,2147 ****
--- 2179,2186 ----
        else if (bb == FOR_COND_BB (parent_bb))
  	{
  	  t = first_exec_stmt (first_non_decl_stmt (FOR_BODY (parent)));
+ 	  while (t && (!is_exec_stmt (t)  || first_non_decl_stmt (t) != t))
+ 	    t = first_exec_stmt (first_non_decl_stmt (t));
  	  if (t == NULL)
  	    FOR_BODY (parent) = stmt;
  	  else


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