#ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
#define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
#include <vector>
namespace llvm {
class IndexedInstrProfReader;
namespace coverage {
class CoverageMappingReader;
struct CoverageMappingRecord;
enum class coveragemap_error {
success = 0,
eof,
no_data_found,
unsupported_version,
truncated,
malformed,
decompression_failed,
invalid_or_missing_arch_specifier
};
const std::error_category &coveragemap_category();
inline std::error_code make_error_code(coveragemap_error E) {
return std::error_code(static_cast<int>(E), coveragemap_category());
}
class CoverageMapError : public ErrorInfo<CoverageMapError> {
public:
CoverageMapError(coveragemap_error Err) : Err(Err) {
assert(Err != coveragemap_error::success && "Not an error");
}
std::string message() const override;
void log(raw_ostream &OS) const override { OS << message(); }
std::error_code convertToErrorCode() const override {
return make_error_code(Err);
}
coveragemap_error get() const { return Err; }
static char ID;
private:
coveragemap_error Err;
};
struct Counter {
enum CounterKind { Zero, CounterValueReference, Expression };
static const unsigned EncodingTagBits = 2;
static const unsigned EncodingTagMask = 0x3;
static const unsigned EncodingCounterTagAndExpansionRegionTagBits =
EncodingTagBits + 1;
private:
CounterKind Kind = Zero;
unsigned ID = 0;
Counter(CounterKind Kind, unsigned ID) : Kind(Kind), ID(ID) {}
public:
Counter() = default;
CounterKind getKind() const { return Kind; }
bool isZero() const { return Kind == Zero; }
bool isExpression() const { return Kind == Expression; }
unsigned getCounterID() const { return ID; }
unsigned getExpressionID() const { return ID; }
friend bool operator==(const Counter &LHS, const Counter &RHS) {
return LHS.Kind == RHS.Kind && LHS.ID == RHS.ID;
}
friend bool operator!=(const Counter &LHS, const Counter &RHS) {
return !(LHS == RHS);
}
friend bool operator<(const Counter &LHS, const Counter &RHS) {
return std::tie(LHS.Kind, LHS.ID) < std::tie(RHS.Kind, RHS.ID);
}
static Counter getZero() { return Counter(); }
static Counter getCounter(unsigned CounterId) {
return Counter(CounterValueReference, CounterId);
}
static Counter getExpression(unsigned ExpressionId) {
return Counter(Expression, ExpressionId);
}
};
struct CounterExpression {
enum ExprKind { Subtract, Add };
ExprKind Kind;
Counter LHS, RHS;
CounterExpression(ExprKind Kind, Counter LHS, Counter RHS)
: Kind(Kind), LHS(LHS), RHS(RHS) {}
};
class CounterExpressionBuilder {
std::vector<CounterExpression> Expressions;
DenseMap<CounterExpression, unsigned> ExpressionIndices;
Counter get(const CounterExpression &E);
struct Term {
unsigned CounterID;
int Factor;
Term(unsigned CounterID, int Factor)
: CounterID(CounterID), Factor(Factor) {}
};
void extractTerms(Counter C, int Sign, SmallVectorImpl<Term> &Terms);
Counter simplify(Counter ExpressionTree);
public:
ArrayRef<CounterExpression> getExpressions() const { return Expressions; }
Counter add(Counter LHS, Counter RHS, bool Simplify = true);
Counter subtract(Counter LHS, Counter RHS, bool Simplify = true);
};
using LineColPair = std::pair<unsigned, unsigned>;
struct CounterMappingRegion {
enum RegionKind {
CodeRegion,
ExpansionRegion,
SkippedRegion,
GapRegion,
BranchRegion
};
Counter Count;
Counter FalseCount;
unsigned FileID, ExpandedFileID;
unsigned LineStart, ColumnStart, LineEnd, ColumnEnd;
RegionKind Kind;
CounterMappingRegion(Counter Count, unsigned FileID, unsigned ExpandedFileID,
unsigned LineStart, unsigned ColumnStart,
unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
: Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),
LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
ColumnEnd(ColumnEnd), Kind(Kind) {}
CounterMappingRegion(Counter Count, Counter FalseCount, unsigned FileID,
unsigned ExpandedFileID, unsigned LineStart,
unsigned ColumnStart, unsigned LineEnd,
unsigned ColumnEnd, RegionKind Kind)
: Count(Count), FalseCount(FalseCount), FileID(FileID),
ExpandedFileID(ExpandedFileID), LineStart(LineStart),
ColumnStart(ColumnStart), LineEnd(LineEnd), ColumnEnd(ColumnEnd),
Kind(Kind) {}
static CounterMappingRegion
makeRegion(Counter Count, unsigned FileID, unsigned LineStart,
unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
return CounterMappingRegion(Count, FileID, 0, LineStart, ColumnStart,
LineEnd, ColumnEnd, CodeRegion);
}
static CounterMappingRegion
makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart,
unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
return CounterMappingRegion(Counter(), FileID, ExpandedFileID, LineStart,
ColumnStart, LineEnd, ColumnEnd,
ExpansionRegion);
}
static CounterMappingRegion
makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart,
unsigned LineEnd, unsigned ColumnEnd) {
return CounterMappingRegion(Counter(), FileID, 0, LineStart, ColumnStart,
LineEnd, ColumnEnd, SkippedRegion);
}
static CounterMappingRegion
makeGapRegion(Counter Count, unsigned FileID, unsigned LineStart,
unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
return CounterMappingRegion(Count, FileID, 0, LineStart, ColumnStart,
LineEnd, (1U << 31) | ColumnEnd, GapRegion);
}
static CounterMappingRegion
makeBranchRegion(Counter Count, Counter FalseCount, unsigned FileID,
unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
unsigned ColumnEnd) {
return CounterMappingRegion(Count, FalseCount, FileID, 0, LineStart,
ColumnStart, LineEnd, ColumnEnd, BranchRegion);
}
inline LineColPair startLoc() const {
return LineColPair(LineStart, ColumnStart);
}
inline LineColPair endLoc() const { return LineColPair(LineEnd, ColumnEnd); }
};
struct CountedRegion : public CounterMappingRegion {
uint64_t ExecutionCount;
uint64_t FalseExecutionCount;
bool Folded;
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
FalseExecutionCount(0), Folded(false) {}
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
uint64_t FalseExecutionCount)
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
FalseExecutionCount(FalseExecutionCount), Folded(false) {}
};
class CounterMappingContext {
ArrayRef<CounterExpression> Expressions;
ArrayRef<uint64_t> CounterValues;
public:
CounterMappingContext(ArrayRef<CounterExpression> Expressions,
ArrayRef<uint64_t> CounterValues = None)
: Expressions(Expressions), CounterValues(CounterValues) {}
void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }
void dump(const Counter &C, raw_ostream &OS) const;
void dump(const Counter &C) const { dump(C, dbgs()); }
Expected<int64_t> evaluate(const Counter &C) const;
unsigned getMaxCounterID(const Counter &C) const;
};
struct FunctionRecord {
std::string Name;
std::vector<std::string> Filenames;
std::vector<CountedRegion> CountedRegions;
std::vector<CountedRegion> CountedBranchRegions;
uint64_t ExecutionCount = 0;
FunctionRecord(StringRef Name, ArrayRef<StringRef> Filenames)
: Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
FunctionRecord(FunctionRecord &&FR) = default;
FunctionRecord &operator=(FunctionRecord &&) = default;
void pushRegion(CounterMappingRegion Region, uint64_t Count,
uint64_t FalseCount) {
if (Region.Kind == CounterMappingRegion::BranchRegion) {
CountedBranchRegions.emplace_back(Region, Count, FalseCount);
if (Region.Count.isZero() && Region.FalseCount.isZero())
CountedBranchRegions.back().Folded = true;
return;
}
if (CountedRegions.empty())
ExecutionCount = Count;
CountedRegions.emplace_back(Region, Count, FalseCount);
}
};
class FunctionRecordIterator
: public iterator_facade_base<FunctionRecordIterator,
std::forward_iterator_tag, FunctionRecord> {
ArrayRef<FunctionRecord> Records;
ArrayRef<FunctionRecord>::iterator Current;
StringRef Filename;
void skipOtherFiles();
public:
FunctionRecordIterator(ArrayRef<FunctionRecord> Records_,
StringRef Filename = "")
: Records(Records_), Current(Records.begin()), Filename(Filename) {
skipOtherFiles();
}
FunctionRecordIterator() : Current(Records.begin()) {}
bool operator==(const FunctionRecordIterator &RHS) const {
return Current == RHS.Current && Filename == RHS.Filename;
}
const FunctionRecord &operator*() const { return *Current; }
FunctionRecordIterator &operator++() {
assert(Current != Records.end() && "incremented past end");
++Current;
skipOtherFiles();
return *this;
}
};
struct ExpansionRecord {
unsigned FileID;
const CountedRegion &Region;
const FunctionRecord &Function;
ExpansionRecord(const CountedRegion &Region,
const FunctionRecord &Function)
: FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}
};
struct CoverageSegment {
unsigned Line;
unsigned Col;
uint64_t Count;
bool HasCount;
bool IsRegionEntry;
bool IsGapRegion;
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
: Line(Line), Col(Col), Count(0), HasCount(false),
IsRegionEntry(IsRegionEntry), IsGapRegion(false) {}
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count,
bool IsRegionEntry, bool IsGapRegion = false,
bool IsBranchRegion = false)
: Line(Line), Col(Col), Count(Count), HasCount(true),
IsRegionEntry(IsRegionEntry), IsGapRegion(IsGapRegion) {}
friend bool operator==(const CoverageSegment &L, const CoverageSegment &R) {
return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry,
L.IsGapRegion) == std::tie(R.Line, R.Col, R.Count,
R.HasCount, R.IsRegionEntry,
R.IsGapRegion);
}
};
class InstantiationGroup {
friend class CoverageMapping;
unsigned Line;
unsigned Col;
std::vector<const FunctionRecord *> Instantiations;
InstantiationGroup(unsigned Line, unsigned Col,
std::vector<const FunctionRecord *> Instantiations)
: Line(Line), Col(Col), Instantiations(std::move(Instantiations)) {}
public:
InstantiationGroup(const InstantiationGroup &) = delete;
InstantiationGroup(InstantiationGroup &&) = default;
size_t size() const { return Instantiations.size(); }
unsigned getLine() const { return Line; }
unsigned getColumn() const { return Col; }
bool hasName() const {
for (unsigned I = 1, E = Instantiations.size(); I < E; ++I)
if (Instantiations[I]->Name != Instantiations[0]->Name)
return false;
return true;
}
StringRef getName() const {
assert(hasName() && "Instantiations don't have a shared name");
return Instantiations[0]->Name;
}
uint64_t getTotalExecutionCount() const {
uint64_t Count = 0;
for (const FunctionRecord *F : Instantiations)
Count += F->ExecutionCount;
return Count;
}
ArrayRef<const FunctionRecord *> getInstantiations() const {
return Instantiations;
}
};
class CoverageData {
friend class CoverageMapping;
std::string Filename;
std::vector<CoverageSegment> Segments;
std::vector<ExpansionRecord> Expansions;
std::vector<CountedRegion> BranchRegions;
public:
CoverageData() = default;
CoverageData(StringRef Filename) : Filename(Filename) {}
StringRef getFilename() const { return Filename; }
std::vector<CoverageSegment>::const_iterator begin() const {
return Segments.begin();
}
std::vector<CoverageSegment>::const_iterator end() const {
return Segments.end();
}
bool empty() const { return Segments.empty(); }
ArrayRef<ExpansionRecord> getExpansions() const { return Expansions; }
ArrayRef<CountedRegion> getBranches() const { return BranchRegions; }
};
class CoverageMapping {
DenseMap<size_t, DenseSet<size_t>> RecordProvenance;
std::vector<FunctionRecord> Functions;
DenseMap<size_t, SmallVector<unsigned, 0>> FilenameHash2RecordIndices;
std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
CoverageMapping() = default;
static Error loadFromReaders(
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
IndexedInstrProfReader &ProfileReader, CoverageMapping &Coverage);
Error loadFunctionRecord(const CoverageMappingRecord &Record,
IndexedInstrProfReader &ProfileReader);
ArrayRef<unsigned>
getImpreciseRecordIndicesForFilename(StringRef Filename) const;
public:
CoverageMapping(const CoverageMapping &) = delete;
CoverageMapping &operator=(const CoverageMapping &) = delete;
static Expected<std::unique_ptr<CoverageMapping>>
load(ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
IndexedInstrProfReader &ProfileReader);
static Expected<std::unique_ptr<CoverageMapping>>
load(ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
ArrayRef<StringRef> Arches = None, StringRef CompilationDir = "");
unsigned getMismatchedCount() const { return FuncHashMismatches.size(); }
ArrayRef<std::pair<std::string, uint64_t>> getHashMismatches() const {
return FuncHashMismatches;
}
std::vector<StringRef> getUniqueSourceFiles() const;
CoverageData getCoverageForFile(StringRef Filename) const;
CoverageData getCoverageForFunction(const FunctionRecord &Function) const;
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const;
iterator_range<FunctionRecordIterator> getCoveredFunctions() const {
return make_range(FunctionRecordIterator(Functions),
FunctionRecordIterator());
}
iterator_range<FunctionRecordIterator>
getCoveredFunctions(StringRef Filename) const {
return make_range(FunctionRecordIterator(Functions, Filename),
FunctionRecordIterator());
}
std::vector<InstantiationGroup>
getInstantiationGroups(StringRef Filename) const;
};
class LineCoverageStats {
uint64_t ExecutionCount;
bool HasMultipleRegions;
bool Mapped;
unsigned Line;
ArrayRef<const CoverageSegment *> LineSegments;
const CoverageSegment *WrappedSegment;
friend class LineCoverageIterator;
LineCoverageStats() = default;
public:
LineCoverageStats(ArrayRef<const CoverageSegment *> LineSegments,
const CoverageSegment *WrappedSegment, unsigned Line);
uint64_t getExecutionCount() const { return ExecutionCount; }
bool hasMultipleRegions() const { return HasMultipleRegions; }
bool isMapped() const { return Mapped; }
unsigned getLine() const { return Line; }
ArrayRef<const CoverageSegment *> getLineSegments() const {
return LineSegments;
}
const CoverageSegment *getWrappedSegment() const { return WrappedSegment; }
};
class LineCoverageIterator
: public iterator_facade_base<LineCoverageIterator,
std::forward_iterator_tag,
const LineCoverageStats> {
public:
LineCoverageIterator(const CoverageData &CD)
: LineCoverageIterator(CD, CD.begin()->Line) {}
LineCoverageIterator(const CoverageData &CD, unsigned Line)
: CD(CD), WrappedSegment(nullptr), Next(CD.begin()), Ended(false),
Line(Line) {
this->operator++();
}
bool operator==(const LineCoverageIterator &R) const {
return &CD == &R.CD && Next == R.Next && Ended == R.Ended;
}
const LineCoverageStats &operator*() const { return Stats; }
LineCoverageIterator &operator++();
LineCoverageIterator getEnd() const {
auto EndIt = *this;
EndIt.Next = CD.end();
EndIt.Ended = true;
return EndIt;
}
private:
const CoverageData &CD;
const CoverageSegment *WrappedSegment;
std::vector<CoverageSegment>::const_iterator Next;
bool Ended;
unsigned Line;
SmallVector<const CoverageSegment *, 4> Segments;
LineCoverageStats Stats;
};
static inline iterator_range<LineCoverageIterator>
getLineCoverageStats(const coverage::CoverageData &CD) {
auto Begin = LineCoverageIterator(CD);
auto End = Begin.getEnd();
return make_range(Begin, End);
}
namespace accessors {
template <class FuncRecordTy, support::endianness Endian>
uint64_t getFuncHash(const FuncRecordTy *Record) {
return support::endian::byte_swap<uint64_t, Endian>(Record->FuncHash);
}
template <class FuncRecordTy, support::endianness Endian>
uint64_t getDataSize(const FuncRecordTy *Record) {
return support::endian::byte_swap<uint32_t, Endian>(Record->DataSize);
}
template <class FuncRecordTy, support::endianness Endian>
uint64_t getFuncNameRef(const FuncRecordTy *Record) {
return support::endian::byte_swap<uint64_t, Endian>(Record->NameRef);
}
template <class FuncRecordTy, support::endianness Endian>
Error getFuncNameViaRef(const FuncRecordTy *Record,
InstrProfSymtab &ProfileNames, StringRef &FuncName) {
uint64_t NameRef = getFuncNameRef<FuncRecordTy, Endian>(Record);
FuncName = ProfileNames.getFuncName(NameRef);
return Error::success();
}
template <class FuncRecordTy, support::endianness Endian>
StringRef getCoverageMappingOutOfLine(const FuncRecordTy *Record,
const char *MappingBuf) {
return {MappingBuf, size_t(getDataSize<FuncRecordTy, Endian>(Record))};
}
template <class FuncRecordTy, support::endianness Endian>
std::pair<const char *, const FuncRecordTy *>
advanceByOneOutOfLine(const FuncRecordTy *Record, const char *MappingBuf) {
return {MappingBuf + getDataSize<FuncRecordTy, Endian>(Record), Record + 1};
}
}
LLVM_PACKED_START
template <class IntPtrT>
struct CovMapFunctionRecordV1 {
using ThisT = CovMapFunctionRecordV1<IntPtrT>;
#define COVMAP_V1
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
#include "llvm/ProfileData/InstrProfData.inc"
#undef COVMAP_V1
CovMapFunctionRecordV1() = delete;
template <support::endianness Endian> uint64_t getFuncHash() const {
return accessors::getFuncHash<ThisT, Endian>(this);
}
template <support::endianness Endian> uint64_t getDataSize() const {
return accessors::getDataSize<ThisT, Endian>(this);
}
template <support::endianness Endian> IntPtrT getFuncNameRef() const {
return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
}
template <support::endianness Endian>
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
IntPtrT NameRef = getFuncNameRef<Endian>();
uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);
FuncName = ProfileNames.getFuncName(NameRef, NameS);
if (NameS && FuncName.empty())
return make_error<CoverageMapError>(coveragemap_error::malformed);
return Error::success();
}
template <support::endianness Endian>
std::pair<const char *, const ThisT *>
advanceByOne(const char *MappingBuf) const {
return accessors::advanceByOneOutOfLine<ThisT, Endian>(this, MappingBuf);
}
template <support::endianness Endian> uint64_t getFilenamesRef() const {
llvm_unreachable("V1 function format does not contain a filenames ref");
}
template <support::endianness Endian>
StringRef getCoverageMapping(const char *MappingBuf) const {
return accessors::getCoverageMappingOutOfLine<ThisT, Endian>(this,
MappingBuf);
}
};
struct CovMapFunctionRecordV2 {
using ThisT = CovMapFunctionRecordV2;
#define COVMAP_V2
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
#include "llvm/ProfileData/InstrProfData.inc"
#undef COVMAP_V2
CovMapFunctionRecordV2() = delete;
template <support::endianness Endian> uint64_t getFuncHash() const {
return accessors::getFuncHash<ThisT, Endian>(this);
}
template <support::endianness Endian> uint64_t getDataSize() const {
return accessors::getDataSize<ThisT, Endian>(this);
}
template <support::endianness Endian> uint64_t getFuncNameRef() const {
return accessors::getFuncNameRef<ThisT, Endian>(this);
}
template <support::endianness Endian>
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
return accessors::getFuncNameViaRef<ThisT, Endian>(this, ProfileNames,
FuncName);
}
template <support::endianness Endian>
std::pair<const char *, const ThisT *>
advanceByOne(const char *MappingBuf) const {
return accessors::advanceByOneOutOfLine<ThisT, Endian>(this, MappingBuf);
}
template <support::endianness Endian> uint64_t getFilenamesRef() const {
llvm_unreachable("V2 function format does not contain a filenames ref");
}
template <support::endianness Endian>
StringRef getCoverageMapping(const char *MappingBuf) const {
return accessors::getCoverageMappingOutOfLine<ThisT, Endian>(this,
MappingBuf);
}
};
struct CovMapFunctionRecordV3 {
using ThisT = CovMapFunctionRecordV3;
#define COVMAP_V3
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
#include "llvm/ProfileData/InstrProfData.inc"
#undef COVMAP_V3
CovMapFunctionRecordV3() = delete;
template <support::endianness Endian> uint64_t getFuncHash() const {
return accessors::getFuncHash<ThisT, Endian>(this);
}
template <support::endianness Endian> uint64_t getDataSize() const {
return accessors::getDataSize<ThisT, Endian>(this);
}
template <support::endianness Endian> uint64_t getFuncNameRef() const {
return accessors::getFuncNameRef<ThisT, Endian>(this);
}
template <support::endianness Endian>
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
return accessors::getFuncNameViaRef<ThisT, Endian>(this, ProfileNames,
FuncName);
}
template <support::endianness Endian> uint64_t getFilenamesRef() const {
return support::endian::byte_swap<uint64_t, Endian>(FilenamesRef);
}
template <support::endianness Endian>
StringRef getCoverageMapping(const char *) const {
return StringRef(&CoverageMapping, getDataSize<Endian>());
}
template <support::endianness Endian>
std::pair<const char *, const CovMapFunctionRecordV3 *>
advanceByOne(const char *) const {
assert(isAddrAligned(Align(8), this) && "Function record not aligned");
const char *Next = ((const char *)this) + sizeof(CovMapFunctionRecordV3) -
sizeof(char) + getDataSize<Endian>();
Next += offsetToAlignedAddr(Next, Align(8));
return {nullptr, reinterpret_cast<const CovMapFunctionRecordV3 *>(Next)};
}
};
struct CovMapHeader {
#define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;
#include "llvm/ProfileData/InstrProfData.inc"
template <support::endianness Endian> uint32_t getNRecords() const {
return support::endian::byte_swap<uint32_t, Endian>(NRecords);
}
template <support::endianness Endian> uint32_t getFilenamesSize() const {
return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
}
template <support::endianness Endian> uint32_t getCoverageSize() const {
return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
}
template <support::endianness Endian> uint32_t getVersion() const {
return support::endian::byte_swap<uint32_t, Endian>(Version);
}
};
LLVM_PACKED_END
enum CovMapVersion {
Version1 = 0,
Version2 = 1,
Version3 = 2,
Version4 = 3,
Version5 = 4,
Version6 = 5,
CurrentVersion = INSTR_PROF_COVMAP_VERSION
};
template <int CovMapVersion, class IntPtrT> struct CovMapTraits {
using CovMapFuncRecordType = CovMapFunctionRecordV3;
using NameRefType = uint64_t;
};
template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version3, IntPtrT> {
using CovMapFuncRecordType = CovMapFunctionRecordV2;
using NameRefType = uint64_t;
};
template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version2, IntPtrT> {
using CovMapFuncRecordType = CovMapFunctionRecordV2;
using NameRefType = uint64_t;
};
template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version1, IntPtrT> {
using CovMapFuncRecordType = CovMapFunctionRecordV1<IntPtrT>;
using NameRefType = IntPtrT;
};
}
template<> struct DenseMapInfo<coverage::CounterExpression> {
static inline coverage::CounterExpression getEmptyKey() {
using namespace coverage;
return CounterExpression(CounterExpression::ExprKind::Subtract,
Counter::getCounter(~0U),
Counter::getCounter(~0U));
}
static inline coverage::CounterExpression getTombstoneKey() {
using namespace coverage;
return CounterExpression(CounterExpression::ExprKind::Add,
Counter::getCounter(~0U),
Counter::getCounter(~0U));
}
static unsigned getHashValue(const coverage::CounterExpression &V) {
return static_cast<unsigned>(
hash_combine(V.Kind, V.LHS.getKind(), V.LHS.getCounterID(),
V.RHS.getKind(), V.RHS.getCounterID()));
}
static bool isEqual(const coverage::CounterExpression &LHS,
const coverage::CounterExpression &RHS) {
return LHS.Kind == RHS.Kind && LHS.LHS == RHS.LHS && LHS.RHS == RHS.RHS;
}
};
}
#endif