Disallow aliases to available_externally.
[oota-llvm.git] / test / Transforms / FunctionImport / funcimport.ll
1 ; Do setup work for all below tests: generate bitcode and combined index
2 ; RUN: llvm-as -function-summary %s -o %t.bc
3 ; RUN: llvm-as -function-summary %p/Inputs/funcimport.ll -o %t2.bc
4 ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
5
6 ; Do the import now
7 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF
8
9 ; Test import with smaller instruction limit
10 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5
11 ; INSTLIM5-NOT: @staticfunc.llvm.2
12
13 define i32 @main() #0 {
14 entry:
15   call void (...) @weakalias()
16   call void (...) @analias()
17   call void (...) @linkoncealias()
18   %call = call i32 (...) @referencestatics()
19   %call1 = call i32 (...) @referenceglobals()
20   %call2 = call i32 (...) @referencecommon()
21   call void (...) @setfuncptr()
22   call void (...) @callfuncptr()
23   call void (...) @weakfunc()
24   ret i32 0
25 }
26
27 ; Won't import weak alias
28 ; CHECK-DAG: declare extern_weak void @weakalias()
29 declare void @weakalias(...) #1
30
31 ; Cannot create an alias to available_externally
32 ; CHECK-DAG: declare void @analias()
33 declare void @analias(...) #1
34
35 ; Aliases import the aliasee function
36 declare void @linkoncealias(...) #1
37 ; CHECK-DAG: define linkonce_odr void @linkoncefunc()
38 ; CHECK-DAG: @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*
39
40 ; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i)
41 ; INSTLIM5-DAG: declare i32 @referencestatics(...)
42 declare i32 @referencestatics(...) #1
43
44 ; The import of referencestatics will expose call to staticfunc that
45 ; should in turn be imported as a promoted/renamed and hidden function.
46 ; Ensure that the call is to the properly-renamed function.
47 ; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.2()
48 ; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.2()
49
50 ; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i)
51 declare i32 @referenceglobals(...) #1
52
53 ; The import of referenceglobals will expose call to globalfunc1 that
54 ; should in turn be imported.
55 ; CHECK-DAG: define available_externally void @globalfunc1()
56
57 ; CHECK-DAG: define available_externally i32 @referencecommon(i32 %i)
58 declare i32 @referencecommon(...) #1
59
60 ; CHECK-DAG: define available_externally void @setfuncptr()
61 declare void @setfuncptr(...) #1
62
63 ; CHECK-DAG: define available_externally void @callfuncptr()
64 declare void @callfuncptr(...) #1
65
66 ; Ensure that all uses of local variable @P which has used in setfuncptr
67 ; and callfuncptr are to the same promoted/renamed global.
68 ; CHECK-DAG: @P.llvm.2 = available_externally hidden global void ()* null
69 ; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.2,
70 ; CHECK-DAG: store void ()* @staticfunc2.llvm.2, void ()** @P.llvm.2,
71
72 ; Won't import weak func
73 ; CHECK-DAG: declare void @weakfunc(...)
74 declare void @weakfunc(...) #1
75