xref: /llvm-project/llvm/test/Transforms/FunctionImport/funcimport.ll (revision af784a5c13328aa4a8ce622260563b459856a8d4)
1; REQUIRES: x86-registered-target
2
3; Do setup work for all below tests: generate bitcode and combined index
4; RUN: opt -module-summary %s -o %t.bc
5; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc
6; RUN: llvm-lto -thinlto -print-summary-global-ids -o %t3 %t.bc %t2.bc 2>&1 | FileCheck %s --check-prefix=GUID
7
8; Do the import now
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; Try again with new pass manager
11; 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
12; RUN: opt -passes='function-import' -debug-only=function-import -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=DUMP
13; "-stats" and "-debug-only" require +Asserts.
14; REQUIRES: asserts
15
16; Test import with smaller instruction limit
17; RUN: opt -passes=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
18; INSTLIM5-NOT: @staticfunc.llvm.
19
20; Test force import all
21; RUN: llvm-lto -thinlto-action=run -force-import-all %t.bc %t2.bc 2>&1 \
22; RUN:  | FileCheck %s --check-prefix=IMPORTALL
23; IMPORTALL-DAG: Error importing module: Failed to import function weakalias due to InterposableLinkage
24
25target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
26target triple = "x86_64-apple-macosx10.11.0"
27
28define i32 @main() #0 {
29entry:
30  call void (...) @weakalias()
31  call void (...) @analias()
32  call void (...) @linkoncealias()
33  %call = call i32 (...) @referencestatics()
34  %call1 = call i32 (...) @referenceglobals()
35  %call2 = call i32 (...) @referencecommon()
36  call void (...) @setfuncptr()
37  call void (...) @callfuncptr()
38  call void (...) @weakfunc()
39  call void (...) @linkoncefunc2()
40  call void (...) @referencelargelinkonce()
41  call void (...) @variadic_no_va_start()
42  call void (...) @variadic_va_start()
43  ret i32 0
44}
45
46; Won't import weak alias
47; CHECK-DAG: declare void @weakalias
48declare void @weakalias(...) #1
49
50; External alias imported as available_externally copy of aliasee
51; CHECK-DAG: define available_externally void @analias
52declare void @analias(...) #1
53
54; External alias imported as available_externally copy of aliasee
55; (linkoncealias is an external alias to a linkonce_odr)
56declare void @linkoncealias(...) #1
57; CHECK-DAG: define available_externally void @linkoncealias()
58
59; INSTLIMDEF-DAG: Import referencestatics
60; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 !thinlto_src_file !1 {
61; INSTLIM5-DAG: declare i32 @referencestatics(...)
62declare i32 @referencestatics(...) #1
63
64; The import of referencestatics will expose call to staticfunc that
65; should in turn be imported as a promoted/renamed and hidden function.
66; Ensure that the call is to the properly-renamed function.
67; INSTLIMDEF-DAG: Import staticfunc
68; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.
69; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.{{.*}} !thinlto_src_module !0 !thinlto_src_file !1 {
70
71; INSTLIMDEF-DAG: Import referenceglobals
72; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 !thinlto_src_file !1 {
73declare i32 @referenceglobals(...) #1
74
75; The import of referenceglobals will expose call to globalfunc1 that
76; should in turn be imported.
77; INSTLIMDEF-DAG: Import globalfunc1
78; CHECK-DAG: define available_externally void @globalfunc1() !thinlto_src_module !0 !thinlto_src_file !1
79
80; INSTLIMDEF-DAG: Import referencecommon
81; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 !thinlto_src_file !1 {
82declare i32 @referencecommon(...) #1
83
84; INSTLIMDEF-DAG: Import setfuncptr
85; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 !thinlto_src_file !1 {
86declare void @setfuncptr(...) #1
87
88; INSTLIMDEF-DAG: Import callfuncptr
89; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 !thinlto_src_file !1 {
90declare void @callfuncptr(...) #1
91
92; Ensure that all uses of local variable @P which has used in setfuncptr
93; and callfuncptr are to the same promoted/renamed global.
94; CHECK-DAG: @P.llvm.{{.*}} = available_externally hidden global ptr null
95; CHECK-DAG: %0 = load ptr, ptr @P.llvm.
96; CHECK-DAG: store ptr @staticfunc2.llvm.{{.*}}, ptr @P.llvm.
97
98; Ensure that @referencelargelinkonce definition is pulled in, but later we
99; also check that the linkonceodr function is not.
100; CHECK-DAG: define available_externally void @referencelargelinkonce() !thinlto_src_module !0 !thinlto_src_file !1 {
101; INSTLIM5-DAG: declare void @linkonceodr()
102declare void @referencelargelinkonce(...)
103
104; Won't import weak func
105; CHECK-DAG: declare void @weakfunc(...)
106declare void @weakfunc(...) #1
107
108; Won't import linkonce func
109; CHECK-DAG: declare void @linkoncefunc2(...)
110declare void @linkoncefunc2(...) #1
111
112; INSTLIMDEF-DAG: Import funcwithpersonality
113; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality ptr @__gxx_personality_v0 !thinlto_src_module !0 !thinlto_src_file !1 {
114; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}()
115
116; We can import variadic functions without a va_start, since the inliner
117; can handle them.
118; INSTLIMDEF-DAG: Import variadic_no_va_start
119; CHECK-DAG: define available_externally void @variadic_no_va_start(...) !thinlto_src_module !0 !thinlto_src_file !1 {
120declare void @variadic_no_va_start(...)
121
122; We can import variadic functions with a va_start, since the inliner
123; can sometimes handle them.
124; CHECK-DAG: define available_externally void @variadic_va_start(...)
125declare void @variadic_va_start(...)
126
127; INSTLIMDEF-DAG: Import globalfunc2
128; INSTLIMDEF-DAG: 15 function-import - Number of functions imported
129; INSTLIMDEF-DAG: 4 function-import - Number of global variables imported
130
131; CHECK-DAG: !0 = !{!"{{.*}}.bc"}
132; CHECK-DAG: !1 = !{!"{{.*}}/Inputs/funcimport.ll"}
133
134; The actual GUID values will depend on path to test.
135; GUID-DAG: GUID {{.*}} is weakalias
136; GUID-DAG: GUID {{.*}} is referenceglobals
137; GUID-DAG: GUID {{.*}} is weakfunc
138; GUID-DAG: GUID {{.*}} is main
139; GUID-DAG: GUID {{.*}} is referencecommon
140; GUID-DAG: GUID {{.*}} is analias
141; GUID-DAG: GUID {{.*}} is referencestatics
142; GUID-DAG: GUID {{.*}} is linkoncealias
143; GUID-DAG: GUID {{.*}} is setfuncptr
144; GUID-DAG: GUID {{.*}} is callfuncptr
145; GUID-DAG: GUID {{.*}} is funcwithpersonality
146; GUID-DAG: GUID {{.*}} is setfuncptr
147; GUID-DAG: GUID {{.*}} is staticfunc2
148; GUID-DAG: GUID {{.*}} is __gxx_personality_v0
149; GUID-DAG: GUID {{.*}} is referencestatics
150; GUID-DAG: GUID {{.*}} is globalfunc1
151; GUID-DAG: GUID {{.*}} is globalfunc2
152; GUID-DAG: GUID {{.*}} is P
153; GUID-DAG: GUID {{.*}} is staticvar
154; GUID-DAG: GUID {{.*}} is commonvar
155; GUID-DAG: GUID {{.*}} is weakalias
156; GUID-DAG: GUID {{.*}} is staticfunc
157; GUID-DAG: GUID {{.*}} is weakfunc
158; GUID-DAG: GUID {{.*}} is referenceglobals
159; GUID-DAG: GUID {{.*}} is weakvar
160; GUID-DAG: GUID {{.*}} is staticconstvar
161; GUID-DAG: GUID {{.*}} is analias
162; GUID-DAG: GUID {{.*}} is globalvar
163; GUID-DAG: GUID {{.*}} is referencecommon
164; GUID-DAG: GUID {{.*}} is linkoncealias
165; GUID-DAG: GUID {{.*}} is callfuncptr
166; GUID-DAG: GUID {{.*}} is linkoncefunc
167
168; DUMP:       Module [[M1:.*]] imports from 1 module
169; DUMP-NEXT:  15 function definitions and 0 function declarations imported from [[M2:.*]]
170; DUMP-NEXT:  4 vars imported from [[M2]]
171
172; DUMP:       Imported 15 functions for Module [[M1]]
173; DUMP-NEXT:  Imported 4 global variables for Module [[M1]]
174