> Analyzes references from toplevel extended assembly.
> 
> We cannot perform IPA optimizations with toplevel assembly, so
> symtab_node only needs ref_by_asm to know that it should not be removed.
> 
>       PR ipa/122458
> 
> gcc/ChangeLog:
> 
>       * Makefile.in: Add new file.
>       * cgraph.h (analyze_toplevel_extended_asm): New.
>       * cgraphunit.cc (symbol_table::finalize_compilation_unit):
>       Call analyze_toplevel_extended_asm.
>       * asm-toplevel.cc: New file.
> 
> gcc/lto/ChangeLog:
> 
>       * lto-common.cc (read_cgraph_and_symbols):
>       Call analyze_toplevel_extended_asm.
> 
> gcc/testsuite/ChangeLog:
> 
>       * gcc.dg/ipa/pr122458.c: New test.
> diff --git a/gcc/asm-toplevel.cc b/gcc/asm-toplevel.cc
> new file mode 100644
> index 00000000000..9d7ba934e29
> --- /dev/null
> +++ b/gcc/asm-toplevel.cc
> @@ -0,0 +1,67 @@
> +/* Toplevel assembly.
> +   Copyright (C) 2025-2025 Free Software Foundation, Inc.

I think it should be only 2025, but that will get changed soon.

> +
> +/* Analyze constraints of toplevel extended assembly.  */
> +void
> +analyze_toplevel_extended_asm ()
> +{
> +  asm_node *anode;
> +  for (anode = symtab->first_asm_symbol (); anode; anode = anode->next)
> +    {
> +      if (TREE_CODE (anode->asm_str) != ASM_EXPR)
> +     continue;
> +
> +      for (tree l = ASM_INPUTS (anode->asm_str); l; l = TREE_CHAIN (l))
> +     walk_tree (&l, walk_through_constraints, (void*) anode, NULL);
> +      for (tree l = ASM_OUTPUTS (anode->asm_str); l; l = TREE_CHAIN (l))
> +     walk_tree (&l, walk_through_constraints, (void*) anode, NULL);

If asm statement takes a global variable as input only, perhaps we can
optimize it to readonly? I.e. it may make sense to make difference
between asm loads and writes, but that can be handled incrementally
and is probably not very important.

Patch is OK,
thanks
Honza

Reply via email to