This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Adding functions at compile time
- From: Ian Lance Taylor <iant at google dot com>
- To: Matt Davis <mattdavis9 at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 11 Sep 2011 22:00:31 -0700
- Subject: Re: Adding functions at compile time
- References: <20110911153753.GA19767@excelsa.hr.cox.net>
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