From: Rafael Espindola Date: Mon, 7 Dec 2015 16:31:41 +0000 (+0000) Subject: Link declaration lazily. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=0178d23ade9b549a91e3409dd15833ea8a451cb4 Link declaration lazily. We already linked available_externally and linkonce lazily, this just adds declarations to the list. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254917 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index a1c3162bf79..8e0904a858b 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1753,6 +1753,9 @@ bool ModuleLinker::linkIfNeeded(GlobalValue &GV) { GV.hasAvailableExternallyLinkage())) return false; + if (GV.isDeclaration()) + return false; + if (const Comdat *SC = GV.getComdat()) { bool LinkFromSrc; Comdat::SelectionKind SK; diff --git a/test/Linker/2003-04-23-LinkOnceLost.ll b/test/Linker/2003-04-23-LinkOnceLost.ll index c699d1eb058..e2b600c877c 100644 --- a/test/Linker/2003-04-23-LinkOnceLost.ll +++ b/test/Linker/2003-04-23-LinkOnceLost.ll @@ -4,3 +4,7 @@ declare void @foo() +define void @use_foo() { + call void @foo() + ret void +} diff --git a/test/Linker/2003-05-31-LinkerRename.ll b/test/Linker/2003-05-31-LinkerRename.ll index ee070b6dbdf..f511be1bf22 100644 --- a/test/Linker/2003-05-31-LinkerRename.ll +++ b/test/Linker/2003-05-31-LinkerRename.ll @@ -6,13 +6,13 @@ ; CHECK-NEXT: ret i32 7 ; CHECK-NEXT: } -; CHECK: declare i32 @foo() - ; CHECK: define i32 @test() { ; CHECK-NEXT: %X = call i32 @foo() ; CHECK-NEXT: ret i32 %X ; CHECK-NEXT: } +; CHECK: declare i32 @foo() + declare i32 @foo() define i32 @test() { diff --git a/test/Linker/ConstantGlobals.ll b/test/Linker/ConstantGlobals.ll index 49f86a51bd7..58c0d711a07 100644 --- a/test/Linker/ConstantGlobals.ll +++ b/test/Linker/ConstantGlobals.ll @@ -6,3 +6,7 @@ ; CHECK-DAG: @Y = external global [1 x i32] @Y = external global [1 x i32] + +define [1 x i32]* @use-Y() { + ret [1 x i32] *@Y +} diff --git a/test/Linker/Inputs/opaque.ll b/test/Linker/Inputs/opaque.ll index f164abd586d..a5f27cba418 100644 --- a/test/Linker/Inputs/opaque.ll +++ b/test/Linker/Inputs/opaque.ll @@ -11,3 +11,11 @@ define void @f1() { getelementptr %A, %A* null, i32 0 ret void } + +define %A* @use_g2() { + ret %A* @g2 +} + +define %B* @use_g3() { + ret %B* @g3 +} diff --git a/test/Linker/Inputs/testlink.ll b/test/Linker/Inputs/testlink.ll index 263d9e77d1a..22a66399be0 100644 --- a/test/Linker/Inputs/testlink.ll +++ b/test/Linker/Inputs/testlink.ll @@ -53,4 +53,6 @@ define internal void @testIntern() { ret void } -declare void @VecSizeCrash1(%VecSize) +define void @VecSizeCrash1(%VecSize) { + ret void +} diff --git a/test/Linker/Inputs/type-unique-dst-types2.ll b/test/Linker/Inputs/type-unique-dst-types2.ll index b565c6d7364..7770ea3cca0 100644 --- a/test/Linker/Inputs/type-unique-dst-types2.ll +++ b/test/Linker/Inputs/type-unique-dst-types2.ll @@ -1,3 +1,7 @@ %A.11 = type { %B } %B = type { i8 } @g1 = external global %A.11 + +define %A.11* @use_g1() { + ret %A.11* @g1 +} diff --git a/test/Linker/Inputs/type-unique-dst-types3.ll b/test/Linker/Inputs/type-unique-dst-types3.ll index c5794ad839a..8a5ac269479 100644 --- a/test/Linker/Inputs/type-unique-dst-types3.ll +++ b/test/Linker/Inputs/type-unique-dst-types3.ll @@ -1,2 +1,6 @@ %A.11 = type opaque @g2 = external global %A.11 + +define %A.11* @use_g2() { + ret %A.11* @g2 +} diff --git a/test/Linker/opaque.ll b/test/Linker/opaque.ll index 4f3f398f8f1..6fd1ae90d4f 100644 --- a/test/Linker/opaque.ll +++ b/test/Linker/opaque.ll @@ -19,3 +19,7 @@ %C = type { %A } @g1 = external global %B + +define %B* @use_g1() { + ret %B* @g1 +} diff --git a/test/Linker/testlink.ll b/test/Linker/testlink.ll index 82a2229f57a..6a316a3bf84 100644 --- a/test/Linker/testlink.ll +++ b/test/Linker/testlink.ll @@ -32,6 +32,11 @@ ; CHECK-DAG: @0 = external global i32 @0 = external global i32 + +define i32* @use0() { + ret i32* @0 +} + ; CHECK-DAG: @Inte = global i32 1 @Inte = global i32 1 @@ -101,4 +106,6 @@ define void @testIntern() { ret void } -declare void @VecSizeCrash(%VecSize) +define void @VecSizeCrash(%VecSize) { + ret void +} diff --git a/test/Linker/type-unique-dst-types.ll b/test/Linker/type-unique-dst-types.ll index 30aecbb970c..1adad49de91 100644 --- a/test/Linker/type-unique-dst-types.ll +++ b/test/Linker/type-unique-dst-types.ll @@ -17,3 +17,7 @@ %A = type { %B } %B = type { i8 } @g3 = external global %A + +define %A* @use_g3() { + ret %A* @g3 +} diff --git a/test/Linker/type-unique-src-type.ll b/test/Linker/type-unique-src-type.ll index 110ecc87e1b..ab7322892e0 100644 --- a/test/Linker/type-unique-src-type.ll +++ b/test/Linker/type-unique-src-type.ll @@ -10,7 +10,7 @@ ; CHECK-NEXT: %B = type { %A } ; CHECK-NEXT: %A = type { i8 } -; CHECK: @g1 = external global %C.0 +; CHECK: @g1 = global %C.0 zeroinitializer ; CHECK: getelementptr %C.0, %C.0* null, i64 0, i32 0, i32 0 %A = type { i8 } @@ -21,4 +21,4 @@ define void @f1() { getelementptr %C, %C* null, i64 0, i32 0, i32 0 ret void } -@g1 = external global %C.0 +@g1 = global %C.0 zeroinitializer diff --git a/test/Linker/unnamed-addr1-a.ll b/test/Linker/unnamed-addr1-a.ll index 6ff0fd90b68..a96f089a99c 100644 --- a/test/Linker/unnamed-addr1-a.ll +++ b/test/Linker/unnamed-addr1-a.ll @@ -15,6 +15,11 @@ define weak void @func-b() unnamed_addr { ret void } @global-c = common unnamed_addr global i32 0 ; CHECK-DAG: @global-c = common unnamed_addr global i32 0 @global-d = external global i32 + +define i32* @use-global-d() { + ret i32* @global-d +} + ; CHECK-DAG: @global-d = global i32 42 @global-e = external unnamed_addr global i32 ; CHECK-DAG: @global-e = unnamed_addr global i32 42 @@ -27,6 +32,11 @@ define weak void @func-b() unnamed_addr { ret void } ; CHECK-DAG: @alias-b = unnamed_addr alias i32, i32* @global-f declare void @func-c() +define void @use-func-c() { + call void @func-c() + ret void +} + ; CHECK-DAG: define weak void @func-c() { define weak void @func-d() { ret void } ; CHECK-DAG: define weak void @func-d() { diff --git a/test/Linker/weakextern.ll b/test/Linker/weakextern.ll index e1754e60547..814550a907b 100644 --- a/test/Linker/weakextern.ll +++ b/test/Linker/weakextern.ll @@ -6,3 +6,7 @@ @kallsyms_names = extern_weak global [0 x i8] @MyVar = extern_weak global i32 @Inte = extern_weak global i32 + +define weak [0 x i8]* @use_kallsyms_names() { + ret [0 x i8]* @kallsyms_names +}