xref: /llvm-project/bolt/test/runtime/X86/user-func-reorder.c (revision d648aa1b8e937de1648524e1f1016b53b29ba2a4)
1 /* Checks that BOLT correctly processes a user-provided function list file,
2  * reorder functions according to this list, update hot_start and hot_end
3  * symbols and insert a function to perform hot text mapping during program
4  * startup.
5  */
6 #include <stdio.h>
7 
foo(int x)8 int foo(int x) {
9   return x + 1;
10 }
11 
fib(int x)12 int fib(int x) {
13   if (x < 2)
14     return x;
15   return fib(x - 1) + fib(x - 2);
16 }
17 
bar(int x)18 int bar(int x) {
19   return x - 1;
20 }
21 
main(int argc,char ** argv)22 int main(int argc, char **argv) {
23   printf("fib(%d) = %d\n", argc, fib(argc));
24   return 0;
25 }
26 
27 /*
28 REQUIRES: system-linux,bolt-runtime
29 
30 RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q
31 
32 RUN: llvm-bolt %t.exe --relocs=1 --lite --reorder-functions=user \
33 RUN:   --hugify --function-order=%p/Inputs/user_func_order.txt -o %t
34 RUN: llvm-nm --numeric-sort --print-armap %t | \
35 RUN:   FileCheck %s -check-prefix=CHECK-NM
36 RUN: %t 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT
37 
38 CHECK-NM:      W  __hot_start
39 CHECK-NM:      T main
40 CHECK-NM-NEXT: T fib
41 CHECK-NM-NEXT: W __hot_end
42 
43 CHECK-OUTPUT: fib(4) = 3
44 */
45