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() 33 ret i32 0 34} 35 36; Won't import weak alias 37; CHECK-DAG: declare void @weakalias 38declare void @weakalias(...) #1 39 40; External alias imported as available_externally copy of aliasee 41; CHECK-DAG: define available_externally void @analias 42declare void @analias(...) #1 43 44; External alias imported as available_externally copy of aliasee 45; (linkoncealias is an external alias to a linkonce_odr) 46declare void @linkoncealias(...) #1 47; CHECK-DAG: define available_externally void @linkoncealias() 48 49; INSTLIMDEF-DAG: Import referencestatics 50; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 { 51; INSTLIM5-DAG: declare i32 @referencestatics(...) 52declare i32 @referencestatics(...) #1 53 54; The import of referencestatics will expose call to staticfunc that 55; should in turn be imported as a promoted/renamed and hidden function. 56; Ensure that the call is to the properly-renamed function. 57; INSTLIMDEF-DAG: Import staticfunc 58; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm. 59; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 { 60 61; INSTLIMDEF-DAG: Import referenceglobals 62; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 { 63declare i32 @referenceglobals(...) #1 64 65; The import of referenceglobals will expose call to globalfunc1 that 66; should in turn be imported. 67; INSTLIMDEF-DAG: Import globalfunc1 68; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0 69 70; INSTLIMDEF-DAG: Import referencecommon 71; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 { 72declare i32 @referencecommon(...) #1 73 74; INSTLIMDEF-DAG: Import setfuncptr 75; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 { 76declare void @setfuncptr(...) #1 77 78; INSTLIMDEF-DAG: Import callfuncptr 79; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 { 80declare void @callfuncptr(...) #1 81 82; Ensure that all uses of local variable @P which has used in setfuncptr 83; and callfuncptr are to the same promoted/renamed global. 84; CHECK-DAG: @P.llvm.{{.*}} = available_externally hidden global void ()* null 85; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm. 86; CHECK-DAG: store void ()* @staticfunc2.llvm.{{.*}}, void ()** @P.llvm. 87 88; Ensure that @referencelargelinkonce definition is pulled in, but later we 89; also check that the linkonceodr function is not. 90; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 { 91; INSTLIM5-DAG: declare void @linkonceodr() 92declare void @referencelargelinkonce(...) 93 94; Won't import weak func 95; CHECK-DAG: declare void @weakfunc(...) 96declare void @weakfunc(...) #1 97 98; Won't import linkonce func 99; CHECK-DAG: declare void @linkoncefunc2(...) 100declare void @linkoncefunc2(...) #1 101 102; INSTLIMDEF-DAG: Import funcwithpersonality 103; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 { 104; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}() 105 106; CHECK-DAG: declare void @variadic(...) 107declare void @variadic(...) 108 109; INSTLIMDEF-DAG: Import globalfunc2 110; INSTLIMDEF-DAG: 13 function-import - Number of functions imported 111; INSTLIMDEF-DAG: 4 function-import - Number of global variables imported 112 113; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"} 114 115; The actual GUID values will depend on path to test. 116; GUID-DAG: GUID {{.*}} is weakalias 117; GUID-DAG: GUID {{.*}} is referenceglobals 118; GUID-DAG: GUID {{.*}} is weakfunc 119; GUID-DAG: GUID {{.*}} is main 120; GUID-DAG: GUID {{.*}} is referencecommon 121; GUID-DAG: GUID {{.*}} is analias 122; GUID-DAG: GUID {{.*}} is referencestatics 123; GUID-DAG: GUID {{.*}} is linkoncealias 124; GUID-DAG: GUID {{.*}} is setfuncptr 125; GUID-DAG: GUID {{.*}} is callfuncptr 126; GUID-DAG: GUID {{.*}} is funcwithpersonality 127; GUID-DAG: GUID {{.*}} is setfuncptr 128; GUID-DAG: GUID {{.*}} is staticfunc2 129; GUID-DAG: GUID {{.*}} is __gxx_personality_v0 130; GUID-DAG: GUID {{.*}} is referencestatics 131; GUID-DAG: GUID {{.*}} is globalfunc1 132; GUID-DAG: GUID {{.*}} is globalfunc2 133; GUID-DAG: GUID {{.*}} is P 134; GUID-DAG: GUID {{.*}} is staticvar 135; GUID-DAG: GUID {{.*}} is commonvar 136; GUID-DAG: GUID {{.*}} is weakalias 137; GUID-DAG: GUID {{.*}} is staticfunc 138; GUID-DAG: GUID {{.*}} is weakfunc 139; GUID-DAG: GUID {{.*}} is referenceglobals 140; GUID-DAG: GUID {{.*}} is weakvar 141; GUID-DAG: GUID {{.*}} is staticconstvar 142; GUID-DAG: GUID {{.*}} is analias 143; GUID-DAG: GUID {{.*}} is globalvar 144; GUID-DAG: GUID {{.*}} is referencecommon 145; GUID-DAG: GUID {{.*}} is linkoncealias 146; GUID-DAG: GUID {{.*}} is callfuncptr 147; GUID-DAG: GUID {{.*}} is linkoncefunc 148 149; DUMP: Module [[M1:.*]] imports from 1 module 150; DUMP-NEXT: 13 functions imported from [[M2:.*]] 151; DUMP-NEXT: 4 vars imported from [[M2]] 152; DUMP: Imported 13 functions for Module [[M1]] 153; DUMP-NEXT: Imported 4 global variables for Module [[M1]] 154