[LLVMdev] Inserting pthread_create call into sequential code

David Blaikie dblaikie at gmail.com
Mon Nov 12 23:54:14 PST 2012


On Mon, Nov 12, 2012 at 6:22 PM, Pankit Thapar <pankit at umich.edu> wrote:
> Hi,
>
> I was working on multithreading a cross iteration loop. I want to insert a
> pthread_create function call and use other pthread functions into my LLVM
> IR.
>
> Issue is how do i get these functions using
> module->getOrInsertFunction("pthread_create"), since the function might not
> be there in IR and then insert function calls to these functions.
>
> So, crux is how do i call pthread function calls into LLVM IR for a
> sequential program.
>
> Pardon me for such a basic doubt as I am a novice in llvm yet.

One quick way you could investigate this is by using the LLVM demo
page http://llvm.org/demo (or the LLVM cpp backend). It's not perfect,
but might do in a pinch.

by compiling simple code like:

void my_func();

int main() {
  my_func();
}

& targeting the cpp backend ("LLVM C++ API code") you can see what
kind of C++ code you might need to write to call an external function.
Then calling pthread_create or any other function is just a matter of
getting the signature right, basically.

- David



More information about the llvm-dev mailing list