Threading support

Hi!

I've read in the mailing list archives that LLVM isn't able to run threaded programs:

http://mail.cs.uiuc.edu/pipermail/llvmdev/2003-December/000758.html

Is there a Bugzilla about this that I could CC myself to? Or should I file one?

   Cheers //Johan

I've read in the mailing list archives that LLVM isn't able to run threaded
programs:
http://mail.cs.uiuc.edu/pipermail/llvmdev/2003-December/000758.html

That is true, the LLVM JIT does not have mutexes to protect it against two
threads that need code generation at the same time. The static compiler
should be fine.

Is there a Bugzilla about this that I could CC myself to? Or should I
file one?

I don't think there is one, go ahead and file one. :slight_smile:

Thanks,

-Chris

Johan,

You are correct that today LLVM doesn't handle multi-threaded programs. However, I believe Misha is working on this now (correct me if I'm wrong Misha). To file a bugzilla on this would be a little redundant. Its a well-known issue and one that is being worked on.

Reid.

Johan Walles wrote:

You are correct that today LLVM doesn't handle multi-threaded programs.
However, I believe Misha is working on this now (correct me if I'm wrong
Misha). To file a bugzilla on this would be a little redundant. Its a
well-known issue and one that is being worked on.

Actually, its best to file a bug report so that others are aware of this
and know that it is being worked on. Or perhaps someone not directly
related to the LLVM project might take it upon themself to fix this bug.

Thanks,
Tanya

http://www.nondot.org/tonic

Hi,

   I'm currently implementing some optimization passes for LLVM and I
came across a problem. I'm new to LLVM so if this question has been
asked before please kindly tell me where can I find the answer.

   There are 2 types of AllocationInst - Alloca and Malloc. But most of
the time from the compiled byte code I can only find the Alloca
statement (actually I never come across a single Malloc statement). the
function "malloc" is called tho. Does anybody know when will a
"MallocInst" be generated? Thanks heaps.

Best Regards,
Patrick

You are correct that today LLVM doesn't handle multi-threaded
programs. However, I believe Misha is working on this now (correct me
if I'm wrong Misha).

Actually, Brian and I started working on the issue, but it was not
completed. There are locking primitives in the JIT, but it is not
completely thread-safe. That is to say, you can run some pthread
programs, but there's the chance that some of them may not work.

Having said that, I *have* run threaded programs successfully with the
JIT.

To file a bugzilla on this would be a little redundant. Its a
well-known issue and one that is being worked on.

As Tanya said -- it's better to have a report so that it's being
tracked, plus we can then add it to the next release page once it is
completely implemented. And, if anyone outside of our group wants to
work on it, they will be able to find it.

That is done by the Raise Allocations pass, -raiseallocs on the command
line. It is automatically run by gccas which is invoked by the C and C++
front ends.

If you manage to turn it off, you can get the effect by post-processing
your own bytecode modules by using

  opt -raiseallocs < input.bc > output.bc

Actually there are two different issues here. First, the JIT does not use
locking, so if you run a threaded program in it, you might get "reentrant
compilation" assertions. Fixing/implementing this should be pretty
straight-forward, it's just that noone has tackled it yet.

Second, and completely seperate, LLVM does not provide any intrinsic
support for threaded programs (such as locking intrinsics, etc). Note
that this is not a bug, and doesn't prevent working on threaded programs,
you just need to use a preexisting threads library, like pthreads. I say
that this is not a bug because it does not prevent the correct compilation
of threaded programs at all. In the future, we may add features to LLVM
to make it easier to express the parallelism to the compiler, allowing for
interesting analysis and optimization potentials, but that's purely a new
feature, not a bug fix...

-Chris