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] PATCH: Serialization of variable initializers


Kenny --

As you and I discussed by phone, it's probably an easier path forward
for variable initializers to leverage your tree-serialization code
than to try to decode the initializer as represented in ELF (a
combination of static data and relocations).  (I like the idea of
using the ELF data because it avoids redundancy, but, hey, if it's
such a great idea we can always come back to it later -- and it's
probably not that great an idea.)

So, as we discussed, I've used an interface similar to what we did for
function bodies.  The parts that you'll need to fill in:

(1) In lto_output, walk the varpool, writing out DECL_INITIAL for
    variables that have it, in the same way that you present walk the
    call graph and write out function bodies.

(2) In lto_read_var_init, reconsitute the data that you wrote out.

Please let me know if you need help with either chunk of that.

Committed.

Thanks,

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2007-08-05  Mark Mitchell  <mark@codesourcery.com>

	* lto.h (lto_file_vtable): Remove read_var_init.  Add map_var_init
	and unmap_var_init.
	(lto_read_var_init): Declare.
	* lto.c (lto_read_variable_formal_parameter_constant_DIE): Use new
	interface for reading variable initializers.
	* lto-elf.c (lto_elf_read_var_init): Remove.
	(lto_elf_file_vtable): Update initializer.
	(lto_elf_read_var_init): Add comment about unused-ness.
	* lto-read.c (lto_read_var_init): New.

Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c	(revision 127229)
+++ gcc/lto/lto.c	(working copy)
@@ -2039,8 +2039,15 @@ lto_read_variable_formal_parameter_const
 	  /* If there is an initializer, read it now.  */
 	  if (!declaration)
 	    {
-	      lto_file *file = fd->base.file;
-	      file->vtable->read_var_init (file, decl);
+	      const void *init;
+	      lto_file *file;
+	      const char *name_str;
+
+	      name_str = IDENTIFIER_POINTER (asm_name);
+	      file = fd->base.file;
+	      init = file->vtable->map_var_init (file, name_str);
+	      lto_read_var_init (fd, context, decl, init);
+	      file->vtable->unmap_var_init (file, name_str, init);
 	    }
 	  /* If this variable has already been declared, merge the
 	     declarations.  */
Index: gcc/lto/lto-elf.c
===================================================================
--- gcc/lto/lto-elf.c	(revision 127226)
+++ gcc/lto/lto-elf.c	(working copy)
@@ -65,14 +65,12 @@ lto_elf_map_fn_body (lto_file *file, con
 static void
 lto_elf_unmap_fn_body (lto_file *file, const char *fn, const void *data);
 
-static void
-lto_elf_read_var_init (lto_file *file, tree var);
-
 /* The vtable for ELF input files.  */
 static const lto_file_vtable lto_elf_file_vtable = {
   lto_elf_map_fn_body,
   lto_elf_unmap_fn_body,
-  lto_elf_read_var_init
+  lto_elf_map_fn_body,
+  lto_elf_unmap_fn_body
 };
 
 /* Return the section header for SECTION.  The return value is never
@@ -502,7 +500,12 @@ lto_elf_build_init (lto_elf_file *elf_fi
   return init;
 }
 
-void
+/* Read the initializer for VAR from FILE, reconsitituing it from the
+   initializer and relocation information in the object file.  This
+   function is not presently used; instead we are reading in
+   serialized trees.  If this function remains unused, it should be
+   removed before mering LTO into mainline.  */
+static void
 lto_elf_read_var_init (lto_file *file,
 		       tree var)
 {
Index: gcc/lto/lto.h
===================================================================
--- gcc/lto/lto.h	(revision 127226)
+++ gcc/lto/lto.h	(working copy)
@@ -89,9 +89,13 @@ typedef struct lto_file_vtable
      MAP_FN_BODY, with the same value of FN.  Release any resources
      allocated by MAP_FN_BODY.  */
   void (*unmap_fn_body)(lto_file *file, const char *fn, const void *data);
-  /* VAR is an initialized variable.  Set DECL_INITIAL for VAR to the
-     appropriate initializer.  */
-  void (*read_var_init)(lto_file *file, tree var);
+  /* Return the address of the variable-initializer data for the function
+     named VAR, or NULL if the data is not available.  */
+  const void *(*map_var_init)(lto_file *file, const char *var);
+  /* DATA is the non-NULL address returned by a previous call to
+     MAP_VAR_INIT, with the same value of VAR.  Release any resources
+     allocated by MAP_VAR_INIT.  */
+  void (*unmap_var_init)(lto_file *file, const char *var, const void *data);
 } lto_file_vtable;
 
 /* An input file.  */
@@ -178,6 +182,19 @@ lto_read_function_body (lto_info_fd *fd,
 			tree fn,
 			const void *data);
 
+/* VAR is a VAR_DECL.  DATA is the LTO data written out during
+   ordinary compilation, encoding the initializer for VAR.  FD and
+   CONTEXT are as for lto_read_function_body.  Upon return,
+   DECL_INITIAL for VAR contains the reconsitituted initializer for
+   VAR.  However, it is not this function's responsibility to provide
+   VAR to the optimizers or code-generators; that will be done by the
+   caller.  */
+extern void
+lto_read_var_init (lto_info_fd *fd,
+		   lto_context *context,
+		   tree var,
+		   const void *data);
+
 /* lto-symtab.c */
 
 /* The NEW_VAR (a VAR_DECL) has just been read.  If there is an
Index: gcc/lto/lto-read.c
===================================================================
--- gcc/lto/lto-read.c	(revision 127226)
+++ gcc/lto/lto-read.c	(working copy)
@@ -1536,6 +1536,13 @@ lto_read_function_body (lto_info_fd *fd,
   input_function (fn_decl, &fun_in, &ib_main);
 }
 
+void 
+lto_read_var_init (lto_info_fd *fd,
+		   lto_context *context,
+		   tree var_decl,
+		   const void *data)
+{
+}
 
 /* Dump the debug STREAM, and two characters B and C.  */
 


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