1; First with legacy PM
2; RUN: opt -S -inline -inliner-function-import-stats=basic < %s 2>&1 | FileCheck %s -check-prefix=CHECK-BASIC -check-prefix=CHECK
3; RUN: opt -S -inline -inliner-function-import-stats=verbose < %s 2>&1 | FileCheck %s -check-prefix="CHECK-VERBOSE" -check-prefix=CHECK
4
5; Do again with new PM
6; RUN: opt -S -passes=inline -inliner-function-import-stats=basic < %s 2>&1 | FileCheck %s -check-prefix=CHECK-BASIC -check-prefix=CHECK
7; RUN: opt -S -passes=inline -inliner-function-import-stats=verbose < %s 2>&1 | FileCheck %s -check-prefix="CHECK-VERBOSE" -check-prefix=CHECK
8
9; RUN: opt -S -passes=inliner-wrapper -inliner-function-import-stats=basic < %s 2>&1 | FileCheck %s -check-prefix=WRAPPER-BASIC -check-prefix=WRAPPER
10; RUN: opt -S -passes=inliner-wrapper -inliner-function-import-stats=verbose < %s 2>&1 | FileCheck %s -check-prefix=WRAPPER-VERBOSE -check-prefix=WRAPPER
11
12; CHECK: ------- Dumping inliner stats for [<stdin>] -------
13; CHECK-BASIC-NOT: -- List of inlined functions:
14; CHECK-BASIC-NOT: -- Inlined not imported function
15; CHECK-VERBOSE: -- List of inlined functions:
16; CHECK-VERBOSE: Inlined not imported function [internal2]: #inlines = 6, #inlines_to_importing_module = 2
17; CHECK-VERBOSE: Inlined imported function [external2]: #inlines = 4, #inlines_to_importing_module = 1
18; CHECK-VERBOSE: Inlined imported function [external1]: #inlines = 3, #inlines_to_importing_module = 2
19; CHECK-VERBOSE: Inlined imported function [external5]: #inlines = 1, #inlines_to_importing_module = 1
20; CHECK-VERBOSE: Inlined imported function [external3]: #inlines = 1, #inlines_to_importing_module = 0
21
22; CHECK: -- Summary:
23; CHECK: All functions: 10, imported functions: 7
24; CHECK: inlined functions: 5 [50% of all functions]
25; CHECK: imported functions inlined anywhere: 4 [57.14% of imported functions]
26; CHECK: imported functions inlined into importing module: 3 [42.86% of imported functions], remaining: 4 [57.14% of imported functions]
27; CHECK: non-imported functions inlined anywhere: 1 [33.33% of non-imported functions]
28; CHECK: non-imported functions inlined into importing module: 1 [33.33% of non-imported functions]
29
30; WRAPPER-VERBOSE: -- List of inlined functions:
31; WRAPPER-VERBOSE: Inlined imported function [external5]: #inlines = 1, #inlines_to_importing_module = 1
32; WRAPPER: -- Summary:
33; WRAPPER: All functions: 10, imported functions: 7
34; WRAPPER: inlined functions: 1 [10% of all functions]
35; WRAPPER: imported functions inlined anywhere: 1 [14.29% of imported functions]
36; WRAPPER: imported functions inlined into importing module: 1 [14.29% of imported functions], remaining: 6 [85.71% of imported functions]
37; WRAPPER: non-imported functions inlined anywhere: 0 [0% of non-imported functions]
38; WRAPPER: non-imported functions inlined into importing module: 0 [0% of non-imported functions]
39
40define void @internal() {
41    call fastcc void @external1()
42    call fastcc void @internal2()
43    call coldcc void @external_big()
44    ret void
45}
46
47define void @internal2() alwaysinline {
48    ret void
49}
50
51define void @internal3() {
52    call fastcc void @external1()
53    call fastcc void @external5()
54    ret void
55}
56
57declare void @external_decl()
58
59define void @external1() alwaysinline !thinlto_src_module !0 {
60    call fastcc void @internal2()
61    call fastcc void @external2();
62    call void @external_decl();
63    ret void
64}
65
66define void @external2() alwaysinline !thinlto_src_module !1 {
67    ret void
68}
69
70define void @external3() alwaysinline !thinlto_src_module !1 {
71    ret void
72}
73
74define void @external4() !thinlto_src_module !1 {
75    call fastcc void @external1()
76    call fastcc void @external2()
77    ret void
78}
79
80define void @external5() !thinlto_src_module !1 {
81    ret void
82}
83
84; Assume big piece of code here. This function won't be inlined, so all the
85; inlined function it will have won't affect real inlines.
86define void @external_big() noinline !thinlto_src_module !1 {
87; CHECK-NOT: call fastcc void @internal2()
88    call fastcc void @internal2()
89    call fastcc void @internal2()
90    call fastcc void @internal2()
91    call fastcc void @internal2()
92
93; CHECK-NOT: call fastcc void @external2()
94    call fastcc void @external2()
95    call fastcc void @external2()
96; CHECK-NOT: call fastcc void @external3()
97    call fastcc void @external3()
98    ret void
99}
100
101; It should not be imported, but it should not break anything.
102define void @external_notcalled() !thinlto_src_module !0 {
103    call void @external_notcalled()
104    ret void
105}
106
107!0 = !{!"file.cc"}
108!1 = !{!"other.cc"}
109