Pankit Thapar
2012-Nov-13 02:22 UTC
[LLVMdev] Inserting pthread_create call into sequential code
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. Regards, Pankit Thapar -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121112/4e7f02ae/attachment.html>
David Blaikie
2012-Nov-13 07:54 UTC
[LLVMdev] Inserting pthread_create call into sequential code
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