Re: [PATCH 3/3] incremental lto: Remap node order for stability.

2024-11-17 Thread Jan Hubicka
> This patch adds remapping of node order for each lto partition.
> Resulting order conserves relative order inside partition, but
> is independent of outside symbols. So if lto partition contains
> identical set of symbols, their remapped order will be stable
> between compilations.
> 
> gcc/ChangeLog:
> 
>   * ipa-devirt.cc (ipa_odr_summary_write):
>   Add unused argument.
>   * ipa-fnsummary.cc (ipa_fn_summary_write): Likewise.
>   * ipa-icf.cc (sem_item_optimizer::write_summary): Likewise.
>   * ipa-modref.cc (modref_write): Likewise.
>   * ipa-prop.cc (ipa_prop_write_jump_functions): Likewise.
>   (ipcp_write_transformation_summaries): Likewise.
>   * ipa-sra.cc (ipa_sra_write_summary): Likewise.
>   * lto-cgraph.cc (lto_symtab_encoder_delete): Delete remap.
>   (lto_output_node): Remap order.
>   (lto_output_varpool_node): Likewise.
>   (output_cgraph_opt_summary): Add unused argument.
>   * lto-streamer-out.cc (produce_asm): Use remapped order.
>   (output_function): Propagate remapped order.
>   (output_constructor): Likewise.
>   (copy_function_or_variable): Likewise.
>   (cmp_int): New.
>   (create_order_remap): New.
>   (lto_output): Create remap. Remap order.
>   * lto-streamer.h (struct lto_symtab_encoder_d): Remap hash_map.
>   (produce_asm): Add order argument.

> ---
>  gcc/ipa-devirt.cc   |  2 +-
>  gcc/ipa-fnsummary.cc|  2 +-
>  gcc/ipa-icf.cc  |  2 +-
>  gcc/ipa-modref.cc   |  4 +-
>  gcc/ipa-prop.cc |  4 +-
>  gcc/ipa-sra.cc  |  2 +-
>  gcc/lto-cgraph.cc   | 10 +++--
>  gcc/lto-streamer-out.cc | 84 +++--
>  gcc/lto-streamer.h  |  5 ++-
>  9 files changed, 91 insertions(+), 24 deletions(-)
> 
> diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
> index c406e5138db..098798281b7 100644
> --- a/gcc/ipa-devirt.cc
> +++ b/gcc/ipa-devirt.cc
> @@ -4131,7 +4131,7 @@ ipa_odr_summary_write (void)
>odr_enum_map = NULL;
>  }
>  
> -  produce_asm (ob, NULL);
> +  produce_asm (ob, NULL, -1);
Arguments of produce_asm seems somewhat magical.
> +/* Compare ints, callback for qsort.  */
> +
> +static int
> +cmp_int (const void *a, const void *b)
> +{
> +  int ia = *(int const*) a;
> +  int ib = *(int const*) b;
> +  return ia - ib;
> +}
Given that it is no longer C source, perhaps std::sort would allow doing
this without extra comparator.  But I am fine with the function as it is :)
> +extern void produce_asm (struct output_block *ob, tree fn, int output_order);

I would suggest renaming produce_asm to produce_symbol_asm 
and making produce_asm wrapper which passes fn=NULL and output_order=-1,
so we do not have odd parameters everywhere in streaming code.

OK with this change.
Honza


[PATCH 3/3] incremental lto: Remap node order for stability.

2024-11-06 Thread Michal Jires
This patch adds remapping of node order for each lto partition.
Resulting order conserves relative order inside partition, but
is independent of outside symbols. So if lto partition contains
identical set of symbols, their remapped order will be stable
between compilations.

gcc/ChangeLog:

* ipa-devirt.cc (ipa_odr_summary_write):
Add unused argument.
* ipa-fnsummary.cc (ipa_fn_summary_write): Likewise.
* ipa-icf.cc (sem_item_optimizer::write_summary): Likewise.
* ipa-modref.cc (modref_write): Likewise.
* ipa-prop.cc (ipa_prop_write_jump_functions): Likewise.
(ipcp_write_transformation_summaries): Likewise.
* ipa-sra.cc (ipa_sra_write_summary): Likewise.
* lto-cgraph.cc (lto_symtab_encoder_delete): Delete remap.
(lto_output_node): Remap order.
(lto_output_varpool_node): Likewise.
(output_cgraph_opt_summary): Add unused argument.
* lto-streamer-out.cc (produce_asm): Use remapped order.
(output_function): Propagate remapped order.
(output_constructor): Likewise.
(copy_function_or_variable): Likewise.
(cmp_int): New.
(create_order_remap): New.
(lto_output): Create remap. Remap order.
* lto-streamer.h (struct lto_symtab_encoder_d): Remap hash_map.
(produce_asm): Add order argument.
---
 gcc/ipa-devirt.cc   |  2 +-
 gcc/ipa-fnsummary.cc|  2 +-
 gcc/ipa-icf.cc  |  2 +-
 gcc/ipa-modref.cc   |  4 +-
 gcc/ipa-prop.cc |  4 +-
 gcc/ipa-sra.cc  |  2 +-
 gcc/lto-cgraph.cc   | 10 +++--
 gcc/lto-streamer-out.cc | 84 +++--
 gcc/lto-streamer.h  |  5 ++-
 9 files changed, 91 insertions(+), 24 deletions(-)

diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index c406e5138db..098798281b7 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -4131,7 +4131,7 @@ ipa_odr_summary_write (void)
   odr_enum_map = NULL;
 }
 
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 }
 
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index b3824783406..badc5e703b2 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -4911,7 +4911,7 @@ ipa_fn_summary_write (void)
}
 }
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 
   ipa_prop_write_jump_functions ();
diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index b10a6baf109..d9cd7d0c1c0 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -2216,7 +2216,7 @@ sem_item_optimizer::write_summary (void)
 }
 
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 }
 
diff --git a/gcc/ipa-modref.cc b/gcc/ipa-modref.cc
index 19359662f8f..7f36fab3db2 100644
--- a/gcc/ipa-modref.cc
+++ b/gcc/ipa-modref.cc
@@ -3739,7 +3739,7 @@ modref_write ()
 {
   streamer_write_uhwi (ob, 0);
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
   return;
 }
@@ -3814,7 +3814,7 @@ modref_write ()
}
 }
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 }
 
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 78d1fb7086d..032358fde22 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -5297,7 +5297,7 @@ ipa_prop_write_jump_functions (void)
 ipa_write_node_info (ob, node);
 }
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 }
 
@@ -5489,7 +5489,7 @@ ipcp_write_transformation_summaries (void)
write_ipcp_transformation_info (ob, cnode, ts);
 }
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 }
 
diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc
index 04920f2aa8e..630f4d6c14f 100644
--- a/gcc/ipa-sra.cc
+++ b/gcc/ipa-sra.cc
@@ -2898,7 +2898,7 @@ ipa_sra_write_summary (void)
 isra_write_node_summary (ob, node);
 }
   streamer_write_char_stream (ob->main_stream, 0);
-  produce_asm (ob, NULL);
+  produce_asm (ob, NULL, -1);
   destroy_output_block (ob);
 }
 
diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index 1d4311a8832..53cc965bdfd 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -96,6 +96,8 @@ lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
encoder->nodes.release ();
if (encoder->map)
  delete encoder->map;
+   if (encoder->order_remap)
+ delete encoder->order_remap;
free (encoder);
 }
 
@@ -406,7 +408,8 @@ lto_output_node (struct lto_simple_output_block *ob, struct 
cgraph_node *node,
 
   streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_t