public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [debug-early] reuse variable DIEs and fix their context
@ 2014-08-27  2:43 Aldy Hernandez
  2014-08-28 13:58 ` Richard Biener
  0 siblings, 1 reply; 40+ messages in thread
From: Aldy Hernandez @ 2014-08-27  2:43 UTC (permalink / raw)
  To: gcc-patches

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

This patch fixes a bunch of guality failures.  With it I get 144 
guality.exp failures vs. 163 for "make check-gcc 
RUNTESTFLAGS=guality.exp".  A lot better than 100% fail rate ;-).

Variable DIEs were not being reused.  Instead, variable DIEs even had 
the wrong context (unilaterally the compilation unit).  The attached 
patch reuses variable DIEs that have been outputted earlier.  It also 
fixes the context by correcting the context on the second round.

I have also added a bit field to the DIE structure to record if a DIE 
has been generated early.

Again, this is all a rough draft, but feel free to comment.

Committed to branch.
Aldy

[-- Attachment #2: curr --]
[-- Type: text/plain, Size: 9548 bytes --]

commit 71d99991672200b6bcfe258ae0bfe92ea59af3ea
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Aug 26 19:12:17 2014 -0700

    	* dwarf2out.c (struct die_struct): Add dumped_early field.
    	(reparent_child): New.
    	(splice_child_die): Use reparent_child.
    	(gen_subprogram_die): Do not regenerate parameters if previously
    	dumped.
    	(gen_variable_die): Fix parent of decls that have been dumped
    	early to reflect correct context.
    	Do not regenerate decls if previously dumped.
    	(dwarf2out_decl): Add return value.
    	(dwarf2out_early_decl): Set dumped_early bit.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 0aa4456..32c17ce 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -102,7 +102,7 @@ along with GCC; see the file COPYING3.  If not see
 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
 static rtx_insn *last_var_location_insn;
 static rtx_insn *cached_next_real_insn;
-static void dwarf2out_decl (tree);
+static dw_die_ref dwarf2out_decl (tree);
 
 #ifdef VMS_DEBUGGING_INFO
 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
@@ -2608,6 +2608,8 @@ typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
   /* Die is used and must not be pruned as unused.  */
   BOOL_BITFIELD die_perennial_p : 1;
   BOOL_BITFIELD comdat_type_p : 1; /* DIE has a type signature */
+  /* Die was generated early via dwarf2out_early_decl.  */
+  BOOL_BITFIELD dumped_early : 1;
   /* Lots of spare bits.  */
 }
 die_node;
@@ -4808,6 +4810,21 @@ add_child_die (dw_die_ref die, dw_die_ref child_die)
   die->die_child = child_die;
 }
 
+/* Unassociate CHILD from its parent, and make its parent be
+   NEW_PARENT.  */
+
+static void
+reparent_child (dw_die_ref child, dw_die_ref new_parent)
+{
+  for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
+    if (p->die_sib == child)
+      {
+	remove_child_with_prev (child, p);
+	break;
+      }
+  add_child_die (new_parent, child);
+}
+
 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
    is the specification, to the end of PARENT's list of children.
    This is done by removing and re-adding it.  */
@@ -4815,8 +4832,6 @@ add_child_die (dw_die_ref die, dw_die_ref child_die)
 static void
 splice_child_die (dw_die_ref parent, dw_die_ref child)
 {
-  dw_die_ref p;
-
   /* We want the declaration DIE from inside the class, not the
      specification DIE at toplevel.  */
   if (child->die_parent != parent)
@@ -4831,14 +4846,7 @@ splice_child_die (dw_die_ref parent, dw_die_ref child)
 	      || (child->die_parent
 		  == get_AT_ref (parent, DW_AT_specification)));
 
-  for (p = child->die_parent->die_child; ; p = p->die_sib)
-    if (p->die_sib == child)
-      {
-	remove_child_with_prev (child, p);
-	break;
-      }
-
-  add_child_die (parent, child);
+  reparent_child (child, parent);
 }
 
 /* Return a pointer to a newly created DIE node.  */
@@ -18288,16 +18296,17 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 	  /* ??? Hmmm, early dwarf generation happened earlier, so no
 	     sense in removing the parameters.  Let's keep them and
 	     augment them with location information later.  */
-#if 0
-	  /* Clear out the declaration attribute and the formal parameters.
-	     Do not remove all children, because it is possible that this
-	     declaration die was forced using force_decl_die(). In such
-	     cases die that forced declaration die (e.g. TAG_imported_module)
-	     is one of the children that we do not want to remove.  */
-	  remove_AT (subr_die, DW_AT_declaration);
-	  remove_AT (subr_die, DW_AT_object_pointer);
-	  remove_child_TAG (subr_die, DW_TAG_formal_parameter);
-#endif
+	  if (!old_die->dumped_early)
+	    {
+	      /* Clear out the declaration attribute and the formal parameters.
+		 Do not remove all children, because it is possible that this
+		 declaration die was forced using force_decl_die(). In such
+		 cases die that forced declaration die (e.g. TAG_imported_module)
+		 is one of the children that we do not want to remove.  */
+	      remove_AT (subr_die, DW_AT_declaration);
+	      remove_AT (subr_die, DW_AT_object_pointer);
+	      remove_child_TAG (subr_die, DW_TAG_formal_parameter);
+	    }
 	}
       else
 	{
@@ -18998,6 +19007,18 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
   if (old_die && !declaration && !local_scope_p (context_die))
     return;
 
+  /* When DIEs are created early, the context is the compilation unit.
+     Adjust the context when we know what it is the second time
+     around.  */
+  if (old_die && old_die->dumped_early)
+    {
+      if (old_die->die_parent != context_die)
+	reparent_child (old_die, context_die);
+      var_die = old_die;
+      old_die = NULL;
+      goto gen_variable_die_location;
+    }
+
   /* For static data members, the declaration in the class is supposed
      to have DW_TAG_member tag; the specification should still be
      DW_TAG_variable referencing the DW_TAG_member DIE.  */
@@ -19081,6 +19102,7 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
   if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
     equate_decl_number_to_die (decl, var_die);
 
+ gen_variable_die_location:
   if (! declaration
       && (! DECL_ABSTRACT (decl_or_origin)
 	  /* Local static vars are shared between all clones/inlines,
@@ -20988,9 +21010,9 @@ gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
 }
 
 
-/* Write the debugging output for DECL.  */
+/* Write the debugging output for DECL and return the DIE.  */
 
-static void
+static dw_die_ref
 dwarf2out_decl (tree decl)
 {
   dw_die_ref context_die = comp_unit_die ();
@@ -20998,7 +21020,7 @@ dwarf2out_decl (tree decl)
   switch (TREE_CODE (decl))
     {
     case ERROR_MARK:
-      return;
+      return NULL;
 
     case FUNCTION_DECL:
       /* What we would really like to do here is to filter out all mere
@@ -21035,7 +21057,7 @@ dwarf2out_decl (tree decl)
 	 or not at all.  */
       if (DECL_INITIAL (decl) == NULL_TREE
 	  && ! DECL_ABSTRACT (decl))
-	return;
+	return NULL;
 
       /* If we're a nested function, initially use a parent of NULL; if we're
 	 a plain function, this will be fixed up in decls_for_scope.  If
@@ -21056,7 +21078,7 @@ dwarf2out_decl (tree decl)
 	 would screw-up the debugger's name lookup mechanism and cause it to
 	 miss things which really ought to be in scope at a given point.  */
       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
-	return;
+	return NULL;
 
       /* For local statics lookup proper context die.  */
       if (TREE_STATIC (decl)
@@ -21067,14 +21089,14 @@ dwarf2out_decl (tree decl)
       /* If we are in terse mode, don't generate any DIEs to represent any
 	 variable declarations or definitions.  */
       if (debug_info_level <= DINFO_LEVEL_TERSE)
-	return;
+	return NULL;
       break;
 
     case CONST_DECL:
       if (debug_info_level <= DINFO_LEVEL_TERSE)
-	return;
+	return NULL;
       if (!is_fortran () && !is_ada ())
-	return;
+	return NULL;
       if (TREE_STATIC (decl) && decl_function_context (decl))
 	context_die = lookup_decl_die (DECL_CONTEXT (decl));
       break;
@@ -21082,24 +21104,24 @@ dwarf2out_decl (tree decl)
     case NAMESPACE_DECL:
     case IMPORTED_DECL:
       if (debug_info_level <= DINFO_LEVEL_TERSE)
-	return;
+	return NULL;
       if (lookup_decl_die (decl) != NULL)
-	return;
+	return NULL;
       break;
 
     case TYPE_DECL:
       /* Don't emit stubs for types unless they are needed by other DIEs.  */
       if (TYPE_DECL_SUPPRESS_DEBUG (decl))
-	return;
+	return NULL;
 
       /* Don't bother trying to generate any DIEs to represent any of the
 	 normal built-in types for the language we are compiling.  */
       if (DECL_IS_BUILTIN (decl))
-	return;
+	return NULL;
 
       /* If we are in terse mode, don't generate any DIEs for types.  */
       if (debug_info_level <= DINFO_LEVEL_TERSE)
-	return;
+	return NULL;
 
       /* If we're a function-scope tag, initially use a parent of NULL;
 	 this will be fixed up in decls_for_scope.  */
@@ -21112,7 +21134,7 @@ dwarf2out_decl (tree decl)
       break;
 
     default:
-      return;
+      return NULL;
     }
 
   gen_decl_die (decl, NULL, context_die);
@@ -21120,6 +21142,7 @@ dwarf2out_decl (tree decl)
   dw_die_ref die = lookup_decl_die (decl);
   if (die)
     check_die (die, 0);
+  return die;
 }
 
 /* Early dumping of DECLs before we lose language data.  */
@@ -21135,8 +21158,8 @@ dwarf2out_early_decl (tree decl)
      cgraph information, causing cgraph_function_possibly_inlined_p()
      to return true.  Trick cgraph_function_possibly_inlined_p()
      while we generate dwarf early.  */
-  bool save = cgraph_global_info_ready;
-  cgraph_global_info_ready = true;
+  bool save = symtab->global_info_ready;
+  symtab->global_info_ready = true;
 
   /* We don't handle TYPE_DECLs.  If required, they'll be reached via
      other DECLs and they can point to template types or other things
@@ -21154,7 +21177,9 @@ dwarf2out_early_decl (tree decl)
 	  push_cfun (DECL_STRUCT_FUNCTION (decl));
 	  current_function_decl = decl;
 	}
-      dwarf2out_decl (decl);
+      dw_die_ref die = dwarf2out_decl (decl);
+      if (die)
+	die->dumped_early = true;
       if (TREE_CODE (decl) == FUNCTION_DECL)
 	{
 	  pop_cfun ();
@@ -21162,7 +21187,7 @@ dwarf2out_early_decl (tree decl)
 	}
     }
  early_decl_exit:
-  cgraph_global_info_ready = save;
+  symtab->global_info_ready = save;
   return;
 }
 

^ permalink raw reply	[flat|nested] 40+ messages in thread
* Re: [debug-early] reuse variable DIEs and fix their context
@ 2015-01-08 15:20 Aldy Hernandez
  0 siblings, 0 replies; 40+ messages in thread
From: Aldy Hernandez @ 2015-01-08 15:20 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, Jan Hubicka, Jason Merrill

Jason suggested keeping it in the branch since it doesn't fix any regressions, so it's living there for now.

AldyOn Jan 8, 2015 4:24 AM, Richard Biener <richard.guenther@gmail.com> wrote:
>
> On Sat, Dec 20, 2014 at 5:49 AM, Aldy Hernandez <aldyh@redhat.com> wrote: 
> > On 12/19/14 11:03, Jason Merrill wrote: 
> > 
> > First of all, my bad Richard.  I vaguely remember you mentioning something 
> > about Java, but it was early enough in the project that I had no idea what 
> > you were talking about.  Thanks for your patience. 
> > 
> >> It looks like java aliases are still using assemble_alias directly; 
> >> switching to using same_body aliases like thunks and such should handle 
> >> the issue. 
> > 
> > 
> > Ah, I see.  Attached is a patch against _MAINLINE_ that fixes the issue I am 
> > seeing, without introducing any regressions. 
>
> Well, I think it's a bit late now (but only affects Java, so...).  Jasons call. 
>
> > Would it be crazy to ask for permission to commit this into mainline, and 
> > avoiding dragging this along on the branch?  If not, I have a similar patch 
> > for the branch I can commit there. 
> > 
> > Let me know. 
>
> Thanks for fixing this! 
> Richard. 
>
> > Thanks for everyone's input. 
> > Aldy 

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2015-01-08 15:20 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27  2:43 [debug-early] reuse variable DIEs and fix their context Aldy Hernandez
2014-08-28 13:58 ` Richard Biener
2014-08-28 17:35   ` Aldy Hernandez
2014-08-28 18:01     ` Jason Merrill
2014-08-28 19:13       ` Richard Biener
2014-08-28 20:14         ` Jason Merrill
2014-08-29  9:09           ` Richard Biener
2014-09-03 17:55       ` Aldy Hernandez
2014-09-04 10:42         ` Richard Biener
2014-09-05  2:38           ` Aldy Hernandez
2014-09-05  9:00             ` Richard Biener
2014-09-09  0:01               ` Aldy Hernandez
2014-09-09  9:16                 ` Richard Biener
2014-09-12  0:51                   ` Aldy Hernandez
2014-09-12  8:13                     ` Richard Biener
2014-09-12 15:15                     ` Jason Merrill
2014-09-12 17:11                       ` Aldy Hernandez
2014-09-12 17:33                         ` Jason Merrill
2014-09-12 17:48                           ` Aldy Hernandez
2014-09-12 17:56                             ` Jason Merrill
2014-09-16 15:49                               ` Aldy Hernandez
2014-09-15  9:32                         ` Richard Biener
2014-09-15 18:46                           ` Jason Merrill
2014-12-18 19:26                       ` Aldy Hernandez
2014-12-19 11:20                         ` Richard Biener
2014-12-19 18:58                           ` Jan Hubicka
2014-12-19 19:01                             ` Jan Hubicka
2014-12-19 19:02                               ` Aldy Hernandez
2014-12-19 19:31                                 ` Jason Merrill
2014-12-19 19:50                                   ` Jan Hubicka
2014-12-20 10:09                                   ` Aldy Hernandez
2015-01-08 12:24                                     ` Richard Biener
2014-12-19 19:03                             ` Aldy Hernandez
2014-09-04 17:53         ` H.J. Lu
2014-09-04 17:54           ` Aldy Hernandez
2014-09-04 18:23             ` Richard Biener
2014-09-04 18:35               ` Aldy Hernandez
2014-09-04 18:38                 ` Christophe Lyon
2014-09-04 19:42                 ` Jan-Benedict Glaw
2015-01-08 15:20 Aldy Hernandez

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).