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