Skip to content

Commit 4310965

Browse files
committed
Offset CallContLPs by MaxInputOffset + 1
Created using spr 1.3.4
1 parent 567d810 commit 4310965

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
8787
continue;
8888

8989
uint32_t NumSecondaryEntryPoints = 0;
90+
// Offset call continuation landing pads by max input offset + 1 to prevent
91+
// confusing them with real entry points. Note we can't use the input size
92+
// as it's not available in BOLTed binary.
93+
const BBHashMapTy &BBHashMap = getBBHashMap(InputAddress);
94+
const uint32_t CallContLPOffset = std::prev(BBHashMap.end())->first + 1;
9095
for (const BinaryBasicBlock &BB : llvm::drop_begin(Function)) {
9196
if (BB.isEntryPoint()) {
9297
++NumSecondaryEntryPoints;
@@ -104,8 +109,8 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
104109
if (!Instr || !BC.MIB->isCall(*Instr))
105110
continue;
106111
++NumSecondaryEntryPoints;
107-
SecondaryEntryPointsMap[OutputAddress].push_back(
108-
Function.getOutputSize() + BB.getOffset());
112+
SecondaryEntryPointsMap[OutputAddress].push_back(CallContLPOffset +
113+
BB.getOffset());
109114
}
110115
if (NumSecondaryEntryPoints)
111116
llvm::sort(SecondaryEntryPointsMap[OutputAddress]);
@@ -124,7 +129,6 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
124129
// Add entries for deleted blocks. They are still required for correct BB
125130
// mapping of branches modified by SCTC. By convention, they would have the
126131
// end of the function as output address.
127-
const BBHashMapTy &BBHashMap = getBBHashMap(InputAddress);
128132
if (BBHashMap.size() != Function.size()) {
129133
const uint64_t EndOffset = Function.getOutputSize();
130134
std::unordered_set<uint32_t> MappedInputOffsets;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,13 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
810810

811811
if (!Func.hasCFG()) {
812812
const uint64_t Address = Func.getAddress();
813+
if (!BAT)
814+
return false;
815+
const uint32_t InputOffset = BAT->translate(Address, Offset, false);
813816
// Check if offset is a secondary entry point or a call continuation
814817
// landing pad (offset shifted by function size).
815-
return BAT && !BAT->getSecondaryEntryPointId(Address, Offset) &&
816-
!BAT->getSecondaryEntryPointId(Address, Func.getSize() + Offset);
818+
return !BAT->getSecondaryEntryPointId(Address, InputOffset) &&
819+
!BAT->getSecondaryEntryPointId(Address, Func.getSize() + InputOffset);
817820
}
818821

819822
// The offset should not be an entry point or a landing pad.

bolt/test/X86/callcont-fallthru.s

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,40 @@
2121
# RUN: --print-cfg --print-only=main | FileCheck %s --check-prefix=CHECK3
2222

2323
## Check fallthrough to a landing pad case.
24-
# RUN: llvm-bolt %t.exe --pa -p %t.pa3 -o %t.out4 --enable-bat \
24+
# RUN: llvm-bolt %t.exe --pa -p %t.pa3 -o %t.out4 \
2525
# RUN: --print-cfg --print-only=main | FileCheck %s --check-prefix=CHECK3
2626

27-
## Check that a landing pad is emitted in BAT
28-
# RUN: llvm-bat-dump %t.out4 --dump-all | FileCheck %s --check-prefix=CHECK-BAT
27+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown --defsym GLOBL=1 \
28+
# RUN: %s -o %t.o
29+
# RUN: %clangxx %cxxflags %t.o -o %t2 -Wl,-q -nostdlib
30+
# RUN: llvm-bolt %t2 --pa -p %t.pa3 -o %t.bat --enable-bat \
31+
# RUN: --print-cfg --print-only=main | FileCheck %s --check-prefix=CHECK3
2932

30-
# CHECK-BAT: 1 secondary entry points:
33+
## Check that a landing pad is emitted in BAT
34+
# RUN: llvm-bat-dump %t.bat --dump-all | FileCheck %s --check-prefix=CHECK-BAT
3135

32-
## Check BAT case of a fallthrough to a call continuation
33-
# link_fdata %s %t.out4 %t.pa.bat PREAGG
34-
# RUN: perf2bolt %t.out4 -p %t.pa.bat --pa -o %t.fdata
35-
# RUN: FileCheck %s --check-prefix=CHECK-BAT-CC --input-file=%t.fdata
36-
# CHECK-BAT-CC: main
36+
# CHECK-BAT: secondary entry points:
3737

3838
## Check BAT case of a fallthrough to a secondary entry point or a landing pad
39-
# link_fdata %s %t.out4 %t.pa.bat2 PREAGG3
39+
# RUN: link_fdata %s %t.bat %t.pa.bat2 PREAGG3
4040

4141
## Secondary entry
42-
# RUN: perf2bolt %t.out4 -p %t.pa.bat2 --pa -o %t.fdata2
42+
# RUN: perf2bolt %t.bat -p %t.pa.bat2 --pa -o %t.fdata2
4343
# RUN: FileCheck %s --check-prefix=CHECK-BAT-ENTRY --input-file=%t.fdata2
4444
# CHECK-BAT-ENTRY: main
4545

4646
## Landing pad
47-
# RUN: llvm-strip --strip-unneeded %t.out4
48-
# RUN: perf2bolt %t.out4 -p %t.pa.bat2 --pa -o %t.fdata3
47+
# RUN: llvm-strip --strip-unneeded %t.bat
48+
# RUN: perf2bolt %t.bat -p %t.pa.bat2 --pa -o %t.fdata3
4949
# RUN: FileCheck %s --check-prefix=CHECK-BAT-LP --input-file=%t.fdata3
5050
# CHECK-BAT-LP: main
5151

52+
## Check BAT case of a fallthrough to a call continuation
53+
# link_fdata %s %t.bat %t.pa.bat PREAGG
54+
# RUN: perf2bolt %t.bat -p %t.pa.bat --pa -o %t.fdata
55+
# RUN: FileCheck %s --check-prefix=CHECK-BAT-CC --input-file=%t.fdata
56+
# CHECK-BAT-CC: main
57+
5258
.globl foo
5359
.type foo, %function
5460
foo:
@@ -107,6 +113,9 @@ Ltmp4:
107113
# CHECK3: callq foo
108114
# CHECK3-NEXT: count: 0
109115

116+
.ifdef GLOBL
117+
.globl Ltmp3
118+
.endif
110119
Ltmp3:
111120
cmpl $0x0, -0x18(%rbp)
112121
Ltmp3_br:

0 commit comments

Comments
 (0)