This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto]: Set DECL_INITIAL and line numbers properly.
- From: Kenneth Zadeck <zadeck at naturalbridge dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, Nathan Froyd <froydnj at codesourcery dot com>
- Date: Fri, 16 Nov 2007 08:24:42 -0500
- Subject: [lto]: Set DECL_INITIAL and line numbers properly.
This patch does three things:
1) It sets the DECL_INITIAL for static local vars.
2) It puts line numbers on the correct tree nodes.
3) It adds more flags that were not being set properly.
2007-11-16 Kenneth Zadeck <zadeck@naturalbridge.com>
* lto-tree-flags.def (tcc_constant): Added static_flag.
(tcc_vl_exp): Added asm_written_flag.
* lto-function-out.c (output_local_vars): Output DECL_INITIAL
for static local vars.
(lto_types_needed_for): Added STRING_CST.
* tree-cfg.c (dump_function_to_file): Add verbose dump for
local vars and parms.
2007-11-16 Kenneth Zadeck <zadeck@naturalbridge.com>
* lto-read.c (data_in.current_node_has_loc): Removed.
(input_line_info): Returns true if node needs line set.
(set_line_info): Always sets line if called.
(clear_line_info): Removed reference to current_node_needs_loc.
(input_expr_operand): Keeps track locally if current node needs a loc.
(input_local_var): Added code to handle DECL_INITIAL for
static local vars. Only set loc if necessary.
Committed as revision 130224.
Kenny
Index: lto-tree-flags.def
===================================================================
--- lto-tree-flags.def (revision 130222)
+++ lto-tree-flags.def (working copy)
@@ -54,6 +54,7 @@
START_CLASS_CASE (tcc_constant)
ADD_CLASS_EXPR_FLAG (side_effects_flag)
+ ADD_CLASS_EXPR_FLAG (static_flag)
ADD_CLASS_EXPR_FLAG (readonly_flag)
ADD_CLASS_EXPR_FLAG (constant_flag)
END_CLASS_CASE (tcc_constant)
@@ -137,6 +138,7 @@
END_CLASS_CASE (tcc_unary)
START_CLASS_CASE (tcc_vl_exp)
+ ADD_CLASS_EXPR_FLAG (asm_written_flag)
ADD_CLASS_EXPR_FLAG (side_effects_flag)
ADD_CLASS_EXPR_FLAG (volatile_flag)
ADD_CLASS_EXPR_FLAG (readonly_flag)
Index: lto-function-out.c
===================================================================
--- lto-function-out.c (revision 130222)
+++ lto-function-out.c (working copy)
@@ -1754,7 +1754,15 @@ output_local_vars (struct output_block *
output_type_ref (ob, TREE_TYPE (decl));
- if (!is_var)
+ if (is_var)
+ {
+ LTO_DEBUG_INDENT_TOKEN ("init");
+ if (DECL_INITIAL (decl))
+ output_expr_operand (ob, DECL_INITIAL (decl));
+ else
+ output_zero (ob);
+ }
+ else
output_type_ref (ob, DECL_ARG_TYPE (decl));
clear_line_info (ob);
@@ -2194,6 +2202,7 @@ lto_static_init (void)
SET_BIT (lto_types_needed_for, INTEGER_CST);
SET_BIT (lto_types_needed_for, NOP_EXPR);
SET_BIT (lto_types_needed_for, REAL_CST);
+ SET_BIT (lto_types_needed_for, STRING_CST);
SET_BIT (lto_types_needed_for, VECTOR_CST );
SET_BIT (lto_types_needed_for, VIEW_CONVERT_EXPR);
#endif
Index: lto/lto-read.c
===================================================================
--- lto/lto-read.c (revision 130222)
+++ lto/lto-read.c (working copy)
@@ -82,7 +82,6 @@ struct data_in
#ifdef USE_MAPPED_LOCATION
int current_col;
#endif
- bool current_node_has_loc;
};
@@ -495,7 +494,7 @@ canon_file_name (const char *string)
/* Based on the FLAGS, read in a file, a line and a col into the
fields in DATA_IN. */
-static void
+static bool
input_line_info (struct input_block *ib, struct data_in *data_in,
lto_flags_type flags)
{
@@ -540,8 +539,7 @@ input_line_info (struct input_block *ib,
data_in->current_line = input_uleb128 (ib);
}
#endif
- if (flags & LTO_SOURCE_HAS_LOC)
- data_in->current_node_has_loc = true;
+ return (flags & LTO_SOURCE_HAS_LOC) != 0;
}
@@ -550,28 +548,24 @@ input_line_info (struct input_block *ib,
static void
set_line_info (struct data_in *data_in, tree node)
{
- if (data_in->current_node_has_loc && data_in->current_file)
- {
#ifdef USE_MAPPED_LOCATION
- if (EXPR_P (node))
- LINEMAP_POSITION_FOR_COLUMN (EXPR_CHECK (node)->exp.locus, line_table, data_in->current_col)
- else if (GIMPLE_STMT_P (node))
- LINEMAP_POSITION_FOR_COLUMN (GIMPLE_STMT_LOCUS (node), line_table, data_in->current_col)
- else if (DECL_P (node))
- LINEMAP_POSITION_FOR_COLUMN (DECL_SOURCE_LOCATION (node), line_table, data_in->current_col)
+ if (EXPR_P (node))
+ LINEMAP_POSITION_FOR_COLUMN (EXPR_CHECK (node)->exp.locus, line_table, data_in->current_col)
+ else if (GIMPLE_STMT_P (node))
+ LINEMAP_POSITION_FOR_COLUMN (GIMPLE_STMT_LOCUS (node), line_table, data_in->current_col)
+ else if (DECL_P (node))
+ LINEMAP_POSITION_FOR_COLUMN (DECL_SOURCE_LOCATION (node), line_table, data_in->current_col)
#else
- if (EXPR_P (node) || GIMPLE_STMT_P (node))
- annotate_with_file_line (node,
- canon_file_name (data_in->current_file),
- data_in->current_line);
- else if (DECL_P (node))
- {
- DECL_SOURCE_LOCATION (node).file = canon_file_name (data_in->current_file);
- DECL_SOURCE_LOCATION (node).line = data_in->current_line;
- }
-#endif
+ if (EXPR_P (node) || GIMPLE_STMT_P (node))
+ annotate_with_file_line (node,
+ canon_file_name (data_in->current_file),
+ data_in->current_line);
+ else if (DECL_P (node))
+ {
+ DECL_SOURCE_LOCATION (node).file = canon_file_name (data_in->current_file);
+ DECL_SOURCE_LOCATION (node).line = data_in->current_line;
}
- data_in->current_node_has_loc = false;
+#endif
}
@@ -587,7 +581,6 @@ clear_line_info (struct data_in *data_in
#endif
data_in->current_file = NULL;
data_in->current_line = 0;
- data_in->current_node_has_loc = false;
}
@@ -603,6 +596,7 @@ input_expr_operand (struct input_block *
lto_flags_type flags;
gcc_assert (code);
tree result = NULL_TREE;
+ bool needs_line_set = false;
if (TEST_BIT (lto_types_needed_for, code))
type = input_type_ref (data_in, ib);
@@ -611,7 +605,7 @@ input_expr_operand (struct input_block *
if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
|| IS_GIMPLE_STMT_CODE_CLASS(TREE_CODE_CLASS (code)))
- input_line_info (ib, data_in, flags);
+ needs_line_set = input_line_info (ib, data_in, flags);
switch (code)
{
@@ -1141,8 +1135,7 @@ input_expr_operand (struct input_block *
if (flags)
process_tree_flags (result, flags);
- if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
- || IS_GIMPLE_STMT_CODE_CLASS(TREE_CODE_CLASS (code)))
+ if (needs_line_set)
set_line_info (data_in, result);
/* It is not enought to just put the flags back as we serialized
@@ -1294,12 +1287,19 @@ input_local_var (struct input_block *ib,
data_in->local_decls[i] = result;
- if (!is_var)
+ if (is_var)
+ {
+ LTO_DEBUG_INDENT_TOKEN ("init");
+ tag = input_record_start (ib);
+ if (tag)
+ DECL_INITIAL (result) = input_expr_operand (ib, data_in, fn, tag);
+ }
+ else
DECL_ARG_TYPE (result) = input_type_ref (data_in, ib);
flags = input_tree_flags (ib, 0, true);
- input_line_info (ib, data_in, flags);
- set_line_info (data_in, result);
+ if (input_line_info (ib, data_in, flags))
+ set_line_info (data_in, result);
LTO_DEBUG_TOKEN ("chain");
tag = input_record_start (ib);
@@ -1508,6 +1508,9 @@ input_phi (struct input_block *ib, basic
SSA_NAME_DEF_STMT (phi_result) = result;
+ /* We have to go thru a lookup process here because the preds in the
+ reconstructed graph are generally in a different order than they
+ were in the original program. */
for (i = 0; i < len; i++)
{
tree def = input_expr_operand (ib, data_in, fn, input_record_start (ib));
Index: tree-cfg.c
===================================================================
--- tree-cfg.c (revision 130222)
+++ tree-cfg.c (working copy)
@@ -6087,6 +6087,8 @@ dump_function_to_file (tree fn, FILE *fi
while (arg)
{
print_generic_expr (file, arg, dump_flags);
+ if (flags & TDF_VERBOSE)
+ print_node (file, "", arg, 4);
if (TREE_CHAIN (arg))
fprintf (file, ", ");
arg = TREE_CHAIN (arg);
@@ -6121,6 +6123,8 @@ dump_function_to_file (tree fn, FILE *fi
var = TREE_VALUE (vars);
print_generic_decl (file, var, flags);
+ if (flags & TDF_VERBOSE)
+ print_node (file, "", var, 4);
fprintf (file, "\n");
any_var = true;