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]

Print per tree stmt RTL dumps for cfgexpand


Hi,

This patch has been in my queue for a long time.  It allows cfgexpand
to do per tree statement RTL dumps, so you get to see exactly what RTL
is generated for each statement.  For example:

;; ptr = &vec_->vec[0] + (struct deferred_access *) ((long unsigned int) D.25481 * 16)
(insn 66 65 67 (parallel [
            (set (reg:DI 74)
                (plus:DI (reg/v/f:DI 59 [ vec_ ])
                    (const_int 8 [0x8])))
            (clobber (reg:CC 17 flags))
        ]) -1 (nil)
    (nil))

(insn 67 66 68 (set (reg:DI 75)
        (zero_extend:DI (reg:SI 58 [ D.25481 ]))) -1 (nil)
    (nil))

(insn 68 67 69 (set (reg:DI 76)
        (reg:DI 75)) -1 (nil)
    (nil))

(insn 69 68 70 (parallel [
            (set (reg:DI 77)
                (ashift:DI (reg:DI 76)
                    (const_int 4 [0x4])))
            (clobber (reg:CC 17 flags))
        ]) -1 (nil)
    (expr_list:REG_EQUAL (mult:DI (reg:DI 75)
            (const_int 16 [0x10]))
        (nil)))

(insn 70 69 0 (parallel [
            (set (reg/v/f:DI 62 [ ptr ])
                (plus:DI (reg:DI 74)
                    (reg:DI 77)))
            (clobber (reg:CC 17 flags))
        ]) -1 (nil)
    (nil))

(note the useless copy from reg 75 to reg 76 ;-):


Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK?

Gr.
Steven

	* cfgexpand.c (maybe_dump_rtl_for_tree_stmt): New function.
	(expand_gimple_cond_expr, expand_gimple_tailcall,
	expand_gimple_basic_block): Use it to dump RTL for each stmt.
	(tree_expand_cfg): Announce full RTL function dump.
	* tree-optimize.c (execute_one_pass): Use normal RTL printing,
	not the graph version.
	* tree-pretty-print.c (dump_generic_node): Allow empty statements
	in the arms of a COND_EXPR for lowered nodes.

Index: cfgexpand.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgexpand.c,v
retrieving revision 2.27
diff -c -3 -p -r2.27 cfgexpand.c
*** cfgexpand.c	28 Sep 2004 07:59:42 -0000	2.27
--- cfgexpand.c	7 Oct 2004 15:36:39 -0000
*************** expand_used_vars (void)
*** 833,838 ****
--- 833,855 ----
  }
  
  
+ /* If we need to produce a detailed dump, print the tree representation
+    for STMT to the dump file.  SINCE is the last RTX after which the RTL
+    generated for STMT should have been appended.  */
+ 
+ static void
+ maybe_dump_rtl_for_tree_stmt (tree stmt, rtx since)
+ {
+   if (dump_file && (dump_flags * TDF_DETAILS))
+     {
+       fprintf (dump_file, "\n;; ");
+       print_generic_expr (dump_file, stmt, TDF_SLIM);
+       fprintf (dump_file, "\n");
+ 
+       print_rtl (dump_file, since ? NEXT_INSN (since) : since);
+     }
+ }
+ 
  /* A subroutine of expand_gimple_basic_block.  Expand one COND_EXPR.
     Returns a new basic block if we've terminated the current basic
     block and created a new one.  */
*************** expand_gimple_cond_expr (basic_block bb,
*** 847,853 ****
    tree pred = COND_EXPR_COND (stmt);
    tree then_exp = COND_EXPR_THEN (stmt);
    tree else_exp = COND_EXPR_ELSE (stmt);
!   rtx last = get_last_insn ();
  
    extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
    if (EXPR_LOCUS (stmt))
--- 864,872 ----
    tree pred = COND_EXPR_COND (stmt);
    tree then_exp = COND_EXPR_THEN (stmt);
    tree else_exp = COND_EXPR_ELSE (stmt);
!   rtx last2, last;
! 
!   last2 = last = get_last_insn ();
  
    extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
    if (EXPR_LOCUS (stmt))
*************** expand_gimple_cond_expr (basic_block bb,
*** 866,877 ****
--- 885,898 ----
      {
        jumpif (pred, label_rtx (GOTO_DESTINATION (then_exp)));
        add_reg_br_prob_note (dump_file, last, true_edge->probability);
+       maybe_dump_rtl_for_tree_stmt (stmt, last);
        return NULL;
      }
    if (TREE_CODE (else_exp) == GOTO_EXPR && IS_EMPTY_STMT (then_exp))
      {
        jumpifnot (pred, label_rtx (GOTO_DESTINATION (else_exp)));
        add_reg_br_prob_note (dump_file, last, false_edge->probability);
+       maybe_dump_rtl_for_tree_stmt (stmt, last);
        return NULL;
      }
    gcc_assert (TREE_CODE (then_exp) == GOTO_EXPR
*************** expand_gimple_cond_expr (basic_block bb,
*** 900,910 ****
      BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
    update_bb_for_insn (new_bb);
  
!   if (dump_file)
!     {
!       dump_bb (bb, dump_file, 0);
!       dump_bb (new_bb, dump_file, 0);
!     }
  
    return new_bb;
  }
--- 921,927 ----
      BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
    update_bb_for_insn (new_bb);
  
!   maybe_dump_rtl_for_tree_stmt (stmt, last2);
  
    return new_bb;
  }
*************** expand_gimple_cond_expr (basic_block bb,
*** 922,939 ****
  static basic_block
  expand_gimple_tailcall (basic_block bb, tree stmt, bool *can_fallthru)
  {
!   rtx last = get_last_insn ();
    edge e;
    edge_iterator ei;
    int probability;
    gcov_type count;
  
    expand_expr_stmt (stmt);
  
    for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
      if (CALL_P (last) && SIBLING_CALL_P (last))
        goto found;
  
    *can_fallthru = true;
    return NULL;
  
--- 939,960 ----
  static basic_block
  expand_gimple_tailcall (basic_block bb, tree stmt, bool *can_fallthru)
  {
!   rtx last2, last;
    edge e;
    edge_iterator ei;
    int probability;
    gcov_type count;
  
+   last2 = last = get_last_insn ();
+ 
    expand_expr_stmt (stmt);
  
    for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
      if (CALL_P (last) && SIBLING_CALL_P (last))
        goto found;
  
+   maybe_dump_rtl_for_tree_stmt (stmt, last);
+ 
    *can_fallthru = true;
    return NULL;
  
*************** expand_gimple_tailcall (basic_block bb, 
*** 1007,1012 ****
--- 1028,1035 ----
  	BB_END (bb) = PREV_INSN (last);
      }
  
+   maybe_dump_rtl_for_tree_stmt (stmt, last2);
+ 
    return bb;
  }
  
*************** expand_gimple_basic_block (basic_block b
*** 1023,1031 ****
  
    if (dump_file)
      {
!       tree_register_cfg_hooks ();
!       dump_bb (bb, dump_file, 0);
!       rtl_register_cfg_hooks ();
      }
  
    if (!bsi_end_p (bsi))
--- 1046,1054 ----
  
    if (dump_file)
      {
!       fprintf (dump_file,
! 	       "\n;; Generating RTL for tree basic block %d\n",
! 	       bb->index);
      }
  
    if (!bsi_end_p (bsi))
*************** expand_gimple_basic_block (basic_block b
*** 1044,1049 ****
--- 1067,1074 ----
  	BB_HEAD (bb) = NEXT_INSN (BB_HEAD (bb));
        bsi_next (&bsi);
        note = emit_note_after (NOTE_INSN_BASIC_BLOCK, BB_HEAD (bb));
+ 
+       maybe_dump_rtl_for_tree_stmt (stmt, last);
      }
    else
      note = BB_HEAD (bb) = emit_note (NOTE_INSN_BASIC_BLOCK);
*************** expand_gimple_basic_block (basic_block b
*** 1096,1102 ****
  		}
  	    }
  	  else
! 	    expand_expr_stmt (stmt);
  	}
      }
  
--- 1121,1131 ----
  		}
  	    }
  	  else
! 	    {
! 	      last = get_last_insn ();
! 	      expand_expr_stmt (stmt);
! 	      maybe_dump_rtl_for_tree_stmt (stmt, last);
! 	    }
  	}
      }
  
*************** expand_gimple_basic_block (basic_block b
*** 1111,1118 ****
      last = PREV_INSN (PREV_INSN (last));
    BB_END (bb) = last;
  
-   if (dump_file)
-     dump_bb (bb, dump_file, 0);
    update_bb_for_insn (bb);
  
    return bb;
--- 1140,1145 ----
*************** tree_expand_cfg (void)
*** 1303,1308 ****
--- 1330,1342 ----
    generating_concat_p = 0;
  
    finalize_block_changes ();
+ 
+   if (dump_file)
+     {
+       fprintf (dump_file,
+ 	       "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
+       /* And the pass manager will dump RTL for us.  */
+     }
  }
  
  struct tree_opt_pass pass_expand =
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.55
diff -c -3 -p -r2.55 tree-optimize.c
*** tree-optimize.c	1 Oct 2004 15:11:10 -0000	2.55
--- tree-optimize.c	7 Oct 2004 15:36:39 -0000
*************** execute_one_pass (struct tree_opt_pass *
*** 505,511 ****
    if (dump_file
        && (pass->properties_provided & (PROP_cfg | PROP_rtl))
  	  == (PROP_cfg | PROP_rtl))
!     print_rtl_graph_with_bb (dump_file_name, get_insns ());
  
    /* Run post-pass cleanup and verification.  */
    todo = pass->todo_flags_finish;
--- 505,511 ----
    if (dump_file
        && (pass->properties_provided & (PROP_cfg | PROP_rtl))
  	  == (PROP_cfg | PROP_rtl))
!     print_rtl_with_bb (dump_file, get_insns ());
  
    /* Run post-pass cleanup and verification.  */
    todo = pass->todo_flags_finish;
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pretty-print.c,v
retrieving revision 2.45
diff -c -3 -p -r2.45 tree-pretty-print.c
*** tree-pretty-print.c	6 Oct 2004 20:14:28 -0000	2.45
--- tree-pretty-print.c	7 Oct 2004 15:36:39 -0000
*************** dump_generic_node (pretty_printer *buffe
*** 845,853 ****
  	  pp_character (buffer, ')');
  	  /* The lowered cond_exprs should always be printed in full.  */
  	  if (COND_EXPR_THEN (node)
! 	      && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
  	      && COND_EXPR_ELSE (node)
! 	      && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
  	    {
  	      pp_space (buffer);
  	      dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
--- 845,855 ----
  	  pp_character (buffer, ')');
  	  /* The lowered cond_exprs should always be printed in full.  */
  	  if (COND_EXPR_THEN (node)
! 	      && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
! 		  || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
  	      && COND_EXPR_ELSE (node)
! 	      && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
! 		  || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
  	    {
  	      pp_space (buffer);
  	      dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);


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