| 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 | |
| 8 | int foo(int x) { return x + 1; } |
| 9 | |
| 10 | int fib(int x) { |
| 11 | if (x < 2) |
| 12 | return x; |
| 13 | return fib(x: x - 1) + fib(x: x - 2); |
| 14 | } |
| 15 | |
| 16 | int bar(int x) { return x - 1; } |
| 17 | |
| 18 | int main(int argc, char **argv) { |
| 19 | printf(format: "fib(%d) = %d\n" , argc, fib(x: argc)); |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | /* |
| 24 | REQUIRES: system-linux,bolt-runtime |
| 25 | |
| 26 | RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q |
| 27 | |
| 28 | RUN: llvm-bolt %t.exe --relocs=1 --lite --reorder-functions=user \ |
| 29 | RUN: --hugify --function-order=%p/Inputs/user_func_order.txt -o %t |
| 30 | RUN: llvm-bolt %t.exe --relocs=1 --lite --reorder-functions=user \ |
| 31 | RUN: --function-order=%p/Inputs/user_func_order.txt -o %t.nohugify |
| 32 | RUN: llvm-nm --numeric-sort --print-armap %t | \ |
| 33 | RUN: FileCheck %s -check-prefix=CHECK-NM |
| 34 | RUN: %t 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT |
| 35 | RUN: llvm-nm --numeric-sort --print-armap %t.nohugify | \ |
| 36 | RUN: FileCheck %s -check-prefix=CHECK-NM-NOHUGIFY |
| 37 | RUN: %t.nohugify 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT-NOHUGIFY |
| 38 | |
| 39 | |
| 40 | CHECK-NM: W __hot_start |
| 41 | CHECK-NM: T main |
| 42 | CHECK-NM-NEXT: T fib |
| 43 | CHECK-NM-NEXT: W __hot_end |
| 44 | CHECK-NM: t __bolt_hugify_start_program |
| 45 | CHECK-NM-NEXT: W __bolt_runtime_start |
| 46 | |
| 47 | CHECK-NM-NOHUGIFY: W __hot_start |
| 48 | CHECK-NM-NOHUGIFY: T main |
| 49 | CHECK-NM-NOHUGIFY-NEXT: T fib |
| 50 | CHECK-NM-NOHUGIFY-NEXT: W __hot_end |
| 51 | |
| 52 | CHECK-OUTPUT: fib(4) = 3 |
| 53 | CHECK-OUTPUT-NOHUGIFY: fib(4) = 3 |
| 54 | */ |
| 55 | |