1*9880d681SAndroid Build Coastguard Worker; Do setup work for all below tests: generate bitcode and combined index 2*9880d681SAndroid Build Coastguard Worker; RUN: opt -module-summary %s -o %t.bc 3*9880d681SAndroid Build Coastguard Worker; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc 4*9880d681SAndroid Build Coastguard Worker; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker; Ensure statics are promoted/renamed correctly from this file (all but 7*9880d681SAndroid Build Coastguard Worker; constant variable need promotion). 8*9880d681SAndroid Build Coastguard Worker; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTSTATIC 9*9880d681SAndroid Build Coastguard Worker; EXPORTSTATIC-DAG: @staticvar.llvm.0 = hidden global 10*9880d681SAndroid Build Coastguard Worker; EXPORTSTATIC-DAG: @staticconstvar = internal unnamed_addr constant 11*9880d681SAndroid Build Coastguard Worker; EXPORTSTATIC-DAG: @P.llvm.0 = hidden global void ()* null 12*9880d681SAndroid Build Coastguard Worker; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.0 13*9880d681SAndroid Build Coastguard Worker; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.0 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker; Ensure that both weak alias to an imported function and strong alias to a 16*9880d681SAndroid Build Coastguard Worker; non-imported function are correctly turned into declarations. 17*9880d681SAndroid Build Coastguard Worker; Also ensures that alias to a linkonce function is turned into a declaration 18*9880d681SAndroid Build Coastguard Worker; and that the associated linkonce function is not in the output, as it is 19*9880d681SAndroid Build Coastguard Worker; lazily linked and never referenced/materialized. 20*9880d681SAndroid Build Coastguard Worker; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORTGLOB1 21*9880d681SAndroid Build Coastguard Worker; IMPORTGLOB1-DAG: define available_externally void @globalfunc1 22*9880d681SAndroid Build Coastguard Worker; IMPORTGLOB1-DAG: declare void @weakalias 23*9880d681SAndroid Build Coastguard Worker; IMPORTGLOB1-DAG: declare void @analias 24*9880d681SAndroid Build Coastguard Worker; IMPORTGLOB1-NOT: @linkoncealias 25*9880d681SAndroid Build Coastguard Worker; IMPORTGLOB1-NOT: @linkoncefunc 26*9880d681SAndroid Build Coastguard Worker; IMPORTGLOB1-NOT: declare void @globalfunc2 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker; Verify that the optimizer run 29*9880d681SAndroid Build Coastguard Worker; RUN: llvm-lto -thinlto-action=optimize %t2.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=OPTIMIZED 30*9880d681SAndroid Build Coastguard Worker; OPTIMIZED: define i32 @main() 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Worker; Verify that the codegen run 33*9880d681SAndroid Build Coastguard Worker; RUN: llvm-lto -thinlto-action=codegen %t2.bc -o - | llvm-nm -o - | FileCheck %s --check-prefix=CODEGEN 34*9880d681SAndroid Build Coastguard Worker; CODEGEN: T _main 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker; Verify that all run together 37*9880d681SAndroid Build Coastguard Worker; RUN: llvm-lto -thinlto-action=run %t2.bc %t.bc 38*9880d681SAndroid Build Coastguard Worker; RUN: llvm-nm -o - < %t.bc.thinlto.o | FileCheck %s --check-prefix=ALL 39*9880d681SAndroid Build Coastguard Worker; RUN: llvm-nm -o - < %t2.bc.thinlto.o | FileCheck %s --check-prefix=ALL2 40*9880d681SAndroid Build Coastguard Worker; ALL: T _callfuncptr 41*9880d681SAndroid Build Coastguard Worker; ALL2: T _main 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 44*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-macosx10.11.0" 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker@globalvar_in_section = global i32 1, align 4 47*9880d681SAndroid Build Coastguard Worker@globalvar = global i32 1, align 4 48*9880d681SAndroid Build Coastguard Worker@staticvar = internal global i32 1, align 4 49*9880d681SAndroid Build Coastguard Worker@staticvar2 = internal global i32 1, align 4 50*9880d681SAndroid Build Coastguard Worker@staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 4 51*9880d681SAndroid Build Coastguard Worker@commonvar = common global i32 0, align 4 52*9880d681SAndroid Build Coastguard Worker@P = internal global void ()* null, align 8 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker@weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*) 55*9880d681SAndroid Build Coastguard Worker@analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*) 56*9880d681SAndroid Build Coastguard Worker@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*) 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Workerdefine void @globalfunc1() #0 { 59*9880d681SAndroid Build Coastguard Workerentry: 60*9880d681SAndroid Build Coastguard Worker ret void 61*9880d681SAndroid Build Coastguard Worker} 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Workerdefine void @globalfunc2() #0 { 64*9880d681SAndroid Build Coastguard Workerentry: 65*9880d681SAndroid Build Coastguard Worker ret void 66*9880d681SAndroid Build Coastguard Worker} 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr void @linkoncefunc() #0 { 69*9880d681SAndroid Build Coastguard Workerentry: 70*9880d681SAndroid Build Coastguard Worker ret void 71*9880d681SAndroid Build Coastguard Worker} 72*9880d681SAndroid Build Coastguard Worker 73*9880d681SAndroid Build Coastguard Workerdefine i32 @referencestatics(i32 %i) #0 { 74*9880d681SAndroid Build Coastguard Workerentry: 75*9880d681SAndroid Build Coastguard Worker %i.addr = alloca i32, align 4 76*9880d681SAndroid Build Coastguard Worker store i32 %i, i32* %i.addr, align 4 77*9880d681SAndroid Build Coastguard Worker %call = call i32 @staticfunc() 78*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* @staticvar, align 4 79*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %0 80*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %i.addr, align 4 81*9880d681SAndroid Build Coastguard Worker %idxprom = sext i32 %1 to i64 82*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @staticconstvar, i64 0, i64 %idxprom 83*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %arrayidx, align 4 84*9880d681SAndroid Build Coastguard Worker %add1 = add nsw i32 %add, %2 85*9880d681SAndroid Build Coastguard Worker ret i32 %add1 86*9880d681SAndroid Build Coastguard Worker} 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard Workerdefine i32 @referenceglobals(i32 %i) #0 { 89*9880d681SAndroid Build Coastguard Workerentry: 90*9880d681SAndroid Build Coastguard Worker %i.addr = alloca i32, align 4 91*9880d681SAndroid Build Coastguard Worker store i32 %i, i32* %i.addr, align 4 92*9880d681SAndroid Build Coastguard Worker call void @globalfunc1() 93*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* @globalvar, align 4 94*9880d681SAndroid Build Coastguard Worker ret i32 %0 95*9880d681SAndroid Build Coastguard Worker} 96*9880d681SAndroid Build Coastguard Worker 97*9880d681SAndroid Build Coastguard Workerdefine i32 @referencecommon(i32 %i) #0 { 98*9880d681SAndroid Build Coastguard Workerentry: 99*9880d681SAndroid Build Coastguard Worker %i.addr = alloca i32, align 4 100*9880d681SAndroid Build Coastguard Worker store i32 %i, i32* %i.addr, align 4 101*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* @commonvar, align 4 102*9880d681SAndroid Build Coastguard Worker ret i32 %0 103*9880d681SAndroid Build Coastguard Worker} 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard Workerdefine void @setfuncptr() #0 { 106*9880d681SAndroid Build Coastguard Workerentry: 107*9880d681SAndroid Build Coastguard Worker store void ()* @staticfunc2, void ()** @P, align 8 108*9880d681SAndroid Build Coastguard Worker ret void 109*9880d681SAndroid Build Coastguard Worker} 110*9880d681SAndroid Build Coastguard Worker 111*9880d681SAndroid Build Coastguard Workerdefine void @callfuncptr() #0 { 112*9880d681SAndroid Build Coastguard Workerentry: 113*9880d681SAndroid Build Coastguard Worker %0 = load void ()*, void ()** @P, align 8 114*9880d681SAndroid Build Coastguard Worker call void %0() 115*9880d681SAndroid Build Coastguard Worker ret void 116*9880d681SAndroid Build Coastguard Worker} 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Worker@weakvar = weak global i32 1, align 4 119*9880d681SAndroid Build Coastguard Workerdefine weak void @weakfunc() #0 { 120*9880d681SAndroid Build Coastguard Workerentry: 121*9880d681SAndroid Build Coastguard Worker ret void 122*9880d681SAndroid Build Coastguard Worker} 123*9880d681SAndroid Build Coastguard Worker 124*9880d681SAndroid Build Coastguard Workerdefine void @callweakfunc() #0 { 125*9880d681SAndroid Build Coastguard Workerentry: 126*9880d681SAndroid Build Coastguard Worker call void @weakfunc() 127*9880d681SAndroid Build Coastguard Worker ret void 128*9880d681SAndroid Build Coastguard Worker} 129*9880d681SAndroid Build Coastguard Worker 130*9880d681SAndroid Build Coastguard Workerdefine internal i32 @staticfunc() #0 { 131*9880d681SAndroid Build Coastguard Workerentry: 132*9880d681SAndroid Build Coastguard Worker ret i32 1 133*9880d681SAndroid Build Coastguard Worker} 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Workerdefine internal void @staticfunc2() #0 { 136*9880d681SAndroid Build Coastguard Workerentry: 137*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* @staticvar2, align 4 138*9880d681SAndroid Build Coastguard Worker ret void 139*9880d681SAndroid Build Coastguard Worker} 140