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]

[PATCH] Debug info for vars set to unused parameters


Hi!

This patch on top of
http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01524.html
provides debug info even for variables with values related to
parameters that aren't actually used in code during expand and afterwards.

Bootstrapped/regtested on x86_64-linux and i686-linux, locstats changes
below.  Ok for trunk?

	32-bit cc1plus before		32-bit cc1plus after
cov%	samples		cumul	 	samples		cumul
0.0	169444/29%	169444/29%	169429/29%	169429/29%
0..10	10935/1%	180379/31%	10934/1%	180363/31%
11..20	10738/1%	191117/33%	10737/1%	191100/33%
21..30	17064/2%	208181/36%	17063/2%	208163/36%
31..40	11045/1%	219226/38%	11046/1%	219209/38%
41..50	14496/2%	233722/40%	14496/2%	233705/40%
51..60	11197/1%	244919/42%	11198/1%	244903/42%
61..70	13085/2%	258004/45%	13085/2%	257988/45%
71..80	13071/2%	271075/47%	13071/2%	271059/47%
81..90	17408/3%	288483/50%	17415/3%	288474/50%
91..99	68140/11%	356623/62%	68134/11%	356608/62%
100	214682/37%	571305/100%	214697/37%	571305/100%
	64-bit cc1plus before		64-bit cc1plus after
cov%	samples		cumul		samples		cumul
0.0	189597/30%	189597/30%	189578/30%	189578/30%
0..10	10400/1%	199997/32%	10398/1%	199976/32%
11..20	11173/1%	211170/34%	11172/1%	211148/34%
21..30	18666/3%	229836/37%	18659/3%	229807/37%
31..40	11455/1%	241291/39%	11456/1%	241263/39%
41..50	15059/2%	256350/41%	15057/2%	256320/41%
51..60	12688/2%	269038/43%	12688/2%	269008/43%
61..70	12945/2%	281983/45%	12947/2%	281955/45%
71..80	17610/2%	299593/48%	17615/2%	299570/48%
81..90	23604/3%	323197/52%	23604/3%	323174/52%
91..99	67849/11%	391046/63%	67852/11%	391026/63%
100	225448/36%	616494/100%	225468/36%	616494/100%


2010-10-30  Jakub Jelinek  <jakub@redhat.com>

	PR debug/45882
	* rtl.def (ENTRY_VALUE): Change format from "e" to "0".
	* rtl.h (ENTRY_VALUE_EXP): Define.
	* rtl.c (rtx_equal_p_cb, rtx_equal_p): Handle ENTRY_VALUE.
	* cselib.c (rtx_equal_for_cselib_p, cselib_hash_rtx): Likewise.
	* print-rtl.c (print_rtx): Likewise.
	* gengtype.c (adjust_field_rtx_def): Likewise.
	* var-tracking.c (vt_add_function_parameters): Adjust
	gen_rtx_ENTRY_VALUE uses, use ENTRY_VALUE_EXP macro.
	* dwarf2out.c (mem_loc_descriptor): Use ENTRY_VALUE_EXP macro.
	* cfgexpand.c (expand_debug_expr): If a SSA_NAME without
	partition is a default definition of a PARM_DECL, use ENTRY_VALUE
	of its DECL_INCOMING_RTL if possible, or its DECL_RTL if set.

	* gcc.dg/guality/pr45882.c: New test.

--- gcc/rtl.def.jj	2010-10-29 02:42:25.417404879 +0200
+++ gcc/rtl.def	2010-10-29 04:35:06.418404652 +0200
@@ -718,9 +718,10 @@ DEF_RTL_EXPR(VAR_LOCATION, "var_location
    addressable.  */
 DEF_RTL_EXPR(DEBUG_IMPLICIT_PTR, "debug_implicit_ptr", "t", RTX_OBJ)
 
-/* Represents value that argument had on function entry.  Should
-   be only used in VAR_LOCATION location expression.  */
-DEF_RTL_EXPR(ENTRY_VALUE, "entry_value", "e", RTX_OBJ)
+/* Represents value that argument had on function entry.  The
+   single argument is the DECL_INCOMING_RTL of the corresponding
+   parameter.  */
+DEF_RTL_EXPR(ENTRY_VALUE, "entry_value", "0", RTX_OBJ)
 
 /* All expressions from this point forward appear only in machine
    descriptions.  */
--- gcc/rtl.h.jj	2010-10-12 08:23:50.945247930 +0200
+++ gcc/rtl.h	2010-10-29 04:35:06.419406386 +0200
@@ -833,6 +833,10 @@ extern void rtl_check_failed_flag (const
    but a value from enum reg_note.  */
 #define REG_NOTES(INSN)	XEXP(INSN, 7)
 
+/* In an ENTRY_VALUE this is the DECL_INCOMING_RTL of the argument in
+   question.  */
+#define ENTRY_VALUE_EXP(RTX) (RTL_CHECKC1 (RTX, 0, ENTRY_VALUE).rt_rtx)
+
 enum reg_note
 {
 #define DEF_REG_NOTE(NAME) NAME,
--- gcc/rtl.c.jj	2010-10-12 08:23:50.950407955 +0200
+++ gcc/rtl.c	2010-10-29 04:35:06.426412851 +0200
@@ -411,6 +411,9 @@ rtx_equal_p_cb (const_rtx x, const_rtx y
       return DEBUG_IMPLICIT_PTR_DECL (x)
 	     == DEBUG_IMPLICIT_PTR_DECL (y);
 
+    case ENTRY_VALUE:
+      return rtx_equal_p_cb (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y), cb);
+
     default:
       break;
     }
@@ -535,6 +538,9 @@ rtx_equal_p (const_rtx x, const_rtx y)
       return DEBUG_IMPLICIT_PTR_DECL (x)
 	     == DEBUG_IMPLICIT_PTR_DECL (y);
 
+    case ENTRY_VALUE:
+      return rtx_equal_p (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y));
+
     default:
       break;
     }
--- gcc/cselib.c.jj	2010-09-09 08:42:55.222426928 +0200
+++ gcc/cselib.c	2010-10-29 04:35:06.427414735 +0200
@@ -704,6 +704,9 @@ rtx_equal_for_cselib_p (rtx x, rtx y)
       return DEBUG_IMPLICIT_PTR_DECL (x)
 	     == DEBUG_IMPLICIT_PTR_DECL (y);
 
+    case ENTRY_VALUE:
+      return rtx_equal_for_cselib_p (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y));
+
     case LABEL_REF:
       return XEXP (x, 0) == XEXP (y, 0);
 
@@ -843,6 +846,10 @@ cselib_hash_rtx (rtx x, int create)
 	      + DECL_UID (DEBUG_IMPLICIT_PTR_DECL (x));
       return hash ? hash : (unsigned int) DEBUG_IMPLICIT_PTR;
 
+    case ENTRY_VALUE:
+      hash += cselib_hash_rtx (ENTRY_VALUE_EXP (x), create);
+      return hash ? hash : (unsigned int) ENTRY_VALUE;
+
     case CONST_INT:
       hash += ((unsigned) CONST_INT << 7) + INTVAL (x);
       return hash ? hash : (unsigned int) CONST_INT;
--- gcc/print-rtl.c.jj	2010-10-29 02:42:25.415404492 +0200
+++ gcc/print-rtl.c	2010-10-30 17:52:22.511279808 +0200
@@ -334,6 +334,14 @@ print_rtx (const_rtx in_rtx)
 		     DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
 #endif
 	  }
+	else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
+	  {
+	    indent += 2;
+	    if (!sawclose)
+	      fprintf (outfile, " ");
+	    print_rtx (ENTRY_VALUE_EXP (in_rtx));
+	    indent -= 2;
+	  }
 	break;
 
       case 'e':
--- gcc/gengtype.c.jj	2010-10-29 02:42:25.449385029 +0200
+++ gcc/gengtype.c	2010-10-29 04:35:06.431405459 +0200
@@ -1192,6 +1192,8 @@ adjust_field_rtx_def (type_p t, options_
 		t = symbol_union_tp, subname = "";
 	      else if (i == BARRIER && aindex >= 3)
 		t = scalar_tp, subname = "rt_int";
+	      else if (i == ENTRY_VALUE && aindex == 0)
+		t = rtx_tp, subname = "rt_rtx";
 	      else
 		{
 		  error_at_line (&lexer_line,
--- gcc/var-tracking.c.jj	2010-10-29 02:42:25.431404360 +0200
+++ gcc/var-tracking.c	2010-10-29 04:35:06.435404006 +0200
@@ -8420,7 +8420,8 @@ vt_add_function_parameters (void)
 	      el = (struct elt_loc_list *)
 		   ggc_alloc_cleared_atomic (sizeof (*el));
 	      el->next = val->locs;
-	      el->loc = gen_rtx_ENTRY_VALUE (GET_MODE (incoming), incoming);
+	      el->loc = gen_rtx_ENTRY_VALUE (GET_MODE (incoming));
+	      ENTRY_VALUE_EXP (el->loc) = incoming;
 	      el->setting_insn = get_insns ();
 	      val->locs = el;
 	      if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
@@ -8437,7 +8438,8 @@ vt_add_function_parameters (void)
 		      el = (struct elt_loc_list *)
 			ggc_alloc_cleared_atomic (sizeof (*el));
 		      el->next = val->locs;
-		      el->loc = gen_rtx_ENTRY_VALUE (indmode, mem);
+		      el->loc = gen_rtx_ENTRY_VALUE (indmode);
+		      ENTRY_VALUE_EXP (el->loc) = mem;
 		      el->setting_insn = get_insns ();
 		      val->locs = el;
 		    }
--- gcc/dwarf2out.c.jj	2010-10-29 02:42:25.480405518 +0200
+++ gcc/dwarf2out.c	2010-10-29 21:02:36.961659396 +0200
@@ -13791,14 +13791,14 @@ mem_loc_descriptor (rtx rtl, enum machin
     case ENTRY_VALUE:
       mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
       mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
-      if (REG_P (XEXP (rtl, 0)))
+      if (REG_P (ENTRY_VALUE_EXP (rtl)))
 	mem_loc_result->dw_loc_oprnd1.v.val_loc
-	  = one_reg_loc_descriptor (dbx_reg_number (XEXP (rtl, 0)),
+	  = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
 				    VAR_INIT_STATUS_INITIALIZED);
-      else if (MEM_P (XEXP (rtl, 0)) && REG_P (XEXP (XEXP (rtl, 0), 0)))
+      else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
 	{
 	  dw_loc_descr_ref ref
-	    = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
+	    = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
 				  VAR_INIT_STATUS_INITIALIZED);
 	  if (ref == NULL)
 	    return NULL;
--- gcc/cfgexpand.c.jj	2010-10-12 19:26:47.925248505 +0200
+++ gcc/cfgexpand.c	2010-10-29 04:35:06.452404511 +0200
@@ -3105,7 +3105,31 @@ expand_debug_expr (tree exp)
 	    int part = var_to_partition (SA.map, exp);
 
 	    if (part == NO_PARTITION)
-	      return NULL;
+	      {
+		/* If this is a reference to a incoming value of parameter
+		   that is never used in the code or where the incoming
+		   value is never used in the code, use PARM_DECL's
+		   DECL_RTL if set.  */
+		if (SSA_NAME_IS_DEFAULT_DEF (exp)
+		    && TREE_CODE (SSA_NAME_VAR (exp)) == PARM_DECL)
+		  {
+		    rtx incoming = DECL_INCOMING_RTL (SSA_NAME_VAR (exp));
+		    if (incoming
+			&& GET_MODE (incoming) != BLKmode
+			&& (REG_P (incoming)
+			    || (MEM_P (incoming) && REG_P (XEXP (incoming, 0)))))
+		      {
+			op0 = gen_rtx_ENTRY_VALUE (GET_MODE (incoming));
+			ENTRY_VALUE_EXP (op0) = incoming;
+			goto adjust_mode;
+		      }
+		    op0 = expand_debug_expr (SSA_NAME_VAR (exp));
+		    if (!op0)
+		      return NULL;
+		    goto adjust_mode;
+		  }
+		return NULL;
+	      }
 
 	    gcc_assert (part >= 0 && (unsigned)part < SA.map->num_partitions);
 
--- gcc/testsuite/gcc.dg/guality/pr45882.c.jj	2010-10-29 04:35:06.453404765 +0200
+++ gcc/testsuite/gcc.dg/guality/pr45882.c	2010-10-29 04:35:06.453404765 +0200
@@ -0,0 +1,30 @@
+/* PR debug/45882 */
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+extern void abort (void);
+int a[1024];
+volatile short int v;
+
+__attribute__((noinline)) int
+foo (int i, int j)
+{
+  int b = i;		/* { dg-final { gdb-test 16 "b" "7" } } */
+  int c = i + 4;	/* { dg-final { gdb-test 16 "c" "11" } } */
+  int d = a[i];		/* { dg-final { gdb-test 16 "d" "112" } } */
+  int e = a[i + 6];	/* { dg-final { gdb-test 16 "e" "142" } } */
+  ++v;
+  return ++j;
+}
+
+int
+main (void)
+{
+  int l;
+  asm ("" : "=r" (l) : "0" (7));
+  a[7] = 112;
+  a[7 + 6] = 142;
+  if (foo (l, 7) != 8)
+    abort ();
+  return l - 7;
+}

	Jakub


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