Hi, this patch makes us to stream out and stream in the order fields of cgraph correctly, so -fno-toplevel-reorder works within single compilation unit with -flto-partition=none.
This is currently needed to build kernel with LTO and it is useful otherwise (i.e. I made the patch originally for some experiments with Mozilla load times) Andi has patch to fix stream in code to stream in linker order that fixes the order with -flto-partition=none completely and I will followup with patch to make partitioning to honor the streaming order. Boostrapped/regtested x86_64-linux, OK? Honza * lto-streamer.h (lto_input_toplevel_asms): Add order_base parameter. * lto-streamer-in.c (lto_input_toplevel_asms): Stream in order. * lto-streamer-out.c (lto_output_toplevel_asms): Stream out order. * lto-cgraph.c (order_base): New static var. (lto_output_node): Stream in order. (lto_output_varpool_node): Stream out order. (input_node): Stream in order. (input_varpool_node): Stream out order. (input_cgraph_1): Initialize order base; update call of lto_input_toplevel_asms. Index: lto-streamer.h =================================================================== --- lto-streamer.h (revision 179413) +++ lto-streamer.h (working copy) @@ -807,7 +807,7 @@ extern void lto_input_function_body (str const char *); extern void lto_input_constructors_and_inits (struct lto_file_decl_data *, const char *); -extern void lto_input_toplevel_asms (struct lto_file_decl_data *); +extern void lto_input_toplevel_asms (struct lto_file_decl_data *, int); extern struct data_in *lto_data_in_create (struct lto_file_decl_data *, const char *, unsigned, VEC(ld_plugin_symbol_resolution_t,heap) *); Index: lto-streamer-in.c =================================================================== --- lto-streamer-in.c (revision 179413) +++ lto-streamer-in.c (working copy) @@ -1144,7 +1144,7 @@ lto_input_tree (struct lto_input_block * /* Input toplevel asms. */ void -lto_input_toplevel_asms (struct lto_file_decl_data *file_data) +lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base) { size_t len; const char *data = lto_get_section_data (file_data, LTO_section_asm, @@ -1173,7 +1173,12 @@ lto_input_toplevel_asms (struct lto_file header->lto_header.minor_version); while ((str = streamer_read_string_cst (data_in, &ib))) - cgraph_add_asm_node (str); + { + struct cgraph_asm_node *node = cgraph_add_asm_node (str); + node->order = streamer_read_hwi (&ib) + order_base; + if (node->order >= cgraph_order) + cgraph_order = node->order + 1; + } clear_line_info (data_in); lto_data_in_delete (data_in); Index: lto-streamer-out.c =================================================================== --- lto-streamer-out.c (revision 179413) +++ lto-streamer-out.c (working copy) @@ -954,7 +954,10 @@ lto_output_toplevel_asms (void) streamer_write_char_stream (ob->string_stream, 0); for (can = cgraph_asm_nodes; can; can = can->next) - streamer_write_string_cst (ob, ob->main_stream, can->asm_str); + { + streamer_write_string_cst (ob, ob->main_stream, can->asm_str); + streamer_write_hwi (ob, can->order); + } streamer_write_string_cst (ob, ob->main_stream, NULL_TREE); Index: lto-cgraph.c =================================================================== --- lto-cgraph.c (revision 179413) +++ lto-cgraph.c (working copy) @@ -54,6 +54,9 @@ static void input_cgraph_opt_summary (VE /* Number of LDPR values known to GCC. */ #define LDPR_NUM_KNOWN (LDPR_RESOLVED_DYN + 1) +/* All node orders are ofsetted by ORDER_BASE. */ +static int order_base; + /* Cgraph streaming is organized as set of record whose type is indicated by a tag. */ enum LTO_cgraph_tags @@ -425,6 +428,7 @@ lto_output_node (struct lto_simple_outpu streamer_write_enum (ob->main_stream, LTO_cgraph_tags, LTO_cgraph_last_tag, tag); + streamer_write_hwi_stream (ob->main_stream, node->order); /* In WPA mode, we only output part of the call-graph. Also, we fake cgraph node attributes. There are two cases that we care. @@ -548,6 +552,7 @@ lto_output_varpool_node (struct lto_simp struct bitpack_d bp; int ref; + streamer_write_hwi_stream (ob->main_stream, node->order); lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl); bp = bitpack_create (ob->main_stream); bp_pack_value (&bp, node->externally_visible, 1); @@ -960,7 +965,9 @@ input_node (struct lto_file_decl_data *f unsigned decl_index; int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND; int clone_ref; + int order; + order = streamer_read_hwi (ib) + order_base; clone_ref = streamer_read_hwi (ib); decl_index = streamer_read_uhwi (ib); @@ -974,6 +981,10 @@ input_node (struct lto_file_decl_data *f else node = cgraph_get_create_node (fn_decl); + node->order = order; + if (order >= cgraph_order) + cgraph_order = order + 1; + node->count = streamer_read_hwi (ib); node->count_materialization_scale = streamer_read_hwi (ib); @@ -1035,10 +1046,15 @@ input_varpool_node (struct lto_file_decl struct bitpack_d bp; int ref = LCC_NOT_FOUND; bool non_null_aliasof; + int order; + order = streamer_read_hwi (ib) + order_base; decl_index = streamer_read_uhwi (ib); var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index); node = varpool_node (var_decl); + node->order = order; + if (order >= cgraph_order) + cgraph_order = order + 1; node->lto_file_data = file_data; bp = streamer_read_bitpack (ib); @@ -1178,6 +1194,7 @@ input_cgraph_1 (struct lto_file_decl_dat unsigned i; tag = streamer_read_enum (ib, LTO_cgraph_tags, LTO_cgraph_last_tag); + order_base = cgraph_order; while (tag) { if (tag == LTO_cgraph_edge) @@ -1196,7 +1213,7 @@ input_cgraph_1 (struct lto_file_decl_dat tag = streamer_read_enum (ib, LTO_cgraph_tags, LTO_cgraph_last_tag); } - lto_input_toplevel_asms (file_data); + lto_input_toplevel_asms (file_data, order_base); /* AUX pointers should be all non-zero for nodes read from the stream. */ #ifdef ENABLE_CHECKING