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 profilng merge 8 - make cfg build debug info friendly


Hi,
we currently lose track of user specified gotos, since these are removed
early by cfg builder.  As a result we can't output correct gcov line
counts for these statements and they never appear in the output.
This patch makes explicit gotos to be always separate gimple statement
and makes them to be turned into NOP when bilding the CFG.

When optimizing we get rid of them early in the newly added cleanup_cfg
pass, but this is already done after profiling so gcov output with patch
I am about to send soon will be right.

This is also neccesary preparationaly work to get CFG built when not
optimizing.  I am about to send summary of this approach soonish.

2004-05-28  Jan Hubicka  <jh@suse.cz>
	* gimple-low.c (lower_cond_expr): Do not allow user defined GOTO in the
	GIMPLE conditional jump construct.
	(expand_var_p): Remove var_ann.
	* tree-cfg.c (make_edges): Only cleanup tree cfg.
	(make_goto_expr_edges): Preserve line number information using nops.
	(tree_block_ends_with_call_p): Do not crash on empty blocks
	* tree-optimize.c (pass_cleanup_cfg): New definition.
	(init_tree_optimization_passes): Do cleanup_cfg as first optimization pass.
Index: gimple-low.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimple-low.c,v
retrieving revision 2.2
retrieving revision 1.1.4.17.2.7
diff -c -3 -p -r2.2 -r1.1.4.17.2.7
*** gimple-low.c	14 May 2004 02:29:20 -0000	2.2
--- gimple-low.c	17 May 2004 22:19:49 -0000	1.1.4.17.2.7
*************** lower_cond_expr (tree_stmt_iterator *tsi
*** 290,299 ****
    lower_stmt_body (else_branch, data);
  
    then_goto = expr_only (then_branch);
!   then_is_goto = then_goto && simple_goto_p (then_goto);
  
    else_goto = expr_only (else_branch);
!   else_is_goto = else_goto && simple_goto_p (else_goto);
  
    if (!then_is_goto || !else_is_goto)
      {
--- 290,301 ----
    lower_stmt_body (else_branch, data);
  
    then_goto = expr_only (then_branch);
!   then_is_goto = (then_goto && simple_goto_p (then_goto)
! 		  && !EXPR_LOCUS (then_goto));
  
    else_goto = expr_only (else_branch);
!   else_is_goto = (else_goto && simple_goto_p (else_goto)
! 		  && !EXPR_LOCUS (else_goto));
  
    if (!then_is_goto || !else_is_goto)
      {
*************** expand_var_p (tree var)
*** 400,407 ****
    if (TREE_CODE (var) != VAR_DECL)
      return true;
  
-   ann = var_ann (var);
- 
    /* Remove all unused, unaliased temporaries.  Also remove unused, unaliased
       local variables during highly optimizing compilations.  */
    ann = var_ann (var);
--- 402,407 ----
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.2
retrieving revision 1.1.4.267.2.14
diff -c -3 -p -r2.2 -r1.1.4.267.2.14
*** tree-cfg.c	15 May 2004 23:07:51 -0000	2.2
--- tree-cfg.c	17 May 2004 22:19:54 -0000	1.1.4.267.2.14
*************** make_edges (void)
*** 473,480 ****
    /* To speed up statement iterator walks, we first purge dead labels.  */
    cleanup_dead_labels ();
  
!   /* Clean up the graph and warn for unreachable code.  */
!   cleanup_tree_cfg ();
  }
  
  
--- 472,480 ----
    /* To speed up statement iterator walks, we first purge dead labels.  */
    cleanup_dead_labels ();
  
!   /* We can not do complette cleanup here as it would mess up coverage info.
!      */
!   delete_unreachable_blocks ();
  }
  
  
*************** make_switch_expr_edges (basic_block bb)
*** 642,648 ****
  basic_block
  label_to_block (tree dest)
  {
!   return VARRAY_BB (label_to_block_map, LABEL_DECL_UID (dest));
  }
  
  
--- 642,662 ----
  basic_block
  label_to_block (tree dest)
  {
!   int uid = LABEL_DECL_UID (dest);
! 
!   /* We would die hard when faced by undefined label.  Emit label to
!      very first basic block.  This will hopefully make even the dataflow
!      and undefined variable warnings quite right.  */
!   if ((errorcount || sorrycount) && uid < 0)
!     {
!       block_stmt_iterator bsi = bsi_start (ENTRY_BLOCK_PTR->succ->dest);
!       tree stmt;
! 
!       stmt = build1 (LABEL_EXPR, void_type_node, dest);
!       bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
!       uid = LABEL_DECL_UID (dest);
!     }
!   return VARRAY_BB (label_to_block_map, uid);
  }
  
  
*************** make_goto_expr_edges (basic_block bb)
*** 675,680 ****
--- 689,703 ----
        if (simple_goto_p (goto_t))
  	{
  	  make_edge (bb, label_to_block (dest), EDGE_FALLTHRU);
+ 
+ 	  /* Preserve the line number information.  */
+ 	  if (EXPR_LOCUS (goto_t))
+ 	    {
+ 	      tree stmt = build_empty_stmt ();
+ 	      SET_EXPR_LOCUS (stmt, EXPR_LOCUS (goto_t));
+ 	      bsi_insert_before (&last, stmt, BSI_NEW_STMT);
+ 	      bsi_next (&last);
+ 	    }
  	  bsi_remove (&last);
  	  return;
  	}
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.16
retrieving revision 1.1.4.122.2.15
diff -c -3 -p -r2.16 -r1.1.4.122.2.15
*** tree-optimize.c	15 May 2004 23:07:52 -0000	2.16
--- tree-optimize.c	21 May 2004 09:10:06 -0000	1.1.4.122.2.15
*************** static struct tree_opt_pass pass_gimple 
*** 84,89 ****
--- 125,147 ----
    TODO_dump_func			/* todo_flags_finish */
  };
  
+ 
+ static struct tree_opt_pass pass_cleanup_cfg = 
+ {
+   "cleanupcfg",				/* name */
+   NULL,					/* gate */
+   cleanup_tree_cfg,			/* execute */
+   NULL,					/* sub */
+   NULL,					/* next */
+   0,					/* static_pass_number */
+   0,					/* tv_id */
+   0,					/* properties_required */
+   0,					/* properties_provided */
+   0,					/* properties_destroyed */
+   0,					/* todo_flags_start */
+   TODO_dump_func			/* todo_flags_finish */
+ };
+ 
  /* Pass: replace the outermost BIND_EXPR.  We removed all of them while
     optimizing, but the tree->rtl expander requires it.  */
  
*************** init_tree_optimization_passes (void)
*** 275,280 ****
--- 275,281 ----
    *p = NULL;
  
    p = &pass_all_optimizations.sub;
+   NEXT_PASS (pass_cleanup_cfg);
    NEXT_PASS (pass_build_cfg);
    NEXT_PASS (pass_tree_profile);
    NEXT_PASS (pass_referenced_vars);


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