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