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