[llvm-dev] LLVM and Pthreads

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] LLVM and Pthreads

Sudhindra kulkarni via llvm-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] LLVM and Pthreads

Sudhindra kulkarni via llvm-dev
On 6 May 2017 at 04:16, Iulia Stirb via llvm-dev
<[hidden email]> wrote:
> I know clang supports -pthread option (here). Does this mean I can call
> pthread routines inside llvm code

LLVM itself can run when pthreads isn't available, so while some parts
do use pthreads they have alternative implementations for other
systems. Take a look at Mutex.cpp for example: the default is Posix
but there's a Windows specific version in lib/Support/Windows.

> and which pthread library is used, the one for Linux OS or the one for Windows?

There's never (to my knowledge) a situation where both of those are
valid answers: if you're running on Linux you'll use a Linux library,
if you're running on Windows you'll use a Windows library.

Tim.
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] LLVM and Pthreads

Sudhindra kulkarni via llvm-dev



On Saturday, May 6, 2017 6:22 PM, Tim Northover <[hidden email]> wrote:


On 6 May 2017 at 04:16, Iulia Stirb via llvm-dev
<[hidden email]> wrote:
> I know clang supports -pthread option (here). Does this mean I can call
> pthread routines inside llvm code

LLVM itself can run when pthreads isn't available, so while some parts
do use pthreads they have alternative implementations for other
systems. Take a look at Mutex.cpp for example: the default is Posix
but there's a Windows specific version in lib/Support/Windows.


> and which pthread library is used, the one for Linux OS or the one for Windows?


There's never (to my knowledge) a situation where both of those are
valid answers: if you're running on Linux you'll use a Linux library,
if you're running on Windows you'll use a Windows library.

Thank you. My question was: is PThreads library for Windows supported by LLVM?

Tim.




_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] LLVM and Pthreads

Sudhindra kulkarni via llvm-dev
No, you cannot use pthreads in windows.

If you want to write multithreaded code you need to use (or create) a portable abstraction
On Sat, May 6, 2017 at 11:22 AM Iulia Stirb via llvm-dev <[hidden email]> wrote:
On Saturday, May 6, 2017 6:22 PM, Tim Northover <[hidden email]> wrote:


On 6 May 2017 at 04:16, Iulia Stirb via llvm-dev
<[hidden email]> wrote:
> I know clang supports -pthread option (here). Does this mean I can call
> pthread routines inside llvm code

LLVM itself can run when pthreads isn't available, so while some parts
do use pthreads they have alternative implementations for other
systems. Take a look at Mutex.cpp for example: the default is Posix
but there's a Windows specific version in lib/Support/Windows.


> and which pthread library is used, the one for Linux OS or the one for Windows?


There's never (to my knowledge) a situation where both of those are
valid answers: if you're running on Linux you'll use a Linux library,
if you're running on Windows you'll use a Windows library.

Thank you. My question was: is PThreads library for Windows supported by LLVM?

Tim.



_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] LLVM and Pthreads

Sudhindra kulkarni via llvm-dev
In reply to this post by Sudhindra kulkarni via llvm-dev
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 ȘTIRB
PhD Student in Computer Science
Associate Teaching Assistant
Department of Computers and Software Engineering
Politehnica University of Timișoara
2 Piața Victoriei, Timișoara, Romania, 300006 
Tel.: +(40) 76 560 3230
Skype: iulia.stirb
----------------------------------------------------------






On Saturday, May 6, 2017, 5:58:03 PM GMT+3, Rob Cameron <[hidden email]> 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 [hidden email] 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
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] LLVM and Pthreads

Sudhindra kulkarni via llvm-dev
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: [hidden email], [hidden email]: iulia.stirb----------------------------------------------------------
>
>
>
>
>  
>
>     On Saturday, May 6, 2017, 5:58:03 PM GMT+3, Rob Cameron <[hidden email]> 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 [hidden email] 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
> > [hidden email]
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>  

> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


--

Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

[hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

signature.asc (235 bytes) Download Attachment