On Wed, Aug 27, 2025 at 6:56 AM Michal Jires <[email protected]> wrote:
>
> asm_node and symbol_node will now inherit from toplevel_node.
> This is now useful for lto partitioning, in future it should be also
> useful for toplevel extended assembly.
>
> gcc/ChangeLog:
>
> * cgraph.h (enum symtab_type): Replace with toplevel_type.
> (enum toplevel_type): New.
> (struct toplevel_node): New.
> (struct asm_node): Inherits from toplevel_node.
> (test): New.
> (symbol_table::finalize_toplevel_asm): Use constructor.
> * coretypes.h (struct toplevel_node): New.
> (struct asm_node): New.
> * lto-streamer-in.cc (lto_input_toplevel_asms): Add
> lto_file_data.
This broke -fdump-ipa-*-details because symtab_type_names was not
updated to handle the two new types.
This is PR 122512. I will do the obvious fix. Please test because it
is obvious that you did run the testsuite or you didn't compare the
testsuite results correctly.
Thanks,
Andrew
> ---
> gcc/cgraph.h | 98 ++++++++++++++++++++++++++++++++----------
> gcc/coretypes.h | 10 +++--
> gcc/lto-streamer-in.cc | 1 +
> 3 files changed, 82 insertions(+), 27 deletions(-)
>
> diff --git a/gcc/cgraph.h b/gcc/cgraph.h
> index deca564a8e3..278479a5510 100644
> --- a/gcc/cgraph.h
> +++ b/gcc/cgraph.h
> @@ -37,10 +37,12 @@ extern void debuginfo_early_stop (void);
> class ipa_opt_pass_d;
> typedef ipa_opt_pass_d *ipa_opt_pass;
>
> -/* Symbol table consists of functions and variables.
> +/* Toplevel consists of functions, variables and assembly.
> TODO: add labels and CONST_DECLs. */
> -enum symtab_type
> +enum toplevel_type
> {
> + TOPLEVEL_BASE,
> + TOPLEVEL_ASM,
> SYMTAB_SYMBOL,
> SYMTAB_FUNCTION,
> SYMTAB_VARIABLE
> @@ -100,18 +102,37 @@ enum symbol_partitioning_class
> SYMBOL_DUPLICATE
> };
>
> +/* Base of all toplevel entries.
> + Inherited by symtab_node and asm_node. */
> +struct GTY ((desc ("%h.type"), tag ("TOPLEVEL_BASE"))) toplevel_node {
> + /* Constructor. */
> + explicit toplevel_node (toplevel_type t)
> + : lto_file_data (NULL), order (-1), type (t)
> + {}
> +
> + /* File stream where this node is being written to. */
> + struct lto_file_decl_data * lto_file_data;
> +
> + /* Ordering of all cgraph nodes. */
> + int order;
> +
> + /* Type of the node. */
> + ENUM_BITFIELD (toplevel_type) type : 8;
> +};
> +
> /* Base of all entries in the symbol table.
> The symtab_node is inherited by cgraph and varpol nodes. */
> -struct GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
> +struct GTY ((tag ("SYMTAB_SYMBOL"),
> chain_next ("%h.next"), chain_prev ("%h.previous")))
> - symtab_node
> + symtab_node: public toplevel_node
> {
> public:
> friend class symbol_table;
>
> /* Constructor. */
> - explicit symtab_node (symtab_type t)
> - : type (t), resolution (LDPR_UNKNOWN), definition (false), alias (false),
> + explicit symtab_node (toplevel_type t)
> + : toplevel_node (t),
> + resolution (LDPR_UNKNOWN), definition (false), alias (false),
> transparent_alias (false), weakref (false), cpp_implicit_alias (false),
> symver (false), analyzed (false), writeonly (false),
> refuse_visibility_changes (false), externally_visible (false),
> @@ -121,9 +142,9 @@ public:
> used_from_other_partition (false), in_other_partition (false),
> address_taken (false), in_init_priority_hash (false),
> need_lto_streaming (false), offloadable (false), ifunc_resolver
> (false),
> - order (-1), next_sharing_asm_name (NULL),
> + next_sharing_asm_name (NULL),
> previous_sharing_asm_name (NULL), same_comdat_group (NULL), ref_list
> (),
> - alias_target (NULL), lto_file_data (NULL), aux (NULL),
> + alias_target (NULL), aux (NULL),
> x_comdat_group (NULL_TREE), x_section (NULL), m_uid (-1)
> {}
>
> @@ -498,9 +519,6 @@ public:
> return m_uid;
> }
>
> - /* Type of the symbol. */
> - ENUM_BITFIELD (symtab_type) type : 8;
> -
> /* The symbols resolution. */
> ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
>
> @@ -609,9 +627,6 @@ public:
> unsigned ifunc_resolver : 1;
>
>
> - /* Ordering of all symtab entries. */
> - int order;
> -
> /* Declaration representing the symbol. */
> tree decl;
>
> @@ -642,9 +657,6 @@ public:
> Once alias is resolved, this pointer become NULL. */
> tree alias_target;
>
> - /* File stream where this node is being written to. */
> - struct lto_file_decl_data * lto_file_data;
> -
> void *GTY ((skip)) aux;
>
> /* Comdat group the symbol is in. Can be private if GGC allowed that. */
> @@ -2162,13 +2174,14 @@ private:
>
> /* Every top level asm statement is put into a asm_node. */
>
> -struct GTY(()) asm_node {
> +struct GTY ((tag ("TOPLEVEL_ASM"))) asm_node: public toplevel_node {
> + explicit asm_node (tree asm_str)
> + : toplevel_node (TOPLEVEL_ASM), next (NULL), asm_str (asm_str)
> + {}
> /* Next asm node. */
> asm_node *next;
> /* String for this asm node. */
> tree asm_str;
> - /* Ordering of all cgraph nodes. */
> - int order;
> };
>
> /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
> @@ -2191,6 +2204,47 @@ is_a_helper <varpool_node *>::test (symtab_node *p)
> return p && p->type == SYMTAB_VARIABLE;
> }
>
> +/* Report whether or not THIS toplevel node is a function, aka cgraph_node.
> */
> +
> +template <>
> +template <>
> +inline bool
> +is_a_helper <cgraph_node *>::test (toplevel_node *p)
> +{
> + return p && p->type == SYMTAB_FUNCTION;
> +}
> +
> +/* Report whether or not THIS toplevel node is a variable, aka varpool_node.
> */
> +
> +template <>
> +template <>
> +inline bool
> +is_a_helper <varpool_node *>::test (toplevel_node *p)
> +{
> + return p && p->type == SYMTAB_VARIABLE;
> +}
> +
> +/* Report whether or not THIS toplevel node is a symtab_node. */
> +
> +template <>
> +template <>
> +inline bool
> +is_a_helper <symtab_node *>::test (toplevel_node *p)
> +{
> + return p && p->type >= SYMTAB_SYMBOL;
> +}
> +
> +/* Report whether or not THIS toplevel node is a toplevel assembly, aka
> + asm_node. */
> +
> +template <>
> +template <>
> +inline bool
> +is_a_helper <asm_node *>::test (toplevel_node *p)
> +{
> + return p && p->type == TOPLEVEL_ASM;
> +}
> +
> typedef void (*cgraph_edge_hook)(cgraph_edge *, void *);
> typedef void (*cgraph_node_hook)(cgraph_node *, void *);
> typedef void (*varpool_node_hook)(varpool_node *, void *);
> @@ -2855,10 +2909,8 @@ symbol_table::finalize_toplevel_asm (tree asm_str)
> {
> asm_node *node;
>
> - node = ggc_cleared_alloc<asm_node> ();
> - node->asm_str = asm_str;
> + node = new (ggc_cleared_alloc<asm_node> ()) asm_node (asm_str);
> node->order = order++;
> - node->next = NULL;
>
> if (asmnodes == NULL)
> asmnodes = node;
> diff --git a/gcc/coretypes.h b/gcc/coretypes.h
> index b6a922a506c..f4a61c4edc3 100644
> --- a/gcc/coretypes.h
> +++ b/gcc/coretypes.h
> @@ -147,12 +147,14 @@ using dw_cfi_ref = struct dw_cfi_node *;
> enum dw_cfi_oprnd_type: int;
> enum dwarf_call_frame_info: int;
>
> -/* Subclasses of symtab_node, using indentation to show the class
> +/* Subclasses of toplevel_node, using indentation to show the class
> hierarchy. */
>
> -struct symtab_node;
> - struct cgraph_node;
> - struct varpool_node;
> +struct toplevel_node;
> + struct asm_node;
> + struct symtab_node;
> + struct cgraph_node;
> + struct varpool_node;
> struct cgraph_edge;
>
> union section;
> diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc
> index be818268f85..2efa1f33967 100644
> --- a/gcc/lto-streamer-in.cc
> +++ b/gcc/lto-streamer-in.cc
> @@ -2004,6 +2004,7 @@ lto_input_toplevel_asms (struct lto_file_decl_data
> *file_data, int order_base)
> {
> asm_node *node = symtab->finalize_toplevel_asm (str);
> node->order = streamer_read_hwi (&ib) + order_base;
> + node->lto_file_data = file_data;
> if (node->order >= symtab->order)
> symtab->order = node->order + 1;
> }
> --
> 2.50.0
>