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 5 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) 8 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 18 19 ; Ensure that weak alias to an imported function is correctly turned into 20 ; a declaration. 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 29 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 33 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() 37 38 ; Verify that the codegen run 39 ; RUN: llvm-lto -thinlto-action=codegen %t2.bc -o - | llvm-nm -o - | FileCheck %s --check-prefix=CODEGEN 40 ; CODEGEN: T _main 41 42 ; Verify that all run together 43 ; RUN: llvm-lto -thinlto-action=run %t2.bc %t.bc 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 46 ; ALL: T _callfuncptr 47 ; ALL2: T _main 48 49 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 50 target triple = "x86_64-apple-macosx10.11.0" 51 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 59 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 (...)*) 63 64 define void @globalfunc1() #0 { 65 entry: 66 ret void 67 } 68 69 define void @globalfunc2() #0 { 70 entry: 71 ret void 72 } 73 74 define linkonce_odr void @linkoncefunc() #0 { 75 entry: 76 ret void 77 } 78 79 define i32 @referencestatics(i32 %i) #0 { 80 entry: 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 91 ret i32 %add1 92 } 93 94 define i32 @referenceglobals(i32 %i) #0 { 95 entry: 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 100 ret i32 %0 101 } 102 103 define i32 @referencecommon(i32 %i) #0 { 104 entry: 105 %i.addr = alloca i32, align 4 106 store i32 %i, i32* %i.addr, align 4 107 %0 = load i32, i32* @commonvar, align 4 108 ret i32 %0 109 } 110 111 define void @setfuncptr() #0 { 112 entry: 113 store void ()* @staticfunc2, void ()** @P, align 8 114 ret void 115 } 116 117 define void @callfuncptr() #0 { 118 entry: 119 %0 = load void ()*, void ()** @P, align 8 120 call void %0() 121 ret void 122 } 123 124 @weakvar = weak global i32 1, align 4 125 define weak void @weakfunc() #0 { 126 entry: 127 ret void 128 } 129 130 define void @callweakfunc() #0 { 131 entry: 132 call void @weakfunc() 133 ret void 134 } 135 136 define internal i32 @staticfunc() #0 { 137 entry: 138 ret i32 1 139 } 140 141 define internal void @staticfunc2() #0 { 142 entry: 143 %0 = load i32, i32* @staticvar2, align 4 144 ret void 145 } 146