[LLVMdev] multiple LLVMContext or just one?

503 views
Skip to first unread message

edA-qa mort-ora-y

unread,
Jan 31, 2013, 1:20:15 AM1/31/13
to <llvmdev@cs.uiuc.edu>
When building multiple modules should I be using multiple LLVMContext's
or just one of them shared between the modules?

I'm a little bit uncertain in regards to how the types work. The IR type
checking appears to check exact ptrs for equality so how would multiple
contexts actually work? Or is the type checking limited to within a
given module?

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.

signature.asc

Lang Hames

unread,
Feb 13, 2013, 8:26:23 PM2/13/13
to edA-qa mort-ora-y, <llvmdev@cs.uiuc.edu>
Hi,

LLVMContext was designed to support multithreading by holding the compilation context for each thread in a separate LLVMContext. If you're building modules in parallel you definitely need one LLVMContext per thread.

If you're talking about compiling multiple modules sequentially with a single context I believe that should work, though I don't know how well tested it is. I think our tools usually create an LLVMContext for each Module to be compiled.

The llvm-link tool links multiple modules that share an LLVMContext (see tools/llvm-link/llvm-link.cpp), so that use case has at least been tested.

- Lang.


_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


Rick Mann

unread,
Feb 13, 2013, 8:36:02 PM2/13/13
to Lang Hames, <llvmdev@cs.uiuc.edu>

On Feb 13, 2013, at 17:26 , Lang Hames <lha...@gmail.com> wrote:

> LLVMContext was designed to support multithreading by holding the compilation context for each thread in a separate LLVMContext. If you're building modules in parallel you definitely need one LLVMContext per thread.
>
> If you're talking about compiling multiple modules sequentially with a single context I believe that should work, though I don't know how well tested it is. I think our tools usually create an LLVMContext for each Module to be compiled.
>
> The llvm-link tool links multiple modules that share an LLVMContext (see tools/llvm-link/llvm-link.cpp), so that use case has at least been tested.

So, are you supposed to have one module and one context per thread when building modules in parallel? Or can you share one module across them all?

What's the linking API?

--
Rick

Lang Hames

unread,
Feb 14, 2013, 2:38:30 PM2/14/13
to Rick Mann, <llvmdev@cs.uiuc.edu>
Hi Rick,

Yes - the usual scheme for compiling modules in parallel is to have one LLVMContext and one Module per thread.

Can you clarify what you mean by sharing one module across "them all"? If you mean "Can multiple threads hack on a single Module?", then the answer is definitely no. A Module can only be associated with one LLVMContext, and you must have a different LLVMContext for each thread.

The linker API docs can be found at http://llvm.org/doxygen/classllvm_1_1Linker.html . I think the best way to understand their use is just to read the llvm-link.cpp source file.

Regards,
Lang.
Reply all
Reply to author
Forward
0 new messages