146 lines · plain
1; Do setup work for all below tests: generate bitcode and combined index2; RUN: opt -module-summary %s -o %t.bc3; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc4; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc5 6; RUN: llvm-lto -thinlto-index-stats %t3.bc | FileCheck %s -check-prefix=STATS7; 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 but10; 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=EXPORTSTATIC12; EXPORTSTATIC-DAG: @staticvar.llvm.0 = hidden global13; Eventually @staticconstvar can be exported as a copy and not promoted14; EXPORTSTATIC-DAG: @staticconstvar.llvm.0 = hidden unnamed_addr constant15; EXPORTSTATIC-DAG: @P.llvm.0 = hidden global ptr null16; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.017; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.018 19; Ensure that weak alias to an imported function is correctly turned into20; a declaration.21; Also ensures that alias to a linkonce function is turned into a declaration22; and that the associated linkonce function is not in the output, as it is23; 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=IMPORTGLOB125; IMPORTGLOB1-DAG: define available_externally void @globalfunc126; IMPORTGLOB1-DAG: declare void @weakalias27; IMPORTGLOB1-NOT: @linkoncealias28; IMPORTGLOB1-NOT: @linkoncefunc29 30; A strong alias is imported as an available_externally copy of its aliasee.31; IMPORTGLOB1-DAG: define available_externally void @analias32; IMPORTGLOB1-NOT: declare void @globalfunc233 34; Verify that the optimizer run35; RUN: llvm-lto -thinlto-action=optimize %t2.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=OPTIMIZED36; OPTIMIZED: define noundef i32 @main()37 38; Verify that the codegen run39; RUN: llvm-lto -thinlto-action=codegen %t2.bc -o - | llvm-nm -o - | FileCheck %s --check-prefix=CODEGEN40; CODEGEN: T _main41 42; Verify that all run together43; RUN: llvm-lto -thinlto-action=run %t2.bc %t.bc -exported-symbol=_main44; RUN: llvm-nm -o - < %t.bc.thinlto.o | FileCheck %s --check-prefix=ALL45; RUN: llvm-nm -o - < %t2.bc.thinlto.o | FileCheck %s --check-prefix=ALL246; ALL: T _callfuncptr47; ALL2: T _main48 49target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"50target triple = "x86_64-apple-macosx10.11.0"51 52@globalvar_in_section = global i32 1, align 453@globalvar = global i32 1, align 454@staticvar = internal global i32 1, align 455@staticvar2 = internal global i32 1, align 456@staticconstvar = internal unnamed_addr constant [2 x i32] [i32 10, i32 20], align 457@commonvar = common global i32 0, align 458@P = internal global ptr null, align 859 60@weakalias = weak alias void (...), ptr @globalfunc161@analias = alias void (...), ptr @globalfunc262@linkoncealias = alias void (...), ptr @linkoncefunc63 64define void @globalfunc1() #0 {65entry:66 ret void67}68 69define void @globalfunc2() #0 {70entry:71 ret void72}73 74define linkonce_odr void @linkoncefunc() #0 {75entry:76 ret void77}78 79define i32 @referencestatics(i32 %i) #0 {80entry:81 %i.addr = alloca i32, align 482 store i32 %i, ptr %i.addr, align 483 %call = call i32 @staticfunc()84 %0 = load i32, ptr @staticvar, align 485 %add = add nsw i32 %call, %086 %1 = load i32, ptr %i.addr, align 487 %idxprom = sext i32 %1 to i6488 %arrayidx = getelementptr inbounds [2 x i32], ptr @staticconstvar, i64 0, i64 %idxprom89 %2 = load i32, ptr %arrayidx, align 490 %add1 = add nsw i32 %add, %291 ret i32 %add192}93 94define i32 @referenceglobals(i32 %i) #0 {95entry:96 %i.addr = alloca i32, align 497 store i32 %i, ptr %i.addr, align 498 call void @globalfunc1()99 %0 = load i32, ptr @globalvar, align 4100 ret i32 %0101}102 103define i32 @referencecommon(i32 %i) #0 {104entry:105 %i.addr = alloca i32, align 4106 store i32 %i, ptr %i.addr, align 4107 %0 = load i32, ptr @commonvar, align 4108 ret i32 %0109}110 111define void @setfuncptr() #0 {112entry:113 store ptr @staticfunc2, ptr @P, align 8114 ret void115}116 117define void @callfuncptr() #0 {118entry:119 %0 = load ptr, ptr @P, align 8120 call void %0()121 ret void122}123 124@weakvar = weak global i32 1, align 4125define weak void @weakfunc() #0 {126entry:127 ret void128}129 130define void @callweakfunc() #0 {131entry:132 call void @weakfunc()133 ret void134}135 136define internal i32 @staticfunc() #0 {137entry:138 ret i32 1139}140 141define internal void @staticfunc2() #0 {142entry:143 %0 = load i32, ptr @staticvar2, align 4144 ret void145}146