[LLVMdev] Advice on implementing fast per-thread data

Chris Lattner sabre at nondot.org
Tue Feb 5 10:12:12 PST 2008


On Mon, 4 Feb 2008, Brian Hurt wrote:
> Another possibility, and I'm not sure how to do this in LLVM, would be to
> sacrifice a register to hold the pointer to the unique per-thread
> structure.  This would be worthwhile to me even on the register-starved
> x86-32.  I suppose I could also just add a "hidden" (compiler-added and
> -maintained) argument to every function which is the pointer to the
> per-thread data.

Thread local storage (TLS) on Linux is better than this.  Instead of 
sacrificing a GPR, it uses a segment register to reach the TLS area, 
making it very very cheap.

> Using the normal thread-local storage scares me, because I don't know the
> performance implications.

You should read up about it then. :)
Start here: http://people.redhat.com/drepper/tls.pdf

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list