1 | /* |
2 | REQUIRES: system-linux,bolt-runtime |
3 | |
4 | RUN: %clang %cflags %s -o %t.exe -Wl,-q |
5 | |
6 | RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \ |
7 | RUN: -o %t.instrumented |
8 | |
9 | # Instrumented program needs to finish returning zero |
10 | RUN: %t.instrumented | FileCheck %s -check-prefix=CHECK-OUTPUT |
11 | |
12 | # Test that the instrumented data makes sense |
13 | RUN: llvm-bolt %t.exe -o %t.bolted --data %t.fdata \ |
14 | RUN: --reorder-blocks=ext-tsp --reorder-functions=hfsort+ \ |
15 | RUN: --print-only=main --print-finalized | FileCheck %s |
16 | |
17 | RUN: %t.bolted | FileCheck %s -check-prefix=CHECK-OUTPUT |
18 | |
19 | CHECK-OUTPUT: The sum is: 30 |
20 | |
21 | # Check that our indirect call has 1 hit recorded in the fdata file and that |
22 | # this was processed correctly by BOLT |
23 | CHECK: jalr a2 # CallProfile: 1 (0 misses) : |
24 | CHECK-NEXT: { add: 1 (0 misses) } |
25 | */ |
26 | |
27 | #include <stdio.h> |
28 | |
29 | typedef int (*func_ptr)(int, int); |
30 | |
31 | int add(int a, int b) { return a + b; } |
32 | |
33 | int main() { |
34 | func_ptr fun; |
35 | fun = add; |
36 | int sum = fun(10, 20); // indirect call to 'add' |
37 | printf(format: "The sum is: %d\n" , sum); |
38 | return 0; |
39 | } |
40 | |