xref: /llvm-project/llvm/test/Transforms/EliminateAvailableExternally/transform-to-local.ll (revision 6329355860e9b66bc7ed68b46c166763e408d4cc)
1901183b5SMircea Trofin; REQUIRES: asserts
2901183b5SMircea Trofin; RUN: opt -passes=elim-avail-extern -avail-extern-to-local -stats -S 2>&1 < %s | FileCheck %s
349112356SMircea Trofin;
4*63293558SMircea Trofin; RUN: echo '[{"Guid":1234, "Counters": [1]}]' | llvm-ctxprof-util fromYAML --input=- --output=%t_profile.ctxprofdata
549112356SMircea Trofin;
649112356SMircea Trofin; Because we pass a contextual profile with a root defined in this module, we expect the outcome to be the same as-if
749112356SMircea Trofin; we passed -avail-extern-to-local, i.e. available_externally don't get elided and instead get converted to local linkage
849112356SMircea Trofin; RUN: opt -passes='assign-guid,require<ctx-prof-analysis>,elim-avail-extern' -use-ctx-profile=%t_profile.ctxprofdata -stats -S 2>&1 < %s | FileCheck %s
9901183b5SMircea Trofin
1049112356SMircea Trofin; If the profile doesn't apply to this module, available_externally won't get converted to internal linkage, and will be
1149112356SMircea Trofin; removed instead.
12*63293558SMircea Trofin; RUN: echo '[{"Guid":5678, "Counters": [1]}]' | llvm-ctxprof-util fromYAML --input=- --output=%t_profile_bad.ctxprofdata
1349112356SMircea Trofin; RUN: opt -passes='assign-guid,require<ctx-prof-analysis>,elim-avail-extern' -use-ctx-profile=%t_profile_bad.ctxprofdata -stats -S 2>&1 < %s | FileCheck %s --check-prefix=NOOP
14901183b5SMircea Trofin
15901183b5SMircea Trofindeclare void @call_out(ptr %fct)
16901183b5SMircea Trofin
17901183b5SMircea Trofindefine available_externally hidden void @f() {
18901183b5SMircea Trofin  ret void
19901183b5SMircea Trofin}
20901183b5SMircea Trofin
21901183b5SMircea Trofindefine available_externally hidden void @g() {
22901183b5SMircea Trofin  ret void
23901183b5SMircea Trofin}
24901183b5SMircea Trofin
2549112356SMircea Trofindefine void @hello(ptr %g) !guid !0 {
26901183b5SMircea Trofin  call void @f()
27901183b5SMircea Trofin  %f = load ptr, ptr @f
28901183b5SMircea Trofin  call void @call_out(ptr %f)
29901183b5SMircea Trofin  ret void
30901183b5SMircea Trofin}
31901183b5SMircea Trofin
3249112356SMircea Trofin!0 = !{i64 1234}
3349112356SMircea Trofin
34901183b5SMircea Trofin; CHECK: define internal void @f.__uniq.{{[0-9|a-f]*}}()
35901183b5SMircea Trofin; CHECK: declare hidden void @g()
36901183b5SMircea Trofin; CHECK: call void @f.__uniq.{{[0-9|a-f]*}}()
37901183b5SMircea Trofin; CHECK-NEXT: load ptr, ptr @f
38901183b5SMircea Trofin; CHECK-NEXT: call void @call_out(ptr %f)
39901183b5SMircea Trofin; CHECK: Statistics Collected
40901183b5SMircea Trofin; CHECK: 1 elim-avail-extern - Number of functions converted
41901183b5SMircea Trofin; CHECK: 1 elim-avail-extern - Number of functions removed
4249112356SMircea Trofin
4349112356SMircea Trofin; NOOP: 2 elim-avail-extern - Number of functions removed