[llvm] r254917 - Link declaration lazily.

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 17:45:03 PST 2015


On Mon, Dec 7, 2015 at 8:31 AM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: rafael
> Date: Mon Dec  7 10:31:41 2015
> New Revision: 254917
>
> URL: http://llvm.org/viewvc/llvm-project?rev=254917&view=rev
> Log:
> Link declaration lazily.
>
> We already linked available_externally and linkonce lazily, this just
> adds declarations to the list.
>
> Modified:
>     llvm/trunk/lib/Linker/LinkModules.cpp
>     llvm/trunk/test/Linker/2003-04-23-LinkOnceLost.ll
>     llvm/trunk/test/Linker/2003-05-31-LinkerRename.ll
>     llvm/trunk/test/Linker/ConstantGlobals.ll
>     llvm/trunk/test/Linker/Inputs/opaque.ll
>     llvm/trunk/test/Linker/Inputs/testlink.ll
>     llvm/trunk/test/Linker/Inputs/type-unique-dst-types2.ll
>     llvm/trunk/test/Linker/Inputs/type-unique-dst-types3.ll
>     llvm/trunk/test/Linker/opaque.ll
>     llvm/trunk/test/Linker/testlink.ll
>     llvm/trunk/test/Linker/type-unique-dst-types.ll
>     llvm/trunk/test/Linker/type-unique-src-type.ll
>     llvm/trunk/test/Linker/unnamed-addr1-a.ll
>     llvm/trunk/test/Linker/weakextern.ll
>
> Modified: llvm/trunk/lib/Linker/LinkModules.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Linker/LinkModules.cpp (original)
> +++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Dec  7 10:31:41 2015
> @@ -1753,6 +1753,9 @@ bool ModuleLinker::linkIfNeeded(GlobalVa
>         GV.hasAvailableExternallyLinkage()))
>      return false;
>
> +  if (GV.isDeclaration())
> +    return false;
>

This breaks Halide (halide-lang.org), which links together a bunch of .ll
files to form its runtime library, and relies on declarations being
preserved by that link step (in particular, it has declarations of various
intrinsics that it wants to look up by name later). Is there any way to
turn this off, to get back the "preserve all globals" behavior we used to
have here?


> +
>    if (const Comdat *SC = GV.getComdat()) {
>      bool LinkFromSrc;
>      Comdat::SelectionKind SK;
>
> Modified: llvm/trunk/test/Linker/2003-04-23-LinkOnceLost.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/2003-04-23-LinkOnceLost.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/2003-04-23-LinkOnceLost.ll (original)
> +++ llvm/trunk/test/Linker/2003-04-23-LinkOnceLost.ll Mon Dec  7 10:31:41
> 2015
> @@ -4,3 +4,7 @@
>
>  declare void @foo()
>
> +define void @use_foo() {
> +  call void @foo()
> +  ret void
> +}
>
> Modified: llvm/trunk/test/Linker/2003-05-31-LinkerRename.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/2003-05-31-LinkerRename.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/2003-05-31-LinkerRename.ll (original)
> +++ llvm/trunk/test/Linker/2003-05-31-LinkerRename.ll Mon Dec  7 10:31:41
> 2015
> @@ -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() {
>
> Modified: llvm/trunk/test/Linker/ConstantGlobals.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/ConstantGlobals.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/ConstantGlobals.ll (original)
> +++ llvm/trunk/test/Linker/ConstantGlobals.ll Mon Dec  7 10:31:41 2015
> @@ -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
> +}
>
> Modified: llvm/trunk/test/Linker/Inputs/opaque.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/opaque.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/Inputs/opaque.ll (original)
> +++ llvm/trunk/test/Linker/Inputs/opaque.ll Mon Dec  7 10:31:41 2015
> @@ -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
> +}
>
> Modified: llvm/trunk/test/Linker/Inputs/testlink.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/testlink.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/Inputs/testlink.ll (original)
> +++ llvm/trunk/test/Linker/Inputs/testlink.ll Mon Dec  7 10:31:41 2015
> @@ -53,4 +53,6 @@ define internal void @testIntern() {
>    ret void
>  }
>
> -declare void @VecSizeCrash1(%VecSize)
> +define void @VecSizeCrash1(%VecSize) {
> +  ret void
> +}
>
> Modified: llvm/trunk/test/Linker/Inputs/type-unique-dst-types2.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/type-unique-dst-types2.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/Inputs/type-unique-dst-types2.ll (original)
> +++ llvm/trunk/test/Linker/Inputs/type-unique-dst-types2.ll Mon Dec  7
> 10:31:41 2015
> @@ -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
> +}
>
> Modified: llvm/trunk/test/Linker/Inputs/type-unique-dst-types3.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/type-unique-dst-types3.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/Inputs/type-unique-dst-types3.ll (original)
> +++ llvm/trunk/test/Linker/Inputs/type-unique-dst-types3.ll Mon Dec  7
> 10:31:41 2015
> @@ -1,2 +1,6 @@
>  %A.11 = type opaque
>  @g2 = external global %A.11
> +
> +define %A.11* @use_g2() {
> +  ret %A.11* @g2
> +}
>
> Modified: llvm/trunk/test/Linker/opaque.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/opaque.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/opaque.ll (original)
> +++ llvm/trunk/test/Linker/opaque.ll Mon Dec  7 10:31:41 2015
> @@ -19,3 +19,7 @@
>  %C = type { %A }
>
>  @g1 = external global %B
> +
> +define %B* @use_g1() {
> +  ret %B* @g1
> +}
>
> Modified: llvm/trunk/test/Linker/testlink.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/testlink.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/testlink.ll (original)
> +++ llvm/trunk/test/Linker/testlink.ll Mon Dec  7 10:31:41 2015
> @@ -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
> +}
>
> Modified: llvm/trunk/test/Linker/type-unique-dst-types.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-dst-types.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/type-unique-dst-types.ll (original)
> +++ llvm/trunk/test/Linker/type-unique-dst-types.ll Mon Dec  7 10:31:41
> 2015
> @@ -17,3 +17,7 @@
>  %A = type { %B }
>  %B = type { i8 }
>  @g3 = external global %A
> +
> +define %A* @use_g3() {
> +  ret %A* @g3
> +}
>
> Modified: llvm/trunk/test/Linker/type-unique-src-type.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-src-type.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/type-unique-src-type.ll (original)
> +++ llvm/trunk/test/Linker/type-unique-src-type.ll Mon Dec  7 10:31:41 2015
> @@ -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
>  }
> - at g1 = external global %C.0
> + at g1 = global %C.0 zeroinitializer
>
> Modified: llvm/trunk/test/Linker/unnamed-addr1-a.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/unnamed-addr1-a.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/unnamed-addr1-a.ll (original)
> +++ llvm/trunk/test/Linker/unnamed-addr1-a.ll Mon Dec  7 10:31:41 2015
> @@ -15,6 +15,11 @@ define weak void @func-b() unnamed_addr
>  @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
>  ; 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() {
>
> Modified: llvm/trunk/test/Linker/weakextern.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/weakextern.ll?rev=254917&r1=254916&r2=254917&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Linker/weakextern.ll (original)
> +++ llvm/trunk/test/Linker/weakextern.ll Mon Dec  7 10:31:41 2015
> @@ -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
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151208/591e07e2/attachment.html>


More information about the llvm-commits mailing list