public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Adding functions at compile time
@ 2011-09-11 15:38 Matt Davis
  2011-09-12  5:00 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Davis @ 2011-09-11 15:38 UTC (permalink / raw)
  To: gcc

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?

-Matt

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Adding functions at compile time
  2011-09-11 15:38 Adding functions at compile time Matt Davis
@ 2011-09-12  5:00 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2011-09-12  5:00 UTC (permalink / raw)
  To: Matt Davis; +Cc: gcc

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-12  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-11 15:38 Adding functions at compile time Matt Davis
2011-09-12  5:00 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).