commit 93ae936f933a6ba49e176f0b7c2a6338f8382117 Author: Ollie Wild Date: Tue Apr 15 13:55:24 2008 -0700 Add LTO support for functions whose DECL_CONTEXT is a type. gcc/ * lto-function-out.c (output_type_ref_1): New function. (output_type_ref): Split into two functions. (output_function): Output an LTO_type record if DECL_CONTEXT (function) is a type. * lto-tags.h (LTO_tags): Add LTO_type enumerator. * lto-tree-tags.def (LTO_type): Add new name. gcc/lto/ * lto-function-in.c (input_type_ref_1): New function. (input_type_ref): Split into two functions. (input_function): Add support for type contexts. diff --git a/gcc/lto-function-out.c b/gcc/lto-function-out.c index 029a35c..3bcc3de 100644 --- a/gcc/lto-function-out.c +++ b/gcc/lto-function-out.c @@ -594,17 +594,14 @@ output_tree_flags (struct output_block *ob, } -/* Look up TYPE in the type table and write the uleb128 index for it. - This is a hack and will be replaced with a real reference to the - type. */ +/* Like output_type_ref, but no debug information is written. */ static void -output_type_ref (struct output_block *ob, tree node) +output_type_ref_1 (struct output_block *ob, tree node) { bool new; unsigned int index; - LTO_DEBUG_TOKEN ("type"); new = lto_output_decl_index (ob->main_stream, ob->decl_state->type_hash_table, &ob->decl_state->next_type_index, @@ -615,6 +612,18 @@ output_type_ref (struct output_block *ob, tree node) } +/* Look up TYPE in the type table and write the uleb128 index for it. + This is a hack and will be replaced with a real reference to the + type. */ + +static void +output_type_ref (struct output_block *ob, tree node) +{ + LTO_DEBUG_TOKEN ("type"); + output_type_ref_1 (ob, node); +} + + /* Look up NAME in the type table and if WRITE, write the uleb128 index for it to OB. */ @@ -1953,6 +1962,7 @@ output_function (struct cgraph_node* node) struct function *fn = DECL_STRUCT_FUNCTION (function); basic_block bb; struct output_block *ob = create_output_block (LTO_section_function_body); + tree context; LTO_SET_DEBUGGING_STREAM (debug_main_stream, main_data); clear_line_info (ob); @@ -1985,10 +1995,17 @@ output_function (struct cgraph_node* node) output_zero (ob); LTO_DEBUG_INDENT_TOKEN ("decl_context"); - if (DECL_CONTEXT (function)) - output_expr_operand (ob, DECL_CONTEXT (function)); - else + context = DECL_CONTEXT (function); + if (!context) output_zero (ob); + else if (TYPE_P (context)) + { + output_record_start (ob, NULL, NULL, LTO_type); + output_type_ref_1 (ob, context); + LTO_DEBUG_UNDENT (); + } + else + output_expr_operand (ob, DECL_CONTEXT (function)); /* We will renumber the statements. The code that does this uses the same ordering that we use for serializing them so we can use diff --git a/gcc/lto-tags.h b/gcc/lto-tags.h index 82aa3e3..3c1d399 100644 --- a/gcc/lto-tags.h +++ b/gcc/lto-tags.h @@ -427,6 +427,7 @@ enum LTO_tags { LTO_asm_clobbers, LTO_function, + LTO_type, LTO_eh_table, /* Each of these requires 4 variants. 1 and 3 are have_inner and 2 diff --git a/gcc/lto-tree-tags.def b/gcc/lto-tree-tags.def index 91b6f93..aa6f47a 100644 --- a/gcc/lto-tree-tags.def +++ b/gcc/lto-tree-tags.def @@ -305,6 +305,7 @@ SET_NAME (LTO_asm_outputs, "asm_outputs") SET_NAME (LTO_asm_clobbers, "asm_clobbers") SET_NAME (LTO_function, "function") + SET_NAME (LTO_type, "type") SET_NAME (LTO_eh_table, "eh_table") SET_NAME (LTO_eh_table_cleanup0, "eh_table_cleanup0") SET_NAME (LTO_eh_table_cleanup1, "eh_table_cleanup1") diff --git a/gcc/lto/lto-function-in.c b/gcc/lto/lto-function-in.c index a637ee4..0c40767 100644 --- a/gcc/lto/lto-function-in.c +++ b/gcc/lto/lto-function-in.c @@ -226,18 +226,27 @@ get_label_decl (struct data_in *data_in, struct lto_input_block *ib) } -/* Get the type referenced by the next token in IB. */ +/* Like get_type_ref, but no debug information is read. */ static tree -input_type_ref (struct data_in *data_in, struct lto_input_block *ib) +input_type_ref_1 (struct data_in *data_in, struct lto_input_block *ib) { int index; - LTO_DEBUG_TOKEN ("type"); index = lto_input_uleb128 (ib); return data_in->file_data->types[index]; } + +/* Get the type referenced by the next token in IB. */ + +static tree +input_type_ref (struct data_in *data_in, struct lto_input_block *ib) +{ + LTO_DEBUG_TOKEN ("type"); + return input_type_ref_1 (data_in, ib); +} + /* Set all of the FLAGS for NODE. */ #define CLEAROUT (BITS_PER_LTO_FLAGS_TYPE - 1) @@ -1506,7 +1515,15 @@ input_function (tree fn_decl, struct data_in *data_in, LTO_DEBUG_INDENT_TOKEN ("decl_context"); tag = input_record_start (ib); if (tag) - DECL_CONTEXT (fn_decl) = input_expr_operand (ib, data_in, fn, tag); + { + if (tag == LTO_type) + { + DECL_CONTEXT (fn_decl) = input_type_ref_1 (data_in, ib); + LTO_DEBUG_UNDENT (); + } + else + DECL_CONTEXT (fn_decl) = input_expr_operand (ib, data_in, fn, tag); + } tag = input_record_start (ib); while (tag)