xref: /llvm-project/llvm/test/tools/llvm-profgen/func-split.test (revision bc380c0930c9e110b7f6dda97ffee417f9cba00d)
1*bc380c09SHongtao Yu; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/func-split.perfscript --binary=%S/Inputs/func-split.perfbin --output=%t --gen-cs-nested-profile=0
2b1a45c62Swlei; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
3*bc380c09SHongtao Yu; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/func-split.perfscript --binary=%S/Inputs/func-split.perfbin --output=%t --ignore-stack-samples --gen-cs-nested-profile=0
4b1a45c62Swlei; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-STRIP-CTX
5b1a45c62Swlei
6484a569eSwlei;CHECK: [foo]:409:0
7b1a45c62Swlei;CHECK:  2.1: 27
8b1a45c62Swlei;CHECK:  3: 27
9b1a45c62Swlei;CHECK:  3.1: 2 bar:2
10b1a45c62Swlei;CHECK:  3.2: 26
11484a569eSwlei;CHECK: [foo:3.1 @ bar]:8:0
12b1a45c62Swlei;CHECK:  1: 1
13b1a45c62Swlei;CHECK:  5: 1
14b1a45c62Swlei;CHECK: [bar]:0:1
15b1a45c62Swlei
16b1a45c62Swlei;CHECK-NOT: foo.cold
17b1a45c62Swlei
18484a569eSwlei;CHECK-STRIP-CTX: foo:1334:0
19b1a45c62Swlei;CHECK-STRIP-CTX:  0: 0
20b1a45c62Swlei;CHECK-STRIP-CTX:  2.1: 27
21b1a45c62Swlei;CHECK-STRIP-CTX:  3: 27
22b1a45c62Swlei;CHECK-STRIP-CTX:  3.1: 1 bar:1
23b1a45c62Swlei;CHECK-STRIP-CTX:  3.2: 26
24b1a45c62Swlei;CHECK-STRIP-CTX:  4: 0
25484a569eSwlei;CHECK-STRIP-CTX: bar:27:1
26b1a45c62Swlei;CHECK-STRIP-CTX:  1: 1
27b1a45c62Swlei;CHECK-STRIP-CTX:  5: 1
28b1a45c62Swlei
29b1a45c62Swlei;CHECK-STRIP-CTX-NOT: foo.cold
30b1a45c62Swlei
31b1a45c62Swlei
32b1a45c62Swlei; clang -g -O3 -fdebug-info-for-profiling func-split.c -mllvm -mfs-count-threshold=0
33b1a45c62Swlei; -fprofile-sample-use=profile.txt -fno-inline -mllvm --enable-split-machine-functions=1
34b1a45c62Swlei
35b1a45c62Swlei#include <stdio.h>
36b1a45c62Swlei
37b1a45c62Swleiint bar(int x, int y) {
38b1a45c62Swlei  if (x % 3) {
39b1a45c62Swlei    return x - y;
40b1a45c62Swlei  }
41b1a45c62Swlei  return x + y;
42b1a45c62Swlei}
43b1a45c62Swlei
44b1a45c62Swleivoid foo() {
45b1a45c62Swlei  int s, i = 0;
46b1a45c62Swlei  while (i++ < 4000 * 4000)
47b1a45c62Swlei    if (i % 91 == 0) s = bar(i, s); else s += 30;
48b1a45c62Swlei  printf("sum is %d\n", s);
49b1a45c62Swlei}
50b1a45c62Swlei
51b1a45c62Swleiint main() {
52b1a45c62Swlei  foo();
53b1a45c62Swlei  return 0;
54b1a45c62Swlei}
55b1a45c62Swlei
56b1a45c62Swlei; profile.txt:
57b1a45c62Swlei
58b1a45c62Swleifoo:106269:0
59b1a45c62Swlei 2.1: 2268
60b1a45c62Swlei 2.2: 2217
61b1a45c62Swlei 3: 2268
62b1a45c62Swlei 3.1: 1 bar:1
63b1a45c62Swlei 3.2: 2192
64b1a45c62Swleibar:1032:1
65b1a45c62Swlei 0: 24
66b1a45c62Swlei 1: 24
67b1a45c62Swlei 2: 16
68b1a45c62Swlei 4: 8
69b1a45c62Swlei 5: 24
70