1; Do setup work for all below tests: generate bitcode and combined index 2; RUN: llvm-as -module-summary %s -o %t.bc 3; RUN: llvm-as -module-summary %p/Inputs/funcimport.ll -o %t2.bc 4; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc 5 6; Do the import now 7; RUN: opt -function-import -stats -print-imports -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF 8; "-stats" requires +Asserts. 9; REQUIRES: asserts 10 11; Test import with smaller instruction limit 12; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5 13; INSTLIM5-NOT: @staticfunc.llvm.2 14 15define i32 @main() #0 { 16entry: 17 call void (...) @weakalias() 18 call void (...) @analias() 19 call void (...) @linkoncealias() 20 %call = call i32 (...) @referencestatics() 21 %call1 = call i32 (...) @referenceglobals() 22 %call2 = call i32 (...) @referencecommon() 23 call void (...) @setfuncptr() 24 call void (...) @callfuncptr() 25 call void (...) @weakfunc() 26 ret i32 0 27} 28 29; Won't import weak alias 30; CHECK-DAG: declare void @weakalias 31declare void @weakalias(...) #1 32 33; Cannot create an alias to available_externally 34; CHECK-DAG: declare void @analias 35declare void @analias(...) #1 36 37; Aliases import the aliasee function 38declare void @linkoncealias(...) #1 39; INSTLIMDEF-DAG: Import linkoncealias 40; INSTLIMDEF-DAG: Import linkoncefunc 41; CHECK-DAG: define linkonce_odr void @linkoncefunc() 42; CHECK-DAG: @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)* 43 44; INSTLIMDEF-DAG: Import referencestatics 45; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) 46; INSTLIM5-DAG: declare i32 @referencestatics(...) 47declare i32 @referencestatics(...) #1 48 49; The import of referencestatics will expose call to staticfunc that 50; should in turn be imported as a promoted/renamed and hidden function. 51; Ensure that the call is to the properly-renamed function. 52; INSTLIMDEF-DAG: Import staticfunc 53; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.2() 54; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.2() 55 56; INSTLIMDEF-DAG: Import referenceglobals 57; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) 58declare i32 @referenceglobals(...) #1 59 60; The import of referenceglobals will expose call to globalfunc1 that 61; should in turn be imported. 62; INSTLIMDEF-DAG: Import globalfunc1 63; CHECK-DAG: define available_externally void @globalfunc1() 64 65; INSTLIMDEF-DAG: Import referencecommon 66; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) 67declare i32 @referencecommon(...) #1 68 69; INSTLIMDEF-DAG: Import setfuncptr 70; CHECK-DAG: define available_externally void @setfuncptr() 71declare void @setfuncptr(...) #1 72 73; INSTLIMDEF-DAG: Import callfuncptr 74; CHECK-DAG: define available_externally void @callfuncptr() 75declare void @callfuncptr(...) #1 76 77; Ensure that all uses of local variable @P which has used in setfuncptr 78; and callfuncptr are to the same promoted/renamed global. 79; CHECK-DAG: @P.llvm.2 = external hidden global void ()* 80; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.2, 81; CHECK-DAG: store void ()* @staticfunc2.llvm.2, void ()** @P.llvm.2, 82 83; Won't import weak func 84; CHECK-DAG: declare void @weakfunc(...) 85declare void @weakfunc(...) #1 86 87; INSTLIMDEF-DAG: Import funcwithpersonality 88; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.2() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 89; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.2() 90 91; INSTLIMDEF-DAG: Import globalfunc2 92; INSTLIMDEF-DAG: 11 function-import - Number of functions imported 93