xref: /llvm-project/bolt/test/X86/bolt-address-translation-yaml.test (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1## Check new BAT format containing hashes for YAML profile.
2
3RUN: yaml2obj %p/Inputs/blarge_new.yaml &> %t.exe
4RUN: llvm-bolt %t.exe -o %t.out --pa -p %p/Inputs/blarge_new.preagg.txt \
5RUN:   --reorder-blocks=ext-tsp --split-functions --split-strategy=cdsplit \
6RUN:   --reorder-functions=cdsort --enable-bat --dyno-stats --skip-funcs=main \
7RUN:   2>&1 | FileCheck --check-prefix WRITE-BAT-CHECK %s
8## Check that branch with entry in BAT is accounted for.
9RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat_branchentry.preagg.txt \
10RUN:   -w %t.yaml -o %t.fdata
11RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o %t.null
12RUN: FileCheck --input-file %t.yaml --check-prefix BRANCHENTRY-YAML-CHECK %s
13RUN: FileCheck --input-file %t.yaml-fdata --check-prefix BRANCHENTRY-YAML-CHECK %s
14BRANCHENTRY-YAML-CHECK:    - name: SolveCubic
15BRANCHENTRY-YAML-CHECK:      bid: 0
16BRANCHENTRY-YAML-CHECK:      hash: 0x700F19D24600000
17BRANCHENTRY-YAML-CHECK-NEXT: succ: [ { bid: 7, cnt: 1 }
18## Check that the order is correct between BAT YAML and FDATA->YAML.
19RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat_order.preagg.txt \
20RUN:   -w %t.yaml -o %t.fdata
21RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o %t.null
22RUN: FileCheck --input-file %t.yaml --check-prefix ORDER-YAML-CHECK %s
23RUN: FileCheck --input-file %t.yaml-fdata --check-prefix ORDER-YAML-CHECK %s
24ORDER-YAML-CHECK:    - name: SolveCubic
25ORDER-YAML-CHECK:      bid: 3
26ORDER-YAML-CHECK:      hash: 0xDDA1DC5F69F900AC
27ORDER-YAML-CHECK-NEXT: calls: [ { off: 0x26, fid: [[#]], cnt: 20 } ]
28ORDER-YAML-CHECK-NEXT: succ: [ { bid: 5, cnt: 7 }
29## Large profile test
30RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat.preagg.txt -w %t.yaml -o %t.fdata \
31RUN:   2>&1 | FileCheck --check-prefix READ-BAT-CHECK %s
32RUN: FileCheck --input-file %t.yaml --check-prefix YAML-BAT-CHECK %s
33## Check that YAML converted from fdata matches YAML created directly with BAT.
34RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null \
35RUN:   2>&1 | FileCheck --check-prefix READ-BAT-FDATA-CHECK %s
36RUN: FileCheck --input-file %t.yaml-fdata --check-prefix YAML-BAT-CHECK %s
37
38## Test resulting YAML profile with the original binary (no-stale mode)
39RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats 2>&1 \
40RUN:   | FileCheck --check-prefix CHECK-BOLT-YAML %s
41
42WRITE-BAT-CHECK: BOLT-INFO: Wrote 5 BAT maps
43WRITE-BAT-CHECK: BOLT-INFO: Wrote 4 function and 22 basic block hashes
44WRITE-BAT-CHECK: BOLT-INFO: BAT section size (bytes): 404
45
46READ-BAT-CHECK-NOT: BOLT-ERROR: unable to save profile in YAML format for input file processed by BOLT
47READ-BAT-CHECK: BOLT-INFO: Parsed 5 BAT entries
48READ-BAT-CHECK: PERF2BOLT: read 79 aggregated LBR entries
49READ-BAT-CHECK: BOLT-INFO: 5 out of 21 functions in the binary (23.8%) have non-empty execution profile
50READ-BAT-FDATA-CHECK: BOLT-INFO: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
51
52YAML-BAT-CHECK:      functions:
53# Function not covered by BAT - has insns in basic block
54YAML-BAT-CHECK:      - name:    main
55YAML-BAT-CHECK-NEXT:   fid:     2
56YAML-BAT-CHECK-NEXT:   hash:    0x9895746D48B2C876
57YAML-BAT-CHECK-NEXT:   exec:    0
58YAML-BAT-CHECK-NEXT:   nblocks: 46
59YAML-BAT-CHECK-NEXT:   blocks:
60YAML-BAT-CHECK-NEXT:   - bid:   0
61YAML-BAT-CHECK-NEXT:     insns: 26
62YAML-BAT-CHECK-NEXT:     hash:  0xA900AE79CFD40000
63YAML-BAT-CHECK-NEXT:     succ:  [ { bid: 3, cnt: 0 }, { bid: 1, cnt: 0 } ]
64# Calls from no-BAT to BAT function
65YAML-BAT-CHECK:        - bid:   28
66YAML-BAT-CHECK-NEXT:     insns: 13
67YAML-BAT-CHECK-NEXT:     hash:  0xB2F04C1F25F00400
68YAML-BAT-CHECK-NEXT:     calls: [ { off: 0x21, fid: [[#SOLVECUBIC:]], cnt: 25 }, { off: 0x2D, fid: [[#]], cnt: 9 } ]
69# Function covered by BAT with calls
70YAML-BAT-CHECK:      - name:    SolveCubic
71YAML-BAT-CHECK-NEXT:   fid:     [[#SOLVECUBIC]]
72YAML-BAT-CHECK-NEXT:   hash:    0x6AF7E61EA3966722
73YAML-BAT-CHECK-NEXT:   exec:    25
74YAML-BAT-CHECK-NEXT:   nblocks: 15
75YAML-BAT-CHECK-NEXT:   blocks:
76YAML-BAT-CHECK-NEXT:   - bid:   0
77YAML-BAT-CHECK-NEXT:     insns: [[#]]
78YAML-BAT-CHECK-NEXT:     hash:  0x700F19D24600000
79YAML-BAT-CHECK-NEXT:     exec:  25
80YAML-BAT-CHECK:        - bid:   3
81YAML-BAT-CHECK-NEXT:     insns: [[#]]
82YAML-BAT-CHECK-NEXT:     hash:  0xDDA1DC5F69F900AC
83YAML-BAT-CHECK-NEXT:     calls: [ { off: 0x26, fid: [[#]], cnt: [[#]] } ]
84YAML-BAT-CHECK-NEXT:     succ:  [ { bid: 5, cnt: [[#]] }
85# Function covered by BAT - doesn't have insns in basic block
86YAML-BAT-CHECK:      - name:    usqrt
87YAML-BAT-CHECK-NEXT:   fid:     [[#]]
88YAML-BAT-CHECK-NEXT:   hash:    0x99E67ED32A203023
89YAML-BAT-CHECK-NEXT:   exec:    21
90YAML-BAT-CHECK-NEXT:   nblocks: 5
91YAML-BAT-CHECK-NEXT:   blocks:
92YAML-BAT-CHECK:        - bid:   1
93YAML-BAT-CHECK-NEXT:       insns: [[#]]
94YAML-BAT-CHECK-NEXT:       hash:  0xD70DC695320E0010
95YAML-BAT-CHECK-NEXT:       succ:  {{.*}} { bid: 2, cnt: [[#]]
96
97CHECK-BOLT-YAML:      pre-processing profile using YAML profile reader
98CHECK-BOLT-YAML-NEXT: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
99CHECK-BOLT-YAML-NOT: invalid (possibly stale) profile
100