[LLVMdev] if llvm can translate and generate the function in parallel with multithread

Jeff Fifield fifield at colorado.edu
Mon Oct 24 09:36:47 PDT 2011


Modifying modules, function, blocks, etc. is not thread safe within the same
context.  In your example code, is the context different in each thread?
 Also calls to getPointerToFunction are thread safe in some cases, but not
in others.  see this: http://llvm.org/docs/ProgrammersManual.html#threading

In my own multithreaded JIT, I always hold a lock on the ExecutionEngine
when performing code transformation.  For example,

FunctionPassManager PM(F->getParent());
PM.add(....);
{
    MutexGuard locked(cg->lock);
    PM.run(*F);
}

where cg is a singleton ExecutionEngine instance that I use throughout my
code. Unfortunately this serializes access to all of my transformation
passes, but at least it's safe.


-Jeff


On Mon, Oct 24, 2011 at 7:25 AM, Michael.Kang <blackfin.kang at gmail.com>wrote:

> We try to use llvm to translate and generate the native code in
> parallel with multi-thread. But some various
> bugs will be triggered. We run the following code in multithread
> environment:
> ##################
> BasicBlock::Create(_CTX(), "dispatch", cpu->cur_func, 0);
> BranchInst::Create(bb_start, label_entry);
> cpu->exec_engine->getPointerToFunction
> ##################3
>
> And cpu variable is stored for every thread.
>
> Thanks
> MK
>
> --
> www.skyeye.org
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111024/d3779f10/attachment.html>


More information about the llvm-dev mailing list