Skip to content

Commit d328954

Browse files
committed
[llvm-profdata] Profile dump for compact binary format
Summary: Fix "llvm-profdata show" so it can work with compact binary format profile. The change is to mark all functions "used" so SampleProfileReaderCompactBinary::read will read in all profiles available for dumping. The function names will be MD5 hash for compact binary format. Reviewers: wmi, davidxl, danielcdh Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65162 llvm-svn: 368731
1 parent 9e51fb6 commit d328954

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

llvm/include/llvm/ProfileData/SampleProfReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ class SampleProfileReaderCompactBinary : public SampleProfileReaderBinary {
462462
DenseMap<StringRef, uint64_t> FuncOffsetTable;
463463
/// The set containing the functions to use when compiling a module.
464464
DenseSet<StringRef> FuncsToUse;
465+
/// Use all functions from the input profile.
466+
bool UseAllFuncs = true;
465467
virtual std::error_code verifySPMagic(uint64_t Magic) override;
466468
virtual std::error_code readNameTable() override;
467469
/// Read a string indirectly via the name table.

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,26 @@ std::error_code SampleProfileReaderBinary::read() {
468468
}
469469

470470
std::error_code SampleProfileReaderCompactBinary::read() {
471-
for (auto Name : FuncsToUse) {
472-
auto GUID = std::to_string(MD5Hash(Name));
473-
auto iter = FuncOffsetTable.find(StringRef(GUID));
474-
if (iter == FuncOffsetTable.end())
475-
continue;
471+
std::vector<uint64_t> OffsetsToUse;
472+
if (UseAllFuncs) {
473+
for (auto FuncEntry : FuncOffsetTable) {
474+
OffsetsToUse.push_back(FuncEntry.second);
475+
}
476+
}
477+
else {
478+
for (auto Name : FuncsToUse) {
479+
auto GUID = std::to_string(MD5Hash(Name));
480+
auto iter = FuncOffsetTable.find(StringRef(GUID));
481+
if (iter == FuncOffsetTable.end())
482+
continue;
483+
OffsetsToUse.push_back(iter->second);
484+
}
485+
}
486+
487+
for (auto Offset : OffsetsToUse) {
476488
const uint8_t *SavedData = Data;
477489
Data = reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
478-
iter->second;
490+
Offset;
479491
if (std::error_code EC = readFuncProfile())
480492
return EC;
481493
Data = SavedData;
@@ -591,6 +603,7 @@ std::error_code SampleProfileReaderCompactBinary::readFuncOffsetTable() {
591603
}
592604

593605
void SampleProfileReaderCompactBinary::collectFuncsToUse(const Module &M) {
606+
UseAllFuncs = false;
594607
FuncsToUse.clear();
595608
for (auto &F : M) {
596609
StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Make sure "llvm-profdata show" works for sample profile in binary compact format
2+
3+
# RUN: llvm-profdata show -sample %S/Inputs/compat-sample.profdata | FileCheck %s
4+
5+
# CHECK: Function: 15822663052811949562: 17, 0, 6 sampled lines
6+
# CHECK-NEXT: Samples collected in the function's body {
7+
# CHECK: Samples collected in inlined callsites {
8+
# CHECK-NEXT: 1: inlined callee: 6309742469962978389: 17, 0, 1

0 commit comments

Comments
 (0)