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