Skip to content

Commit 42339ce

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents e38f98f + f34ba3d commit 42339ce

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ class DataAggregator : public DataReader {
502502
/// entries).
503503
void imputeFallThroughs();
504504

505+
/// Register profiled functions for lite mode.
506+
void registerProfiledFunctions();
507+
505508
/// Debugging dump methods
506509
void dump() const;
507510
void dump(const PerfBranchSample &Sample) const;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,26 @@ void DataAggregator::imputeFallThroughs() {
581581
outs() << "BOLT-INFO: imputed " << InferredTraces << " traces\n";
582582
}
583583

584+
void DataAggregator::registerProfiledFunctions() {
585+
DenseSet<uint64_t> Addrs;
586+
for (const auto &Trace : llvm::make_first_range(Traces)) {
587+
if (Trace.Branch != Trace::FT_ONLY &&
588+
Trace.Branch != Trace::FT_EXTERNAL_ORIGIN)
589+
Addrs.insert(Trace.Branch);
590+
Addrs.insert(Trace.From);
591+
}
592+
593+
for (const auto [PC, _] : BasicSamples)
594+
Addrs.insert(PC);
595+
596+
for (const PerfMemSample &MemSample : MemSamples)
597+
Addrs.insert(MemSample.PC);
598+
599+
for (const uint64_t Addr : Addrs)
600+
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr))
601+
Func->setHasProfileAvailable();
602+
}
603+
584604
Error DataAggregator::preprocessProfile(BinaryContext &BC) {
585605
this->BC = &BC;
586606

@@ -603,6 +623,7 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
603623
exit(0);
604624
}
605625

626+
registerProfiledFunctions();
606627
return Error::success();
607628
}
608629

@@ -906,11 +927,10 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace,
906927
if (BF.isPseudo())
907928
return Branches;
908929

909-
if (!BF.isSimple())
930+
// Can only record traces in CFG state
931+
if (!BF.hasCFG())
910932
return std::nullopt;
911933

912-
assert(BF.hasCFG() && "can only record traces in CFG state");
913-
914934
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
915935
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
916936

@@ -1348,10 +1368,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13481368
}
13491369

13501370
const uint64_t FromOffset = Addr[0]->Offset;
1351-
BinaryFunction *FromFunc = getBinaryFunctionContainingAddress(FromOffset);
1352-
if (FromFunc)
1353-
FromFunc->setHasProfileAvailable();
1354-
13551371
int64_t Count = Counters[0];
13561372
int64_t Mispreds = Counters[1];
13571373

@@ -1362,11 +1378,6 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13621378
return std::error_code();
13631379
}
13641380

1365-
const uint64_t ToOffset = Addr[1]->Offset;
1366-
BinaryFunction *ToFunc = getBinaryFunctionContainingAddress(ToOffset);
1367-
if (ToFunc)
1368-
ToFunc->setHasProfileAvailable();
1369-
13701381
/// For fall-through types, adjust locations to match Trace container.
13711382
if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
13721383
Addr[2] = Location(Addr[1]->Offset); // Trace To
@@ -1614,9 +1625,6 @@ std::error_code DataAggregator::parseBranchEvents() {
16141625
Traces.reserve(TraceMap.size());
16151626
for (const auto &[Trace, Info] : TraceMap) {
16161627
Traces.emplace_back(Trace, Info);
1617-
for (const uint64_t Addr : {Trace.Branch, Trace.From})
1618-
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
1619-
BF->setHasProfileAvailable();
16201628
}
16211629
clear(TraceMap);
16221630

@@ -1677,9 +1685,6 @@ std::error_code DataAggregator::parseBasicEvents() {
16771685
continue;
16781686
++NumTotalSamples;
16791687

1680-
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
1681-
BF->setHasProfileAvailable();
1682-
16831688
++BasicSamples[Sample->PC];
16841689
EventNames.insert(Sample->EventName);
16851690
}
@@ -1717,9 +1722,6 @@ std::error_code DataAggregator::parseMemEvents() {
17171722
if (std::error_code EC = Sample.getError())
17181723
return EC;
17191724

1720-
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
1721-
BF->setHasProfileAvailable();
1722-
17231725
MemSamples.emplace_back(std::move(Sample.get()));
17241726
}
17251727

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -714,21 +714,6 @@ Error RewriteInstance::run() {
714714

715715
preprocessProfileData();
716716

717-
// Skip disassembling if we have a translation table and we are running an
718-
// aggregation job.
719-
if (opts::AggregateOnly && BAT->enabledFor(InputFile)) {
720-
// YAML profile in BAT mode requires CFG for .bolt.org.text functions
721-
if (!opts::SaveProfile.empty() ||
722-
opts::ProfileFormat == opts::ProfileFormatKind::PF_YAML) {
723-
selectFunctionsToProcess();
724-
disassembleFunctions();
725-
processMetadataPreCFG();
726-
buildFunctionsCFG();
727-
}
728-
processProfileData();
729-
return Error::success();
730-
}
731-
732717
selectFunctionsToProcess();
733718

734719
readDebugInfo();

bolt/test/X86/unclaimed-jt-entries.s

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
2020
# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q
21+
22+
## Check that non-simple function profile is emitted in perf2bolt mode
23+
# RUN: link_fdata %s %t.exe %t.pa PREAGG
24+
# RUN: llvm-strip -N L5 -N L5_ret %t.exe
25+
# RUN: perf2bolt %t.exe -p %t.pa --pa -o %t.fdata -strict=0 -print-profile \
26+
# RUN: -print-only=main | FileCheck %s --check-prefix=CHECK-P2B
27+
# CHECK-P2B: PERF2BOLT: traces mismatching disassembled function contents: 0
28+
# CHECK-P2B: Binary Function "main"
29+
# CHECK-P2B: IsSimple : 0
30+
# RUN: FileCheck %s --input-file %t.fdata --check-prefix=CHECK-FDATA
31+
# CHECK-FDATA: 1 main 0 1 main 7 0 1
32+
2133
# RUN: llvm-bolt %t.exe -v=1 -o %t.out 2>&1 | FileCheck %s
2234

2335
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
@@ -33,8 +45,10 @@
3345
.size main, .Lend-main
3446
main:
3547
jmp *L4-24(,%rdi,8)
36-
.L5:
48+
# PREAGG: T #main# #L5# #L5_ret# 1
49+
L5:
3750
movl $4, %eax
51+
L5_ret:
3852
ret
3953
.L9:
4054
movl $2, %eax
@@ -58,7 +72,7 @@ L4:
5872
.quad .L3
5973
.quad .L6
6074
.quad .L3
61-
.quad .L5
75+
.quad L5
6276
.quad .L3
6377
.quad .L3
6478
.quad .L3

0 commit comments

Comments
 (0)