Change how globalopt handles aliases in llvm.used.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 11 Jun 2013 17:48:06 +0000 (17:48 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 11 Jun 2013 17:48:06 +0000 (17:48 +0000)
commitd1b6ca23b42ad8180780c0e714e9a900e04785b1
treeded741e78e15ddf3655076d7d160a119c6b7fbc4
parent9e26acb5b55f47a4a963c1535fd6b9cb640fa4b6
Change how globalopt handles aliases in llvm.used.

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
}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183756 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/IPO/GlobalOpt.cpp
test/Transforms/GlobalOpt/alias-used.ll