Skip to content

Commit

Permalink
[InstrProf][Correlator] Do not compress names when reading debug info
Browse files Browse the repository at this point in the history
There is no need to compress the names string when correlating with
debug info since InstrProfReader will immediately uncompress it anyway.
This also removes the dependency on zlib in this case.

Reviewed By: kyulee

Differential Revision: https://reviews.llvm.org/D118176
  • Loading branch information
ellishg committed Jan 25, 2022
1 parent 6427f4c commit f170595
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
@@ -1,5 +1,3 @@
// REQUIRES: zlib

// Value profiling is currently not supported in lightweight mode.
// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
Expand Down
@@ -1,5 +1,3 @@
// REQUIRES: zlib

// Value profiling is currently not supported in lightweight mode.
// RUN: %clang_pgogen -o %t.normal -mllvm --disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp %S/../Inputs/instrprof-debug-info-correlate-foo.cpp
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
Expand Down
17 changes: 7 additions & 10 deletions llvm/include/llvm/ProfileData/InstrProfCorrelator.h
Expand Up @@ -83,22 +83,19 @@ class InstrProfCorrelatorImpl : public InstrProfCorrelator {
/// Return the number of ProfileData elements.
size_t getDataSize() const { return Data.size(); }

/// Return a pointer to the compressed names string that this class
/// constructs.
const char *getCompressedNamesPointer() const {
return CompressedNames.c_str();
}
/// Return a pointer to the names string that this class constructs.
const char *getNamesPointer() const { return Names.c_str(); }

/// Return the number of bytes in the compressed names string.
size_t getCompressedNamesSize() const { return CompressedNames.size(); }
/// Return the number of bytes in the names string.
size_t getNamesSize() const { return Names.size(); }

static llvm::Expected<std::unique_ptr<InstrProfCorrelatorImpl<IntPtrT>>>
get(std::unique_ptr<InstrProfCorrelator::Context> Ctx,
const object::ObjectFile &Obj);

protected:
std::vector<RawInstrProf::ProfileData<IntPtrT>> Data;
std::string CompressedNames;
std::string Names;

Error correlateProfileData() override;
virtual void correlateProfileDataImpl() = 0;
Expand All @@ -110,7 +107,7 @@ class InstrProfCorrelatorImpl : public InstrProfCorrelator {
InstrProfCorrelatorImpl(InstrProfCorrelatorKind Kind,
std::unique_ptr<InstrProfCorrelator::Context> Ctx)
: InstrProfCorrelator(Kind, std::move(Ctx)){};
std::vector<std::string> Names;
std::vector<std::string> NamesVec;
llvm::DenseSet<IntPtrT> CounterOffsets;

// Byte-swap the value if necessary.
Expand Down Expand Up @@ -140,7 +137,7 @@ class DwarfInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
static bool isDIEOfProbe(const DWARFDie &Die);

/// Iterate over DWARF DIEs to find those that symbolize instrumentation
/// probes and construct the ProfileData vector and CompressedNames string.
/// probes and construct the ProfileData vector and Names string.
///
/// Here is some example DWARF for an instrumentation probe we are looking
/// for:
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/ProfileData/InstrProfCorrelator.cpp
Expand Up @@ -125,12 +125,12 @@ InstrProfCorrelatorImpl<IntPtrT>::get(

template <class IntPtrT>
Error InstrProfCorrelatorImpl<IntPtrT>::correlateProfileData() {
assert(Data.empty() && CompressedNames.empty() && Names.empty());
assert(Data.empty() && Names.empty() && NamesVec.empty());
correlateProfileDataImpl();
auto Result =
collectPGOFuncNameStrings(Names, /*doCompression=*/true, CompressedNames);
collectPGOFuncNameStrings(NamesVec, /*doCompression=*/false, Names);
CounterOffsets.clear();
Names.clear();
NamesVec.clear();
return Result;
}

Expand All @@ -155,7 +155,7 @@ void InstrProfCorrelatorImpl<IntPtrT>::addProbe(StringRef FunctionName,
maybeSwap<uint32_t>(NumCounters),
/*NumValueSites=*/{maybeSwap<uint16_t>(0), maybeSwap<uint16_t>(0)},
});
Names.push_back(FunctionName.str());
NamesVec.push_back(FunctionName.str());
}

template <class IntPtrT>
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Expand Up @@ -411,8 +411,8 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
assert(CountersDelta == 0 && NamesDelta == 0);
Data = Correlator->getDataPointer();
DataEnd = Data + Correlator->getDataSize();
NamesStart = Correlator->getCompressedNamesPointer();
NamesEnd = NamesStart + Correlator->getCompressedNamesSize();
NamesStart = Correlator->getNamesPointer();
NamesEnd = NamesStart + Correlator->getNamesSize();
} else {
Data = reinterpret_cast<const RawInstrProf::ProfileData<IntPtrT> *>(
Start + DataOffset);
Expand Down

0 comments on commit f170595

Please sign in to comment.