[lto] Emit location information for statements

Diego Novillo dnovillo@google.com
Fri May 15 21:10:00 GMT 2009


As referenced in my previous message
(http://gcc.gnu.org/ml/gcc-patches/2009-05/msg00927.html), this
patch emits location information for statements in gimple files.

Tested on x86_64.


Diego.



	* lto-function-out.c (output_stmt_location): New.
	(output_gimple_stmt): Call it.
	* lto-function-in.c (input_stmt_location): New.
	(input_gimple_stmt): Call it.

Index: lto-function-out.c
===================================================================
--- lto-function-out.c	(revision 147590)
+++ lto-function-out.c	(working copy)
@@ -1629,6 +1629,30 @@ output_phi (struct output_block *ob, gim
 }
 
 
+/* Emit the location of STMT to outpub block OB.  */
+
+static void
+output_stmt_location (struct output_block *ob, gimple stmt)
+{
+  expanded_location xloc;
+
+  xloc = expand_location (gimple_location (stmt));
+  if (xloc.file == NULL)
+    {
+      output_string (ob, ob->main_stream, xloc.file);
+      return;
+    }
+
+  output_string (ob, ob->main_stream, xloc.file);
+  output_sleb128 (ob, xloc.line);
+  output_sleb128 (ob, xloc.column);
+
+  ob->current_file = file;
+  ob->current_line = line;
+  ob->current_col = column;
+}
+
+
 /* Emit statement STMT on the main stream of output block OB.  */
 
 static void
@@ -1648,6 +1672,9 @@ output_gimple_stmt (struct output_block 
   /* Emit the number of operands in the statement.  */
   lto_output_uleb128_stream (ob->main_stream, gimple_num_ops (stmt));
 
+  /* Emit location information for the statement.  */
+  output_stmt_location (ob, stmt);
+
   /* Emit the tuple header.  FIXME lto.  This is emitting fields that are not
      necessary to emit (e.g., gimple_statement_base.bb,
      gimple_statement_base.block).  */
Index: lto-function-in.c
===================================================================
--- lto-function-in.c	(revision 147590)
+++ lto-function-in.c	(working copy)
@@ -1680,6 +1680,51 @@ input_ssa_names (struct lto_input_block 
 }
 
 
+/* Read location information from input block IB using the descriptors
+   in DATA_IN.  */
+
+static location_t
+input_stmt_location (struct lto_input_block *ib, struct data_in *data_in)
+{
+  location_t loc;
+  const char *file;
+  HOST_WIDE_INT line, column;
+
+  file = input_string (data_in, ib);
+  line = lto_input_sleb128 (ib);
+  column = lto_input_sleb128 (ib);
+
+  if (file)
+    {
+      if (data_in->current_file)
+	linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+
+      data_in->current_file = canon_file_name (file);
+    }
+
+  if (line != data_in->current_line)
+    {
+      data_in->current_line = line;
+      if (!file)
+	linemap_line_start (line_table, data_in->current_line, 80);
+    }
+
+  if (file)
+    linemap_add (line_table, LC_ENTER, false, data_in->current_file,
+		 data_in->current_line);
+
+  if (column != data_in->current_col)
+    data_in->current_col = column;
+
+  if (file && line != -1 && column && -1)
+    LINEMAP_POSITION_FOR_COLUMN (loc, line_table, data_in->current_col);
+  else
+    loc = UNKNOWN_LOCATION;
+
+  return loc;
+}
+
+
 /* Read a statement with tag TAG in function FN from block IB using
    descriptors in DATA_IN.  */
 
@@ -1692,6 +1737,7 @@ input_gimple_stmt (struct lto_input_bloc
   unsigned HOST_WIDE_INT num_ops;
   size_t i, nbytes;
   char *buf;
+  location_t location;
 
   if (tag == LTO_gimple_asm)
     code = GIMPLE_ASM;
@@ -1721,6 +1767,9 @@ input_gimple_stmt (struct lto_input_bloc
   /* Read the number of operands in the statement.  */
   num_ops = lto_input_uleb128 (ib);
 
+  /* Read location information.  */
+  location = input_stmt_location (ib, data_in);
+
   /* Read the tuple header.  FIXME lto.  This seems unnecessarily slow
      and it is reading pointers in the tuple that need to be re-built
      locally (e.g, basic block, lexical block, operand vectors, etc).  */
@@ -1796,6 +1845,9 @@ input_gimple_stmt (struct lto_input_bloc
   /* Mark the statement modified so its operand vectors can be filled in.  */
   gimple_set_modified (stmt, true);
 
+  /* Set location information for STMT.  */
+  gimple_set_location (stmt, location);
+
   return stmt;
 }
 



More information about the Gcc-patches mailing list