Skip to content

Commit

Permalink
Revert "[Coverage] Allow Clang coverage to be used with debug info co…
Browse files Browse the repository at this point in the history
…rrelation."

This reverts commit 32db121 and subsequent commits.

This causes time regression on llvm-cov even with debug info correlation off.
  • Loading branch information
ZequanWu committed Sep 27, 2023
1 parent 58f7543 commit 4d5d9a5
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 339 deletions.
20 changes: 0 additions & 20 deletions clang/lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
// is textually included.
#define COVMAP_V3

namespace llvm {
extern cl::opt<bool> DebugInfoCorrelate;
} // namespace llvm

static llvm::cl::opt<bool> EmptyLineCommentCoverage(
"emptyline-comment-coverage",
llvm::cl::desc("Emit emptylines and comment lines as skipped regions (only "
Expand Down Expand Up @@ -1835,22 +1831,6 @@ void CoverageMappingModuleGen::emit() {
llvm::GlobalValue::InternalLinkage, NamesArrVal,
llvm::getCoverageUnusedNamesVarName());
}
const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx);
uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION;
if (llvm::DebugInfoCorrelate)
ProfileVersion |= VARIANT_MASK_DBG_CORRELATE;
auto *VersionVariable = new llvm::GlobalVariable(
CGM.getModule(), llvm::Type::getInt64Ty(Ctx), true,
llvm::GlobalValue::WeakAnyLinkage,
llvm::Constant::getIntegerValue(IntTy64, llvm::APInt(64, ProfileVersion)),
VarName);
VersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
llvm::Triple TT(CGM.getModule().getTargetTriple());
if (TT.supportsCOMDAT()) {
VersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage);
VersionVariable->setComdat(CGM.getModule().getOrInsertComdat(VarName));
}
}

unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) {
Expand Down
9 changes: 0 additions & 9 deletions clang/test/CodeGen/coverage-profile-raw-version.c

This file was deleted.

78 changes: 0 additions & 78 deletions compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ class BinaryCoverageReader : public CoverageMappingReader {
BinaryCoverageReader &operator=(const BinaryCoverageReader &) = delete;

static Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
create(MemoryBufferRef ObjectBuffer,
StringRef Arch,
create(MemoryBufferRef ObjectBuffer, StringRef Arch,
SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
InstrProfSymtab& IndexedProfSymTab,
StringRef CompilationDir = "",
SmallVectorImpl<object::BuildIDRef> *BinaryIDs = nullptr);

Expand Down
12 changes: 0 additions & 12 deletions llvm/include/llvm/ProfileData/InstrProfCorrelator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class InstrProfCorrelator {
/// \param MaxWarnings the maximum number of warnings to emit (0 = no limit)
virtual Error correlateProfileData(int MaxWarnings) = 0;

virtual Error correlateCovUnusedFuncNames(int MaxWarnings) = 0;

/// Process debug info and dump the correlation data.
/// \param MaxWarnings the maximum number of warnings to emit (0 = no limit)
virtual Error dumpYaml(int MaxWarnings, raw_ostream &OS) = 0;
Expand All @@ -54,12 +52,6 @@ class InstrProfCorrelator {
/// Return the number of bytes in the names string.
size_t getNamesSize() const { return Names.size(); }

const char *getCovUnusedFuncNamesPointer() const {
return CovUnusedFuncNames.c_str();
}

size_t getCovUnusedFuncNamesSize() const { return CovUnusedFuncNames.size(); }

/// Return the size of the counters section in bytes.
uint64_t getCountersSectionSize() const {
return Ctx->CountersSectionEnd - Ctx->CountersSectionStart;
Expand All @@ -68,7 +60,6 @@ class InstrProfCorrelator {
static const char *FunctionNameAttributeName;
static const char *CFGHashAttributeName;
static const char *NumCountersAttributeName;
static const char *CovFunctionNameAttributeName;

enum InstrProfCorrelatorKind { CK_32Bit, CK_64Bit };
InstrProfCorrelatorKind getKind() const { return Kind; }
Expand All @@ -92,7 +83,6 @@ class InstrProfCorrelator {

std::string Names;
std::vector<std::string> NamesVec;
std::string CovUnusedFuncNames;

struct Probe {
std::string FunctionName;
Expand Down Expand Up @@ -215,8 +205,6 @@ class DwarfInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
void correlateProfileDataImpl(
int MaxWarnings,
InstrProfCorrelator::CorrelationData *Data = nullptr) override;

Error correlateCovUnusedFuncNames(int MaxWarnings) override;
};

} // end namespace llvm
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,11 @@ Error CoverageMapping::loadFromFile(
MemoryBufferRef CovMappingBufRef =
CovMappingBufOrErr.get()->getMemBufferRef();
SmallVector<std::unique_ptr<MemoryBuffer>, 4> Buffers;
InstrProfSymtab &ProfSymTab = ProfileReader.getSymtab();

SmallVector<object::BuildIDRef> BinaryIDs;
auto CoverageReadersOrErr = BinaryCoverageReader::create(
CovMappingBufRef, Arch, Buffers, ProfSymTab,
CompilationDir, FoundBinaryIDs ? &BinaryIDs : nullptr);
CovMappingBufRef, Arch, Buffers, CompilationDir,
FoundBinaryIDs ? &BinaryIDs : nullptr);
if (Error E = CoverageReadersOrErr.takeError()) {
E = handleMaybeNoDataFoundError(std::move(E));
if (E)
Expand Down
67 changes: 20 additions & 47 deletions llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Debug.h"
Expand Down Expand Up @@ -1022,23 +1021,9 @@ static Expected<std::vector<SectionRef>> lookupSections(ObjectFile &OF,
return Sections;
}

static Error getProfileNamesFromDebugInfo(StringRef FileName,
InstrProfSymtab &ProfileNames) {
std::unique_ptr<InstrProfCorrelator> Correlator;
if (auto E = InstrProfCorrelator::get(FileName).moveInto(Correlator))
return E;
if (auto E = Correlator->correlateCovUnusedFuncNames(0))
return E;
if (auto E = ProfileNames.create(
StringRef(Correlator->getCovUnusedFuncNamesPointer(),
Correlator->getCovUnusedFuncNamesSize())))
return E;
return Error::success();
}

static Expected<std::unique_ptr<BinaryCoverageReader>>
loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
InstrProfSymtab &ProfSymTab, StringRef CompilationDir = "",
StringRef CompilationDir = "",
object::BuildIDRef *BinaryID = nullptr) {
std::unique_ptr<ObjectFile> OF;
if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin.get())) {
Expand Down Expand Up @@ -1067,30 +1052,11 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,

// Look for the sections that we are interested in.
auto ObjFormat = OF->getTripleObjectFormat();
// Without debug info correlation, all function names are stored in the
// binary's profile name section.
// When debug info correlation is enabled, instrumented function names are
// stored in the indexed profile file, and unused function names are stored in
// the binary's debug info.
InstrProfSymtab ProfileNames = ProfSymTab;
auto NamesSection =
lookupSections(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
/*AddSegmentInfo=*/false));
if (auto E = NamesSection.takeError()) {
if (OF->hasDebugInfo()) {
if (auto E =
getProfileNamesFromDebugInfo(OF->getFileName(), ProfileNames))
return make_error<CoverageMapError>(coveragemap_error::malformed);
}
consumeError(std::move(E));
} else {
std::vector<SectionRef> NamesSectionRefs = *NamesSection;
if (NamesSectionRefs.size() != 1)
return make_error<CoverageMapError>(coveragemap_error::malformed);
if (Error E = ProfileNames.create(NamesSectionRefs.back()))
return std::move(E);
}

/*AddSegmentInfo=*/false));
if (auto E = NamesSection.takeError())
return std::move(E);
auto CoverageSection =
lookupSections(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
/*AddSegmentInfo=*/false));
Expand All @@ -1105,6 +1071,15 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
return CoverageMappingOrErr.takeError();
StringRef CoverageMapping = CoverageMappingOrErr.get();

InstrProfSymtab ProfileNames;
std::vector<SectionRef> NamesSectionRefs = *NamesSection;
if (NamesSectionRefs.size() != 1)
return make_error<CoverageMapError>(
coveragemap_error::malformed,
"the size of coverage mapping section is not one");
if (Error E = ProfileNames.create(NamesSectionRefs.back()))
return std::move(E);

// Look for the coverage records section (Version4 only).
auto CoverageRecordsSections =
lookupSections(*OF, getInstrProfSectionName(IPSK_covfun, ObjFormat,
Expand Down Expand Up @@ -1176,8 +1151,7 @@ Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
BinaryCoverageReader::create(
MemoryBufferRef ObjectBuffer, StringRef Arch,
SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
InstrProfSymtab &ProfSymTab, StringRef CompilationDir,
SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
StringRef CompilationDir, SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
std::vector<std::unique_ptr<BinaryCoverageReader>> Readers;

if (ObjectBuffer.getBuffer().size() > sizeof(TestingFormatMagic)) {
Expand Down Expand Up @@ -1221,8 +1195,8 @@ BinaryCoverageReader::create(
}

return BinaryCoverageReader::create(
ArchiveOrErr.get()->getMemoryBufferRef(), Arch,
ObjectFileBuffers, ProfSymTab, CompilationDir, BinaryIDs);
ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
CompilationDir, BinaryIDs);
}
}

Expand All @@ -1235,8 +1209,8 @@ BinaryCoverageReader::create(
return ChildBufOrErr.takeError();

auto ChildReadersOrErr = BinaryCoverageReader::create(
ChildBufOrErr.get(), Arch, ObjectFileBuffers, ProfSymTab,
CompilationDir, BinaryIDs);
ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir,
BinaryIDs);
if (!ChildReadersOrErr)
return ChildReadersOrErr.takeError();
for (auto &Reader : ChildReadersOrErr.get())
Expand All @@ -1256,9 +1230,8 @@ BinaryCoverageReader::create(
}

object::BuildIDRef BinaryID;
auto ReaderOrErr =
loadBinaryFormat(std::move(Bin), Arch, ProfSymTab, CompilationDir,
BinaryIDs ? &BinaryID : nullptr);
auto ReaderOrErr = loadBinaryFormat(std::move(Bin), Arch, CompilationDir,
BinaryIDs ? &BinaryID : nullptr);
if (!ReaderOrErr)
return ReaderOrErr.takeError();
Readers.push_back(std::move(ReaderOrErr.get()));
Expand Down

0 comments on commit 4d5d9a5

Please sign in to comment.