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 -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.
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; FIXME: Add this checking back when follow on fix to add alias summary
38; records is committed.
39; Aliases import the aliasee function
40declare void @linkoncealias(...) #1
41
42; INSTLIMDEF-DAG: Import referencestatics
43; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i)
44; INSTLIM5-DAG: declare i32 @referencestatics(...)
45declare i32 @referencestatics(...) #1
46
47; The import of referencestatics will expose call to staticfunc that
48; should in turn be imported as a promoted/renamed and hidden function.
49; Ensure that the call is to the properly-renamed function.
50; INSTLIMDEF-DAG: Import staticfunc
51; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.
52; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.
53
54; INSTLIMDEF-DAG: Import referenceglobals
55; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i)
56declare i32 @referenceglobals(...) #1
57
58; The import of referenceglobals will expose call to globalfunc1 that
59; should in turn be imported.
60; INSTLIMDEF-DAG: Import globalfunc1
61; CHECK-DAG: define available_externally void @globalfunc1()
62
63; INSTLIMDEF-DAG: Import referencecommon
64; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i)
65declare i32 @referencecommon(...) #1
66
67; INSTLIMDEF-DAG: Import setfuncptr
68; CHECK-DAG: define available_externally void @setfuncptr()
69declare void @setfuncptr(...) #1
70
71; INSTLIMDEF-DAG: Import callfuncptr
72; CHECK-DAG: define available_externally void @callfuncptr()
73declare void @callfuncptr(...) #1
74
75; Ensure that all uses of local variable @P which has used in setfuncptr
76; and callfuncptr are to the same promoted/renamed global.
77; CHECK-DAG: @P.llvm.{{.*}} = external hidden global void ()*
78; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.
79; CHECK-DAG: store void ()* @staticfunc2.llvm.{{.*}}, void ()** @P.llvm.
80
81; Won't import weak func
82; CHECK-DAG: declare void @weakfunc(...)
83declare void @weakfunc(...) #1
84
85; INSTLIMDEF-DAG: Import funcwithpersonality
86; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
87; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}()
88
89; INSTLIMDEF-DAG: Import globalfunc2
90; INSTLIMDEF-DAG: 11 function-import - Number of functions imported
91
92; The actual GUID values will depend on path to test.
93; GUID-DAG: GUID {{.*}} is weakalias
94; GUID-DAG: GUID {{.*}} is referenceglobals
95; GUID-DAG: GUID {{.*}} is weakfunc
96; GUID-DAG: GUID {{.*}} is main
97; GUID-DAG: GUID {{.*}} is referencecommon
98; GUID-DAG: GUID {{.*}} is analias
99; GUID-DAG: GUID {{.*}} is referencestatics
100; GUID-DAG: GUID {{.*}} is linkoncealias
101; GUID-DAG: GUID {{.*}} is setfuncptr
102; GUID-DAG: GUID {{.*}} is callfuncptr
103; GUID-DAG: GUID {{.*}} is funcwithpersonality
104; GUID-DAG: GUID {{.*}} is setfuncptr
105; GUID-DAG: GUID {{.*}} is staticfunc2
106; GUID-DAG: GUID {{.*}} is __gxx_personality_v0
107; GUID-DAG: GUID {{.*}} is referencestatics
108; GUID-DAG: GUID {{.*}} is globalfunc1
109; GUID-DAG: GUID {{.*}} is globalfunc2
110; GUID-DAG: GUID {{.*}} is P
111; GUID-DAG: GUID {{.*}} is staticvar
112; GUID-DAG: GUID {{.*}} is commonvar
113; GUID-DAG: GUID {{.*}} is weakalias
114; GUID-DAG: GUID {{.*}} is staticfunc
115; GUID-DAG: GUID {{.*}} is weakfunc
116; GUID-DAG: GUID {{.*}} is referenceglobals
117; GUID-DAG: GUID {{.*}} is weakvar
118; GUID-DAG: GUID {{.*}} is staticconstvar
119; GUID-DAG: GUID {{.*}} is analias
120; GUID-DAG: GUID {{.*}} is globalvar
121; GUID-DAG: GUID {{.*}} is referencecommon
122; GUID-DAG: GUID {{.*}} is linkoncealias
123; GUID-DAG: GUID {{.*}} is callfuncptr
124; GUID-DAG: GUID {{.*}} is linkoncefunc
125