15 #ifndef LLVM_PROFILEDATA_COVERAGEMAPPING_H_
16 #define LLVM_PROFILEDATA_COVERAGEMAPPING_H_
28 #include <system_error>
55 std::string
message()
const override;
75 class IndexedInstrProfReader;
78 class CoverageMappingReader;
79 struct CoverageMappingRecord;
81 class CoverageMapping;
82 struct CounterExpressions;
113 return LHS.Kind == RHS.Kind && LHS.ID == RHS.ID;
117 return !(LHS == RHS);
121 return std::tie(LHS.Kind, LHS.ID) < std::tie(RHS.Kind, RHS.ID);
147 : Kind(Kind), LHS(LHS), RHS(RHS) {}
155 std::vector<CounterExpression> Expressions;
171 void extractTerms(
Counter C,
int Sign,
215 : Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),
216 LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
217 ColumnEnd(ColumnEnd), Kind(Kind) {}
230 ColumnStart, LineEnd, ColumnEnd,
242 inline std::pair<unsigned, unsigned>
startLoc()
const {
246 inline std::pair<unsigned, unsigned>
endLoc()
const {
268 : Expressions(Expressions), CounterValues(CounterValues) {}
292 : Name(Name), Filenames(Filenames.
begin(), Filenames.
end()) {}
307 std::forward_iterator_tag, FunctionRecord> {
313 void skipOtherFiles();
318 : Records(Records_), Current(Records.
begin()), Filename(Filename) {
325 return Current == RHS.Current && Filename == RHS.Filename;
331 assert(Current != Records.end() &&
"incremented past end");
353 :
FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}
374 IsRegionEntry(IsRegionEntry) {}
379 IsRegionEntry(IsRegionEntry) {}
393 std::string Filename;
394 std::vector<CoverageSegment> Segments;
395 std::vector<ExpansionRecord> Expansions;
406 std::vector<CoverageSegment>::const_iterator
begin()
const {
407 return Segments.begin();
409 std::vector<CoverageSegment>::const_iterator
end()
const {
410 return Segments.end();
412 bool empty()
const {
return Segments.empty(); }
424 std::vector<FunctionRecord> Functions;
425 unsigned MismatchedFunctionCount;
443 load(
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
491 std::vector<const FunctionRecord *>
512 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
517 template <support::endianness Endian> uint64_t
getFuncHash()
const {
518 return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
522 return support::endian::byte_swap<uint32_t, Endian>(DataSize);
526 return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
529 template <support::endianness Endian>
531 IntPtrT NameRef = getFuncNameRef<Endian>();
533 FuncName = ProfileNames.
getFuncName(NameRef, NameS);
534 if (NameS && FuncName.empty())
541 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
545 template <support::endianness Endian> uint64_t
getFuncHash()
const {
546 return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
550 return support::endian::byte_swap<uint32_t, Endian>(DataSize);
554 return support::endian::byte_swap<uint64_t, Endian>(NameRef);
557 template <support::endianness Endian>
559 uint64_t NameRef = getFuncNameRef<Endian>();
568 #define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;
571 return support::endian::byte_swap<uint32_t, Endian>(NRecords);
574 return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
577 return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
580 return support::endian::byte_swap<uint32_t, Endian>(
Version);
611 using namespace coverage;
612 return CounterExpression(CounterExpression::ExprKind::Subtract,
613 Counter::getCounter(~0U),
614 Counter::getCounter(~0U));
618 using namespace coverage;
620 Counter::getCounter(~0U),
621 Counter::getCounter(~0U));
625 return static_cast<unsigned>(
638 #endif // LLVM_PROFILEDATA_COVERAGEMAPPING_H_
StringRef getFilename() const
Get the name of the file this data covers.
const_iterator end(StringRef path)
Get end iterator over path.
static coverage::CounterExpression getTombstoneKey()
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
bool operator==(const FunctionRecordIterator &RHS) const
static const unsigned EncodingTagMask
static Counter getZero()
Return the counter that represents the number zero.
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count, bool IsRegionEntry)
std::vector< const FunctionRecord * > getInstantiations(StringRef Filename) const
Get the list of function instantiations in the file.
static CounterMappingRegion makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
void setCounts(ArrayRef< uint64_t > Counts)
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
Expected< int64_t > evaluate(const Counter &C) const
Return the number of times that a region of code associated with this counter was executed...
CovMapFunctionRecord CovMapFuncRecordType
CoverageData getCoverageForFunction(const FunctionRecord &Function) const
Get the coverage for a particular function.
static bool isEqual(const coverage::CounterExpression &LHS, const coverage::CounterExpression &RHS)
iterator_range< FunctionRecordIterator > getCoveredFunctions(StringRef Filename) const
Gets all of the functions in a particular file.
std::error_code make_error_code(coveragemap_error E)
const_iterator begin(StringRef path)
Get begin iterator over path.
friend bool operator==(const Counter &LHS, const Counter &RHS)
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const
Get the coverage for an expansion within a coverage set.
void pushRegion(CounterMappingRegion Region, uint64_t Count)
A Counter expression is a value that represents an arithmetic operation with two counters.
FunctionRecord(StringRef Name, ArrayRef< StringRef > Filenames)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
friend bool operator!=(const Counter &LHS, const Counter &RHS)
friend bool operator<(const Counter &LHS, const Counter &RHS)
friend bool operator==(const CoverageSegment &L, const CoverageSegment &R)
static Expected< std::unique_ptr< CoverageMapping > > load(StringRef ObjectFilename, StringRef ProfileFilename, StringRef Arch=StringRef())
Load the coverage mapping from the given files.
Iterator over Functions, optionally filtered to a single file.
static Expected< std::unique_ptr< CoverageMapping > > load(CoverageMappingReader &CoverageReader, IndexedInstrProfReader &ProfileReader)
Load the coverage mapping using the given readers.
unsigned Col
The column where this segment begins.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
uint64_t getFuncHash() const
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
Tagged union holding either a T or a Error.
const CountedRegion & Region
The region that expands to this record.
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize)
Return function's PGO name from the function name's symbol address in the object file.
std::vector< CoverageSegment >::const_iterator begin() const
Function Alias Analysis false
Coverage information to be processed or displayed.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
CoverageMapError(coveragemap_error Err)
Counter add(Counter LHS, Counter RHS)
Return a counter that represents the expression that adds LHS and RHS.
static CounterMappingRegion makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
iterator_range< FunctionRecordIterator > getCoveredFunctions() const
Gets all of the functions covered by this profile.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
const std::error_category & coveragemap_category()
unsigned getExpressionID() const
The execution count information starting at a point in a file.
static CounterMappingRegion makeRegion(Counter Count, unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
Coverage mapping information for a single function.
uint64_t ExecutionCount
The number of times this function was executed.
unsigned getMismatchedCount()
The number of functions that couldn't have their profiles mapped.
void dump(const Counter &C, llvm::raw_ostream &OS) const
CounterKind getKind() const
CoverageData getCoverageForFile(StringRef Filename) const
Get the coverage for a particular file.
A CodeRegion associates some code with a counter.
A Counter mapping context is used to connect the counters, expressions and the obtained counter value...
unsigned getCounterID() const
A Counter mapping region associates a source range with a specific counter.
bool IsRegionEntry
Whether this enters a new region or returns to a previous count.
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
static ManagedStatic< _object_error_category > error_category
uint32_t getDataSize() const
CounterMappingRegion(Counter Count, unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
Associates a source range with an execution count.
std::pair< unsigned, unsigned > startLoc() const
static coverage::CounterExpression getEmptyKey()
uint64_t getFuncNameRef() const
Counter subtract(Counter LHS, Counter RHS)
Return a counter that represents the expression that subtracts RHS from LHS.
static unsigned getHashValue(const coverage::CounterExpression &V)
CounterExpression(ExprKind Kind, Counter LHS, Counter RHS)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Code coverage information for a single function.
static ErrorSuccess success()
Create a success value.
uint64_t getFuncHash() const
FunctionRecordIterator(ArrayRef< FunctionRecord > Records_, StringRef Filename="")
std::vector< CoverageSegment >::const_iterator end() const
ExpansionRecord(const CountedRegion &Region, const FunctionRecord &Function)
uint64_t Count
The execution count, or zero if no count was recorded.
bool HasCount
When false, the segment was uninstrumented or skipped.
An ExpansionRegion represents a file expansion region that associates a source range with the expansi...
A SkippedRegion represents a source range with code that was skipped by a preprocessor or similar mea...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A range adaptor for a pair of iterators.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Base class for user error types.
static const unsigned EncodingCounterTagAndExpansionRegionTagBits
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
The mapping of profile information to coverage data.
unsigned Line
The line where this segment begins.
CoverageData(StringRef Filename)
std::string message() const override
Return the error message as a string.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
bool isExpression() const
CounterMappingContext(ArrayRef< CounterExpression > Expressions, ArrayRef< uint64_t > CounterValues=None)
std::vector< CountedRegion > CountedRegions
Regions in the function along with their counts.
#define LLVM_PACKED_START
std::string Name
Raw function name.
unsigned FileID
The abstract file this expansion covers.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
IntPtrT getFuncNameRef() const
static const unsigned EncodingTagBits
ArrayRef< CounterExpression > getExpressions() const
FunctionRecord & operator=(FunctionRecord &&)=default
std::vector< std::string > Filenames
Associated files.
Lightweight error class with error context and mandatory checking.
StringSet - A wrapper for StringMap that provides set-like functionality.
std::pair< unsigned, unsigned > endLoc() const
const FunctionRecord & operator*() const
This class implements an extremely fast bulk output stream that can only output to a stream...
void dump(const Counter &C) const
uint32_t getDataSize() const
StringRef - Represent a constant reference to a string, i.e.
Reader for the indexed binary instrprof format.
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.
A Counter expression builder is used to construct the counter expressions.
std::vector< StringRef > getUniqueSourceFiles() const
Returns a lexicographically sorted, unique list of files that are covered.
CovMapFunctionRecordV1< IntPtrT > CovMapFuncRecordType
ArrayRef< ExpansionRecord > getExpansions() const
Expansions that can be further processed.
A Counter is an abstract value that describes how to compute the execution count for a region of code...
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
const FunctionRecord & Function
Coverage for the expansion.
Coverage information for a macro expansion or #included file.
FunctionRecordIterator & operator++()