File: asm-dump.c

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (80 lines) | stat: -rw-r--r-- 2,501 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
 * Test for asm-dump functionality.
 *
 * REQUIRES: system-linux,bolt-runtime
 *
 * Compile the source
 * RUN: %clang -fPIC %s -o %t.exe -Wl,-q
 *
 * Profile collection: instrument the binary
 * RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata -o %t.instr
 *
 * Profile collection: run instrumented binary (and capture output)
 * RUN: %t.instr > %t.result
 *
 * Run BOLT with asm-dump
 * RUN: llvm-bolt %t.exe -p %t.fdata --funcs=main --asm-dump=%t -o /dev/null \
 * RUN:   | FileCheck %s --check-prefix=CHECK-BOLT
 *
 * Check asm file contents
 * RUN: cat %t/main.s | FileCheck %s --check-prefix=CHECK-FILE
 *
 * Now check if asm-dump file can be consumed by BOLT infra
 * Strip dot from compiler-local symbols:
 * RUN: sed -i 's/\.L/L/g' %t/main.s
 *
 * Recompile the asm file into objfile
 * RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
 *
 * Reconstruct fdata
 * RUN: link_fdata %t/main.s %t.o %t.fdata.reconst
 *
 * XXX: reenable once dumping data is supported
 * Check if reoptimized file produces the same results
 * dontrun: %t.exe.reopt > %t.result.reopt
 * dontrun: cmp %t.result %t.result.reopt
 *
 * Delete our BB symbols so BOLT doesn't mark them as entry points
 * RUN: llvm-strip --strip-unneeded %t.o
 *
 * Recompile the binary
 * RUN: %clang -fPIC %t.o -o %t.exe.reopt -Wl,-q
 *
 * Finally consume reoptimized file with reconstructed fdata
 * RUN: llvm-bolt %t.exe.reopt -p %t.fdata.reconst -o /dev/null \
 * RUN:   | FileCheck %s --check-prefix=CHECK-REOPT
 *
 * CHECK-BOLT: BOLT-INFO: Dumping function assembly to {{.*}}/main.s
 *
 * CHECK-FILE:      .globl main
 * CHECK-FILE-NEXT: .type main, %function
 * CHECK-FILE-NEXT: main:
 * CHECK-FILE-NEXT: # FDATA: 0 [unknown] 0 1 main 0 0 1
 * CHECK-FILE-NEXT: .cfi_startproc
 * CHECK-FILE-NEXT: .LBB{{.*}}:
 * CHECK-FILE:      .cfi_def_cfa_offset 16
 * CHECK-FILE:      leaq  {{.*}}(%rip)
 * CHECK-FILE:      callq puts@PLT
 * CHECK-FILE:      .cfi_endproc
 * CHECK-FILE-NEXT: .size main, .-main
 * CHECK-FILE:      .section .rodata
 *
 * CHECK-REOPT: BOLT-INFO: 1 out of {{.*}} functions in the binary {{.*}} have
 * CHECK-REOPT: non-empty execution profile
 */
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]) {
  for (int I = 0; I < 10; I++) {
    if (I != 9)
      continue;
    if (argc > 1 &&
        strncmp(argv[1], "--help", strlen("--help")) == 0) {
      puts("Help message\n");
    } else {
      puts("Hello, World!\n");
    }
  }
  return 0;
}