15 #ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H 16 #define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H 38 #include <system_error> 45 class IndexedInstrProfReader;
73 std::string message()
const override;
93 static const unsigned EncodingTagBits = 2;
94 static const unsigned EncodingTagMask = 0x3;
95 static const unsigned EncodingCounterTagAndExpansionRegionTagBits =
109 bool isZero()
const {
return Kind == Zero; }
118 return LHS.Kind == RHS.Kind && LHS.ID == RHS.ID;
122 return !(LHS == RHS);
126 return std::tie(LHS.Kind, LHS.ID) < std::tie(RHS.Kind, RHS.ID);
134 return Counter(CounterValueReference, CounterId);
140 return Counter(Expression, ExpressionId);
152 : Kind(Kind), LHS(LHS), RHS(RHS) {}
176 Term(
unsigned CounterID,
int Factor)
177 : CounterID(CounterID), Factor(Factor) {}
230 unsigned LineStart,
unsigned ColumnStart,
231 unsigned LineEnd,
unsigned ColumnEnd,
RegionKind Kind)
232 : Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),
233 LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
234 ColumnEnd(ColumnEnd), Kind(Kind) {}
238 unsigned ColumnStart,
unsigned LineEnd,
unsigned ColumnEnd) {
240 LineEnd, ColumnEnd, CodeRegion);
245 unsigned ColumnStart,
unsigned LineEnd,
unsigned ColumnEnd) {
247 ColumnStart, LineEnd, ColumnEnd,
252 makeSkipped(
unsigned FileID,
unsigned LineStart,
unsigned ColumnStart,
253 unsigned LineEnd,
unsigned ColumnEnd) {
255 LineEnd, ColumnEnd, SkippedRegion);
260 unsigned ColumnStart,
unsigned LineEnd,
unsigned ColumnEnd) {
262 LineEnd, (1U << 31) | ColumnEnd, GapRegion);
289 : Expressions(Expressions), CounterValues(CounterValues) {}
313 : Name(Name), Filenames(Filenames.
begin(), Filenames.
end()) {}
319 if (CountedRegions.empty())
320 ExecutionCount = Count;
321 CountedRegions.emplace_back(Region, Count);
328 std::forward_iterator_tag, FunctionRecord> {
334 void skipOtherFiles();
339 : Records(Records_), Current(Records.
begin()), Filename(Filename) {
346 return Current == RHS.Current && Filename == RHS.Filename;
352 assert(Current != Records.
end() &&
"incremented past end");
374 : FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}
396 : Line(Line), Col(Col), Count(0), HasCount(
false),
397 IsRegionEntry(IsRegionEntry), IsGapRegion(
false) {}
400 bool IsRegionEntry,
bool IsGapRegion =
false)
401 : Line(Line), Col(Col), Count(Count), HasCount(
true),
402 IsRegionEntry(IsRegionEntry), IsGapRegion(IsGapRegion) {}
422 std::vector<const FunctionRecord *> Instantiations;
425 std::vector<const FunctionRecord *> Instantiations)
426 : Line(Line), Col(Col), Instantiations(
std::move(Instantiations)) {}
433 size_t size()
const {
return Instantiations.size(); }
443 for (
unsigned I = 1,
E = Instantiations.size();
I <
E; ++
I)
444 if (Instantiations[
I]->
Name != Instantiations[0]->
Name)
451 assert(hasName() &&
"Instantiations don't have a shared name");
452 return Instantiations[0]->Name;
459 Count +=
F->ExecutionCount;
465 return Instantiations;
477 std::string Filename;
478 std::vector<CoverageSegment> Segments;
479 std::vector<ExpansionRecord> Expansions;
491 std::vector<CoverageSegment>::const_iterator
begin()
const {
492 return Segments.begin();
495 std::vector<CoverageSegment>::const_iterator
end()
const {
496 return Segments.end();
499 bool empty()
const {
return Segments.empty(); }
511 std::vector<FunctionRecord> Functions;
512 std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
526 load(
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
546 return FuncHashMismatches;
551 std::vector<StringRef> getUniqueSourceFiles()
const;
583 std::vector<InstantiationGroup>
584 getInstantiationGroups(
StringRef Filename)
const;
589 uint64_t ExecutionCount;
590 bool HasMultipleRegions;
622 LineCoverageIterator, std::forward_iterator_tag, LineCoverageStats> {
628 : CD(CD), WrappedSegment(nullptr), Next(CD.
begin()), Ended(
false),
629 Line(Line), Segments(),
Stats() {
634 return &CD == &R.CD && Next == R.Next && Ended == R.Ended;
645 EndIt.Next = CD.end();
653 std::vector<CoverageSegment>::const_iterator Next;
664 auto End = Begin.getEnd();
679 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name; 684 template <support::endianness Endian> uint64_t
getFuncHash()
const {
685 return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
690 return support::endian::byte_swap<uint32_t, Endian>(DataSize);
695 return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
699 template <support::endianness Endian>
701 IntPtrT NameRef = getFuncNameRef<Endian>();
703 FuncName = ProfileNames.
getFuncName(NameRef, NameS);
704 if (NameS && FuncName.empty())
711 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name; 715 template <support::endianness Endian> uint64_t
getFuncHash()
const {
716 return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
721 return support::endian::byte_swap<uint32_t, Endian>(DataSize);
726 return support::endian::byte_swap<uint64_t, Endian>(NameRef);
730 template <support::endianness Endian>
732 uint64_t NameRef = getFuncNameRef<Endian>();
741 #define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name; 744 return support::endian::byte_swap<uint32_t, Endian>(NRecords);
748 return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
752 return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
756 return support::endian::byte_swap<uint32_t, Endian>(
Version);
790 using namespace coverage;
792 return CounterExpression(CounterExpression::ExprKind::Subtract,
798 using namespace coverage;
806 return static_cast<unsigned>(
819 #endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
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...
LineCoverageStats & operator*()
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
uint64_t getExecutionCount() const
This class represents lattice values for constants.
static Counter getZero()
Return the counter that represents the number zero.
unsigned getMismatchedCount() const
The number of functions that couldn't have their profiles mapped.
static CounterMappingRegion makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
#define LLVM_PACKED_START
void setCounts(ArrayRef< uint64_t > Counts)
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
LineColPair endLoc() const
static bool isEqual(const coverage::CounterExpression &LHS, const coverage::CounterExpression &RHS)
LineCoverageIterator(const CoverageData &CD)
std::error_code make_error_code(coveragemap_error E)
IntPtrT getFuncNameRef() const
friend bool operator==(const Counter &LHS, const Counter &RHS)
const CoverageSegment * getWrappedSegment() const
void pushRegion(CounterMappingRegion Region, uint64_t Count)
unsigned getLine() const
Get the line where the common function was defined.
A Counter expression is a value that represents an arithmetic operation with two counters.
block Block Frequency true
FunctionRecord(StringRef Name, ArrayRef< StringRef > Filenames)
uint64_t getTotalExecutionCount() const
Get the total execution count of all instantiations in this group.
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...
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)
gvn Early GVN Hoisting of Expressions
Iterator over Functions, optionally filtered to a single file.
const LineCoverageStats & operator*() const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
unsigned Col
The column where this segment begins.
ArrayRef< CounterExpression > getExpressions() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
An iterator over the LineCoverageStats objects for lines described by a CoverageData instance...
Tagged union holding either a T or a Error.
block placement Basic Block Placement Stats
uint64_t getFuncNameRef() const
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count, bool IsRegionEntry, bool IsGapRegion=false)
const CountedRegion & Region
The region that expands to this record.
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
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::pair< unsigned, unsigned > LineColPair
const FunctionRecord & operator*() const
Coverage information to be processed or displayed.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
ArrayRef< const FunctionRecord * > getInstantiations() const
Get the instantiations in this group.
CoverageMapError(coveragemap_error Err)
bool hasMultipleRegions() const
static CounterMappingRegion makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
ArrayRef< const CoverageSegment * > getLineSegments() const
const std::error_category & coveragemap_category()
iterator_range< FunctionRecordIterator > getCoveredFunctions(StringRef Filename) const
Gets all of the functions in a particular file.
The execution count information starting at a point in a file.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
An instantiation group contains a FunctionRecord list, such that each record corresponds to a distinc...
A CodeRegion associates some code with a counter.
A Counter mapping context is used to connect the counters, expressions and the obtained counter value...
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.
bool operator==(const FunctionRecordIterator &RHS) const
static ManagedStatic< _object_error_category > error_category
size_t size() const
Get the number of instantiations in this group.
LineColPair startLoc() 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.
static coverage::CounterExpression getEmptyKey()
static unsigned getHashValue(const coverage::CounterExpression &V)
uint32_t getDataSize() const
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.
iterator_range< FunctionRecordIterator > getCoveredFunctions() const
Gets all of the functions covered by this profile.
Coverage statistics for a single line.
FunctionRecordIterator(ArrayRef< FunctionRecord > Records_, StringRef Filename="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool operator==(const LineCoverageIterator &R) 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.
std::vector< CoverageSegment >::const_iterator begin() const
Get an iterator over the coverage segments for this object.
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...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isExpression() const
A range adaptor for a pair of iterators.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
std::vector< CoverageSegment >::const_iterator end() const
Base class for user error types.
LineCoverageIterator getEnd() const
The mapping of profile information to coverage data.
unsigned Line
The line where this segment begins.
CoverageData(StringRef Filename)
uint64_t getFuncHash() const
void dump(const Counter &C) const
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
unsigned getExpressionID() const
CounterKind getKind() const
bool hasName() const
Check if the instantiations in this group have a common mangled name.
CounterMappingContext(ArrayRef< CounterExpression > Expressions, ArrayRef< uint64_t > CounterValues=None)
std::vector< CountedRegion > CountedRegions
Regions in the function along with their counts.
std::string Name
Raw function name.
ArrayRef< ExpansionRecord > getExpansions() const
Expansions that can be further processed.
unsigned FileID
The abstract file this expansion covers.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool IsGapRegion
Whether this enters a gap region.
unsigned getCounterID() const
std::vector< std::string > Filenames
Associated files.
Lightweight error class with error context and mandatory checking.
StringRef getName() const
Get the common mangled name for instantiations in this group.
This class implements an extremely fast bulk output stream that can only output to a stream...
LineCoverageIterator(const CoverageData &CD, unsigned Line)
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.
static iterator_range< LineCoverageIterator > getLineCoverageStats(const coverage::CoverageData &CD)
Get a LineCoverageIterator range for the lines described by CD.
uint64_t getFuncHash() const
A Counter is an abstract value that describes how to compute the execution count for a region of code...
unsigned getColumn() const
Get the column where the common function was defined.
static CounterMappingRegion makeGapRegion(Counter Count, unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
const FunctionRecord & Function
Coverage for the expansion.
StringRef getFilename() const
Get the name of the file this data covers.
Coverage information for a macro expansion or #included file.
uint32_t getDataSize() const
FunctionRecordIterator & operator++()