14#ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
15#define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
37#include <system_error>
44class IndexedInstrProfReader;
82 std::string
message()
const override;
137 return std::tie(
LHS.Kind,
LHS.ID) < std::tie(
RHS.Kind,
RHS.ID);
170 std::vector<CounterExpression> Expressions;
187 Term(
unsigned CounterID,
int Factor)
188 : CounterID(CounterID), Factor(Factor) {}
335 : Expressions(Expressions), CounterValues(CounterValues) {}
379 if (
Region.Count.isZero() &&
Region.FalseCount.isZero())
392 std::forward_iterator_tag, FunctionRecord> {
398 void skipOtherFiles();
403 : Records(Records_), Current(Records.begin()), Filename(Filename) {
410 return Current ==
RHS.Current && Filename ==
RHS.Filename;
416 assert(Current != Records.
end() &&
"incremented past end");
465 bool IsBranchRegion =
false)
470 return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry,
471 L.IsGapRegion) == std::tie(R.Line, R.Col, R.Count,
472 R.HasCount, R.IsRegionEntry,
487 std::vector<const FunctionRecord *> Instantiations;
490 std::vector<const FunctionRecord *> Instantiations)
491 : Line(Line), Col(Col), Instantiations(
std::
move(Instantiations)) {}
498 size_t size()
const {
return Instantiations.size(); }
508 for (
unsigned I = 1,
E = Instantiations.size();
I <
E; ++
I)
509 if (Instantiations[
I]->
Name != Instantiations[0]->
Name)
516 assert(
hasName() &&
"Instantiations don't have a shared name");
517 return Instantiations[0]->Name;
524 Count +=
F->ExecutionCount;
530 return Instantiations;
542 std::string Filename;
543 std::vector<CoverageSegment> Segments;
544 std::vector<ExpansionRecord> Expansions;
545 std::vector<CountedRegion> BranchRegions;
557 std::vector<CoverageSegment>::const_iterator
begin()
const {
558 return Segments.begin();
561 std::vector<CoverageSegment>::const_iterator
end()
const {
562 return Segments.end();
565 bool empty()
const {
return Segments.empty(); }
580 std::vector<FunctionRecord> Functions;
582 std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
587 static Error loadFromReaders(
588 ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
607 getImpreciseRecordIndicesForFilename(
StringRef Filename)
const;
615 load(
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
626 bool CheckBinaryIDs =
false);
639 return FuncHashMismatches;
676 std::vector<InstantiationGroup>
683 bool HasMultipleRegions;
715 std::forward_iterator_tag,
716 const LineCoverageStats> {
722 : CD(CD), WrappedSegment(nullptr), Next(CD.begin()), Ended(
false),
728 return &CD == &R.CD && Next == R.Next && Ended == R.Ended;
737 EndIt.Next = CD.
end();
745 std::vector<CoverageSegment>::const_iterator Next;
756 auto End = Begin.getEnd();
790template <
class FuncRecordTy, support::endianness Endian>
792 return support::endian::byte_swap<uint64_t, Endian>(
Record->FuncHash);
796template <
class FuncRecordTy, support::endianness Endian>
798 return support::endian::byte_swap<uint32_t, Endian>(
Record->DataSize);
802template <
class FuncRecordTy, support::endianness Endian>
804 return support::endian::byte_swap<uint64_t, Endian>(
Record->NameRef);
809template <
class FuncRecordTy, support::endianness Endian>
820template <
class FuncRecordTy, support::endianness Endian>
822 const char *MappingBuf) {
823 return {MappingBuf, size_t(getDataSize<FuncRecordTy, Endian>(
Record))};
828template <
class FuncRecordTy, support::endianness Endian>
829std::pair<const char *, const FuncRecordTy *>
831 return {MappingBuf + getDataSize<FuncRecordTy, Endian>(
Record),
Record + 1};
837template <
class IntPtrT>
842#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
848 return accessors::getFuncHash<ThisT, Endian>(
this);
852 return accessors::getDataSize<ThisT, Endian>(
this);
857 return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
861 template <support::endianness Endian>
863 IntPtrT NameRef = getFuncNameRef<Endian>();
865 FuncName = ProfileNames.
getFuncName(NameRef, NameS);
866 if (NameS && FuncName.
empty())
871 template <support::endianness Endian>
872 std::pair<const char *, const ThisT *>
874 return accessors::advanceByOneOutOfLine<ThisT, Endian>(
this, MappingBuf);
881 template <support::endianness Endian>
883 return accessors::getCoverageMappingOutOfLine<ThisT, Endian>(
this,
892#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
898 return accessors::getFuncHash<ThisT, Endian>(
this);
902 return accessors::getDataSize<ThisT, Endian>(
this);
906 return accessors::getFuncNameRef<ThisT, Endian>(
this);
909 template <support::endianness Endian>
911 return accessors::getFuncNameViaRef<ThisT, Endian>(
this, ProfileNames,
915 template <support::endianness Endian>
916 std::pair<const char *, const ThisT *>
918 return accessors::advanceByOneOutOfLine<ThisT, Endian>(
this, MappingBuf);
925 template <support::endianness Endian>
927 return accessors::getCoverageMappingOutOfLine<ThisT, Endian>(
this,
936#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
942 return accessors::getFuncHash<ThisT, Endian>(
this);
946 return accessors::getDataSize<ThisT, Endian>(
this);
950 return accessors::getFuncNameRef<ThisT, Endian>(
this);
953 template <support::endianness Endian>
955 return accessors::getFuncNameViaRef<ThisT, Endian>(
this, ProfileNames,
961 return support::endian::byte_swap<uint64_t, Endian>(FilenamesRef);
966 template <support::endianness Endian>
973 template <support::endianness Endian>
974 std::pair<const char *, const CovMapFunctionRecordV3 *>
978 sizeof(
char) + getDataSize<Endian>();
989#define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;
992 return support::endian::byte_swap<uint32_t, Endian>(NRecords);
996 return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
1000 return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
1004 return support::endian::byte_swap<uint32_t, Endian>(Version);
1055 using namespace coverage;
1057 return CounterExpression(CounterExpression::ExprKind::Subtract,
1058 Counter::getCounter(~0U),
1059 Counter::getCounter(~0U));
1063 using namespace coverage;
1065 return CounterExpression(CounterExpression::ExprKind::Add,
1066 Counter::getCounter(~0U),
1067 Counter::getCounter(~0U));
1071 return static_cast<unsigned>(
1072 hash_combine(V.Kind, V.LHS.getKind(), V.LHS.getCounterID(),
1073 V.RHS.getKind(), V.RHS.getCounterID()));
This file declares a library for handling Build IDs and using them to find debug info.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_PACKED_START
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Base class for user error types.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Class representing an expression and its matching format.
Reader for the indexed binary instrprof format.
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize)
Return function's PGO name from the function name's symbol address in the object file.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
A Counter expression builder is used to construct the counter expressions.
ArrayRef< CounterExpression > getExpressions() const
Counter subtract(Counter LHS, Counter RHS, bool Simplify=true)
Return a counter that represents the expression that subtracts RHS from LHS.
Counter add(Counter LHS, Counter RHS, bool Simplify=true)
Return a counter that represents the expression that adds LHS and RHS.
A Counter mapping context is used to connect the counters, expressions and the obtained counter value...
CounterMappingContext(ArrayRef< CounterExpression > Expressions, ArrayRef< uint64_t > CounterValues=std::nullopt)
void setCounts(ArrayRef< uint64_t > Counts)
void dump(const Counter &C) const
Expected< int64_t > evaluate(const Counter &C) const
Return the number of times that a region of code associated with this counter was executed.
unsigned getMaxCounterID(const Counter &C) const
void dump(const Counter &C, raw_ostream &OS) const
Coverage information to be processed or displayed.
ArrayRef< ExpansionRecord > getExpansions() const
Expansions that can be further processed.
ArrayRef< CountedRegion > getBranches() const
Branches that can be further processed.
std::vector< CoverageSegment >::const_iterator begin() const
Get an iterator over the coverage segments for this object.
std::vector< CoverageSegment >::const_iterator end() const
StringRef getFilename() const
Get the name of the file this data covers.
CoverageData(StringRef Filename)
std::string message() const override
Return the error message as a string.
CoverageMapError(coveragemap_error Err)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
coveragemap_error get() const
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
The mapping of profile information to coverage data.
unsigned getMismatchedCount() const
The number of functions that couldn't have their profiles mapped.
std::vector< StringRef > getUniqueSourceFiles() const
Returns a lexicographically sorted, unique list of files that are covered.
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const
Get the coverage for an expansion within a coverage set.
ArrayRef< std::pair< std::string, uint64_t > > getHashMismatches() const
A hash mismatch occurs when a profile record for a symbol does not have the same hash as a coverage m...
iterator_range< FunctionRecordIterator > getCoveredFunctions(StringRef Filename) const
Gets all of the functions in a particular file.
iterator_range< FunctionRecordIterator > getCoveredFunctions() const
Gets all of the functions covered by this profile.
CoverageData getCoverageForFunction(const FunctionRecord &Function) const
Get the coverage for a particular function.
CoverageMapping(const CoverageMapping &)=delete
std::vector< InstantiationGroup > getInstantiationGroups(StringRef Filename) const
Get the list of function instantiation groups in a particular file.
CoverageData getCoverageForFile(StringRef Filename) const
Get the coverage for a particular file.
CoverageMapping & operator=(const CoverageMapping &)=delete
static Expected< std::unique_ptr< CoverageMapping > > load(ArrayRef< std::unique_ptr< CoverageMappingReader > > CoverageReaders, IndexedInstrProfReader &ProfileReader)
Load the coverage mapping using the given readers.
Iterator over Functions, optionally filtered to a single file.
FunctionRecordIterator & operator++()
bool operator==(const FunctionRecordIterator &RHS) const
const FunctionRecord & operator*() const
FunctionRecordIterator(ArrayRef< FunctionRecord > Records_, StringRef Filename="")
An instantiation group contains a FunctionRecord list, such that each record corresponds to a distinc...
InstantiationGroup(const InstantiationGroup &)=delete
unsigned getLine() const
Get the line where the common function was defined.
unsigned getColumn() const
Get the column where the common function was defined.
bool hasName() const
Check if the instantiations in this group have a common mangled name.
size_t size() const
Get the number of instantiations in this group.
ArrayRef< const FunctionRecord * > getInstantiations() const
Get the instantiations in this group.
uint64_t getTotalExecutionCount() const
Get the total execution count of all instantiations in this group.
InstantiationGroup(InstantiationGroup &&)=default
StringRef getName() const
Get the common mangled name for instantiations in this group.
An iterator over the LineCoverageStats objects for lines described by a CoverageData instance.
LineCoverageIterator(const CoverageData &CD)
const LineCoverageStats & operator*() const
bool operator==(const LineCoverageIterator &R) const
LineCoverageIterator getEnd() const
LineCoverageIterator & operator++()
LineCoverageIterator(const CoverageData &CD, unsigned Line)
Coverage statistics for a single line.
bool hasMultipleRegions() const
const CoverageSegment * getWrappedSegment() const
uint64_t getExecutionCount() const
ArrayRef< const CoverageSegment * > getLineSegments() const
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
A range adaptor for a pair of iterators.
BuildIDFetcher searches local cache directories for debug info.
This class implements an extremely fast bulk output stream that can only output to a stream.
The virtual file system interface.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
constexpr size_t NameSize
uint64_t getFuncNameRef(const FuncRecordTy *Record)
Return the function lookup key. The value is considered opaque.
StringRef getCoverageMappingOutOfLine(const FuncRecordTy *Record, const char *MappingBuf)
Read coverage mapping out-of-line, from MappingBuf.
uint64_t getDataSize(const FuncRecordTy *Record)
Return the coverage map data size for the function.
Error getFuncNameViaRef(const FuncRecordTy *Record, InstrProfSymtab &ProfileNames, StringRef &FuncName)
Return the PGO name of the function.
std::pair< const char *, const FuncRecordTy * > advanceByOneOutOfLine(const FuncRecordTy *Record, const char *MappingBuf)
Advance to the next out-of-line coverage mapping and its associated function record.
uint64_t getFuncHash(const FuncRecordTy *Record)
Return the structural hash associated with the function.
const std::error_category & coveragemap_category()
std::error_code make_error_code(coveragemap_error E)
static iterator_range< LineCoverageIterator > getLineCoverageStats(const coverage::CoverageData &CD)
Get a LineCoverageIterator range for the lines described by CD.
@ invalid_or_missing_arch_specifier
std::pair< unsigned, unsigned > LineColPair
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment)
Returns the necessary adjustment for aligning Addr to Alignment bytes, rounding up.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static coverage::CounterExpression getTombstoneKey()
static bool isEqual(const coverage::CounterExpression &LHS, const coverage::CounterExpression &RHS)
static unsigned getHashValue(const coverage::CounterExpression &V)
static coverage::CounterExpression getEmptyKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
Associates a source range with an execution count.
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount, uint64_t FalseExecutionCount)
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
uint64_t FalseExecutionCount
A Counter expression is a value that represents an arithmetic operation with two counters.
CounterExpression(ExprKind Kind, Counter LHS, Counter RHS)
A Counter mapping region associates a source range with a specific counter.
LineColPair endLoc() const
static CounterMappingRegion makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
static CounterMappingRegion makeBranchRegion(Counter Count, Counter FalseCount, unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
CounterMappingRegion(Counter Count, Counter FalseCount, unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
static CounterMappingRegion makeGapRegion(Counter Count, unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
CounterMappingRegion(Counter Count, unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
static CounterMappingRegion makeRegion(Counter Count, unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
Counter FalseCount
Secondary Counter used for Branch Regions (FalseCount).
static CounterMappingRegion makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
Counter Count
Primary Counter that is also used for Branch Regions (TrueCount).
LineColPair startLoc() const
@ ExpansionRegion
An ExpansionRegion represents a file expansion region that associates a source range with the expansi...
@ SkippedRegion
A SkippedRegion represents a source range with code that was skipped by a preprocessor or similar mea...
@ GapRegion
A GapRegion is like a CodeRegion, but its count is only set as the line execution count when its the ...
@ BranchRegion
A BranchRegion represents leaf-level boolean expressions and is associated with two counters,...
@ CodeRegion
A CodeRegion associates some code with a counter.
A Counter is an abstract value that describes how to compute the execution count for a region of code...
static const unsigned EncodingTagBits
static Counter getZero()
Return the counter that represents the number zero.
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
friend bool operator==(const Counter &LHS, const Counter &RHS)
unsigned getCounterID() const
CounterKind
The CounterExpression kind (Add or Subtract) is encoded in bit 0 next to the CounterKind.
unsigned getExpressionID() const
static const unsigned EncodingCounterTagAndExpansionRegionTagBits
CounterKind getKind() const
bool isExpression() const
friend bool operator!=(const Counter &LHS, const Counter &RHS)
friend bool operator<(const Counter &LHS, const Counter &RHS)
static const unsigned EncodingTagMask
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.
CovMapFunctionRecordV1()=delete
std::pair< const char *, const ThisT * > advanceByOne(const char *MappingBuf) const
StringRef getCoverageMapping(const char *MappingBuf) const
uint64_t getFuncHash() const
uint64_t getFilenamesRef() const
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
Return the PGO name of the function.
IntPtrT getFuncNameRef() const
Return function lookup key. The value is consider opaque.
uint64_t getDataSize() const
uint64_t getFilenamesRef() const
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
CovMapFunctionRecordV2()=delete
uint64_t getDataSize() const
std::pair< const char *, const ThisT * > advanceByOne(const char *MappingBuf) const
StringRef getCoverageMapping(const char *MappingBuf) const
uint64_t getFuncHash() const
uint64_t getFuncNameRef() const
uint64_t getFuncHash() const
std::pair< const char *, const CovMapFunctionRecordV3 * > advanceByOne(const char *) const
uint64_t getFuncNameRef() const
StringRef getCoverageMapping(const char *) const
Read the inline coverage mapping.
uint64_t getFilenamesRef() const
Get the filename set reference.
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
uint64_t getDataSize() const
CovMapFunctionRecordV3()=delete
Coverage mapping information for a single function.
The execution count information starting at a point in a file.
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
bool HasCount
When false, the segment was uninstrumented or skipped.
unsigned Col
The column where this segment begins.
friend bool operator==(const CoverageSegment &L, const CoverageSegment &R)
bool IsRegionEntry
Whether this enters a new region or returns to a previous count.
uint64_t Count
The execution count, or zero if no count was recorded.
unsigned Line
The line where this segment begins.
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count, bool IsRegionEntry, bool IsGapRegion=false, bool IsBranchRegion=false)
bool IsGapRegion
Whether this enters a gap region.
Coverage information for a macro expansion or #included file.
const CountedRegion & Region
The region that expands to this record.
unsigned FileID
The abstract file this expansion covers.
ExpansionRecord(const CountedRegion &Region, const FunctionRecord &Function)
const FunctionRecord & Function
Coverage for the expansion.
Code coverage information for a single function.
std::vector< CountedRegion > CountedBranchRegions
Branch Regions in the function along with their counts.
std::string Name
Raw function name.
std::vector< CountedRegion > CountedRegions
Regions in the function along with their counts.
FunctionRecord & operator=(FunctionRecord &&)=default
std::vector< std::string > Filenames
Mapping from FileID (i.e.
FunctionRecord(FunctionRecord &&FR)=default
FunctionRecord(StringRef Name, ArrayRef< StringRef > Filenames)
uint64_t ExecutionCount
The number of times this function was executed.
void pushRegion(CounterMappingRegion Region, uint64_t Count, uint64_t FalseCount)