[LLVMdev] Fwd: A Question

Kenneth Uildriks kennethuil at gmail.com
Mon Sep 27 11:32:22 PDT 2010


---------- Forwarded message ----------
From: Kenneth Uildriks <kennethuil at gmail.com>
Date: Mon, Sep 27, 2010 at 1:31 PM
Subject: Re: A Question
To: Tarek Chammah <tchammah at uwaterloo.ca>


On Mon, Sep 27, 2010 at 12:49 PM, Tarek Chammah <tchammah at uwaterloo.ca> wrote:
> Hi Kenneth,
>
> If I understand you correctly, say on my Linux machine I can link in
> the pthreads library, and when I generate the IR I can then call its
> threading routines.  What if I want to transform existing C source
> codes to automatically use threading routines?  I figure I would do
> some analysis on the existing source's IR, then modify it and generate
> IR calls to use the threading routines (linked in to the executable).
>
> But where would I create the function declarations for the threading
> routines?  Would I generate IR for the declarations?  Or inject them
> as source includes at parse time into the source program I am
> analyzing?

You can generate IR for the declarations while you're transforming it.
 Once you've loaded the
.bc into a Module, you can call
module->getOrInsertFunction("pthread_XXX", etc.).  As long as
you don't add any BasicBlocks to it, it's a declaration.  Just create
calls to it where needed.

As soon as you're finished modifying the Module, write it out with the
BitcodeWriter.

Or wrap your transformer up in a Pass and just add the declarations to
the module in your pass init and insert calls to them in your
handlers.

Hopefully, your transformer won't have to even look at the C source.




More information about the llvm-dev mailing list