lto: Compute partition boundary with asm_nodes

Previous patch added asm_node streaming, so we need to add referenced
symbols to partition.

asm_nodes must be added to partition before computing the boundary.

gcc/ChangeLog:

	* lto-cgraph.cc (compute_ltrans_boundary): Add symbols
	referenced from asm_nodes.
	* lto-streamer-out.cc (lto_output): Move adding asm_nodes
	to...
	* passes.cc (ipa_write_summaries): ...here.

gcc/testsuite/ChangeLog:

	* gcc.dg/lto/toplevel-extended-asm-1_0.c: New test.
	* gcc.dg/lto/toplevel-extended-asm-1_1.c: New test.
This commit is contained in:
Michal Jires
2025-11-16 04:17:07 +01:00
parent f7a08611ee
commit 4faf70b615
5 changed files with 54 additions and 9 deletions

View File

@@ -899,6 +899,24 @@ compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
lto_set_symtab_encoder_encode_initializer (encoder, vnode);
create_references (encoder, vnode);
}
for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next (&lsei))
{
toplevel_node *tnode = lsei_node (lsei);
if (asm_node* node = dyn_cast <asm_node*> (tnode))
{
symtab_node* ref;
for (unsigned i = 0; node->symbols_referenced.iterate (i, &ref); i++)
{
if (!lto_symtab_encoder_in_partition_p (encoder, ref))
{
if (cgraph_node* cref = dyn_cast <cgraph_node*> (ref))
add_node_to (encoder, cref, false);
else if (varpool_node *vref = dyn_cast <varpool_node *> (ref))
lto_symtab_encoder_encode (encoder, vref);
}
}
}
}
/* Pickle in also the initializer of all referenced readonly variables
to help folding. Constant pool variables are not shared, so we must
pickle those too. */

View File

@@ -2817,15 +2817,6 @@ 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 = safe_as_a<asm_node*>(anode->next))
lto_set_symtab_encoder_in_partition (encoder, anode);
}
create_order_remap (encoder);
prune_offload_funcs ();

View File

@@ -2911,6 +2911,11 @@ ipa_write_summaries (void)
if (vnode->need_lto_streaming)
lto_set_symtab_encoder_in_partition (encoder, vnode);
asm_node *anode;
for (anode = symtab->first_asm_symbol (); anode;
anode = safe_as_a<asm_node*> (anode->next))
lto_set_symtab_encoder_in_partition (encoder, anode);
ipa_write_summaries_1 (compute_ltrans_boundary (encoder),
flag_generate_offload);

View File

@@ -0,0 +1,19 @@
/* { dg-lto-do link } */
/* { dg-lto-options {{-O2 -flto -flto-partition=1to1} } } */
void asm_fn();
void asm_fn_used();
asm(".global %cc0\n%cc0:" :: ":" (asm_fn));
asm(".global %cc0\n%cc0:" :: ":" (asm_fn_used));
__attribute__((noinline))
int privatized_fn(int v) { return v + v;}
extern void call_privatized_fn();
int main() {
privatized_fn (0);
call_privatized_fn ();
}

View File

@@ -0,0 +1,12 @@
extern void asm_fn_used();
__attribute__((used))
void local_caller() {
asm_fn_used();
}
__attribute__((noipa))
static void privatized_fn() { asm volatile ("");}
asm(".long %cc0" :: "s"(privatized_fn));
void call_privatized_fn() { privatized_fn();}