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 -disable-force-link-odr -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 -disable-force-link-odr -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; "-stats" requires +Asserts. 11; REQUIRES: asserts 12 13; Test import with smaller instruction limit 14; RUN: opt -disable-force-link-odr -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 15; INSTLIM5-NOT: @staticfunc.llvm. 16 17; Test import with smaller instruction limit and without the -disable-force-link-odr 18; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=5 -S | FileCheck %s --check-prefix=INSTLIM5ODR 19; INSTLIM5ODR: define linkonce_odr void @linkonceodr() { 20 21 22define i32 @main() #0 { 23entry: 24 call void (...) @weakalias() 25 call void (...) @analias() 26 call void (...) @linkoncealias() 27 %call = call i32 (...) @referencestatics() 28 %call1 = call i32 (...) @referenceglobals() 29 %call2 = call i32 (...) @referencecommon() 30 call void (...) @setfuncptr() 31 call void (...) @callfuncptr() 32 call void (...) @weakfunc() 33 call void (...) @linkoncefunc2() 34 call void (...) @referencelargelinkonce() 35 call void (...) @variadic() 36 ret i32 0 37} 38 39; Won't import weak alias 40; CHECK-DAG: declare void @weakalias 41declare void @weakalias(...) #1 42 43; Cannot create an alias to available_externally 44; CHECK-DAG: declare void @analias 45declare void @analias(...) #1 46 47; FIXME: Add this checking back when follow on fix to add alias summary 48; records is committed. 49; Aliases import the aliasee function 50declare void @linkoncealias(...) #1 51 52; INSTLIMDEF-DAG: Import referencestatics 53; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 { 54; INSTLIM5-DAG: declare i32 @referencestatics(...) 55declare i32 @referencestatics(...) #1 56 57; The import of referencestatics will expose call to staticfunc that 58; should in turn be imported as a promoted/renamed and hidden function. 59; Ensure that the call is to the properly-renamed function. 60; INSTLIMDEF-DAG: Import staticfunc 61; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm. 62; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 { 63 64; INSTLIMDEF-DAG: Import referenceglobals 65; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 { 66declare i32 @referenceglobals(...) #1 67 68; The import of referenceglobals will expose call to globalfunc1 that 69; should in turn be imported. 70; INSTLIMDEF-DAG: Import globalfunc1 71; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0 72 73; INSTLIMDEF-DAG: Import referencecommon 74; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 { 75declare i32 @referencecommon(...) #1 76 77; INSTLIMDEF-DAG: Import setfuncptr 78; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 { 79declare void @setfuncptr(...) #1 80 81; INSTLIMDEF-DAG: Import callfuncptr 82; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 { 83declare void @callfuncptr(...) #1 84 85; Ensure that all uses of local variable @P which has used in setfuncptr 86; and callfuncptr are to the same promoted/renamed global. 87; CHECK-DAG: @P.llvm.{{.*}} = external hidden global void ()* 88; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm. 89; CHECK-DAG: store void ()* @staticfunc2.llvm.{{.*}}, void ()** @P.llvm. 90 91; Ensure that @referencelargelinkonce definition is pulled in, but later we 92; also check that the linkonceodr function is not. 93; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 { 94; INSTLIM5-DAG: declare void @linkonceodr() 95declare void @referencelargelinkonce(...) 96 97; Won't import weak func 98; CHECK-DAG: declare void @weakfunc(...) 99declare void @weakfunc(...) #1 100 101; Won't import linkonce func 102; CHECK-DAG: declare void @linkoncefunc2(...) 103declare void @linkoncefunc2(...) #1 104 105; INSTLIMDEF-DAG: Import funcwithpersonality 106; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 { 107; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}() 108 109; CHECK-DAG: declare void @variadic(...) 110declare void @variadic(...) 111 112; INSTLIMDEF-DAG: Import globalfunc2 113; INSTLIMDEF-DAG: 13 function-import - Number of functions imported 114; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"} 115 116; The actual GUID values will depend on path to test. 117; GUID-DAG: GUID {{.*}} is weakalias 118; GUID-DAG: GUID {{.*}} is referenceglobals 119; GUID-DAG: GUID {{.*}} is weakfunc 120; GUID-DAG: GUID {{.*}} is main 121; GUID-DAG: GUID {{.*}} is referencecommon 122; GUID-DAG: GUID {{.*}} is analias 123; GUID-DAG: GUID {{.*}} is referencestatics 124; GUID-DAG: GUID {{.*}} is linkoncealias 125; GUID-DAG: GUID {{.*}} is setfuncptr 126; GUID-DAG: GUID {{.*}} is callfuncptr 127; GUID-DAG: GUID {{.*}} is funcwithpersonality 128; GUID-DAG: GUID {{.*}} is setfuncptr 129; GUID-DAG: GUID {{.*}} is staticfunc2 130; GUID-DAG: GUID {{.*}} is __gxx_personality_v0 131; GUID-DAG: GUID {{.*}} is referencestatics 132; GUID-DAG: GUID {{.*}} is globalfunc1 133; GUID-DAG: GUID {{.*}} is globalfunc2 134; GUID-DAG: GUID {{.*}} is P 135; GUID-DAG: GUID {{.*}} is staticvar 136; GUID-DAG: GUID {{.*}} is commonvar 137; GUID-DAG: GUID {{.*}} is weakalias 138; GUID-DAG: GUID {{.*}} is staticfunc 139; GUID-DAG: GUID {{.*}} is weakfunc 140; GUID-DAG: GUID {{.*}} is referenceglobals 141; GUID-DAG: GUID {{.*}} is weakvar 142; GUID-DAG: GUID {{.*}} is staticconstvar 143; GUID-DAG: GUID {{.*}} is analias 144; GUID-DAG: GUID {{.*}} is globalvar 145; GUID-DAG: GUID {{.*}} is referencecommon 146; GUID-DAG: GUID {{.*}} is linkoncealias 147; GUID-DAG: GUID {{.*}} is callfuncptr 148; GUID-DAG: GUID {{.*}} is linkoncefunc 149