[LLVMdev] IR code generation and JIT execution in a multithread environment

Gordon Henriksen gordonhenriksen at me.com
Mon Jan 12 09:34:59 PST 2009


On Jan 12, 2009, at 11:10, Edgar Geisler wrote:

> my goal is to create a service with multiple threads, each of them  
> generating IR code and JIT'ing/executing it in their threads and  
> some threads will share generated code through a code repository...


Hi Edgar,

Module and Value are unsafe for concurrent access--even disjoint  
instances thereof. So you'll need to hold a global mutex while  
loading, building, or transforming IR. The JIT can execute threaded  
code, but itself holds a global lock during code generation.

I think serializing code generation in a JIT will usually be adequate,  
since presumably the compiled program (rather than the compiler)  
should dominate runtime. However, if your project truly needs  
concurrent JIT compilation, LLVM doesn't yet meet your needs. Chris  
Lattner has disclosed an open project at Apple for providing  
multithreaded code generation and IR manipulation, but no code has yet  
hit the repository AFAIK.

You could certainly spawn subprocesses to do concurrent static code  
generation, however.

— Gordon





More information about the llvm-dev mailing list