This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Adding functions at compile time


Matt Davis <mattdavis9@gmail.com> writes:

> I am creating a few functions at compile time, via a gcc plugin.  I create the
> functions and their bodies, and insert them into the call graph.  This is all
> done before "cgraph_finalize_compilation_unit()" has been called.  I then have
> another compiler pass, which gets started after the SSA representation has been
> generated, and it is this pass that uses the functions created previously, in
> the much earlier pass.  The problem is that by the time the created functions
> are used, the cgraph has already removed those nodes since they are disjoint.  I
> tried creating and modifying the functions in the same pass, but that was not
> successful either.  I did not see any flag I could set in the cgraph nodes,
> which are created in the first pass I mentioned preventing them from being
> removed.  Is there a way I can keep those nodes around so the functions created
> at compile time actually get built?

In effect, you want to give your functions the "used" attribute.  If you
look at handle_used_attribute in c-family/c-common.c, you will see that
you want to set DECL_PRESERVE_P.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]