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]

[lto] add interface for dumping TYPE_DECLs


The patch below adds an interface for resolving TYPE_DECLs while writing
LTO objects.  Kenny claims he needs this, but has not yet finished the
code that uses it.  The purpose of this commit is to minimize
synchronization errors when that patch does land.

The patch also features a small cleanup in dwarf2out.c  BLOCKs
occasionally show up as the DECL_CONTEXT of a decl, which the previous
code didn't handle well.  This code doesn't handle it any better (the
problem seems to come and go), but at least the interface is there the
next time it shows up.

Committed to the LTO branch.

-Nathan

gcc/
	* dwarf2out.h (lto_typedecl_ref): Declare.
	* dwarf2out.c (force_die_for_context): New function.
	(force_decl_die): Use it.  Handle TYPE_DECLs.
	(force_type_die): Use it.
	(force_block_die): New function.
	(lto_typedecl_ref): New function.

gcc/lto/
	* lto.h (lto_resolve_typedecl_ref): Declare.
	* lto.c (lto_resolve_typedecl_ref): New function.

Index: gcc/dwarf2out.h
===================================================================
--- gcc/dwarf2out.h	(revision 129580)
+++ gcc/dwarf2out.h	(working copy)
@@ -72,4 +72,8 @@ extern void lto_fn_ref (tree fn, lto_out
 
 /* Upon return, *REF contains a reference to FIELD, which must be a
    FIELD_DECL.  */
-extern void lto_field_ref (tree fn, lto_out_ref *ref);
+extern void lto_field_ref (tree field, lto_out_ref *ref);
+
+/* Upon return, *REF contains a reference to TDECL, which must be a
+   TYPE_DECL.  */
+extern void lto_typedecl_ref (tree tdecl, lto_out_ref *ref);
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revision 129580)
+++ gcc/dwarf2out.c	(working copy)
@@ -4308,6 +4308,8 @@ static void decls_for_scope (tree, dw_di
 static int is_redundant_typedef (const_tree);
 static void gen_namespace_die (tree);
 static void gen_decl_die (tree, dw_die_ref);
+static dw_die_ref force_die_for_context (tree);
+static dw_die_ref force_block_die (tree);
 static dw_die_ref force_decl_die (tree);
 static dw_die_ref force_type_die (tree);
 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
@@ -13452,6 +13454,31 @@ is_redundant_typedef (const_tree decl)
   return 0;
 }
 
+/* Returns the context DIE for CONTEXT.  A DIE will always be returned.  */
+
+static dw_die_ref
+force_die_for_context (tree context)
+{
+  if (!context)
+    return comp_unit_die;
+  if (TYPE_P (context))
+    return force_type_die (context);
+  if (DECL_P (context))
+    return force_decl_die (context);
+  if (TREE_CODE (context) == BLOCK)
+    return force_block_die (context);
+
+  gcc_unreachable ();
+}
+
+/* Returns the DIE for block.  A DIE will always be returned.  */
+
+static dw_die_ref
+force_block_die (tree block)
+{
+  gcc_unreachable ();
+}
+
 /* Returns the DIE for decl.  A DIE will always be returned.  */
 
 static dw_die_ref
@@ -13463,18 +13490,8 @@ force_decl_die (tree decl)
   decl_die = lookup_decl_die (decl);
   if (!decl_die)
     {
-      dw_die_ref context_die;
       tree decl_context = DECL_CONTEXT (decl);
-      if (decl_context)
-	{
-	  /* Find die that represents this context.  */
-	  if (TYPE_P (decl_context))
-	    context_die = force_type_die (decl_context);
-	  else
-	    context_die = force_decl_die (decl_context);
-	}
-      else
-	context_die = comp_unit_die;
+      dw_die_ref context_die = force_die_for_context (decl_context);
 
       decl_die = lookup_decl_die (decl);
       if (decl_die)
@@ -13501,6 +13518,7 @@ force_decl_die (tree decl)
 	  DECL_EXTERNAL (decl) = saved_external_flag;
 	  break;
 
+	case TYPE_DECL:
 	case NAMESPACE_DECL:
 	  dwarf2out_decl (decl);
 	  break;
@@ -13529,16 +13547,7 @@ force_type_die (tree type)
   type_die = lookup_type_die (type);
   if (!type_die)
     {
-      dw_die_ref context_die;
-      if (TYPE_CONTEXT (type))
-	{
-	  if (TYPE_P (TYPE_CONTEXT (type)))
-	    context_die = force_type_die (TYPE_CONTEXT (type));
-	  else
-	    context_die = force_decl_die (TYPE_CONTEXT (type));
-	}
-      else
-	context_die = comp_unit_die;
+      dw_die_ref context_die = force_die_for_context (TYPE_CONTEXT (type));
 
       type_die = lookup_type_die (type);
       if (type_die)
@@ -15144,6 +15153,19 @@ lto_field_ref (tree field,
   lto_init_ref (ref, die, DECL_CONTEXT (field));
 }
 
+void
+lto_typedecl_ref (tree decl, lto_out_ref *ref)
+{
+  dw_die_ref die;
+
+  gcc_assert (TREE_CODE (decl) == TYPE_DECL);
+
+  /* Generate the DIE for DECL.  */
+  die = force_decl_die (decl);
+  /* Construct the reference.  */
+  lto_init_ref (ref, die, DECL_CONTEXT (decl));
+}
+
 #else
 
 /* This should never be used, but its address is needed for comparisons.  */
Index: gcc/lto/lto.h
===================================================================
--- gcc/lto/lto.h	(revision 129580)
+++ gcc/lto/lto.h	(working copy)
@@ -166,6 +166,11 @@ extern tree lto_resolve_field_ref (lto_i
 				lto_context *context,
 				const lto_ref *ref);
 
+/* Return the TYPE_DECL referred to by REF.  */
+extern tree lto_resolve_typedecl_ref (lto_info_fd *info_fd,
+                                      lto_context *context,
+                                      const lto_ref *ref);
+
 /* lto-elf.c */
 
 /* Open the ELF input file indicated by FILENAME.  Return */
Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c	(revision 129730)
+++ gcc/lto/lto.c	(working copy)
@@ -3543,6 +3543,32 @@ lto_resolve_field_ref (lto_info_fd *info
   return field;
 }
 
+tree 
+lto_resolve_typedecl_ref (lto_info_fd *info_fd,
+			  lto_context *context,
+			  const lto_ref *ref)
+{
+  lto_die_ptr die;
+  lto_context *new_context = context;
+  tree decl;
+
+  /* At present, we only support a single DWARF section.  */
+  if (ref->section != 0)
+    lto_abi_mismatch_error ();
+  /* Map REF to a DIE.  */
+  die = lto_resolve_reference (info_fd, ref->offset, context, &new_context);
+  /* Map DIE to a decl.  */
+  decl = lto_read_DIE_at_ptr (info_fd, context, die);
+  if (!decl || TREE_CODE (decl) != TYPE_DECL)
+    lto_file_corrupt_error ((lto_fd *)info_fd);
+
+  /* Clean up.  */
+  if (new_context != context)
+    XDELETE (new_context);
+
+  return decl;
+}
+
 void
 lto_main (int debug_p ATTRIBUTE_UNUSED)
 {


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