1 ## Check a common case for BOLT address translation tables. These tables are used
2 ## to translate profile activity happening in a bolted binary back to the
3 ## original binary, so you can run BOLT again, with updated profile collected
4 ## in a production environment that only runs bolted binaries. As BOLT only
5 ## takes no-bolt binaries as inputs, this translation is necessary to cover
8 # RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
9 # RUN: llvm-bolt %t.exe -o %t.out --data %p/Inputs/blarge.fdata \
10 # RUN: --reorder-blocks=normal --split-functions --enable-bat 2>&1 | FileCheck %s
11 # RUN: llvm-bat-dump %t.out --dump-all \
12 # RUN: --translate=0x401180 | FileCheck %s --check-prefix=CHECK-BAT-DUMP
14 ## In this test we focus on function usqrt at address 0x401170. This is a
15 ## non-reloc binary case, so we don't expect this address to change, that's
16 ## why we hardcode its address here. This address also comes hardcoded in the
17 ## blarge.yaml input file.
19 ## This is the layout of the function before BOLT reorder blocks:
21 ## BB Layout : .LBB02, .Ltmp39, .LFT1, .Ltmp38, .LFT2
23 ## This is the layout of the function after BOLT reorder blocks:
25 ## BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT3
27 ## .Ltmp38 is originally at offset 0x39 but gets moved to 0xc (see full dump
30 ## We check that BAT is able to translate references happening in .Ltmp38 to
31 ## its original offset.
34 ## This binary has 3 functions with profile, all of them are split, so 6 maps.
35 ## BAT creates one map per function fragment.
37 # CHECK: BOLT: 3 out of 7 functions were overwritten.
38 # CHECK: BOLT-INFO: Wrote 6 BAT maps
39 # CHECK: BOLT-INFO: Wrote 3 function and 58 basic block hashes
40 # CHECK: BOLT-INFO: BAT section size (bytes): 940
42 # usqrt mappings (hot part). We match against any key (left side containing
43 # the bolted binary offsets) because BOLT may change where it puts instructions
44 # depending on whether it is relaxing a branch or not. But the original input
45 # binary offsets (right side) should be the same because these addresses are
46 # hardcoded in the blarge.yaml file.
48 # CHECK-BAT-DUMP: Function Address: 0x401170, hash: 0xace6cbc638b31983
49 # CHECK-BAT-DUMP-NEXT: BB mappings:
50 # CHECK-BAT-DUMP-NEXT: 0x0 -> 0x0 hash: 0x36007ba1d80c0000
51 # CHECK-BAT-DUMP-NEXT: 0x8 -> 0x8 (branch)
52 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x39 hash: 0x5c06705524800039
53 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x3d (branch)
54 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x10 hash: 0xd70d7a64320e0010
55 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x30 (branch)
57 # CHECK-BAT-DUMP: 3 cold mappings
59 # Now check that the translation 0x401180 maps back to its correct
60 # input offset (offset 3d in the usqrt input function).
62 # COM: CHECK-BAT-DUMP: Translating addresses according to parsed BAT tables:
63 # CHECK-BAT-DUMP: 0x401180 -> usqrt + 0x3d
65 # -------------------------
66 # Full dump for reference (this is not checked):
67 # -------------------------
69 Binary Function "usqrt" after finalize-functions
77 Orc Section : .local.text.usqrt
83 Hash : a6468f132ec176ca
84 BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT3
88 .LBB02 (4 instructions, align : 1)
93 00000000: movl $0x20, %r8d
94 00000006: xorl %eax, %eax
95 00000008: xorl %edx, %edx # Offset: 8
97 Successors: .Ltmp39 (mispreds: 0, count: 0)
99 .Ltmp38 (2 instructions, align : 1)
103 Predecessors: .Ltmp39, .LFT2
104 0000000c: subl $0x1, %r8d
105 00000010: je .LFT3 # Offset: 61
106 Successors: .LFT3 (mispreds: 0, count: 0), .Ltmp39 (mispreds: 33, count: 4711)
108 .Ltmp39 (10 instructions, align : 1)
112 Predecessors: .Ltmp38, .LBB02
113 00000012: movq %rdi, %rcx
114 00000015: addq %rax, %rax
115 00000018: shlq $0x2, %rdi
116 0000001c: andl $0xc0000000, %ecx
117 00000022: shrq $0x1e, %rcx
118 00000026: leaq (%rcx,%rdx,4), %rdx
119 0000002a: leaq 0x1(%rax,%rax), %rcx
120 0000002f: cmpq %rcx, %rdx
121 00000032: jb .Ltmp38 # Offset: 48
123 Successors: .Ltmp38 (mispreds: 171, count: 2886), .LFT2 (mispreds: 0, count: 0)
125 ------- HOT-COLD SPLIT POINT -------
127 .LFT2 (3 instructions, align : 1)
131 Predecessors: .Ltmp39
132 00000036: subq %rcx, %rdx
133 00000039: addq $0x1, %rax # Offset: 53
134 0000003d: jmp .Ltmp38
135 Successors: .Ltmp38 (mispreds: 0, count: 0)
137 .LFT3 (2 instructions, align : 1)
141 Predecessors: .Ltmp38
142 0000003f: movq %rax, (%rsi)
143 00000042: retq # Offset: 66
145 DWARF CFI Instructions:
147 End of Function "usqrt"