[llvm-dev] LLVM and Pthreads

Doerfert, Johannes via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 22 07:03:12 PDT 2019


Hi Iulia,

The declaration Rob has shared was never part of mainline LLVM (afaik).
The implementation Rob provided should however still work.
Have you tried it?

There is no need to add/change anything in the machine representation.

Cheers,
  Johannes



On 04/22, Iulia Stirb via llvm-dev wrote:
> Hello all,
> I am returning to this subject after a while and I was looking for 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?
> Kind regards,
> ----------------------------------------------------------Iulia ȘTIRBPhD Student in Computer ScienceAssociate Teaching AssistantDepartment of Computers and Software EngineeringPolitehnica University of Timișoara2 Piața Victoriei, Timișoara, Romania, 300006 Tel.: +(40) 76 560 3230E-mail: iulia.stirb at gmail.com, iulia_s24 at yahoo.comSkype: iulia.stirb----------------------------------------------------------
> 
> 
> 
> 
>  
> 
>     On Saturday, May 6, 2017, 5:58:03 PM GMT+3, Rob Cameron <cameron at cs.sfu.ca> wrote:  
>  
>  Hi, Iulia.
> 
> You can create calls to pthread routines.  For example, this is a declaration
> in one of our header files.
> 
>   //  Create a call to:  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
>   //                    void *(*start_routine)(void*), void *arg);
>   llvm::Value * CreatePThreadCreateCall(llvm::Value * thread, llvm::Value * attr, 
>                                         llvm::Function * start_routine, llvm::Value * arg);
> 
> Here is our implementation (mMod is the Module * containing the code we are building).
> 
> Value * CBuilder::CreatePThreadCreateCall(Value * thread, Value * attr, Function * start_routine, Value * arg) {
>     Type * const voidPtrTy = getVoidPtrTy();
>     Function * pthreadCreateFunc = mMod->getFunction("pthread_create");
>     if (pthreadCreateFunc == nullptr) {
>         Type * pthreadTy = getSizeTy();
>         FunctionType * funVoidPtrVoidTy = FunctionType::get(getVoidTy(), {getVoidPtrTy()}, false);
>         FunctionType * fty = FunctionType::get(getInt32Ty(), {pthreadTy->getPointerTo(), voidPtrTy, funVoidPtrVoidTy->getPointerTo(), voidPtrTy}, false);
>         pthreadCreateFunc = Function::Create(fty, Function::ExternalLinkage, "pthread_create", mMod);
>         pthreadCreateFunc->setCallingConv(CallingConv::C);
>     }
>     return CreateCall(pthreadCreateFunc, {thread, attr, start_routine, CreatePointerCast(arg, voidPtrTy)});
> }
> 
> The actual routine called is determined at link time.  In our case, 
> we rely on the ExecutionEngine to dynamically link to the pthread routines 
> available on our target platform.  This approach works well for us on both
> Linux and Mac OS.  I don't know what happens with Windows OS.
> 
> 
> 
> ----- On May 6, 2017, at 4:16 AM, Iulia Stirb via llvm-dev llvm-dev at lists.llvm.org wrote:
> 
> > Hello,
> > I know clang supports -pthread option (here). Does this mean I can call pthread
> > routines inside llvm code and which pthread library is used, the one for Linux
> > OS or the one for Windows?
> > Thank you.Iulia
> > 
> > 
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>   

> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-- 

Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

jdoerfert at anl.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190422/abde8ef1/attachment.sig>


More information about the llvm-dev mailing list