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]

Re: [lto] PATCH: Add support for referencing types from function bodies


Kenneth Zadeck wrote:

2006-09-03 Mark Mitchell <mark@codesourcery.com>

	* gcc/tree.h (SYMTAB_DIE): Remove reference to SDB format in
	comments.
	* gcc/dwarf2out.c (assign_symbol_name): New function.
	(assign_symbol_names): Use it.
	(lto_init_ref): New function.
	(lto_type_ref): Likewise.
	(lto_var_ref): Likewise.
	(lto_fn_ref): Likewise.
	* gcc/dwarf2out.h (lto_out_ref): New structure.
	(lto_type_ref): Declare.
	(lto_var_ref): Likewise.
	(lto_fn_ref): Likewise.

I do not see any of this code in the posted patch.

Indeed. I'm not sure what happened there; I've attached the code. Sorry!


And what about field_decls and const_decls (at least for the ones in
enums)?  Seems like I need an interface to access these?

Yes, you will need FIELD_DECLs. But, you would need RECORD_TYPEs first, and we can't read those in yet. :-)


I don't think we should bother with CONST_DECLs. The only purpose of a CONST_DECL is to provide a name for a value. But, we don't need that for optimization; all you need is to know the integral value and its type. Using an INTEGER_CST with the appropriate type will use less memory in the LTO front end.

In fact, I think that GIMPLE should not use CONST_DECLs, for the same reason; CONST_DECLs should be replaced by their equivalent INTEGER_CSTs during gimplificiation.

Also is the purpose of the section, so that you can link several .o
files together without merging the type sections.  I assume that each
lto_out_ref will be assembled into a 64 bit
value, 32 bits for the section number and 32 bits for the offset within
the section.  Or do these things need to be bigger for a 64 bit machine?

The purpose of the section value is that there will likely eventually be multiple DWARF sections. We know that for C++, we must generate separate DWARF sections for COMDAT groups in order to (a) get smaller program imagines, and (b) avoid some of the non-standard linker processing we currently perform. So, the section index will tell us where to look to find the DWARF information.


I don't think the values for the section index need to be more than 32 bits. There are not going to be more section indices than there are functions in an object file, so unless we're planning on having object files with 4 billion functions, we're OK. The offset should probably be a 64-bit value to accommodate large files. However, there's no reason that the number of bits needs to be consistent across all targets, or that we can't change it in the future. (Of course, it does need to be consistent across all *hosts* for a given target.) Given that the plan is to represent function bodies with something very gimplish, rather than going for a compiler-independent format, every revision of the compiler is presumably going to invalidate all LTO information generated with previous compilers, so you can adjust the widths as need be.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
Index: tree.h
===================================================================
--- tree.h	(revision 116334)
+++ tree.h	(working copy)
@@ -1160,7 +1160,7 @@ extern void omp_clause_range_check_faile
    This is interesting in an inline function, since it might not need
    to be compiled separately.
    Nonzero in a RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
-   if the sdb debugging info for the type has been written.
+   if the debugging info for the type has been written.
    In a BLOCK node, nonzero if reorder_blocks has already seen this block.
    In an SSA_NAME node, nonzero if the SSA_NAME occurs in an abnormal
    PHI node.  */
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 116334)
+++ dwarf2out.c	(working copy)
@@ -6232,6 +6232,27 @@ gen_internal_sym (const char *prefix)
   return xstrdup (buf);
 }
 
+/* Mark DIE as requiring an assembly label of its own.  Upon return,
+   DIE_SYMBOL will be set to the label that will be used for this
+   purpose.  */
+static void
+assign_symbol_name (dw_die_ref die)
+{
+  if (die->die_symbol)
+    return;
+
+  if (comdat_symbol_id)
+    {
+      char *p = alloca (strlen (comdat_symbol_id) + 64);
+
+      sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
+	       comdat_symbol_id, comdat_symbol_number++);
+      die->die_symbol = xstrdup (p);
+    }
+  else
+    die->die_symbol = gen_internal_sym ("LDIE");
+}
+
 /* Assign symbols to all worthy DIEs under DIE.  */
 
 static void
@@ -6240,18 +6261,7 @@ assign_symbol_names (dw_die_ref die)
   dw_die_ref c;
 
   if (is_symbol_die (die))
-    {
-      if (comdat_symbol_id)
-	{
-	  char *p = alloca (strlen (comdat_symbol_id) + 64);
-
-	  sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
-		   comdat_symbol_id, comdat_symbol_number++);
-	  die->die_symbol = xstrdup (p);
-	}
-      else
-	die->die_symbol = gen_internal_sym ("LDIE");
-    }
+    assign_symbol_name (die);
 
   FOR_EACH_CHILD (die, c, assign_symbol_names (c));
 }
@@ -14310,6 +14320,75 @@ dwarf2out_finish (const char *filename)
   if (debug_str_hash)
     htab_traverse (debug_str_hash, output_indirect_string, NULL);
 }
+
+/* Initialize REF.  SCOPE indicates the lexical scope containing the
+   entity being referenced.  */
+static void
+lto_init_ref (tree scope ATTRIBUTE_UNUSED, 
+	      lto_out_ref *ref)
+{
+  /* At present, we use only one DWARF section.  When we begin using
+     multiple sections, SCOPE will be used to figure out the section
+     and corresponding BASE_LABEL.  */
+  ref->section = 0;
+  ref->base_label = ".debug_info";
+  ref->label = NULL;
+}
+
+void 
+lto_type_ref (tree type, lto_out_ref *ref)
+{
+  dw_die_ref die;
+  tree scope;
+  dw_die_ref scope_die;
+
+  gcc_assert (TYPE_P (type));
+
+  /* Check to see if we already have a DIE.  */
+  die = lookup_type_die (type);
+  /* Create the DIE, if it does not already exist.  */
+  if (!die)
+    {
+      scope = TYPE_CONTEXT (type);
+      if (scope)
+	{
+	  /* We do not yet support lexically scoped types.  */
+	  sorry ("nested types are not supported by LTO");
+	  scope_die = NULL;
+	}
+      else
+	scope_die = comp_unit_die;
+      gen_type_die (type, scope_die);
+      die = lookup_type_die (type);
+    }
+  gcc_assert (die);
+  /* Make sure the DIE has a label.  */
+  assign_symbol_name (die);
+  /* Construct the reference.  */
+  lto_init_ref (scope, ref);
+  ref->label = die->die_symbol;
+
+  return;
+}
+
+void 
+lto_var_ref (tree var ATTRIBUTE_UNUSED, 
+	     lto_out_ref *ref ATTRIBUTE_UNUSED)
+{
+  gcc_assert (TREE_CODE (var) == VAR_DECL);
+  /* Not yet implemented.  */
+  abort ();
+}
+
+void 
+lto_fn_ref (tree fn ATTRIBUTE_UNUSED, 
+	    lto_out_ref *ref ATTRIBUTE_UNUSED)
+{
+  gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
+  /* Not yet implemented.  */
+  abort ();
+}
+
 #else
 
 /* This should never be used, but its address is needed for comparisons.  */
Index: dwarf2out.h
===================================================================
--- dwarf2out.h	(revision 116334)
+++ dwarf2out.h	(working copy)
@@ -26,3 +26,44 @@ extern void debug_dwarf (void);
 struct die_struct;
 extern void debug_dwarf_die (struct die_struct *);
 extern void dwarf2out_set_demangle_name_func (const char *(*) (const char *));
+
+/* The LTO representations for the bodies of functions may refer to
+   the LTO representations of global functions, variables, and
+   types.
+
+   Because LTO operates on relocatable object files, using an ordinary
+   label would require that the link-time optimizer perform much of
+   the relocation processing normally performed by a linker.
+   Therefore, the references used are pairs of the form (SECTION,
+   OFFSET).
+
+   The functions below indicate the OFFSET by using two labels.  The
+   caller is responsible for emitting the offset as the difference
+   between these two labels.  The labels are guaranteed to be in the
+   same section.  The functions lto_{type,var,fn}_ref in the LTO front
+   end are used to resolve these references in the LTO front end.  */
+
+/* A reference to a global entity.  */
+typedef struct lto_out_ref {
+  /* The index of the compilation unit containing the entity.  */
+  unsigned section;
+  /* The label corresponding to the base of the DWARF 2 section
+     containing this entity.  This string must not be freed by the
+     caller.  */
+  const char *base_label;
+  /* The label for the entity itself.  This string must not be freed
+     by the caller.  */
+  const char *label;
+} lto_out_ref;
+
+/* Upon return, *REF contains a reference to TYPE, which must be a
+   TYPE.  */
+extern void lto_type_ref (tree type, lto_out_ref *ref);
+
+/* Upon return, *REF contains a reference to VAR, which must be a
+   VAR_DECL.  */
+extern void lto_var_ref (tree var, lto_out_ref *ref);
+
+/* Upon return, *REF contains a reference to FN, which must be a
+   FUNCTION_DECL.  */
+extern void lto_fn_ref (tree fn, lto_out_ref *ref);

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