1 /**
2  * Test for asm-dump functionality.
3  *
4  * REQUIRES: system-linux,bolt-runtime
5  *
6  * Compile the source
7  * RUN: %clang -fPIC %s -o %t.exe -Wl,-q
8  *
9  * Profile collection: instrument the binary
10  * RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata -o %t.instr
11  *
12  * Profile collection: run instrumented binary (and capture output)
13  * RUN: %t.instr > %t.result
14  *
15  * Run BOLT with asm-dump
16  * RUN: llvm-bolt %t.exe -p %t.fdata --funcs=main --asm-dump=%t -o /dev/null \
17  * RUN:   | FileCheck %s --check-prefix=CHECK-BOLT
18  *
19  * Check asm file contents
20  * RUN: cat %t/main.s | FileCheck %s --check-prefix=CHECK-FILE
21  *
22  * Now check if asm-dump file can be consumed by BOLT infra
23  * Strip dot from compiler-local symbols:
24  * RUN: sed -i 's/\.L/L/g' %t/main.s
25  *
26  * Recompile the asm file into objfile
27  * RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
28  *
29  * Reconstruct fdata
30  * RUN: link_fdata %t/main.s %t.o %t.fdata.reconst
31  *
32  * XXX: reenable once dumping data is supported
33  * Check if reoptimized file produces the same results
34  * dontrun: %t.exe.reopt > %t.result.reopt
35  * dontrun: cmp %t.result %t.result.reopt
36  *
37  * Delete our BB symbols so BOLT doesn't mark them as entry points
38  * RUN: llvm-strip --strip-unneeded %t.o
39  *
40  * Recompile the binary
41  * RUN: %clang -fPIC %t.o -o %t.exe.reopt -Wl,-q
42  *
43  * Finally consume reoptimized file with reconstructed fdata
44  * RUN: llvm-bolt %t.exe.reopt -p %t.fdata.reconst -o /dev/null \
45  * RUN:   | FileCheck %s --check-prefix=CHECK-REOPT
46  *
47  * CHECK-BOLT: BOLT-INFO: Dumping function assembly to {{.*}}/main.s
48  *
49  * CHECK-FILE:      .globl main
50  * CHECK-FILE-NEXT: .type main, %function
51  * CHECK-FILE-NEXT: main:
52  * CHECK-FILE-NEXT: # FDATA: 0 [unknown] 0 1 main 0 0 1
53  * CHECK-FILE-NEXT: .cfi_startproc
54  * CHECK-FILE-NEXT: .LBB{{.*}}:
55  * CHECK-FILE:      .cfi_def_cfa_offset 16
56  * CHECK-FILE:      leaq  {{.*}}(%rip)
57  * CHECK-FILE:      callq puts@PLT
58  * CHECK-FILE:      .cfi_endproc
59  * CHECK-FILE-NEXT: .size main, .-main
60  * CHECK-FILE:      .section .rodata
61  *
62  * CHECK-REOPT: BOLT-INFO: 1 out of {{.*}} functions in the binary {{.*}} have
63  * CHECK-REOPT: non-empty execution profile
64  */
65 #include <stdio.h>
66 #include <string.h>
67 
main(int argc,char * argv[])68 int main(int argc, char* argv[]) {
69   for (int I = 0; I < 10; I++) {
70     if (I != 9)
71       continue;
72     if (argc > 1 &&
73         strncmp(argv[1], "--help", strlen("--help")) == 0) {
74       puts("Help message\n");
75     } else {
76       puts("Hello, World!\n");
77     }
78   }
79   return 0;
80 }
81