1 ; Do setup work for all below tests: generate bitcode and combined index
2 ; RUN: opt -module-summary %s -o %t.bc
3 ; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc
4 ; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
6 ; RUN: llvm-lto -thinlto-index-stats %t3.bc | FileCheck %s -check-prefix=STATS
7 ; STATS: Index {{.*}} contains 24 nodes (13 functions, 3 alias, 8 globals) and 19 edges (8 refs and 11 calls)
9 ; Ensure statics are promoted/renamed correctly from this file (all but
10 ; constant variable need promotion).
11 ; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTSTATIC
12 ; EXPORTSTATIC-DAG: @staticvar.llvm.0 = hidden global
13 ; Eventually @staticconstvar can be exported as a copy and not promoted
14 ; EXPORTSTATIC-DAG: @staticconstvar.llvm.0 = hidden unnamed_addr constant
15 ; EXPORTSTATIC-DAG: @P.llvm.0 = hidden global void ()* null
16 ; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.0
17 ; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.0
19 ; Ensure that weak alias to an imported function is correctly turned into
21 ; Also ensures that alias to a linkonce function is turned into a declaration
22 ; and that the associated linkonce function is not in the output, as it is
23 ; lazily linked and never referenced/materialized.
24 ; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORTGLOB1
25 ; IMPORTGLOB1-DAG: define available_externally void @globalfunc1
26 ; IMPORTGLOB1-DAG: declare void @weakalias
27 ; IMPORTGLOB1-NOT: @linkoncealias
28 ; IMPORTGLOB1-NOT: @linkoncefunc
30 ; A strong alias is imported as an available_externally copy of its aliasee.
31 ; IMPORTGLOB1-DAG: define available_externally void @analias
32 ; IMPORTGLOB1-NOT: declare void @globalfunc2
34 ; Verify that the optimizer run
35 ; RUN: llvm-lto -thinlto-action=optimize %t2.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=OPTIMIZED
36 ; OPTIMIZED: define i32 @main()
38 ; Verify that the codegen run
39 ; RUN: llvm-lto -thinlto-action=codegen %t2.bc -o - | llvm-nm -o - | FileCheck %s --check-prefix=CODEGEN
42 ; Verify that all run together
43 ; RUN: llvm-lto -thinlto-action=run %t2.bc %t.bc -exported-symbol=_main
44 ; RUN: llvm-nm -o - < %t.bc.thinlto.o | FileCheck %s --check-prefix=ALL
45 ; RUN: llvm-nm -o - < %t2.bc.thinlto.o | FileCheck %s --check-prefix=ALL2
49 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
50 target triple = "x86_64-apple-macosx10.11.0"
52 @globalvar_in_section = global i32 1, align 4
53 @globalvar = global i32 1, align 4
54 @staticvar = internal global i32 1, align 4
55 @staticvar2 = internal global i32 1, align 4
56 @staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4
57 @commonvar = common global i32 0, align 4
58 @P = internal global void ()* null, align 8
60 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
61 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
62 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
64 define void @globalfunc1() #0 {
69 define void @globalfunc2() #0 {
74 define linkonce_odr void @linkoncefunc() #0 {
79 define i32 @referencestatics(i32 %i) #0 {
81 %i.addr = alloca i32, align 4
82 store i32 %i, i32* %i.addr, align 4
83 %call = call i32 @staticfunc()
84 %0 = load i32, i32* @staticvar, align 4
85 %add = add nsw i32 %call, %0
86 %1 = load i32, i32* %i.addr, align 4
87 %idxprom = sext i32 %1 to i64
88 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom
89 %2 = load i32, i32* %arrayidx, align 4
90 %add1 = add nsw i32 %add, %2
94 define i32 @referenceglobals(i32 %i) #0 {
96 %i.addr = alloca i32, align 4
97 store i32 %i, i32* %i.addr, align 4
98 call void @globalfunc1()
99 %0 = load i32, i32* @globalvar, align 4
103 define i32 @referencecommon(i32 %i) #0 {
105 %i.addr = alloca i32, align 4
106 store i32 %i, i32* %i.addr, align 4
107 %0 = load i32, i32* @commonvar, align 4
111 define void @setfuncptr() #0 {
113 store void ()* @staticfunc2, void ()** @P, align 8
117 define void @callfuncptr() #0 {
119 %0 = load void ()*, void ()** @P, align 8
124 @weakvar = weak global i32 1, align 4
125 define weak void @weakfunc() #0 {
130 define void @callweakfunc() #0 {
132 call void @weakfunc()
136 define internal i32 @staticfunc() #0 {
141 define internal void @staticfunc2() #0 {
143 %0 = load i32, i32* @staticvar2, align 4