> > *************** cgraph_add_thunk (struct cgraph_node *de
> > *** 621,626 ****
> > --- 622,636 ----
> >     node->thunk.virtual_offset_p = virtual_offset != NULL;
> >     node->thunk.alias = real_alias;
> >     node->thunk.thunk_p = true;
> > +   node->local.finalized = true;
> > + 
> > +   if (cgraph_decide_is_function_needed (node, decl))
> > +     cgraph_mark_needed_node (node);
> > + 
> > +   if ((TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
> > +       || (DECL_VIRTUAL_P (decl)
> > +     && optimize && (DECL_COMDAT (decl) || DECL_EXTERNAL (decl))))
> 
> && optimize ?  That somehow looks weird.

The tests arranges that virtual functions are kept in cgraph even if they don't
seem to be needed.  This is because type based devirtualization may create
direct references for them and we won't see them before this happens.  The
functions, when they did not became reachable, are removed after IPA inline
pass.

With -O0 we don't care about devirtualization and it already knows to now 
introduce
new references to already optimized out functions.
As FIXME on the other occurence of this test says, this will all go away once we
have MAY edges in the callgraph.  Then we will see what functions are possible
destinations of virtual calls.

> > --- 370,377 ----
> >      to those so we need to analyze them.
> >      FIXME: We should introduce may edges for this purpose and update
> >      their handling in unreachable function removal and inliner too.  */
> > !       || (DECL_VIRTUAL_P (decl)
> > !     && optimize && (DECL_COMDAT (decl) || DECL_EXTERNAL (decl))))
> 
> again?

Same reason.

> > !       if (gimple_has_body_p (node->decl))
> > !         {
> > !     error ("Thunk is not supposed to have body");
> > !           error_found = true;
> 
> Is that true for targets that do not have asm thunks?  Thus, did
> we get rid of the path in the C++ FE that emits thunks as regular
> GENERIC functions?

C++ FE never emits thunks as regular generic functions.  Cgraph does that at a
time function they are associated to is expanded and at that time the thunk
info is cleared and they are turned into regular node (and output to assemby at
the same time).

> > !   if (node->thunk.thunk_p)
> > !     {
> > !       cgraph_create_edge (node, cgraph_get_node (node->thunk.alias),
> > !                     NULL, 0, CGRAPH_FREQ_BASE);
> 
> Ick ;)
> 
> Why not do this at thunk cgraph node creation time?

Well, analysis anyway has to walk them, because it does the reachability 
computation.
Also at the time we get thunk, C++ frontend did not finalized yet the function. 
 I am
trying to move us away from creating random stale nodes and instead creating 
all function
nodes at the time they are finalized and all external nodes at cgraph 
construction.

Honza

Reply via email to