public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@redhat.com>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PR debug/41343] introduce debug expr temps
Date: Tue, 06 Oct 2009 06:43:00 -0000	[thread overview]
Message-ID: <orbpkljdiy.fsf@huru.localdomain> (raw)
In-Reply-To: <84fc9c000910030740ne077924se095544e2a81e792@mail.gmail.com> 	(Richard Guenther's message of "Sat, 3 Oct 2009 16:40:41 +0200")

[-- Attachment #1: Type: text/plain, Size: 3042 bytes --]

On Oct  3, 2009, Richard Guenther <richard.guenther@gmail.com> wrote:

> Hm, ok.  One reason why I liked the idea of using SSA_NAMEs much is
> that it would make it very easy to get rid of old no longer used debug
> temps.  How do you address this?

I don't.  I'm not sure we're going to have very many of these.  Say, a
debug temp bind should only become dead if we were to remove the basic
block containing the only reference to the debug temp.  In general we do
this only when the block is unreachable.  But if the block is
unreachable, we'd remove it before the debug temp was introduced, and
the absence of references to the DEF would prevent the creation of the
debug temp in the first place.

Of course we could construct cases in which the order of creation of the
debug temp and the removal of the blocks would cause it to remain
around.  I have an intuition that this won't happen very often, though.
I guess I should try to substantiate this intuition ;-)

Anyhow, if we find it not to be true, it shouldn't be too hard to get
debug temps into SSA operands, especially if we're to add vops to debug
bind stmts as well.

> Any reason why in

> +      if (TREE_CODE (t) == DEBUG_EXPR_DECL)
> +       DECL_UID (t) = --next_debug_decl_uid;

> you count backward?  You always print the negative value later...

Mainly to make accidental overlaps with DECL_UIDs less likely.  I
figured negative values would cause crashes or errors if we used
DECL_UIDs inappropriately.

> for both gsi_replace and gsi_remove you shouldn't really insert
> debug-temps.  The replaced/removed stmt may be inserted elsewhere
> again

But the bind point is that where the stmt was before, and the moved DEF
might very well be referenced at a point between the bind point and the
reinsertion point.

> @@ -206,7 +206,7 @@ release_ssa_name (tree var)
>        use_operand_p imm = &(SSA_NAME_IMM_USE_NODE (var));

>        if (MAY_HAVE_DEBUG_STMTS)
> -       propagate_var_def_into_debug_stmts (var, NULL, NULL);
> +       insert_debug_temp_for_var_def (NULL, var);

> and here I thought that doesn't work because the stmt is already
> unlinked?

It works, but it will drop debug expressions that refer to the removed
DEF, instead of replacing them with a debug temp.

> If you want it more generic I'd say we want to have a release_defs_p
> argument to gsi_remove () / gsi_replace () that controls whether
> the removed/replaced stmt is going to die.

That's not enough, and it would require bringing back the sequential
searching for uses in the same block, and the requirements for
domination information, that isn't always available.

> On the RTL parts I don't have a strong opinion - though I wonder why
> VALUE flows in here so much (I though that was only a cselib thing).

VTA uses cselib heavily.


Here's an updated patch I'm testing, that fixes a debug regression in
tree-ssa-dce: when removing a SSA DEF that caused a debug bind stmt to
be introduced, we'd remove debug bind stmts shortly thereafter, because
they wouldn't be marked as necessary.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vta-temp-values-pr41343.patch --]
[-- Type: text/x-diff, Size: 26630 bytes --]

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/41343
	PR debug/41447
	PR debug/41264
	* tree.def (DEBUG_EXPR_DECL): New.
	* rtl.def (DEBUG_EXPR): New.
	* gengtype.c (adjust_field_rtx_def): Handle it.
	* tree-ssa.c (propagate_var_def_into_debug_stmts): Rename to...
	(insert_debug_temp_for_var_def): ... this.  Drop support for
	moving.  Take iterator for def stmt; insert debug stmt before it.
	(propagate_defs_into_debug_stmts): Rename to...
	(insert_debug_temps_for_defs): ... this.  Likewise.
	* tree.c (next_debug_decl_uid): New.
	(make_node_stat): Count debug decls separately.
	(copy_node_stat): Likewise.
	* cfgexpand.c (expand_debug_expr): Handle DEBUG_EXPR_DECL.
	* var-tracking.c (dv_is_decl_p): Recognize it.
	(VALUE_RECURSED_INTO): Apply to DEBUG_EXPRs too.
	(track_expr_p): Track expanded DEBUG_EXPR_DECLs.
	(vt_expand_loc_callback): Expand DEBUG_EXPRs.
	(emit_note_insn_var_location): Don't emit notes for DEBUG_EXPR_DECLs.
	* cselib.c (cselib_expand_value_rtx_1): Use callback for DEBUG_EXPR.
	* tree-ssa-operands.c (get_expr_operands): Skip DEBUG_EXPR_DECLs in
	debug bind stmts.
	* emit-rtl.c (verify_rtx_sharing): Handle DEBUG_EXPR and VALUE.
	(copy_rtx_if_shared_1, reset_used_flags, set_used_flags): Likewise.
	* rtl.c (copy_rtx): Likewise.
	(rtx_equal_p_cb, rtx_equal_p): Handle DEBUG_EXPR.
	* print-rtl.c (print_rtx): Likewise.
	* sched-vis.c (print_value): Likewise.
	(print_insn): Handle DEBUG_EXPR_DECL.
	* tree-dump.c (dequeue_and_dump): Likewise.
	* tree-pretty-print.c (dump_decl_name, dump_generic_node): Likewise.
	* gimple-iterator (gsi_replace, gsi_remove): Insert debug temps.
	* tree-ssa-loop-im.c (rewrite_bittest, move_computations_stmt): Drop
	propagation into debug stmts.
	* tree-ssa-reassoc.c (rewrite_expr_tree, linearize_expr): Likewise.
	* tree-ssa-sink.c (statement_sink_location): Likewise.
	* tree-ssa-forwprop (forward_propagate_addr_expr): Likewise.
	* tree-ssanames.c (release_ssa_name): Adjust for rename.
	* tree-flow.h: Likewise.
	* tree-ssa-dce.c (eliminate_unnecessary_stmts): Don't discard
	just-inserted debug stmts.

Index: gcc/tree.def
===================================================================
--- gcc/tree.def.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/tree.def	2009-10-02 03:02:54.000000000 -0300
@@ -351,6 +351,10 @@ DEFTREECODE (PARM_DECL, "parm_decl", tcc
 DEFTREECODE (TYPE_DECL, "type_decl", tcc_declaration, 0)
 DEFTREECODE (RESULT_DECL, "result_decl", tcc_declaration, 0)
 
+/* A "declaration" of a debug temporary.  It should only appear in
+   DEBUG stmts.  */
+DEFTREECODE (DEBUG_EXPR_DECL, "debug_expr_decl", tcc_declaration, 0)
+
 /* A namespace declaration.  Namespaces appear in DECL_CONTEXT of other
    _DECLs, providing a hierarchy of names.  */
 DEFTREECODE (NAMESPACE_DECL, "namespace_decl", tcc_declaration, 0)
Index: gcc/rtl.def
===================================================================
--- gcc/rtl.def.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/rtl.def	2009-10-02 03:02:54.000000000 -0300
@@ -88,6 +88,10 @@ DEF_RTL_EXPR(UNKNOWN, "UnKnown", "*", RT
    DECL codes in trees.  */
 DEF_RTL_EXPR(VALUE, "value", "0", RTX_OBJ)
 
+/* The RTL generated for a DEBUG_EXPR_DECL.  It links back to the
+   DEBUG_EXPR_DECL in the first operand.  */
+DEF_RTL_EXPR(DEBUG_EXPR, "debug_expr", "0", RTX_OBJ)
+
 /* ---------------------------------------------------------------------
    Expressions used in constructing lists.
    --------------------------------------------------------------------- */
Index: gcc/gengtype.c
===================================================================
--- gcc/gengtype.c.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/gengtype.c	2009-10-02 03:02:54.000000000 -0300
@@ -1118,6 +1118,8 @@ adjust_field_rtx_def (type_p t, options_
 		t = scalar_tp, subname = "rt_int";
 	      else if (i == VALUE && aindex == 0)
 		t = scalar_tp, subname = "rt_int";
+	      else if (i == DEBUG_EXPR && aindex == 0)
+		t = tree_tp, subname = "rt_tree";
 	      else if (i == REG && aindex == 1)
 		t = scalar_tp, subname = "rt_int";
 	      else if (i == REG && aindex == 2)
Index: gcc/tree-ssa.c
===================================================================
--- gcc/tree-ssa.c.orig	2009-10-02 02:56:06.000000000 -0300
+++ gcc/tree-ssa.c	2009-10-02 03:02:55.000000000 -0300
@@ -295,15 +295,12 @@ find_released_ssa_name (tree *tp, int *w
   return NULL_TREE;
 }
 
-/* Given a VAR whose definition STMT is to be moved to the iterator
-   position TOGSIP in the TOBB basic block, verify whether we're
-   moving it across any of the debug statements that use it, and
-   adjust them as needed.  If TOBB is NULL, then the definition is
-   understood as being removed, and TOGSIP is unused.  */
+/* Insert a DEBUG BIND stmt before the DEF of VAR if VAR is referenced
+   by other DEBUG stmts, and replace uses of the DEF with the
+   newly-created debug temp.  */
+
 void
-propagate_var_def_into_debug_stmts (tree var,
-				    basic_block tobb,
-				    const gimple_stmt_iterator *togsip)
+insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
 {
   imm_use_iterator imm_iter;
   gimple stmt;
@@ -316,49 +313,25 @@ propagate_var_def_into_debug_stmts (tree
 
   FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
     {
-      basic_block bb;
-      gimple_stmt_iterator si;
-
       if (!is_gimple_debug (stmt))
 	continue;
 
-      if (tobb)
-	{
-	  bb = gimple_bb (stmt);
-
-	  if (bb != tobb)
-	    {
-	      gcc_assert (dom_info_available_p (CDI_DOMINATORS));
-	      if (dominated_by_p (CDI_DOMINATORS, bb, tobb))
-		continue;
-	    }
-	  else
-	    {
-	      si = *togsip;
-
-	      if (gsi_end_p (si))
-		continue;
-
-	      do
-		{
-		  gsi_prev (&si);
-		  if (gsi_end_p (si))
-		    break;
-		}
-	      while (gsi_stmt (si) != stmt);
-
-	      if (gsi_end_p (si))
-		continue;
-	    }
-	}
-
       /* Here we compute (lazily) the value assigned to VAR, but we
 	 remember if we tried before and failed, so that we don't try
 	 again.  */
       if (!value && !no_value)
 	{
-	  gimple def_stmt = SSA_NAME_DEF_STMT (var);
+	  gimple def_stmt;
 
+	  if (gsi)
+	    def_stmt = gsi_stmt (*gsi);
+	  else
+	    def_stmt = SSA_NAME_DEF_STMT (var);
+
+	  /* If we didn't get an insertion point, and the stmt has
+	     already been removed, we won't be able to insert the
+	     debug bind stmt, so we'll have to drop debug
+	     information.  */
 	  if (is_gimple_assign (def_stmt))
 	    {
 	      if (!dom_info_available_p (CDI_DOMINATORS))
@@ -395,7 +368,9 @@ propagate_var_def_into_debug_stmts (tree
 		     wrong order, so we don't even check for dead SSA
 		     NAMEs.  SSA verification shall catch any
 		     errors.  */
-		  if (!walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
+		  if ((!gsi && !gimple_bb (def_stmt))
+		      || !walk_gimple_op (def_stmt, find_released_ssa_name,
+					  &wi))
 		    no_value = true;
 		}
 
@@ -405,42 +380,68 @@ propagate_var_def_into_debug_stmts (tree
 
 	  if (!value)
 	    no_value = true;
+	  else
+	    {
+	      tree temp = make_node (DEBUG_EXPR_DECL);
+	      gimple def_temp;
+
+	      def_temp = gimple_build_debug_bind (temp, unshare_expr (value),
+						  def_stmt);
+
+	      DECL_ARTIFICIAL (temp) = 1;
+	      TREE_TYPE (temp) = TREE_TYPE (value);
+	      if (DECL_P (value))
+		DECL_MODE (temp) = DECL_MODE (value);
+	      else
+		DECL_MODE (temp) = TYPE_MODE (TREE_TYPE (value));
+
+	      value = temp;
+
+	      if (gsi)
+		gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
+	      else
+		{
+		  gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
+		  gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
+		}
+	    }
 	}
 
       if (no_value)
 	gimple_debug_bind_reset_value (stmt);
       else
 	FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
-	  SET_USE (use_p, unshare_expr (value));
+	  SET_USE (use_p, value);
 
       update_stmt (stmt);
     }
 }
 
 
-/* Given a STMT to be moved to the iterator position TOBSIP in the
-   TOBB basic block, verify whether we're moving it across any of the
-   debug statements that use it.  If TOBB is NULL, then the definition
-   is understood as being removed, and TOBSIP is unused.  */
+/* Insert a DEBUG BIND stmt before STMT for each DEF referenced by
+   other DEBUG stmts, and replace uses of the DEF with the
+   newly-created debug temp.  */
 
 void
-propagate_defs_into_debug_stmts (gimple def, basic_block tobb,
-				 const gimple_stmt_iterator *togsip)
+insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
 {
+  gimple stmt;
   ssa_op_iter op_iter;
   def_operand_p def_p;
 
   if (!MAY_HAVE_DEBUG_STMTS)
     return;
 
-  FOR_EACH_SSA_DEF_OPERAND (def_p, def, op_iter, SSA_OP_DEF)
+  stmt = gsi_stmt (*gsi);
+
+  FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, op_iter, SSA_OP_DEF)
     {
       tree var = DEF_FROM_PTR (def_p);
 
       if (TREE_CODE (var) != SSA_NAME)
 	continue;
 
-      propagate_var_def_into_debug_stmts (var, tobb, togsip);
+      insert_debug_temp_for_var_def (gsi, var);
     }
 }
 
Index: gcc/tree.c
===================================================================
--- gcc/tree.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/tree.c	2009-10-02 03:02:55.000000000 -0300
@@ -152,6 +152,8 @@ static const char * const tree_node_kind
 static GTY(()) int next_decl_uid;
 /* Unique id for next type created.  */
 static GTY(()) int next_type_uid = 1;
+/* Unique id for next debug decl created.  */
+static GTY(()) int next_debug_decl_uid;
 
 /* Since we cannot rehash a type after it is in the table, we have to
    keep the hash code.  */
@@ -872,7 +874,10 @@ make_node_stat (enum tree_code code MEM_
 	    DECL_ALIGN (t) = 1;
 	}
       DECL_SOURCE_LOCATION (t) = input_location;
-      DECL_UID (t) = next_decl_uid++;
+      if (TREE_CODE (t) == DEBUG_EXPR_DECL)
+	DECL_UID (t) = --next_debug_decl_uid;
+      else
+	DECL_UID (t) = next_decl_uid++;
       if (TREE_CODE (t) == LABEL_DECL)
 	LABEL_DECL_UID (t) = -1;
 
@@ -948,7 +953,10 @@ copy_node_stat (tree node MEM_STAT_DECL)
 
   if (TREE_CODE_CLASS (code) == tcc_declaration)
     {
-      DECL_UID (t) = next_decl_uid++;
+      if (code == DEBUG_EXPR_DECL)
+	DECL_UID (t) = --next_debug_decl_uid;
+      else
+	DECL_UID (t) = next_decl_uid++;
       if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
 	  && DECL_HAS_VALUE_EXPR_P (node))
 	{
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/cfgexpand.c	2009-10-02 03:02:55.000000000 -0300
@@ -2358,6 +2358,18 @@ expand_debug_expr (tree exp)
       op1 = wrap_constant (GET_MODE_INNER (mode), op1);
       return gen_rtx_CONCAT (mode, op0, op1);
 
+    case DEBUG_EXPR_DECL:
+      op0 = DECL_RTL_IF_SET (exp);
+
+      if (op0)
+	return op0;
+
+      op0 = gen_rtx_DEBUG_EXPR (mode);
+      XTREE (op0, 0) = exp;
+      SET_DECL_RTL (exp, op0);
+
+      return op0;
+
     case VAR_DECL:
     case PARM_DECL:
     case FUNCTION_DECL:
Index: gcc/var-tracking.c
===================================================================
--- gcc/var-tracking.c.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/var-tracking.c	2009-10-02 03:02:55.000000000 -0300
@@ -732,6 +732,7 @@ dv_is_decl_p (decl_or_value dv)
     case (int)PARM_DECL:
     case (int)RESULT_DECL:
     case (int)FUNCTION_DECL:
+    case (int)DEBUG_EXPR_DECL:
     case (int)COMPONENT_REF:
       return true;
 
@@ -2222,7 +2223,7 @@ dataflow_set_union (dataflow_set *dst, d
 
 /* Whether the value is currently being expanded.  */
 #define VALUE_RECURSED_INTO(x) \
-  (RTL_FLAG_CHECK1 ("VALUE_RECURSED_INTO", (x), VALUE)->used)
+  (RTL_FLAG_CHECK2 ("VALUE_RECURSED_INTO", (x), VALUE, DEBUG_EXPR)->used)
 /* Whether the value is in changed_variables hash table.  */
 #define VALUE_CHANGED(x) \
   (RTL_FLAG_CHECK1 ("VALUE_CHANGED", (x), VALUE)->frame_related)
@@ -4112,6 +4113,9 @@ track_expr_p (tree expr, bool need_rtl)
   rtx decl_rtl;
   tree realdecl;
 
+  if (TREE_CODE (expr) == DEBUG_EXPR_DECL)
+    return DECL_RTL_SET_P (expr);
+
   /* If EXPR is not a parameter or a variable do not track it.  */
   if (TREE_CODE (expr) != VAR_DECL && TREE_CODE (expr) != PARM_DECL)
     return 0;
@@ -6271,11 +6275,12 @@ vt_expand_loc_callback (rtx x, bitmap re
   decl_or_value dv;
   variable var;
   location_chain loc;
-  rtx result;
+  rtx result, subreg, xret;
 
-  if (GET_CODE (x) == SUBREG)
+  switch (GET_CODE (x))
     {
-      rtx subreg = SUBREG_REG (x);
+    case SUBREG:
+      subreg = SUBREG_REG (x);
 
       if (GET_CODE (SUBREG_REG (x)) != VALUE)
 	return x;
@@ -6297,22 +6302,31 @@ vt_expand_loc_callback (rtx x, bitmap re
 	result = gen_rtx_raw_SUBREG (GET_MODE (x), subreg, SUBREG_BYTE (x));
 
       return result;
-    }
 
-  if (GET_CODE (x) != VALUE)
-    return x;
+    case DEBUG_EXPR:
+      dv = dv_from_decl (XTREE (x, 0));
+      xret = NULL;
+      break;
+
+    case VALUE:
+      dv = dv_from_value (x);
+      xret = x;
+      break;
+
+    default:
+      return x;
+    }
 
   if (VALUE_RECURSED_INTO (x))
-    return x;
+    return NULL;
 
-  dv = dv_from_value (x);
   var = (variable) htab_find_with_hash (vars, dv, dv_htab_hash (dv));
 
   if (!var)
-    return x;
+    return xret;
 
   if (var->n_var_parts == 0)
-    return x;
+    return xret;
 
   gcc_assert (var->n_var_parts == 1);
 
@@ -6332,7 +6346,7 @@ vt_expand_loc_callback (rtx x, bitmap re
   if (result)
     return result;
   else
-    return x;
+    return xret;
 }
 
 /* Expand VALUEs in LOC, using VARS as well as cselib's equivalence
@@ -6382,6 +6396,9 @@ emit_note_insn_var_location (void **varp
 
   decl = dv_as_decl (var->dv);
 
+  if (TREE_CODE (decl) == DEBUG_EXPR_DECL)
+    goto clear;
+
   gcc_assert (decl);
 
   complete = true;
Index: gcc/cselib.c
===================================================================
--- gcc/cselib.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/cselib.c	2009-10-02 03:02:55.000000000 -0300
@@ -1213,6 +1213,13 @@ cselib_expand_value_rtx_1 (rtx orig, str
 	result = expand_loc (CSELIB_VAL_PTR (orig)->locs, evd, max_depth);
 	return result;
       }
+
+    case DEBUG_EXPR:
+      if (evd->callback)
+	return evd->callback (orig, evd->regs_active, max_depth,
+			      evd->callback_arg);
+      return orig;
+
     default:
       break;
     }
Index: gcc/tree-ssa-operands.c
===================================================================
--- gcc/tree-ssa-operands.c.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/tree-ssa-operands.c	2009-10-02 03:02:55.000000000 -0300
@@ -894,6 +894,10 @@ get_expr_operands (gimple stmt, tree *ex
       add_stmt_operand (expr_p, stmt, flags);
       return;
 
+    case DEBUG_EXPR_DECL:
+      gcc_assert (gimple_debug_bind_p (stmt));
+      return;
+
     case MISALIGNED_INDIRECT_REF:
       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags);
       /* fall through */
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c.orig	2009-10-02 02:56:09.000000000 -0300
+++ gcc/emit-rtl.c	2009-10-02 03:02:55.000000000 -0300
@@ -2393,6 +2393,8 @@ verify_rtx_sharing (rtx orig, rtx insn)
   switch (code)
     {
     case REG:
+    case DEBUG_EXPR:
+    case VALUE:
     case CONST_INT:
     case CONST_DOUBLE:
     case CONST_FIXED:
@@ -2593,6 +2595,8 @@ repeat:
   switch (code)
     {
     case REG:
+    case DEBUG_EXPR:
+    case VALUE:
     case CONST_INT:
     case CONST_DOUBLE:
     case CONST_FIXED:
@@ -2712,6 +2716,8 @@ repeat:
   switch (code)
     {
     case REG:
+    case DEBUG_EXPR:
+    case VALUE:
     case CONST_INT:
     case CONST_DOUBLE:
     case CONST_FIXED:
@@ -2783,6 +2789,8 @@ set_used_flags (rtx x)
   switch (code)
     {
     case REG:
+    case DEBUG_EXPR:
+    case VALUE:
     case CONST_INT:
     case CONST_DOUBLE:
     case CONST_FIXED:
Index: gcc/rtl.c
===================================================================
--- gcc/rtl.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/rtl.c	2009-10-02 03:02:55.000000000 -0300
@@ -232,6 +232,8 @@ copy_rtx (rtx orig)
   switch (code)
     {
     case REG:
+    case DEBUG_EXPR:
+    case VALUE:
     case CONST_INT:
     case CONST_DOUBLE:
     case CONST_FIXED:
@@ -381,6 +383,7 @@ rtx_equal_p_cb (const_rtx x, const_rtx y
     case SYMBOL_REF:
       return XSTR (x, 0) == XSTR (y, 0);
 
+    case DEBUG_EXPR:
     case VALUE:
     case SCRATCH:
     case CONST_DOUBLE:
@@ -496,6 +499,7 @@ rtx_equal_p (const_rtx x, const_rtx y)
     case SYMBOL_REF:
       return XSTR (x, 0) == XSTR (y, 0);
 
+    case DEBUG_EXPR:
     case VALUE:
     case SCRATCH:
     case CONST_DOUBLE:
Index: gcc/print-rtl.c
===================================================================
--- gcc/print-rtl.c.orig	2009-10-02 02:56:09.000000000 -0300
+++ gcc/print-rtl.c	2009-10-02 03:02:55.000000000 -0300
@@ -318,6 +318,12 @@ print_rtx (const_rtx in_rtx)
 	    dump_addr (outfile, "/", (void*)val);
 #endif
 	  }
+	else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
+	  {
+#ifndef GENERATOR_FILE
+	    fprintf (outfile, " D#%i", -DECL_UID (XTREE (in_rtx, 0)));
+#endif
+	  }
 	break;
 
       case 'e':
Index: gcc/sched-vis.c
===================================================================
--- gcc/sched-vis.c.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/sched-vis.c	2009-10-02 03:02:55.000000000 -0300
@@ -521,6 +521,10 @@ print_value (char *buf, const_rtx x, int
       cur = safe_concat (buf, cur, t);
       cur = safe_concat (buf, cur, "]");
       break;
+    case DEBUG_EXPR:
+      sprintf (t, "D#%i", -DECL_UID (XTREE (x, 0)));
+      cur = safe_concat (buf, cur, t);
+      break;
     default:
       print_exp (t, x, verbose);
       cur = safe_concat (buf, cur, t);
@@ -670,11 +674,18 @@ print_insn (char *buf, const_rtx x, int 
 	if (DECL_P (INSN_VAR_LOCATION_DECL (insn)))
 	  {
 	    tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (insn));
+	    char idbuf[32];
 	    if (id)
 	      name = IDENTIFIER_POINTER (id);
+	    else if (TREE_CODE (INSN_VAR_LOCATION_DECL (insn))
+		     == DEBUG_EXPR_DECL)
+	      {
+		sprintf (idbuf, "D#%i",
+			 -DECL_UID (INSN_VAR_LOCATION_DECL (insn)));
+		name = idbuf;
+	      }
 	    else
 	      {
-		char idbuf[32];
 		sprintf (idbuf, "D.%i",
 			 DECL_UID (INSN_VAR_LOCATION_DECL (insn)));
 		name = idbuf;
Index: gcc/tree-dump.c
===================================================================
--- gcc/tree-dump.c.orig	2009-10-02 02:56:09.000000000 -0300
+++ gcc/tree-dump.c	2009-10-02 03:02:55.000000000 -0300
@@ -511,6 +511,10 @@ dequeue_and_dump (dump_info_p di)
       dump_child ("cnst", DECL_INITIAL (t));
       break;
 
+    case DEBUG_EXPR_DECL:
+      dump_int (di, "-uid", -DECL_UID (t));
+      /* Fall through.  */
+
     case VAR_DECL:
     case PARM_DECL:
     case FIELD_DECL:
Index: gcc/tree-pretty-print.c
===================================================================
--- gcc/tree-pretty-print.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/tree-pretty-print.c	2009-10-02 03:02:55.000000000 -0300
@@ -183,6 +183,8 @@ dump_decl_name (pretty_printer *buffer, 
     {
       if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
         pp_printf (buffer, "L.%d", (int) LABEL_DECL_UID (node));
+      else if (TREE_CODE (node) == DEBUG_EXPR_DECL)
+	pp_printf (buffer, "D#%i", -DECL_UID (node));
       else
 	{
 	  char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
@@ -1051,6 +1053,7 @@ dump_generic_node (pretty_printer *buffe
     case VAR_DECL:
     case PARM_DECL:
     case FIELD_DECL:
+    case DEBUG_EXPR_DECL:
     case NAMESPACE_DECL:
       dump_decl_name (buffer, node, flags);
       break;
Index: gcc/gimple-iterator.c
===================================================================
--- gcc/gimple-iterator.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/gimple-iterator.c	2009-10-02 03:02:55.000000000 -0300
@@ -368,6 +368,8 @@ gsi_replace (gimple_stmt_iterator *gsi, 
   if (stmt == orig_stmt)
     return;
 
+  insert_debug_temps_for_defs (gsi);
+
   gimple_set_location (stmt, gimple_location (orig_stmt));
   gimple_set_bb (stmt, gsi_bb (*gsi));
 
@@ -470,6 +472,8 @@ gsi_remove (gimple_stmt_iterator *i, boo
   gimple_seq_node cur, next, prev;
   gimple stmt = gsi_stmt (*i);
 
+  insert_debug_temps_for_defs (i);
+
   /* Free all the data flow information for STMT.  */
   gimple_set_bb (stmt, NULL);
   delink_stmt_imm_use (stmt);
Index: gcc/tree-ssa-loop-im.c
===================================================================
--- gcc/tree-ssa-loop-im.c.orig	2009-10-02 02:56:07.000000000 -0300
+++ gcc/tree-ssa-loop-im.c	2009-10-02 03:02:55.000000000 -0300
@@ -879,7 +879,6 @@ rewrite_bittest (gimple_stmt_iterator *b
       gimple_cond_set_rhs (use_stmt, build_int_cst_type (TREE_TYPE (name), 0));
 
       gsi_insert_before (bsi, stmt1, GSI_SAME_STMT);
-      propagate_defs_into_debug_stmts (gsi_stmt (*bsi), NULL, NULL);
       gsi_replace (bsi, stmt2, true);
 
       return stmt1;
@@ -1060,7 +1059,6 @@ move_computations_stmt (struct dom_walk_
 
       mark_virtual_ops_for_renaming (stmt);
       gsi_insert_on_edge (loop_preheader_edge (level), stmt);
-      propagate_defs_into_debug_stmts (gsi_stmt (bsi), NULL, NULL);
       gsi_remove (&bsi, false);
     }
 }
Index: gcc/tree-ssa-reassoc.c
===================================================================
--- gcc/tree-ssa-reassoc.c.orig	2009-10-02 02:56:06.000000000 -0300
+++ gcc/tree-ssa-reassoc.c	2009-10-02 03:02:55.000000000 -0300
@@ -1405,7 +1405,6 @@ rewrite_expr_tree (gimple stmt, unsigned
 	    {
 	      stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt1));
 	      gsirhs1 = gsi_for_stmt (stmt2);
-	      propagate_defs_into_debug_stmts (stmt2, gimple_bb (stmt), &gsinow);
 	      gsi_move_before (&gsirhs1, &gsinow);
 	      gsi_prev (&gsinow);
 	      stmt1 = stmt2;
@@ -1452,7 +1451,6 @@ linearize_expr (gimple stmt)
 
   gsinow = gsi_for_stmt (stmt);
   gsirhs = gsi_for_stmt (binrhs);
-  propagate_defs_into_debug_stmts (binrhs, gimple_bb (stmt), &gsinow);
   gsi_move_before (&gsirhs, &gsinow);
 
   gimple_assign_set_rhs2 (stmt, gimple_assign_rhs1 (binrhs));
Index: gcc/tree-ssa-sink.c
===================================================================
--- gcc/tree-ssa-sink.c.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/tree-ssa-sink.c	2009-10-02 03:02:55.000000000 -0300
@@ -385,9 +385,6 @@ statement_sink_location (gimple stmt, ba
 
       *togsi = gsi_after_labels (commondom);
 
-      if (debug_stmts)
-	propagate_defs_into_debug_stmts (stmt, commondom, togsi);
-
       return true;
     }
 
@@ -406,8 +403,6 @@ statement_sink_location (gimple stmt, ba
 
       *togsi = gsi_for_stmt (use);
 
-      propagate_defs_into_debug_stmts (stmt, sinkbb, togsi);
-
       return true;
     }
 
@@ -441,8 +436,6 @@ statement_sink_location (gimple stmt, ba
 
   *togsi = gsi_after_labels (sinkbb);
 
-  propagate_defs_into_debug_stmts (stmt, sinkbb, togsi);
-
   return true;
 }
 
Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c.orig	2009-10-02 02:56:08.000000000 -0300
+++ gcc/tree-ssa-forwprop.c	2009-10-02 03:02:55.000000000 -0300
@@ -939,7 +939,6 @@ forward_propagate_addr_expr (tree name, 
   gimple use_stmt;
   bool all = true;
   bool single_use_p = has_single_use (name);
-  bool debug = false;
 
   FOR_EACH_IMM_USE_STMT (use_stmt, iter, name)
     {
@@ -950,9 +949,7 @@ forward_propagate_addr_expr (tree name, 
 	 there is nothing we can do.  */
       if (gimple_code (use_stmt) != GIMPLE_ASSIGN)
 	{
-	  if (is_gimple_debug (use_stmt))
-	    debug = true;
-	  else
+	  if (!is_gimple_debug (use_stmt))
 	    all = false;
 	  continue;
 	}
@@ -995,9 +992,6 @@ forward_propagate_addr_expr (tree name, 
 	}
     }
 
-  if (all && debug)
-    propagate_var_def_into_debug_stmts (name, NULL, NULL);
-
   return all;
 }
 
Index: gcc/tree-ssanames.c
===================================================================
--- gcc/tree-ssanames.c.orig	2009-10-02 02:56:06.000000000 -0300
+++ gcc/tree-ssanames.c	2009-10-02 03:02:55.000000000 -0300
@@ -206,7 +206,7 @@ release_ssa_name (tree var)
       use_operand_p imm = &(SSA_NAME_IMM_USE_NODE (var));
 
       if (MAY_HAVE_DEBUG_STMTS)
-	propagate_var_def_into_debug_stmts (var, NULL, NULL);
+	insert_debug_temp_for_var_def (NULL, var);
 
 #ifdef ENABLE_CHECKING
       verify_imm_links (stderr, var);
Index: gcc/tree-flow.h
===================================================================
--- gcc/tree-flow.h.orig	2009-10-02 02:56:12.000000000 -0300
+++ gcc/tree-flow.h	2009-10-02 03:02:55.000000000 -0300
@@ -636,10 +636,8 @@ typedef bool (*walk_use_def_chains_fn) (
 
 extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *, bool);
 
-void propagate_defs_into_debug_stmts (gimple, basic_block,
-				      const gimple_stmt_iterator *);
-void propagate_var_def_into_debug_stmts (tree, basic_block,
-					 const gimple_stmt_iterator *);
+void insert_debug_temps_for_defs (gimple_stmt_iterator *);
+void insert_debug_temp_for_var_def (gimple_stmt_iterator *, tree);
 void release_defs_bitset (bitmap toremove);
 
 /* In tree-into-ssa.c  */
Index: gcc/tree-ssa-dce.c
===================================================================
--- gcc/tree-ssa-dce.c.orig	2009-09-22 15:11:30.000000000 -0300
+++ gcc/tree-ssa-dce.c	2009-10-06 01:46:01.000000000 -0300
@@ -1071,7 +1071,7 @@ eliminate_unnecessary_stmts (void)
 {
   bool something_changed = false;
   basic_block bb;
-  gimple_stmt_iterator gsi;
+  gimple_stmt_iterator gsi, psi;
   gimple stmt;
   tree call;
   VEC (basic_block, heap) *h;
@@ -1111,10 +1111,13 @@ eliminate_unnecessary_stmts (void)
       bb = VEC_pop (basic_block, h);
 
       /* Remove dead statements.  */
-      for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
+      for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi = psi)
 	{
 	  stmt = gsi_stmt (gsi);
 
+	  psi = gsi;
+	  gsi_prev (&psi);
+
 	  stats.total++;
 
 	  /* If GSI is not necessary then remove it.  */
@@ -1122,14 +1125,6 @@ eliminate_unnecessary_stmts (void)
 	    {
 	      remove_dead_stmt (&gsi, bb);
 	      something_changed = true;
-
-	      /* If stmt was the last stmt in the block, we want to
-		 move gsi to the stmt that became the last stmt, but
-		 gsi_prev would crash.  */
-	      if (gsi_end_p (gsi))
-		gsi = gsi_last_bb (bb);
-	      else
-		gsi_prev (&gsi);
 	    }
 	  else if (is_gimple_call (stmt))
 	    {
@@ -1159,10 +1154,7 @@ eliminate_unnecessary_stmts (void)
 		    }
 		  notice_special_calls (stmt);
 		}
-	      gsi_prev (&gsi);
 	    }
-	  else
-	    gsi_prev (&gsi);
 	}
     }
 

[-- Attachment #3: Type: text/plain, Size: 257 bytes --]


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

  reply	other threads:[~2009-10-06  5:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-22 19:51 Alexandre Oliva
2009-09-23  8:42 ` Richard Guenther
2009-09-23 11:54   ` Richard Guenther
2009-09-23 12:02     ` Richard Guenther
2009-09-30  8:24       ` Alexandre Oliva
2009-09-30  9:54         ` Richard Guenther
2009-10-02  6:06           ` Alexandre Oliva
2009-10-02  7:10   ` Alexandre Oliva
2009-10-03 15:02     ` Richard Guenther
2009-10-06  6:43       ` Alexandre Oliva [this message]
2009-10-06 10:30         ` Richard Guenther
2009-10-07  8:35           ` Alexandre Oliva
2009-10-07 10:24             ` Richard Guenther
2009-10-08 19:48               ` Alexandre Oliva
2009-10-09  7:48             ` Alexandre Oliva
2009-10-09 11:29               ` Richard Guenther
2009-10-11 13:05                 ` Alexandre Oliva
2009-10-11 14:26                   ` Richard Guenther
2009-10-12  6:36                     ` Alexandre Oliva
2009-10-12  8:58                       ` Richard Guenther
2009-10-12 19:01                         ` Alexandre Oliva
2009-10-13  6:02                           ` Eric Botcazou
2009-10-13  6:41                             ` Jakub Jelinek
2009-10-13  9:38                               ` Richard Guenther
2009-10-13 21:01                           ` Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=orbpkljdiy.fsf@huru.localdomain \
    --to=aoliva@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).