Add Available Externally linkage type to isWeakForLinker()
authorMehdi Amini <mehdi.amini@apple.com>
Tue, 8 Dec 2015 19:01:29 +0000 (19:01 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Tue, 8 Dec 2015 19:01:29 +0000 (19:01 +0000)
Per LangRef: "Globals with available_externally linkage are
allowed to be discarded at will, and are otherwise the same
as linkonce_odr", since linkonce_odr is in this list it makes
sense to have available_externally there as well.

Reviewers: rafael

Differential Revision: http://reviews.llvm.org/D15323

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255043 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/GlobalValue.h
test/Transforms/GlobalOpt/available_externally_global_ctors.ll [new file with mode: 0644]

index 2f91726..3461b9e 100644 (file)
@@ -256,7 +256,8 @@ public:
   static bool isWeakForLinker(LinkageTypes Linkage)  {
     return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage ||
            Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage ||
-           Linkage == CommonLinkage || Linkage == ExternalWeakLinkage;
+           Linkage == CommonLinkage || Linkage == ExternalWeakLinkage ||
+           Linkage == AvailableExternallyLinkage;
   }
 
   bool hasExternalLinkage() const { return isExternalLinkage(Linkage); }
diff --git a/test/Transforms/GlobalOpt/available_externally_global_ctors.ll b/test/Transforms/GlobalOpt/available_externally_global_ctors.ll
new file mode 100644 (file)
index 0000000..39dc054
--- /dev/null
@@ -0,0 +1,22 @@
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; RUN: opt -S -globalopt < %s | FileCheck %s
+
+; Verify that the initialization of the available_externally global is not eliminated
+; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo_static_init, i8* null }]
+
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @foo_static_init, i8* null }]
+@foo_external = available_externally global void ()* null, align 8
+
+define internal void @foo_static_init() {
+entry:
+  store void ()* @foo_impl, void ()** @foo_external, align 8
+  ret void
+}
+
+define internal void @foo_impl() {
+entry:
+  ret void
+}
+