Change how globalopt handles aliases in llvm.used

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon May 27 16:25:27 PDT 2013


Now that the simple fix is safely in the 3.3 branch, I would like to
revisit the more complete one.

The first patch (verify.patch) just checks that every entry in
llvm.used has a name. As far as I can tell this is a reasonable
restriction since the language reference defines llvm.used in terms of
an invisible reference.

The second patch (global-opt.patch) is the actual change. Instead of a
custom implementation of replaceAllUsesWith, we just call
replaceAllUsesWith and recreate llvm.used and llvm.compiler-used.

This change is particularity interesting because it makes llvm see
through what clang is doing with static used functions in extern "C"
contexts. With this change, running clang -O2 in

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

produces

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

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: verify.patch
Type: application/octet-stream
Size: 465 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130527/d13a9843/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: global-opt.patch
Type: application/octet-stream
Size: 13185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130527/d13a9843/attachment-0001.obj>


More information about the llvm-commits mailing list