[gcc r15-1099] lto: Implement cache partitioning
https://gcc.gnu.org/g:5b6d5a886ee45bb969b4de23528311472b4ab66b commit r15-1099-g5b6d5a886ee45bb969b4de23528311472b4ab66b Author: Michal Jires Date: Fri Nov 17 21:17:18 2023 +0100 lto: Implement cache partitioning This patch implements new cache partitioning. It tries to keep symbols from single source file together to minimize propagation of divergence. It starts with symbols already grouped by source files. If reasonably possible it only either combines several files into one final partition, or, if a file is large, split the file into several final partitions. Intermediate representation is partition_set which contains set of groups of symbols (each group corresponding to original source file) and number of final partitions this partition_set should split into. First partition_fixed_split splits partition_set into constant number of partition_sets with equal number of symbols groups. If for example there are 39 source files, the resulting partition_sets will contain 10, 10, 10, and 9 source files. This splitting intentionally ignores estimated instruction counts to minimize propagation of divergence. Second partition_over_target_split separates too large files and splits them into individual symbols to be combined back into several smaller files in next step. Third partition_binary_split splits partition_set into two halves until it should be split into only one final partition, at which point the remaining symbols are joined into one final partition. Bootstrapped/regtested on x86_64-pc-linux-gnu gcc/ChangeLog: * common.opt: Add cache partitioning. * flag-types.h (enum lto_partition_model): Likewise. gcc/lto/ChangeLog: * lto-partition.cc (new_partition): Use new_partition_no_push. (new_partition_no_push): New. (free_ltrans_partition): New. (free_ltrans_partitions): Use free_ltrans_partition. (join_partitions): New. (split_partition_into_nodes): New. (is_partition_reorder): New. (class partition_set): New. (distribute_n_partitions): New. (partition_over_target_split): New. (partition_binary_split): New. (partition_fixed_split): New. (class partitioner_base): New. (class partitioner_default): New. (lto_cache_map): New. * lto-partition.h (lto_cache_map): New. * lto.cc (do_whole_program_analysis): Use lto_cache_map. gcc/testsuite/ChangeLog: * gcc.dg/completion-2.c: Add -flto-partition=cache. Diff: --- gcc/common.opt | 3 + gcc/flag-types.h| 3 +- gcc/lto/lto-partition.cc| 605 +++- gcc/lto/lto-partition.h | 1 + gcc/lto/lto.cc | 2 + gcc/testsuite/gcc.dg/completion-2.c | 1 + 6 files changed, 605 insertions(+), 10 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 2c078fdd1f8..f2bc47fdc5e 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2233,6 +2233,9 @@ Enum(lto_partition_model) String(1to1) Value(LTO_PARTITION_1TO1) EnumValue Enum(lto_partition_model) String(max) Value(LTO_PARTITION_MAX) +EnumValue +Enum(lto_partition_model) String(cache) Value(LTO_PARTITION_CACHE) + flto-partition= Common Joined RejectNegative Enum(lto_partition_model) Var(flag_lto_partition) Init(LTO_PARTITION_BALANCED) Specify the algorithm to partition symbols and vars at linktime. diff --git a/gcc/flag-types.h b/gcc/flag-types.h index 5a2b461fa75..1e497f0bb91 100644 --- a/gcc/flag-types.h +++ b/gcc/flag-types.h @@ -396,7 +396,8 @@ enum lto_partition_model { LTO_PARTITION_ONE = 1, LTO_PARTITION_BALANCED = 2, LTO_PARTITION_1TO1 = 3, - LTO_PARTITION_MAX = 4 + LTO_PARTITION_MAX = 4, + LTO_PARTITION_CACHE = 5 }; /* flag_lto_linker_output initialization values. */ diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc index 19f91e5d660..44b457d0b2a 100644 --- a/gcc/lto/lto-partition.cc +++ b/gcc/lto/lto-partition.cc @@ -37,6 +37,9 @@ along with GCC; see the file COPYING3. If not see #include "ipa-fnsummary.h" #include "lto-partition.h" +#include +#include + vec ltrans_partitions; static void add_symbol_to_partition (ltrans_partition part, symtab_node *node); @@ -60,20 +63,41 @@ cmp_partitions_order (const void *a, const void *b) return orderb - ordera; } -/* Create new partition with name NAME. */ - +/* Create new partition with name NAME. + Does not push into ltrans_partitions. */ static ltrans_partition -new_partition (const char *name) +new_partition_no_push (const char *name) { ltrans_partition part = XCNEW (struct ltrans_partition_def); part->encoder = lto_symtab_encoder_new (false); part->name = name; part->insns = 0;
[gcc r15-1063] lto: Remove random_seed from section name.
https://gcc.gnu.org/g:346f33e27809ae012696c4731c8ebcec2414dbfb commit r15-1063-g346f33e27809ae012696c4731c8ebcec2414dbfb Author: Michal Jires Date: Tue Jan 9 17:49:34 2024 +0100 lto: Remove random_seed from section name. This patch removes suffixes from section names during LTO linking. These suffixes were originally added for ld -r to work (PR lto/44992). They were added to all LTO object files, but are only useful before WPA. After that they waste space, and if kept random, make LTO caching impossible. Bootstrapped/regtested on x86_64-pc-linux-gnu gcc/ChangeLog: * lto-streamer.cc (lto_get_section_name): Remove suffixes after WPA. gcc/lto/ChangeLog: * lto-common.cc (lto_section_with_id): Dont load suffix during LTRANS. Diff: --- gcc/lto-streamer.cc | 11 +-- gcc/lto/lto-common.cc | 7 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gcc/lto-streamer.cc b/gcc/lto-streamer.cc index 8032bbf7108..40ca6b2da1b 100644 --- a/gcc/lto-streamer.cc +++ b/gcc/lto-streamer.cc @@ -132,11 +132,18 @@ lto_get_section_name (int section_type, const char *name, doesn't confuse the reader with merged sections. For options don't add a ID, the option reader cannot deal with them - and merging should be ok here. */ - if (section_type == LTO_section_opts) + and merging should be ok here. + + LTRANS files (output of wpa, input and output of ltrans) are handled + directly inside of linker/lto-wrapper, so name uniqueness for external + tools is not needed. + Randomness would inhibit incremental LTO. */ + if (section_type == LTO_section_opts || flag_ltrans) strcpy (post, ""); else if (f != NULL) sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, f->id); + else if (flag_wpa) +strcpy (post, ""); else sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, get_random_seed (false)); char *res = concat (section_name_prefix, sep, add, post, NULL); diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc index 2ce94cc3282..34aa63b179c 100644 --- a/gcc/lto/lto-common.cc +++ b/gcc/lto/lto-common.cc @@ -2176,6 +2176,13 @@ lto_section_with_id (const char *name, unsigned HOST_WIDE_INT *id) if (strncmp (name, section_name_prefix, strlen (section_name_prefix))) return 0; + + if (flag_ltrans) +{ + *id = 0; + return 1; +} + s = strrchr (name, '.'); if (!s) return 0;
[gcc r15-1062] lto: Skip flag OPT_fltrans_output_list_.
https://gcc.gnu.org/g:ca43678c3d8aff1b8774e0b05c9a4a42fd271b13 commit r15-1062-gca43678c3d8aff1b8774e0b05c9a4a42fd271b13 Author: Michal Jires Date: Fri Nov 17 21:16:37 2023 +0100 lto: Skip flag OPT_fltrans_output_list_. Bootstrapped/regtested on x86_64-pc-linux-gnu gcc/ChangeLog: * lto-opts.cc (lto_write_options): Skip OPT_fltrans_output_list_. Diff: --- gcc/lto-opts.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/lto-opts.cc b/gcc/lto-opts.cc index b3d19f8b361..a3a1d110329 100644 --- a/gcc/lto-opts.cc +++ b/gcc/lto-opts.cc @@ -152,6 +152,7 @@ lto_write_options (void) case OPT_fprofile_prefix_map_: case OPT_fcanon_prefix_map: case OPT_fwhole_program: + case OPT_fltrans_output_list_: continue; default: