[llvm-commits] [PATCH] Implement local-dynamic TLS model for x86 (PR3985)

Hans Wennborg hans at chromium.org
Fri Jun 1 06:05:07 PDT 2012


On Wed, May 30, 2012 at 8:48 AM, Hans Wennborg <hans at chromium.org> wrote:
> On Fri, May 25, 2012 at 9:51 PM, Hans Wennborg <hans at chromium.org> wrote:
>> On Wed, May 23, 2012 at 5:44 PM, Hans Wennborg <hans at chromium.org> wrote:
>>> Taking another stab at this.
>>>
>>> The attached patch implements support for the local-dynamic TLS model on x86.
>>
>> Attached is a new patch that will not move the calls around, but
>> removes all calls except the first on each execution path. It also
>> doesn't add the pass when CodeGenOpt::None is used.
>
> Ping?

The patch solves a TODO from 2007 (and PR3985), so I think it would be
great if we could get this fixed.

For anyone who would like to review this, I thought I'd provide some pointers:

Thread-local Storage for ELF is documented in [1]. Specifically, the
local-dynamic model is in section 4.2.

My patch basically does two things:

1. Lowering of thread-local accesses with the local-dynamic model. The
lowering is similar to how general-dynamic accesses are handled. It
starts in X86TargetLowering::LowerGlobalAddress. I'm adding a new node
type: X86ISD::TLSBASEADDR (general-dynamic uses X86ISD::TLSADDR). I'm
adding new pseudo instructions TLS_base_addr32 and TLS_base_addr64
(general-dynamic uses TLS_addr{32,64}), and so on. Finally the
LowerTlsAddr function in X86MCInstLower.cpp is updated to handle the
local-dynamic case. I've tried to mimic the general-dynamic case as
much as I can here, but since I'm unfamiliar with codegen, it would be
great if someone could check for any subtle mistakes.

2. Adding a MachineFunctionPass to clean up. The point of the
local-dynamic model is that once you have obtained the base address
for the TLS storage of a module (using a call to __get_tls_addr), you
can use that address to access all other local-dynamic variables too.
My patch adds a pass that walks the dominator tree to remove all but
the first TLS_base_addr instruction per execution path. The pass is
not added when using CodeGenOpt::None, and it only processes functions
with 2 or more local-dynamic accesses. I put the pass in
X86InstrInfo.cpp, because it is similar to the CGBR (Create Global
Base Reg pass) that already lives there, but I'd be happy to move it
if someone knows a better place.

Comments welcome :)

Thanks,
Hans

[1]. http://www.akkadia.org/drepper/tls.pdf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: local-dynamic3.patch
Type: application/octet-stream
Size: 25961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120601/8bd2917c/attachment.obj>


More information about the llvm-commits mailing list