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]

[vta] more propagation of information in debug annotations


A long time ago, I noticed we were dropping a lot of useful debug
information early on.  I know I said a few days ago that I was going
to work next on the transformation of debug insns in var location
notes, but I got a personal request to look into a problem that turned
out to be partially caused by this early loss of information.

So I fixed it, and ran into a few other issues, some caused by the
formerly-unexpected presence of addressable memory in debug
annotations, some caused by the resulting complexity of debug
annotations, and a few latent issues exposed by these changes, because
of which -fvar-tracking-assignments caused slightly different code to
be generated.

Today's patchset fixes all of these.

I'm starting with the most complex patch, that addresses the issue of
propagation of non-constant SSA assignments and addressable-memory
expressions into debug annotations, and the immediate fallout.


ATM, I don't add VOPs to debug annotations.  I can't quite see where
they'd be useful, but I haven't thought too hard about this issue.  I
just know that, if we end up having reason to add them, we have to be
very careful to avoid messing with the decl UIDs out of the various
memory tags.  Thoughts?


I'm checking this in the vta branch.  Bootstrap-debugged and
bootstrap4-debug/g0ed on x86_64-linux-gnu, i686-linux-gnu,
ppc64-linux-gnu and ia64-linux-gnu.

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

	* tree-into-ssa.c (adjust_debug_stmts_for_var_def_move):
	Propagate value from SSA defs.
	(prepare_block_for_update): Do not skip debug insns.
	* tree-ssa-operands.c (add_vop): Reject debug insns.
	(get_indirect_ref_operands): Do no more than recursing for
	debug insns.
	(get_expr_operands): Don't add vops to debug insns.
	(parse_ssa_operands): Likewise.
	* tree-ssa-propagate.c (set_rhs): Handle debug insns.
	* tree-flow-inline.h (get_subvars_for_var): Don't require
	annotated vars.
	* dwarf2out.c (mem_loc_descriptor): Handle MINUS.
	* cfgexpand.c (expand_debug_expr): Avoid infinite recursion in
	unsimplifyable conversions.

Index: gcc/tree-into-ssa.c
===================================================================
--- gcc/tree-into-ssa.c.orig	2008-01-04 17:01:19.000000000 -0200
+++ gcc/tree-into-ssa.c	2008-01-07 18:05:12.000000000 -0200
@@ -1,5 +1,5 @@
 /* Rewrite a program in Normal form into SSA.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Diego Novillo <dnovillo@redhat.com>
 
@@ -1141,6 +1141,8 @@ adjust_debug_stmts_for_var_def_move (tre
   imm_use_iterator imm_iter;
   tree stmt;
   use_operand_p use_p;
+  tree value = NULL;
+  bool no_value = false;
 
   if (!MAY_HAVE_DEBUG_STMTS)
     return;
@@ -1182,8 +1184,38 @@ adjust_debug_stmts_for_var_def_move (tre
 	    }
 	}
 
-      FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
-	SET_USE (use_p, unshare_expr (SSA_NAME_VALUE (var)));
+      if (!value && !no_value)
+	{
+	  if (SSA_NAME_VALUE (var))
+	    value = SSA_NAME_VALUE (var);
+	  else
+	    {
+	      tree def_stmt = SSA_NAME_DEF_STMT (var);
+
+	      if (TREE_CODE (def_stmt) == GIMPLE_MODIFY_STMT)
+		{
+		  value = GIMPLE_STMT_OPERAND (def_stmt, 1);
+		  switch (TREE_CODE (value))
+		    {
+		    case CALL_EXPR:
+		      value = NULL;
+		      break;
+
+		    default:
+		      break;
+		    }
+		}
+	    }
+
+	  if (!value)
+	    no_value = true;
+	}
+
+      if (no_value)
+	VAR_DEBUG_VALUE_VALUE (stmt) = VAR_DEBUG_VALUE_NOVALUE;
+      else
+	FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+	  SET_USE (use_p, unshare_expr (value));
 
       update_stmt (stmt);
     }
@@ -2697,9 +2729,6 @@ prepare_block_for_update (basic_block bb
       
       stmt = bsi_stmt (si);
 
-      if (IS_DEBUG_STMT (stmt))
-	continue;
-
       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_ALL_USES)
 	{
 	  tree use = USE_FROM_PTR (use_p);
Index: gcc/tree-ssa-operands.c
===================================================================
--- gcc/tree-ssa-operands.c.orig	2007-11-23 18:05:54.000000000 -0200
+++ gcc/tree-ssa-operands.c	2008-01-06 14:09:30.000000000 -0200
@@ -1,5 +1,6 @@
 /* SSA operands management for trees.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -628,6 +629,8 @@ add_vop (tree stmt, tree op, int num, vo
   voptype_p new_vop;
   int x;
 
+  gcc_assert (!IS_DEBUG_STMT (stmt));
+
   new_vop = alloc_vop (num);
   for (x = 0; x < num; x++)
     {
@@ -1656,6 +1659,9 @@ get_indirect_ref_operands (tree stmt, tr
   if (TREE_THIS_VOLATILE (expr))
     s_ann->has_volatile_ops = true; 
 
+  if ((flags & opf_debug_use) != 0)
+    goto recurse;
+
   if (SSA_VAR_P (ptr))
     {
       struct ptr_info_def *pi = NULL;
@@ -1719,9 +1725,12 @@ get_indirect_ref_operands (tree stmt, tr
       gcc_unreachable ();
     }
 
+ recurse:
   /* If requested, add a USE operand for the base pointer.  */
   if (recurse_on_base)
-    get_expr_operands (stmt, pptr, opf_use);
+    get_expr_operands (stmt, pptr, opf_use
+		       | ((flags & opf_debug_use) != 0
+			  ? opf_debug_use | opf_no_vops : 0));
 }
 
 
@@ -2233,7 +2242,7 @@ get_expr_operands (tree stmt, tree *expr
     case VAR_DEBUG_VALUE:
       if (VAR_DEBUG_VALUE_VALUE (stmt) != VAR_DEBUG_VALUE_NOVALUE)
 	get_expr_operands (stmt, &VAR_DEBUG_VALUE_VALUE (stmt),
-			   opf_use | opf_debug_use);
+			   opf_use | opf_debug_use | opf_no_vops);
       return;
 
     case CONSTRUCTOR:
@@ -2390,7 +2399,7 @@ parse_ssa_operands (tree stmt)
     case VAR_DEBUG_VALUE:
       if (VAR_DEBUG_VALUE_VALUE (stmt) != VAR_DEBUG_VALUE_NOVALUE)
 	get_expr_operands (stmt, &VAR_DEBUG_VALUE_VALUE (stmt),
-			   opf_use | opf_debug_use);
+			   opf_use | opf_debug_use | opf_no_vops);
       return;
 
     case COND_EXPR:
Index: gcc/tree-ssa-propagate.c
===================================================================
--- gcc/tree-ssa-propagate.c.orig	2007-11-23 18:05:53.000000000 -0200
+++ gcc/tree-ssa-propagate.c	2008-01-05 05:51:27.000000000 -0200
@@ -721,6 +721,10 @@ set_rhs (tree *stmt_p, tree expr)
         GIMPLE_STMT_OPERAND (stmt, 1) = expr;
       break;
 
+    case VAR_DEBUG_VALUE:
+      VAR_DEBUG_VALUE_VALUE (stmt) = expr;
+      break;
+
     case COND_EXPR:
       if (!is_gimple_condexpr (expr))
         return false;
Index: gcc/tree-flow-inline.h
===================================================================
--- gcc/tree-flow-inline.h.orig	2007-11-23 18:05:53.000000000 -0200
+++ gcc/tree-flow-inline.h	2008-01-07 18:18:30.000000000 -0200
@@ -1,5 +1,5 @@
 /* Inline functions for tree-flow.h
-   Copyright (C) 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
    Contributed by Diego Novillo <dnovillo@redhat.com>
 
 This file is part of GCC.
@@ -1704,16 +1704,23 @@ lookup_subvars_for_var (const_tree var)
    NULL, if there are no subvariables.  */
 
 static inline subvar_t
-get_subvars_for_var (tree var)
+get_subvars_for_var (tree ssa_var)
 {
+  tree var = ssa_var;
+  var_ann_t ann;
   subvar_t subvars;
 
   gcc_assert (SSA_VAR_P (var));  
   
   if (TREE_CODE (var) == SSA_NAME)
-    subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
+    var = SSA_NAME_VAR (var);
+
+  ann = var_ann (var);
+  if (!ann)
+    subvars = NULL;
   else
-    subvars = *(lookup_subvars_for_var (var));
+    subvars = ann->subvars;
+
   return subvars;
 }
 
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c.orig	2007-12-28 16:19:29.000000000 -0200
+++ gcc/dwarf2out.c	2008-01-06 09:41:12.000000000 -0200
@@ -1,6 +1,6 @@
 /* Output Dwarf2 format symbol table information from GCC.
    Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
    Contributed by Gary Funck (gary@intrepid.com).
    Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
    Extensively modified by Jason Merrill (jason@cygnus.com).
@@ -9198,6 +9198,10 @@ mem_loc_descriptor (rtx rtl, enum machin
 
     /* If a pseudo-reg is optimized away, it is possible for it to
        be replaced with a MEM containing a multiply or shift.  */
+    case MINUS:
+      op = DW_OP_minus;
+      goto do_binop;
+
     case MULT:
       op = DW_OP_mul;
       goto do_binop;
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c.orig	2007-12-28 16:20:15.000000000 -0200
+++ gcc/cfgexpand.c	2008-01-07 18:18:30.000000000 -0200
@@ -1,5 +1,5 @@
 /* A pass for lowering trees to RTL.
-   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -1776,6 +1776,12 @@ expand_debug_expr (tree exp)
 	tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
 					&mode1, &unsignedp, &volatilep, true);
 
+	if (tem == exp)
+	  {
+	    gcc_assert (TREE_CODE (exp) == VIEW_CONVERT_EXPR);
+	    tem = TREE_OPERAND (exp, 0);
+	  }
+
 	op0 = expand_debug_expr (tem);
 
 	if (!op0)
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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