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 BAT cold-to-hot entries
41 # usqrt mappings (hot part). We match against any key (left side containing
42 # the bolted binary offsets) because BOLT may change where it puts instructions
43 # depending on whether it is relaxing a branch or not. But the original input
44 # binary offsets (right side) should be the same because these addresses are
45 # hardcoded in the blarge.yaml file.
47 # CHECK-BAT-DUMP: Function Address: 0x401170
48 # CHECK-BAT-DUMP-NEXT: BB mappings:
49 # CHECK-BAT-DUMP-NEXT: 0x0 -> 0x0
50 # CHECK-BAT-DUMP-NEXT: 0x8 -> 0x8 (branch)
51 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x39
52 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x3d (branch)
53 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x10
54 # CHECK-BAT-DUMP-NEXT: 0x{{.*}} -> 0x30 (branch)
56 # CHECK-BAT-DUMP: 3 cold mappings
58 # Now check that the translation 0x401180 maps back to its correct
59 # input offset (offset 3d in the usqrt input function).
61 # COM: CHECK-BAT-DUMP: Translating addresses according to parsed BAT tables:
62 # CHECK-BAT-DUMP: 0x401180 -> usqrt + 0x3d
64 # -------------------------
65 # Full dump for reference (this is not checked):
66 # -------------------------
68 Binary Function "usqrt" after finalize-functions
76 Orc Section : .local.text.usqrt
82 Hash : a6468f132ec176ca
83 BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT2, .LFT3
87 .LBB02 (4 instructions, align : 1)
92 00000000: movl $0x20, %r8d
93 00000006: xorl %eax, %eax
94 00000008: xorl %edx, %edx # Offset: 8
96 Successors: .Ltmp39 (mispreds: 0, count: 0)
98 .Ltmp38 (2 instructions, align : 1)
102 Predecessors: .Ltmp39, .LFT2
103 0000000c: subl $0x1, %r8d
104 00000010: je .LFT3 # Offset: 61
105 Successors: .LFT3 (mispreds: 0, count: 0), .Ltmp39 (mispreds: 33, count: 4711)
107 .Ltmp39 (10 instructions, align : 1)
111 Predecessors: .Ltmp38, .LBB02
112 00000012: movq %rdi, %rcx
113 00000015: addq %rax, %rax
114 00000018: shlq $0x2, %rdi
115 0000001c: andl $0xc0000000, %ecx
116 00000022: shrq $0x1e, %rcx
117 00000026: leaq (%rcx,%rdx,4), %rdx
118 0000002a: leaq 0x1(%rax,%rax), %rcx
119 0000002f: cmpq %rcx, %rdx
120 00000032: jb .Ltmp38 # Offset: 48
122 Successors: .Ltmp38 (mispreds: 171, count: 2886), .LFT2 (mispreds: 0, count: 0)
124 ------- HOT-COLD SPLIT POINT -------
126 .LFT2 (3 instructions, align : 1)
130 Predecessors: .Ltmp39
131 00000036: subq %rcx, %rdx
132 00000039: addq $0x1, %rax # Offset: 53
133 0000003d: jmp .Ltmp38
134 Successors: .Ltmp38 (mispreds: 0, count: 0)
136 .LFT3 (2 instructions, align : 1)
140 Predecessors: .Ltmp38
141 0000003f: movq %rax, (%rsi)
142 00000042: retq # Offset: 66
144 DWARF CFI Instructions:
146 End of Function "usqrt"