|
13 | 13 | // - Generate ThinLTO summary file with LLVM bitcodes, and run `function-import` pass.
|
14 | 14 | // - Run `pgo-icall-prom` pass for the IR module which needs to import callees.
|
15 | 15 |
|
| 16 | +// This test and IR test llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll |
| 17 | +// are complementary to each other; a compiler-rt test has better test coverage |
| 18 | +// on different platforms, and the IR test is less restrictive in terms of |
| 19 | +// running environment and could be executed more widely. |
| 20 | + |
16 | 21 | // Use lld as linker for more robust test. We need to REQUIRE LLVMgold.so for
|
17 | 22 | // LTO if default linker is GNU ld or gold anyway.
|
18 | 23 | // REQUIRES: lld-available
|
|
40 | 45 | // RUN: env LLVM_PROFILE_FILE=main.profraw %run ./main
|
41 | 46 | // RUN: llvm-profdata merge main.profraw -o main.profdata
|
42 | 47 |
|
43 |
| -// Use profile on lib and get bitcode, test that local function callee0 has |
44 |
| -// expected !PGOFuncName metadata and external function callee1 doesn't have |
45 |
| -// !PGOFuncName metadata. Explicitly skip ICP pass to test ICP happens as |
| 48 | +// Use profile on lib and get bitcode. Explicitly skip ICP pass to test ICP happens as |
46 | 49 | // expected in the IR module that imports functions from lib.
|
47 | 50 | // RUN: %clang -mllvm -disable-icp -fprofile-use=main.profdata -flto=thin -O2 -c lib.cpp -o lib.bc
|
48 |
| -// RUN: llvm-dis lib.bc -o - | FileCheck %s --check-prefix=PGOName |
49 | 51 |
|
50 | 52 | // Use profile on main and get bitcode.
|
51 | 53 | // RUN: %clang -fprofile-use=main.profdata -flto=thin -O2 -c main.cpp -o main.bc
|
|
58 | 60 | // block with a function-entry-count of one, so they are actually hot functions
|
59 | 61 | // per default profile summary hotness cutoff.
|
60 | 62 | // RUN: opt -passes=function-import -import-instr-limit=100 -import-cold-multiplier=1 -summary-file summary.thinlto.bc main.bc -o main.import.bc -print-imports 2>&1 | FileCheck %s --check-prefix=IMPORTS
|
61 |
| -// Test that '_Z11global_funcv' has indirect calls annotated with value profiles. |
62 |
| -// RUN: llvm-dis main.import.bc -o - | FileCheck %s --check-prefix=IR |
63 | 63 |
|
64 | 64 | // Test that both candidates are ICP'ed and there is no `!VP` in the IR.
|
65 | 65 | // RUN: opt main.import.bc -icp-lto -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom 2>&1 | FileCheck %s --check-prefixes=ICP-IR,ICP-REMARK --implicit-check-not="!VP"
|
66 | 66 |
|
67 |
| -// IMPORTS: main.cpp: Import _Z7callee1v |
68 |
| -// IMPORTS: main.cpp: Import _ZL7callee0v.llvm.[[#]] |
69 |
| -// IMPORTS: main.cpp: Import _Z11global_funcv |
70 |
| - |
71 |
| -// PGOName: define {{(dso_local )?}}void @_Z7callee1v() #[[#]] !prof ![[#]] { |
72 |
| -// PGOName: define internal void @_ZL7callee0v() #[[#]] !prof ![[#]] !PGOFuncName ![[#MD:]] { |
73 |
| -// PGOName: ![[#MD]] = !{!"{{.*}}lib.cpp;_ZL7callee0v"} |
74 |
| - |
75 |
| -// IR-LABEL: define available_externally {{.*}} void @_Z11global_funcv() {{.*}} !prof ![[#]] { |
76 |
| -// IR-NEXT: entry: |
77 |
| -// IR-NEXT: %0 = load ptr, ptr @calleeAddrs |
78 |
| -// IR-NEXT: tail call void %0(), !prof ![[#PROF1:]] |
79 |
| -// IR-NEXT: %1 = load ptr, ptr getelementptr inbounds ([2 x ptr], ptr @calleeAddrs, |
80 |
| -// IR-NEXT: tail call void %1(), !prof ![[#PROF2:]] |
81 |
| - |
82 |
| -// The GUID of indirect callee is the MD5 hash of `/path/to/lib.cpp;_ZL7callee0v` |
83 |
| -// that depends on the directory. Use [[#]] for its MD5 hash. |
84 |
| -// Use {{.*}} for integer types so the test works on 32-bit and 64-bit systems. |
85 |
| -// IR: ![[#PROF1]] = !{!"VP", i32 0, {{.*}} 1, {{.*}} [[#]], {{.*}} 1} |
86 |
| -// IR: ![[#PROF2]] = !{!"VP", i32 0, {{.*}} 1, {{.*}} -3993653843325621743, {{.*}} 1} |
87 |
| - |
88 |
| -// ICP-REMARK: Promote indirect call to _ZL7callee0v.llvm.[[#]] with count 1 out of 1 |
89 |
| -// ICP-REMARK: Promote indirect call to _Z7callee1v with count 1 out of 1 |
| 67 | +// IMPORTS-DAG: main.cpp: Import {{.*}}callee1{{.*}} |
| 68 | +// IMPORTS-DAG: main.cpp: Import {{.*}}callee0{{.*}}llvm.[[#]] |
| 69 | +// IMPORTS-DAG: main.cpp: Import {{.*}}global_func{{.*}} |
| 70 | + |
| 71 | +// PGOName-DAG: define {{.*}}callee1{{.*}} !prof ![[#]] { |
| 72 | +// PGOName-DAG: define internal {{.*}}callee0{{.*}} !prof ![[#]] !PGOFuncName ![[#MD:]] { |
| 73 | +// PGOName-DAG: ![[#MD]] = !{!"{{.*}}lib.cpp;{{.*}}callee0{{.*}}"} |
| 74 | + |
| 75 | +// ICP-REMARK: Promote indirect call to {{.*}}callee0{{.*}}llvm.[[#]] with count 1 out of 1 |
| 76 | +// ICP-REMARK: Promote indirect call to {{.*}}callee1{{.*}} with count 1 out of 1 |
90 | 77 |
|
91 | 78 | // ICP-IR: br i1 %[[#]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof ![[#BRANCH_WEIGHT1:]]
|
92 | 79 | // ICP-IR: br i1 %[[#]], label %if.true.direct_targ1, label %if.false.orig_indirect2, !prof ![[#BRANCH_WEIGHT1]]
|
|
0 commit comments