Toplevel assembly is now streamed as partitioned instead of into the
first partition.

gcc/ChangeLog:

        * lto-cgraph.cc (output_symtab): Remove asm_nodes_out.
        * lto-streamer-out.cc (lto_output_toplevel_asms): Use
        partitioning.
        (create_order_remap): Remove asm_nodes_out.
        (lto_output): In LGEN add asm_nodes into partition.
        * lto-streamer.h (lto_output_toplevel_asms): Add encoder.

gcc/lto/ChangeLog:

        * lto.cc (stream_out_partitions): Remove asm_nodes_out.
---
 gcc/lto-cgraph.cc       | 15 +++----------
 gcc/lto-streamer-out.cc | 47 +++++++++++++++++++++--------------------
 gcc/lto-streamer.h      |  3 +--
 gcc/lto/lto.cc          |  2 --
 4 files changed, 28 insertions(+), 39 deletions(-)

diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index 017686ed9b2..86f676ce053 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -45,9 +45,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "symtab-thunks.h"
 #include "symtab-clones.h"
 
-/* True when asm nodes has been output.  */
-bool asm_nodes_output = false;
-
 static void output_cgraph_opt_summary (void);
 static void input_cgraph_opt_summary (vec<symtab_node *>  nodes);
 
@@ -1052,15 +1049,9 @@ output_symtab (void)
 
   lto_destroy_simple_output_block (ob);
 
-  /* Emit toplevel asms.
-     When doing WPA we must output every asm just once.  Since we do not 
partition asm
-     nodes at all, output them to first output.  This is kind of hack, but 
should work
-     well.  */
-  if (!asm_nodes_output && !lto_stream_offload_p)
-    {
-      asm_nodes_output = true;
-      lto_output_toplevel_asms ();
-    }
+  /* Emit toplevel asms.  */
+  if (!lto_stream_offload_p)
+    lto_output_toplevel_asms (encoder);
 
   output_refs (encoder);
 }
diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index e5de8d80cf4..d03c41f38e4 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -2554,14 +2554,18 @@ output_constructor (struct varpool_node *node, int 
output_order)
 /* Emit toplevel asms.  */
 
 void
-lto_output_toplevel_asms (void)
+lto_output_toplevel_asms (lto_symtab_encoder_t encoder)
 {
   struct output_block *ob;
-  struct asm_node *can;
   char *section_name;
   struct lto_simple_header_with_strings header;
 
-  if (!symtab->first_asm_symbol ())
+  bool any_asm = false;
+  for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
+    if (is_a <asm_node*> (lto_symtab_encoder_deref (encoder, i)))
+      any_asm = true;
+
+  if (!any_asm)
     return;
 
   ob = create_output_block (LTO_section_asm);
@@ -2569,17 +2573,22 @@ lto_output_toplevel_asms (void)
   /* Make string 0 be a NULL string.  */
   streamer_write_char_stream (ob->string_stream, 0);
 
-  for (can = symtab->first_asm_symbol (); can; can = can->next)
+  for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
     {
-      if (TREE_CODE (can->asm_str) != STRING_CST)
+      toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
+      asm_node *anode = dyn_cast <asm_node*> (tnode);
+      if (!anode)
+       continue;
+
+      if (TREE_CODE (anode->asm_str) != STRING_CST)
        {
-         sorry_at (EXPR_LOCATION (can->asm_str),
+         sorry_at (EXPR_LOCATION (anode->asm_str),
                    "LTO streaming of toplevel extended %<asm%> "
                    "unimplemented");
          continue;
        }
-      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, anode->asm_str);
+      streamer_write_hwi (ob, anode->order);
     }
 
   streamer_write_string_cst (ob, ob->main_stream, NULL_TREE);
@@ -2783,19 +2792,12 @@ create_order_remap (lto_symtab_encoder_t encoder)
 {
   auto_vec<int> orders;
   unsigned i;
-  struct asm_node* anode;
   encoder->order_remap = new hash_map<int_hash<int, -1, -2>, int>;
   unsigned n_nodes = lto_symtab_encoder_size (encoder);
 
   for (i = 0; i < n_nodes; i++)
     orders.safe_push (lto_symtab_encoder_deref (encoder, i)->order);
 
-  if (!asm_nodes_output)
-    {
-      for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
-       orders.safe_push (anode->order);
-    }
-
   orders.qsort (cmp_int);
   int ord = 0;
   int last_order = -1;
@@ -2809,14 +2811,6 @@ create_order_remap (lto_symtab_encoder_t encoder)
          ord++;
        }
     }
-
-  /* Asm nodes are currently always output only into first partition.
-     We can remap already here.  */
-  if (!asm_nodes_output)
-    {
-      for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
-       anode->order = *encoder->order_remap->get (anode->order);
-    }
 }
 
 /* Main entry point from the pass manager.  */
@@ -2831,6 +2825,13 @@ lto_output (void)
   lto_symtab_encoder_t encoder = lto_get_out_decl_state 
()->symtab_node_encoder;
   auto_vec<symtab_node *> symbols_to_copy;
 
+  if (!flag_wpa)
+    {
+      asm_node *anode;
+      for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
+       lto_set_symtab_encoder_in_partition (encoder, anode);
+    }
+
   create_order_remap (encoder);
 
   prune_offload_funcs ();
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index a1ec3b67b2f..a398f4394be 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -897,7 +897,7 @@ extern void lto_output_fn_decl_ref (struct 
lto_out_decl_state *,
                                    struct lto_output_stream *, tree);
 extern tree lto_input_var_decl_ref (lto_input_block *, lto_file_decl_data *);
 extern tree lto_input_fn_decl_ref (lto_input_block *, lto_file_decl_data *);
-extern void lto_output_toplevel_asms (void);
+extern void lto_output_toplevel_asms (lto_symtab_encoder_t);
 extern void produce_asm (struct output_block *ob);
 extern void lto_output ();
 extern void produce_asm_for_decls ();
@@ -916,7 +916,6 @@ void lto_prepare_function_for_streaming (cgraph_node *);
 
 
 /* In lto-cgraph.cc  */
-extern bool asm_nodes_output;
 lto_symtab_encoder_t lto_symtab_encoder_new (bool);
 int lto_symtab_encoder_encode (lto_symtab_encoder_t, toplevel_node *);
 void lto_symtab_encoder_delete (lto_symtab_encoder_t);
diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc
index 7935b1d1cd8..a4b1bc22cdf 100644
--- a/gcc/lto/lto.cc
+++ b/gcc/lto/lto.cc
@@ -267,7 +267,6 @@ stream_out_partitions (char *temp_filename, int blen, int 
min, int max,
              {
                /* There are no free tokens, lets do the job outselves.  */
                stream_out_partitions_1 (temp_filename, blen, min, max);
-               asm_nodes_output = true;
                return;
              }
          }
@@ -296,7 +295,6 @@ stream_out_partitions (char *temp_filename, int blen, int 
min, int max,
       if (jinfo != NULL && jinfo->is_connected)
        jinfo->disconnect ();
     }
-  asm_nodes_output = true;
 #else
   stream_out_partitions_1 (temp_filename, blen, min, max);
 #endif
-- 
2.50.0

Reply via email to