<html><head></head><body><div class="ydp808b4f71yahoo-style-wrap" style="font-family:verdana, helvetica, sans-serif;font-size:10px;"><div><div><font size="2">Hello all,</font></div><div><font size="2"><br></font></div><div><font size="2">I am returning to this subject after a while and I was looking for <span>CBuilder::CreatePThreadCreateCall function below. I cannot find it anywere and I guess it has been rename or changed into a more generic one. I would want to insert a phtread call into the input source code. Which builder class to use for that instead of CBuilder class? If I insert the call into IR representation, do I need to insert the call also into machine representation?</span></font></div><div><font size="2"><span><br></span></font></div><div><font size="2"><span>Kind regards,</span></font><br></div><div class="ydp808b4f71signature"><div style="font-family:verdana, helvetica, sans-serif;font-size:10px;"><div>----------------------------------------------------------</div><div>Iulia ȘTIRB</div><div>PhD Student in Computer Science</div><div>Associate Teaching Assistant</div><div>Department of Computers and Software Engineering</div><div>Politehnica University of Timișoara</div><div>2 Piața Victoriei, Timișoara, Romania, 300006 </div><div>Tel.: +(40) 76 560 3230</div><div>E-mail: iulia.stirb@gmail.com, iulia_s24@yahoo.com</div><div>Skype: iulia.stirb</div><div><span><span style="color:rgb(0, 0, 0);font-family:verdana, helvetica, sans-serif;font-size:10px;">----------------------------------------------------------</span></span><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div>
        <div><br></div><div><br></div>
        
        </div><div id="ydpf5b1eeafyahoo_quoted_6734507420" class="ydpf5b1eeafyahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    On Saturday, May 6, 2017, 5:58:03 PM GMT+3, Rob Cameron <cameron@cs.sfu.ca> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir="ltr">Hi, Iulia.<br clear="none"><br clear="none">You can create calls to pthread routines.   For example, this is a declaration<br clear="none">in one of our header files.<br clear="none"><br clear="none">  //  Create a call to:  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,<br clear="none">  //                    void *(*start_routine)(void*), void *arg);<br clear="none">  llvm::Value * CreatePThreadCreateCall(llvm::Value * thread, llvm::Value * attr, <br clear="none">                                        llvm::Function * start_routine, llvm::Value * arg);<br clear="none"><br clear="none">Here is our implementation (mMod is the Module * containing the code we are building).<br clear="none"><br clear="none">Value * CBuilder::CreatePThreadCreateCall(Value * thread, Value * attr, Function * start_routine, Value * arg) {<br clear="none">    Type * const voidPtrTy = getVoidPtrTy();<br clear="none">    Function * pthreadCreateFunc = mMod->getFunction("pthread_create");<br clear="none">    if (pthreadCreateFunc == nullptr) {<br clear="none">        Type * pthreadTy = getSizeTy();<br clear="none">        FunctionType * funVoidPtrVoidTy = FunctionType::get(getVoidTy(), {getVoidPtrTy()}, false);<br clear="none">        FunctionType * fty = FunctionType::get(getInt32Ty(), {pthreadTy->getPointerTo(), voidPtrTy, funVoidPtrVoidTy->getPointerTo(), voidPtrTy}, false);<br clear="none">        pthreadCreateFunc = Function::Create(fty, Function::ExternalLinkage, "pthread_create", mMod);<br clear="none">        pthreadCreateFunc->setCallingConv(CallingConv::C);<br clear="none">    }<br clear="none">    return CreateCall(pthreadCreateFunc, {thread, attr, start_routine, CreatePointerCast(arg, voidPtrTy)});<br clear="none">}<br clear="none"><br clear="none">The actual routine called is determined at link time.  In our case, <br clear="none">we rely on the ExecutionEngine to dynamically link to the pthread routines <br clear="none">available on our target platform.   This approach works well for us on both<br clear="none">Linux and Mac OS.   I don't know what happens with Windows OS.<br clear="none"><br clear="none"><br clear="none"><div class="ydpf5b1eeafyqt5344387778" id="ydpf5b1eeafyqtfd96493"><br clear="none">----- On May 6, 2017, at 4:16 AM, Iulia Stirb via llvm-dev <a shape="rect" href="mailto:llvm-dev@lists.llvm.org" rel="nofollow" target="_blank">llvm-dev@lists.llvm.org</a> wrote:<br clear="none"><br clear="none">> Hello,<br clear="none">> I know clang supports -pthread option (here). Does this mean I can call pthread<br clear="none">> routines inside llvm code and which pthread library is used, the one for Linux<br clear="none">> OS or the one for Windows?<br clear="none">> Thank you.Iulia</div><br clear="none">> <br clear="none">> <br clear="none">> _______________________________________________<br clear="none">> LLVM Developers mailing list<br clear="none">> <a shape="rect" href="mailto:llvm-dev@lists.llvm.org" rel="nofollow" target="_blank">llvm-dev@lists.llvm.org</a><br clear="none">> <a shape="rect" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="nofollow" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><div class="ydpf5b1eeafyqt5344387778" id="ydpf5b1eeafyqtfd88896"><br clear="none"></div></div></div>
            </div>
        </div></body></html>