brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · fa0de9b Raw
82 lines · c
1/**2 ** Test for asm-dump functionality.3 *4 * REQUIRES: x86_64-linux,bolt-runtime5 *6 * Compile the source7 * RUN: %clang -fPIC %s -o %t.exe -Wl,-q8 *9 * Profile collection: instrument the binary10 * RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata -o \11 * RUN:   %t.instr12 *13 * Profile collection: run instrumented binary (and capture output)14 * RUN: %t.instr > %t.result15 *16 * Run BOLT with asm-dump17 * RUN: llvm-bolt %t.exe -p %t.fdata --funcs=main --asm-dump=%t -o %t.null \18 * RUN:   | FileCheck %s --check-prefix=CHECK-BOLT19 *20 * Check asm file contents21 * RUN: cat %t/main.s | FileCheck %s --check-prefix=CHECK-FILE22 *23 * Now check if asm-dump file can be consumed by BOLT infra24 * Strip dot from compiler-local symbols:25 * RUN: sed -i 's/\.L/L/g' %t/main.s26 *27 * Recompile the asm file into objfile28 * RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o29 *30 * Reconstruct fdata31 * RUN: link_fdata %t/main.s %t.o %t.fdata.reconst32 *33 * XXX: re-enable once dumping data is supported34 * Check if reoptimized file produces the same results35 * dontrun: %t.exe.reopt > %t.result.reopt36 * dontrun: cmp %t.result %t.result.reopt37 *38 * Delete our BB symbols so BOLT doesn't mark them as entry points39 * RUN: llvm-strip --strip-unneeded %t.o40 *41 * Recompile the binary42 * RUN: %clang -fPIC %t.o -o %t.exe.reopt -Wl,-q43 *44 * Finally consume reoptimized file with reconstructed fdata45 * RUN: llvm-bolt %t.exe.reopt -p %t.fdata.reconst -o %t.null \46 * RUN:   | FileCheck %s --check-prefix=CHECK-REOPT47 *48 * CHECK-BOLT: BOLT-INFO: Dumping function assembly to {{.*}}/main.s49 *50 * CHECK-FILE:      .globl main51 * CHECK-FILE-NEXT: .type main, %function52 * CHECK-FILE-NEXT: main:53 * CHECK-FILE-NEXT: # FDATA: 0 [unknown] 0 1 main 0 0 154 * CHECK-FILE-NEXT: .cfi_startproc55 * CHECK-FILE-NEXT: .LBB{{.*}}:56 * CHECK-FILE:      .cfi_def_cfa_offset 1657 * CHECK-FILE:      leaq  {{.*}}(%rip)58 * CHECK-FILE:      callq puts@PLT59 * CHECK-FILE:      .cfi_endproc60 * CHECK-FILE-NEXT: .size main, .-main61 * CHECK-FILE:      .section .rodata62 *63 * CHECK-REOPT: BOLT-INFO: 1 out of {{.*}} functions in the binary {{.*}} have64 * CHECK-REOPT: non-empty execution profile65 */66#include <stdio.h>67#include <string.h>68 69int main(int argc, char* argv[]) {70  for (int I = 0; I < 10; I++) {71    if (I != 9)72      continue;73    if (argc > 1 &&74        strncmp(argv[1], "--help", strlen("--help")) == 0) {75      puts("Help message\n");76    } else {77      puts("Hello, World!\n");78    }79  }80  return 0;81}82