Skip to content

Commit 75df61e

Browse files
committed
[test] Improve PGO tests
1 parent 2d7374a commit 75df61e

File tree

4 files changed

+117
-73
lines changed

4 files changed

+117
-73
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <string.h>
2+
3+
void (*f0)();
4+
void (*f1)();
5+
void (*f2)();
6+
7+
char dst[200];
8+
char src[200];
9+
volatile int n;
10+
11+
__attribute__((noinline)) void foo() {}
12+
13+
__attribute__((noinline)) void bar() {
14+
f0 = foo;
15+
f1 = foo;
16+
f2 = foo;
17+
n = 4;
18+
}
19+
int main(int argc, char *argv[]) {
20+
int i;
21+
bar();
22+
if (argc == 1) {
23+
f0();
24+
for (i = 0; i < 9; i++)
25+
f1();
26+
for (i = 0; i < 99; i++)
27+
f2();
28+
} else {
29+
memcpy((void *)dst, (void *)src, n);
30+
for (i = 0; i < 6; i++)
31+
memcpy((void *)(dst + 2), (void *)src, n + 1);
32+
for (i = 0; i < 66; i++)
33+
memcpy((void *)(dst + 9), (void *)src, n + 2);
34+
}
35+
}
36+
37+
// CHECK: Counters:
38+
// CHECK-NEXT: main:
39+
// CHECK-NEXT: Hash: 0x0a9bd81e87ab6e87
40+
// CHECK-NEXT: Counters: 6
41+
// CHECK-NEXT: Indirect Call Site Count: 3
42+
// CHECK-NEXT: Number of Memory Intrinsics Calls: 3
43+
// CHECK-NEXT: Block counts: [27, 297, 12, 132, 3, 2]
44+
// CHECK-NEXT: Indirect Target Results:
45+
// CHECK-NEXT: [ 0, foo, 3 ]
46+
// CHECK-NEXT: [ 1, foo, 27 ]
47+
// CHECK-NEXT: [ 2, foo, 297 ]
48+
// CHECK-NEXT: Memory Intrinsic Size Results:
49+
// CHECK-NEXT: [ 0, 4, 2 ]
50+
// CHECK-NEXT: [ 1, 5, 12 ]
51+
// CHECK-NEXT: [ 2, 6, 132 ]
52+
// CHECK-NEXT: Instrumentation level: IR entry_first = 0
53+
// CHECK-NEXT: Functions shown: 1
54+
// CHECK-NEXT: Total functions: 3
55+
// CHECK-NEXT: Maximum function count: 327
56+
// CHECK-NEXT: Maximum internal block count: 297
57+
// CHECK-NEXT: Statistics for indirect call sites profile:
58+
// CHECK-NEXT: Total number of sites: 3
59+
// CHECK-NEXT: Total number of sites with values: 3
60+
// CHECK-NEXT: Total number of profiled values: 3
61+
// CHECK-NEXT: Value sites histogram:
62+
// CHECK-NEXT: NumTargets, SiteCount
63+
// CHECK-NEXT: 1, 3
64+
// CHECK-NEXT: Statistics for memory intrinsic calls sizes profile:
65+
// CHECK-NEXT: Total number of sites: 3
66+
// CHECK-NEXT: Total number of sites with values: 3
67+
// CHECK-NEXT: Total number of profiled values: 3
68+
// CHECK-NEXT: Value sites histogram:
69+
// CHECK-NEXT: NumTargets, SiteCount
70+
// CHECK-NEXT: 1, 3
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: lld-available
2+
/// Test ld with GC.
3+
4+
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections
5+
// RUN: rm -rf %t.profdir
6+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
7+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
8+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
9+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
10+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
11+
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c
Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,28 @@
1-
// RUN: %clang_pgogen -o %t -O3 %s
1+
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c
22
// RUN: rm -rf %t.profdir
33
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
44
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
55
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
66
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
77
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
8-
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %s
8+
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c
99

10-
#include <string.h>
11-
12-
void (*f0)();
13-
void (*f1)();
14-
void (*f2)();
15-
16-
char dst[200];
17-
char src[200];
18-
volatile int n;
19-
20-
__attribute__((noinline)) void foo() {}
21-
22-
__attribute__((noinline)) void bar() {
23-
f0 = foo;
24-
f1 = foo;
25-
f2 = foo;
26-
n = 4;
27-
}
28-
int main(int argc, char *argv[]) {
29-
int i;
30-
bar();
31-
if (argc == 1) {
32-
f0();
33-
for (i = 0; i < 9; i++)
34-
f1();
35-
for (i = 0; i < 99; i++)
36-
f2();
37-
} else {
38-
memcpy((void *)dst, (void *)src, n);
39-
for (i = 0; i < 6; i++)
40-
memcpy((void *)(dst + 2), (void *)src, n + 1);
41-
for (i = 0; i < 66; i++)
42-
memcpy((void *)(dst + 9), (void *)src, n + 2);
43-
}
44-
}
10+
/// -z start-stop-gc requires binutils 2.37. Don't test the option for now.
11+
/// TODO: Add -Wl,--gc-sections.
12+
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=bfd -ffunction-sections -fdata-sections
13+
// RUN: rm -rf %t.profdir
14+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
15+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
16+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
17+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
18+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
19+
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c
4520

46-
// CHECK: Counters:
47-
// CHECK: main:
48-
// CHECK: Hash: 0x0a9bd81e87ab6e87
49-
// CHECK: Counters: 6
50-
// CHECK: Indirect Call Site Count: 3
51-
// CHECK: Number of Memory Intrinsics Calls: 3
52-
// CHECK: Block counts: [27, 297, 12, 132, 3, 2]
53-
// CHECK: Indirect Target Results:
54-
// CHECK: [ 0, foo, 3 ]
55-
// CHECK: [ 1, foo, 27 ]
56-
// CHECK: [ 2, foo, 297 ]
57-
// CHECK: Memory Intrinsic Size Results:
58-
// CHECK: [ 0, 4, 2 ]
59-
// CHECK: [ 1, 5, 12 ]
60-
// CHECK: [ 2, 6, 132 ]
61-
// CHECK: Instrumentation level: IR
62-
// CHECK: Functions shown: 1
63-
// CHECK: Total functions: 3
64-
// CHECK: Maximum function count: 327
65-
// CHECK: Maximum internal block count: 297
66-
// CHECK: Statistics for indirect call sites profile:
67-
// CHECK: Total number of sites: 3
68-
// CHECK: Total number of sites with values: 3
69-
// CHECK: Total number of profiled values: 3
70-
// CHECK: Value sites histogram:
71-
// CHECK: NumTargets, SiteCount
72-
// CHECK: 1, 3
73-
// CHECK: Statistics for memory intrinsic calls sizes profile:
74-
// CHECK: Total number of sites: 3
75-
// CHECK: Total number of sites with values: 3
76-
// CHECK: Total number of profiled values: 3
77-
// CHECK: Value sites histogram:
78-
// CHECK: NumTargets, SiteCount
79-
// CHECK: 1, 3
21+
// RUN: %clang_pgogen -o %t -O3 %S/Inputs/instrprof-value-merge.c -fuse-ld=gold -ffunction-sections -fdata-sections
22+
// RUN: rm -rf %t.profdir
23+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
24+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
25+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t
26+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
27+
// RUN: env LLVM_PROFILE_FILE=%t.profdir/default_%m.profraw %run %t 1
28+
// RUN: llvm-profdata show -counts -function=main -ic-targets -memop-sizes %t.profdir/default_*.profraw | FileCheck %S/Inputs/instrprof-value-merge.c

llvm/test/Instrumentation/InstrProfiling/profiling.ll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
; RUN: opt < %s -mtriple=x86_64 -passes=instrprof -S | FileCheck %s --check-prefixes=CHECK,ELF
1+
; RUN: opt < %s -mtriple=x86_64 -passes=instrprof -S | FileCheck %s --check-prefixes=CHECK,ELF,ELF_GENERIC
2+
; RUN: opt < %s -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=CHECK,ELF_LINUX
23
; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -passes=instrprof -S | FileCheck %s --check-prefixes=CHECK,MACHO
34
; RUN: opt < %s -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=CHECK,WIN
45

56
; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s
67

7-
; CHECK: @__llvm_profile_runtime = external global i32
8+
; ELF_GENERIC: @__llvm_profile_runtime = external global i32
9+
; ELF_LINUX-NOT: @__llvm_profile_runtime
10+
; MACHO: @__llvm_profile_runtime = external global i32
11+
; WIN: @__llvm_profile_runtime = external global i32
812

913
@__profn_foo = hidden constant [3 x i8] c"foo"
1014
; CHECK-NOT: __profn_foo
@@ -53,3 +57,13 @@ declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
5357
; ELF: @llvm.compiler.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
5458
; MACHO: @llvm.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
5559
; WIN: @llvm.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo {{.*}} @__profd_bar {{.*}} @__profd_baz
60+
61+
; ELF_GENERIC: define internal void @__llvm_profile_register_functions() unnamed_addr {
62+
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*))
63+
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_bar to i8*))
64+
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_function(i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_baz to i8*))
65+
; ELF_GENERIC-NEXT: call void @__llvm_profile_register_names_function(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__llvm_prf_nm, i32 0, i32 0), i64 19)
66+
; ELF_GENERIC-NEXT: ret void
67+
; ELF_GENERIC-NEXT: }
68+
69+
; ELF_LINUX-NOT: @__llvm_profile_register_functions()

0 commit comments

Comments
 (0)