This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Use aliases instead of separate copies for !DECL_ONE_ONLY C[12] ctors or D[12] dtors with identical bodies (PR c++/3187, take 2)
> 2009-11-13 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/3187
> * cgraph.h (struct cgraph_node): Add same_body and same_body_alias
> fields.
> (cgraph_same_body_alias): New prototype.
> * cgraphunit.c (cgraph_expand_function, cgraph_emit_thunks,
> cgraph_materialize_all_clones): Handle same_body aliases.
> * cgraph.c (cgraph_allocate_node): New function.
> (cgraph_create_node): Use it.
> (cgraph_node_for_decl, cgraph_node, cgraph_get_node,
> cgraph_node_for_asm, cgraph_remove_node): Handle same_body aliases.
> (cgraph_same_body_alias, cgraph_remove_same_body_alias): New
> functions.
You will need to update LTO streamer to handle same_body_aliases and
build the alias nodes.
> +/* Remove same body alias node. */
> +
> +static void
> +cgraph_remove_same_body_alias (struct cgraph_node *node)
I guess we are losing bit of precision here by removing the aliases all
at once only after all possible references to each of them disappear.
Doing per-alias reachability in cgraph_remove_unreachable_node would be
probably possible, but bit ugly (we will need to tag cgraph edge with
extra info to what alias edge goes) and I guess it is not worthwhile at
all. Or do you foresee a lot of redundant COMDAT symbol table entries
created this way?
> @@ -1041,7 +1041,12 @@ cgraph_emit_thunks (void)
> cgraph_mark_functions_to_output in cgraph_optimize). */
> if (n->reachable
> && !DECL_EXTERNAL (n->decl))
> - lang_hooks.callgraph.emit_associated_thunks (n->decl);
Hopefully we can move thunks into same body aliases too incrementally.
> @@ -1910,7 +1923,22 @@ cgraph_materialize_all_clones (void)
> {
> gimple new_stmt;
> gimple_stmt_iterator gsi;
> -
> +
> + if (e->callee->same_body)
> + {
> + struct cgraph_node *alias;
> +
> + for (alias = e->callee->same_body;
> + alias;
> + alias = alias->next)
> + if (decl == alias->decl)
> + break;
> + /* Don't update call from same body alias to the real
> + function. */
> + if (alias)
> + continue;
I don't get this. You have functions a,b,c,d in same body group and you
make cgraph so all calleers ends going to a, then you constant propagate
and discover that first argument of a is always 1 but a/b/c/d are also
exported from unit, so you decide to clone.
In this case you want to update all the calls no matter if they go to
a,b,c, or d, since they are all having first argument of 1.
Also can it happen for a/b/c/d to have different visibilities? (ie. some
externally visible, others not?)
In that case the combined node has to be most restrictive version of it.
Otherwise cgraph part of patch seems fine to me.
Honza