1 ; REQUIRES: x86-registered-target
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
9 ; 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
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.
16 ; Test import with smaller instruction limit
17 ; 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
18 ; INSTLIM5-NOT: @staticfunc.llvm.
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
25 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
26 target triple = "x86_64-apple-macosx10.11.0"
28 define i32 @main() #0 {
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()
46 ; Won't import weak alias
47 ; CHECK-DAG: declare void @weakalias
48 declare void @weakalias(...) #1
50 ; External alias imported as available_externally copy of aliasee
51 ; CHECK-DAG: define available_externally void @analias
52 declare void @analias(...) #1
54 ; External alias imported as available_externally copy of aliasee
55 ; (linkoncealias is an external alias to a linkonce_odr)
56 declare void @linkoncealias(...) #1
57 ; CHECK-DAG: define available_externally void @linkoncealias()
59 ; INSTLIMDEF-DAG: Import referencestatics
60 ; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 {
61 ; INSTLIM5-DAG: declare i32 @referencestatics(...)
62 declare i32 @referencestatics(...) #1
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 {
71 ; INSTLIMDEF-DAG: Import referenceglobals
72 ; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i) !thinlto_src_module !0 {
73 declare i32 @referenceglobals(...) #1
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
80 ; INSTLIMDEF-DAG: Import referencecommon
81 ; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i) !thinlto_src_module !0 {
82 declare i32 @referencecommon(...) #1
84 ; INSTLIMDEF-DAG: Import setfuncptr
85 ; CHECK-DAG: define available_externally void @setfuncptr() !thinlto_src_module !0 {
86 declare void @setfuncptr(...) #1
88 ; INSTLIMDEF-DAG: Import callfuncptr
89 ; CHECK-DAG: define available_externally void @callfuncptr() !thinlto_src_module !0 {
90 declare void @callfuncptr(...) #1
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 void ()* null
95 ; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.
96 ; CHECK-DAG: store void ()* @staticfunc2.llvm.{{.*}}, void ()** @P.llvm.
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 {
101 ; INSTLIM5-DAG: declare void @linkonceodr()
102 declare void @referencelargelinkonce(...)
104 ; Won't import weak func
105 ; CHECK-DAG: declare void @weakfunc(...)
106 declare void @weakfunc(...) #1
108 ; Won't import linkonce func
109 ; CHECK-DAG: declare void @linkoncefunc2(...)
110 declare void @linkoncefunc2(...) #1
112 ; INSTLIMDEF-DAG: Import funcwithpersonality
113 ; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 {
114 ; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}()
116 ; We can import variadic functions without a va_start, since the inliner
118 ; INSTLIMDEF-DAG: Import variadic_no_va_start
119 ; CHECK-DAG: define available_externally void @variadic_no_va_start(...) !thinlto_src_module !0 {
120 declare void @variadic_no_va_start(...)
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(...)
125 declare void @variadic_va_start(...)
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
131 ; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"}
133 ; The actual GUID values will depend on path to test.
134 ; GUID-DAG: GUID {{.*}} is weakalias
135 ; GUID-DAG: GUID {{.*}} is referenceglobals
136 ; GUID-DAG: GUID {{.*}} is weakfunc
137 ; GUID-DAG: GUID {{.*}} is main
138 ; GUID-DAG: GUID {{.*}} is referencecommon
139 ; GUID-DAG: GUID {{.*}} is analias
140 ; GUID-DAG: GUID {{.*}} is referencestatics
141 ; GUID-DAG: GUID {{.*}} is linkoncealias
142 ; GUID-DAG: GUID {{.*}} is setfuncptr
143 ; GUID-DAG: GUID {{.*}} is callfuncptr
144 ; GUID-DAG: GUID {{.*}} is funcwithpersonality
145 ; GUID-DAG: GUID {{.*}} is setfuncptr
146 ; GUID-DAG: GUID {{.*}} is staticfunc2
147 ; GUID-DAG: GUID {{.*}} is __gxx_personality_v0
148 ; GUID-DAG: GUID {{.*}} is referencestatics
149 ; GUID-DAG: GUID {{.*}} is globalfunc1
150 ; GUID-DAG: GUID {{.*}} is globalfunc2
151 ; GUID-DAG: GUID {{.*}} is P
152 ; GUID-DAG: GUID {{.*}} is staticvar
153 ; GUID-DAG: GUID {{.*}} is commonvar
154 ; GUID-DAG: GUID {{.*}} is weakalias
155 ; GUID-DAG: GUID {{.*}} is staticfunc
156 ; GUID-DAG: GUID {{.*}} is weakfunc
157 ; GUID-DAG: GUID {{.*}} is referenceglobals
158 ; GUID-DAG: GUID {{.*}} is weakvar
159 ; GUID-DAG: GUID {{.*}} is staticconstvar
160 ; GUID-DAG: GUID {{.*}} is analias
161 ; GUID-DAG: GUID {{.*}} is globalvar
162 ; GUID-DAG: GUID {{.*}} is referencecommon
163 ; GUID-DAG: GUID {{.*}} is linkoncealias
164 ; GUID-DAG: GUID {{.*}} is callfuncptr
165 ; GUID-DAG: GUID {{.*}} is linkoncefunc
167 ; DUMP: Module [[M1:.*]] imports from 1 module
168 ; DUMP-NEXT: 15 functions imported from [[M2:.*]]
169 ; DUMP-NEXT: 4 vars imported from [[M2]]
170 ; DUMP: Imported 15 functions for Module [[M1]]
171 ; DUMP-NEXT: Imported 4 global variables for Module [[M1]]