[patch] Don't rauw an alias in llvm.used (v2)

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon May 6 06:16:26 PDT 2013


>> I ended implementing two options. The first one (add-back.patch)
>> looked the simplest at first: Just call replaceAllUsesWith and patch
>> llvm.used back to its previous state. The main problem in here is
>> detecting if any other changes were made. We have to walk the
>> constant's uses to find out.
>>
>> Since we ale walking the uses anyway, another option (cow.patch) is to
>> duplicate a bit of the copy on write logic in replaceAllUsesWith to
>> special case use chains that end up in llvm.used. In the end I think I
>> like this one a bit more. What do you think?
>
>
> Yes, I also prefer cow.patch. Thanks for looking into this!

Sorry, I noticed there was a third option:
* Call replaceAllUsesWith only if there uses other than the ones from
llvm.used and llvm.compiler_used.
* Rebuild llvm.used and llvm.compiler_used only at the end of
OptimizeGlobalAliases.

This has the advantage that it is easy to extend to handle the extra
optimization where we rename the target. With that enabled clang
compiles

extern "C" {
__attribute__((used)) static void foo() {}
}

to

@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to
i8*)], section "llvm.metadata"
define internal void @foo() #0 {
entry:
  ret void
}

Which is really cool. LLVM understands the hack clang did to keep the
name foo visible and removes it :-)

> Nick

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 9041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130506/4115725b/attachment.obj>


More information about the llvm-commits mailing list