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 -print-summary-global-ids -o %t3 %t.bc %t2.bc 2>&1 | FileCheck %s --check-prefix=GUID 5 6; Do the import now 7; RUN: opt -function-import -stats -print-imports -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF 8; Try again with new pass manager 9; RUN: opt -passes='function-import' -stats -print-imports -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF 10; RUN: opt -passes='function-import' -debug-only=function-import -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=DUMP 11; "-stats" and "-debug-only" require +Asserts. 12; REQUIRES: asserts 13 14; Test import with smaller instruction limit 15; RUN: opt -function-import -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5 16; INSTLIM5-NOT: @staticfunc.llvm. 17 18 19define i32 @main() #0 { 20entry: 21 call void (...) @weakalias() 22 call void (...) @analias() 23 call void (...) @linkoncealias() 24 %call = call i32 (...) @referencestatics() 25 %call1 = call i32 (...) @referenceglobals() 26 %call2 = call i32 (...) @referencecommon() 27 call void (...) @setfuncptr() 28 call void (...) @callfuncptr() 29 call void (...) @weakfunc() 30 call void (...) @linkoncefunc2() 31 call void (...) @referencelargelinkonce() 32 call void (...) @variadic_no_va_start() 33 call void (...) @variadic_va_start() 34 ret i32 0 35} 36 37; Won't import weak alias 38; CHECK-DAG: declare void @weakalias 39declare void @weakalias(...) #1 40 41; External alias imported as available_externally copy of aliasee 42; CHECK-DAG: define available_externally void @analias 43declare void @analias(...) #1 44 45; External alias imported as available_externally copy of aliasee 46; (linkoncealias is an external alias to a linkonce_odr) 47declare void @linkoncealias(...) #1 48; CHECK-DAG: define available_externally void @linkoncealias() 49 50; INSTLIMDEF-DAG: Import referencestatics 51; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 { 52; INSTLIM5-DAG: declare i32 @referencestatics(...) 53declare i32 @referencestatics(...) #1 54 55; The import of referencestatics will expose call to staticfunc that 56; should in turn be imported as a promoted/renamed and hidden function. 57; Ensure that the call is to the properly-renamed function. 58; INSTLIMDEF-DAG: Import staticfunc 59; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm. 60; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 { 61 62; INSTLIMDEF-DAG: Import referenceglobals 63; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 { 64declare i32 @referenceglobals(...) #1 65 66; The import of referenceglobals will expose call to globalfunc1 that 67; should in turn be imported. 68; INSTLIMDEF-DAG: Import globalfunc1 69; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0 70 71; INSTLIMDEF-DAG: Import referencecommon 72; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 { 73declare i32 @referencecommon(...) #1 74 75; INSTLIMDEF-DAG: Import setfuncptr 76; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 { 77declare void @setfuncptr(...) #1 78 79; INSTLIMDEF-DAG: Import callfuncptr 80; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 { 81declare void @callfuncptr(...) #1 82 83; Ensure that all uses of local variable @P which has used in setfuncptr 84; and callfuncptr are to the same promoted/renamed global. 85; CHECK-DAG: @P.llvm.{{.*}} = available_externally hidden global void ()* null 86; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm. 87; CHECK-DAG: store void ()* @staticfunc2.llvm.{{.*}}, void ()** @P.llvm. 88 89; Ensure that @referencelargelinkonce definition is pulled in, but later we 90; also check that the linkonceodr function is not. 91; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 { 92; INSTLIM5-DAG: declare void @linkonceodr() 93declare void @referencelargelinkonce(...) 94 95; Won't import weak func 96; CHECK-DAG: declare void @weakfunc(...) 97declare void @weakfunc(...) #1 98 99; Won't import linkonce func 100; CHECK-DAG: declare void @linkoncefunc2(...) 101declare void @linkoncefunc2(...) #1 102 103; INSTLIMDEF-DAG: Import funcwithpersonality 104; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 { 105; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}() 106 107; We can import variadic functions without a va_start, since the inliner 108; can handle them. 109; INSTLIMDEF-DAG: Import variadic_no_va_start 110; CHECK-DAG: define available_externally void @variadic_no_va_start(...) !thinlto_src_module !0 { 111declare void @variadic_no_va_start(...) 112 113; We can import variadic functions with a va_start, since the inliner 114; can sometimes handle them. 115; CHECK-DAG: define available_externally void @variadic_va_start(...) 116declare void @variadic_va_start(...) 117 118; INSTLIMDEF-DAG: Import globalfunc2 119; INSTLIMDEF-DAG: 15 function-import - Number of functions imported 120; INSTLIMDEF-DAG: 4 function-import - Number of global variables imported 121 122; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"} 123 124; The actual GUID values will depend on path to test. 125; GUID-DAG: GUID {{.*}} is weakalias 126; GUID-DAG: GUID {{.*}} is referenceglobals 127; GUID-DAG: GUID {{.*}} is weakfunc 128; GUID-DAG: GUID {{.*}} is main 129; GUID-DAG: GUID {{.*}} is referencecommon 130; GUID-DAG: GUID {{.*}} is analias 131; GUID-DAG: GUID {{.*}} is referencestatics 132; GUID-DAG: GUID {{.*}} is linkoncealias 133; GUID-DAG: GUID {{.*}} is setfuncptr 134; GUID-DAG: GUID {{.*}} is callfuncptr 135; GUID-DAG: GUID {{.*}} is funcwithpersonality 136; GUID-DAG: GUID {{.*}} is setfuncptr 137; GUID-DAG: GUID {{.*}} is staticfunc2 138; GUID-DAG: GUID {{.*}} is __gxx_personality_v0 139; GUID-DAG: GUID {{.*}} is referencestatics 140; GUID-DAG: GUID {{.*}} is globalfunc1 141; GUID-DAG: GUID {{.*}} is globalfunc2 142; GUID-DAG: GUID {{.*}} is P 143; GUID-DAG: GUID {{.*}} is staticvar 144; GUID-DAG: GUID {{.*}} is commonvar 145; GUID-DAG: GUID {{.*}} is weakalias 146; GUID-DAG: GUID {{.*}} is staticfunc 147; GUID-DAG: GUID {{.*}} is weakfunc 148; GUID-DAG: GUID {{.*}} is referenceglobals 149; GUID-DAG: GUID {{.*}} is weakvar 150; GUID-DAG: GUID {{.*}} is staticconstvar 151; GUID-DAG: GUID {{.*}} is analias 152; GUID-DAG: GUID {{.*}} is globalvar 153; GUID-DAG: GUID {{.*}} is referencecommon 154; GUID-DAG: GUID {{.*}} is linkoncealias 155; GUID-DAG: GUID {{.*}} is callfuncptr 156; GUID-DAG: GUID {{.*}} is linkoncefunc 157 158; DUMP: Module [[M1:.*]] imports from 1 module 159; DUMP-NEXT: 15 functions imported from [[M2:.*]] 160; DUMP-NEXT: 4 vars imported from [[M2]] 161; DUMP: Imported 15 functions for Module [[M1]] 162; DUMP-NEXT: Imported 4 global variables for Module [[M1]] 163