Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class BinaryCoverageReader : public CoverageMappingReader {
private:
std::vector<std::string> Filenames;
std::vector<ProfileMappingRecord> MappingRecords;
InstrProfSymtab ProfileNames;
std::unique_ptr<InstrProfSymtab> ProfileNames;
size_t CurrentRecord = 0;
std::vector<StringRef> FunctionsFilenames;
std::vector<CounterExpression> Expressions;
Expand All @@ -195,8 +195,9 @@ class BinaryCoverageReader : public CoverageMappingReader {
// D69471, which can split up function records into multiple sections on ELF.
FuncRecordsStorage FuncRecords;

BinaryCoverageReader(FuncRecordsStorage &&FuncRecords)
: FuncRecords(std::move(FuncRecords)) {}
BinaryCoverageReader(std::unique_ptr<InstrProfSymtab> Symtab,
FuncRecordsStorage &&FuncRecords)
: ProfileNames(std::move(Symtab)), FuncRecords(std::move(FuncRecords)) {}

public:
BinaryCoverageReader(const BinaryCoverageReader &) = delete;
Expand All @@ -209,12 +210,10 @@ class BinaryCoverageReader : public CoverageMappingReader {
SmallVectorImpl<object::BuildIDRef> *BinaryIDs = nullptr);

static Expected<std::unique_ptr<BinaryCoverageReader>>
createCoverageReaderFromBuffer(StringRef Coverage,
FuncRecordsStorage &&FuncRecords,
InstrProfSymtab &&ProfileNames,
uint8_t BytesInAddress,
llvm::endianness Endian,
StringRef CompilationDir = "");
createCoverageReaderFromBuffer(
StringRef Coverage, FuncRecordsStorage &&FuncRecords,
std::unique_ptr<InstrProfSymtab> ProfileNamesPtr, uint8_t BytesInAddress,
llvm::endianness Endian, StringRef CompilationDir = "");

Error readNextRecord(CoverageMappingRecord &Record) override;
};
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ class InstrProfSymtab {
public:
InstrProfSymtab() = default;

// Not copyable or movable.
// Consider std::unique_ptr for move.
InstrProfSymtab(const InstrProfSymtab &) = delete;
InstrProfSymtab &operator=(const InstrProfSymtab &) = delete;
InstrProfSymtab(InstrProfSymtab &&) = delete;
InstrProfSymtab &operator=(InstrProfSymtab &&) = delete;

/// Create InstrProfSymtab from an object file section which
/// contains function PGO names. When section may contain raw
/// string data or string data in compressed form. This method
Expand Down
35 changes: 19 additions & 16 deletions llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,31 +894,34 @@ static Error readCoverageMappingData(
Expected<std::unique_ptr<BinaryCoverageReader>>
BinaryCoverageReader::createCoverageReaderFromBuffer(
StringRef Coverage, FuncRecordsStorage &&FuncRecords,
InstrProfSymtab &&ProfileNames, uint8_t BytesInAddress,
std::unique_ptr<InstrProfSymtab> ProfileNamesPtr, uint8_t BytesInAddress,
llvm::endianness Endian, StringRef CompilationDir) {
std::unique_ptr<BinaryCoverageReader> Reader(
new BinaryCoverageReader(std::move(FuncRecords)));
Reader->ProfileNames = std::move(ProfileNames);
if (ProfileNamesPtr == nullptr)
return make_error<CoverageMapError>(coveragemap_error::malformed,
"Caller must provide ProfileNames");
std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader(
std::move(ProfileNamesPtr), std::move(FuncRecords)));
InstrProfSymtab &ProfileNames = *Reader->ProfileNames;
StringRef FuncRecordsRef = Reader->FuncRecords->getBuffer();
if (BytesInAddress == 4 && Endian == llvm::endianness::little) {
if (Error E = readCoverageMappingData<uint32_t, llvm::endianness::little>(
Reader->ProfileNames, Coverage, FuncRecordsRef,
Reader->MappingRecords, CompilationDir, Reader->Filenames))
ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
CompilationDir, Reader->Filenames))
return std::move(E);
} else if (BytesInAddress == 4 && Endian == llvm::endianness::big) {
if (Error E = readCoverageMappingData<uint32_t, llvm::endianness::big>(
Reader->ProfileNames, Coverage, FuncRecordsRef,
Reader->MappingRecords, CompilationDir, Reader->Filenames))
ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
CompilationDir, Reader->Filenames))
return std::move(E);
} else if (BytesInAddress == 8 && Endian == llvm::endianness::little) {
if (Error E = readCoverageMappingData<uint64_t, llvm::endianness::little>(
Reader->ProfileNames, Coverage, FuncRecordsRef,
Reader->MappingRecords, CompilationDir, Reader->Filenames))
ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
CompilationDir, Reader->Filenames))
return std::move(E);
} else if (BytesInAddress == 8 && Endian == llvm::endianness::big) {
if (Error E = readCoverageMappingData<uint64_t, llvm::endianness::big>(
Reader->ProfileNames, Coverage, FuncRecordsRef,
Reader->MappingRecords, CompilationDir, Reader->Filenames))
ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
CompilationDir, Reader->Filenames))
return std::move(E);
} else
return make_error<CoverageMapError>(
Expand Down Expand Up @@ -963,8 +966,8 @@ loadTestingFormat(StringRef Data, StringRef CompilationDir) {
if (Data.size() < ProfileNamesSize)
return make_error<CoverageMapError>(coveragemap_error::malformed,
"the size of ProfileNames is too big");
InstrProfSymtab ProfileNames;
if (Error E = ProfileNames.create(Data.substr(0, ProfileNamesSize), Address))
auto ProfileNames = std::make_unique<InstrProfSymtab>();
if (Error E = ProfileNames->create(Data.substr(0, ProfileNamesSize), Address))
return std::move(E);
Data = Data.substr(ProfileNamesSize);

Expand Down Expand Up @@ -1099,7 +1102,7 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
OF->isLittleEndian() ? llvm::endianness::little : llvm::endianness::big;

// Look for the sections that we are interested in.
InstrProfSymtab ProfileNames;
auto ProfileNames = std::make_unique<InstrProfSymtab>();
std::vector<SectionRef> NamesSectionRefs;
// If IPSK_name is not found, fallback to search for IPK_covname, which is
// used when binary correlation is enabled.
Expand All @@ -1116,7 +1119,7 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
return make_error<CoverageMapError>(
coveragemap_error::malformed,
"the size of coverage mapping section is not one");
if (Error E = ProfileNames.create(NamesSectionRefs.back()))
if (Error E = ProfileNames->create(NamesSectionRefs.back()))
return std::move(E);

auto CoverageSection = lookupSections(*OF, IPSK_covmap);
Expand Down