Save discriminator info for LTO
authorAlexandre Oliva <oliva@adacore.com>
Tue, 31 Jul 2018 21:19:25 +0000 (21:19 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Tue, 31 Jul 2018 21:19:25 +0000 (21:19 +0000)
for  gcc/ChangeLog

* gimple-streamer-in.c (input_bb): Restore BB discriminator.
* gimple-streamer-out.c (output_bb): Save it.
* lto-streamer-in.c (input_struct_function_base): Restore
instance discriminator if available.  Create map on demand.
* lto-streamer-out.c (output_struct_function_base): Save it if
available.
* final.c (decl_to_instance_map): Document LTO strategy.

From-SVN: r263183

gcc/ChangeLog
gcc/final.c
gcc/gimple-streamer-in.c
gcc/gimple-streamer-out.c
gcc/lto-streamer-in.c
gcc/lto-streamer-out.c

index 4eda71bca0faa484ebcc8fa197989adaabe86332..9b0ccfdaf317f3164354486cf94e4e585d869ba1 100644 (file)
@@ -1,3 +1,13 @@
+2018-07-31  Alexandre Oliva <oliva@adacore.com>
+
+       * gimple-streamer-in.c (input_bb): Restore BB discriminator.
+       * gimple-streamer-out.c (output_bb): Save it.
+       * lto-streamer-in.c (input_struct_function_base): Restore
+       instance discriminator if available.  Create map on demand.
+       * lto-streamer-out.c (output_struct_function_base): Save it if
+       available.
+       * final.c (decl_to_instance_map): Document LTO strategy.
+
 2018-07-31  Alexandre Oliva  <oliva@adacore.com>
             Olivier Hainque  <hainque@adacore.com>
 
index a8338e0394c1d62aa01a414da22aabbee48d3242..842e5e067db7419076c07a603283e42231a44353 100644 (file)
@@ -3154,7 +3154,11 @@ final_scan_insn (rtx_insn *insn, FILE *file, int optimize_p,
 \f
 
 /* Map DECLs to instance discriminators.  This is allocated and
-   defined in ada/gcc-interfaces/trans.c, when compiling with -gnateS.  */
+   defined in ada/gcc-interfaces/trans.c, when compiling with -gnateS.
+   Mappings from this table are saved and restored for LTO, so
+   link-time compilation will have this map set, at least in
+   partitions containing at least one DECL with an associated instance
+   discriminator.  */
 
 decl_to_instance_map_t *decl_to_instance_map;
 
index 6ffef29bf1f80e37e9ca15cb407d8e4df66807d9..31ba4cc4e00eda0f893f739d42fd4ea9794962d0 100644 (file)
@@ -270,6 +270,7 @@ input_bb (struct lto_input_block *ib, enum LTO_tags tag,
     bb->count
       = bb->count.apply_scale (count_materialization_scale, REG_BR_PROB_BASE);
   bb->flags = streamer_read_hwi (ib);
+  bb->discriminator = streamer_read_hwi (ib);
 
   /* LTO_bb1 has statements.  LTO_bb0 does not.  */
   if (tag == LTO_bb0)
index d120aa902952ab5db8f795f694915a25f8913de4..3a2368047cc6836fd1ac727d5e9ec604f911685a 100644 (file)
@@ -212,6 +212,7 @@ output_bb (struct output_block *ob, basic_block bb, struct function *fn)
   streamer_write_uhwi (ob, bb->index);
   bb->count.stream_out (ob);
   streamer_write_hwi (ob, bb->flags);
+  streamer_write_hwi (ob, bb->discriminator);
 
   if (!gsi_end_p (bsi) || phi_nodes (bb))
     {
index 8529c82376b8f1230053c710d014405d7d1cf634..4ddcc8f7ddd9c4e9754d5b88942da1c2fb7d7cfd 100644 (file)
@@ -1013,6 +1013,14 @@ input_struct_function_base (struct function *fn, struct data_in *data_in,
   /* Input the function start and end loci.  */
   fn->function_start_locus = stream_input_location_now (&bp, data_in);
   fn->function_end_locus = stream_input_location_now (&bp, data_in);
+
+  /* Restore the instance discriminators if present.  */
+  int instance_number = bp_unpack_value (&bp, 1);
+  if (instance_number)
+    {
+      instance_number = bp_unpack_value (&bp, sizeof (int) * CHAR_BIT);
+      maybe_create_decl_to_instance_map ()->put (fn->decl, instance_number);
+    }
 }
 
 
index 78b90e7f59624bb18c45d444757e13a68a3c26fa..9e28d678342c1d4a48293b8becef816a227472ea 100644 (file)
@@ -2038,6 +2038,14 @@ output_struct_function_base (struct output_block *ob, struct function *fn)
   stream_output_location (ob, &bp, fn->function_start_locus);
   stream_output_location (ob, &bp, fn->function_end_locus);
 
+  /* Save the instance discriminator if present.  */
+  int *instance_number_p = NULL;
+  if (decl_to_instance_map)
+    instance_number_p = decl_to_instance_map->get (fn->decl);
+  bp_pack_value (&bp, !!instance_number_p, 1);
+  if (instance_number_p)
+    bp_pack_value (&bp, *instance_number_p, sizeof (int) * CHAR_BIT);
+
   streamer_write_bitpack (&bp);
 }