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] Emit location information for statements


On Mon, May 18, 2009 at 13:31, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Diego" == Diego Novillo <dnovillo@google.com> writes:
>
> Diego> As referenced in my previous message
> Diego> (http://gcc.gnu.org/ml/gcc-patches/2009-05/msg00927.html), this
> Diego> patch emits location information for statements in gimple files.
>
> I saw something odd in this patch. ÂI don't know whether it is a bug
> or not, but I figured I would mention it just in case.

Oops, thanks Tom.  I managed to cut and paste the wrong patch to
my email.

This is the actual patch that I had committed as revision 147597:


Diego.

Index: lto-function-out.c
===================================================================
--- lto-function-out.c	(revision 147596)
+++ lto-function-out.c	(revision 147597)
@@ -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 = xloc.file;
+  ob->current_line = xloc.line;
+  ob->current_col = xloc.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 147596)
+++ lto-function-in.c	(revision 147597)
@@ -1680,6 +1680,49 @@ 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);
+  if (file == NULL)
+    return UNKNOWN_LOCATION;
+
+  file = canon_file_name (file);
+  line = lto_input_sleb128 (ib);
+  column = lto_input_sleb128 (ib);
+
+  if (file != data_in->current_file)
+    {
+      data_in->current_file = file;
+      linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+    }
+
+  if (line != data_in->current_line)
+    {
+      data_in->current_line = line;
+      if (!file)
+	linemap_line_start (line_table, data_in->current_line, 80);
+    }
+
+  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;
+
+  LINEMAP_POSITION_FOR_COLUMN (loc, line_table, data_in->current_col);
+
+  return loc;
+}
+
+
 /* Read a statement with tag TAG in function FN from block IB using
    descriptors in DATA_IN.  */

@@ -1692,6 +1735,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 +1765,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 +1843,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;
 }

Index: ChangeLog.lto
===================================================================
--- ChangeLog.lto	(revision 147596)
+++ ChangeLog.lto	(revision 147597)
@@ -1,5 +1,12 @@
 2009-05-15  Diego Novillo  <dnovillo@google.com>

+	* 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.
+
+2009-05-15  Diego Novillo  <dnovillo@google.com>
+
 	* lto-tags.h (LTO_SOURCE_FILE): Add brackets around value.
 	(LTO_SOURCE_LINE): Likewise.
 	(LTO_SOURCE_COL): Likewise.


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