14 #ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H 15 #define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H 37 #include <system_error> 44 class IndexedInstrProfReader;
72 std::string message()
const override;
92 static const unsigned EncodingTagBits = 2;
93 static const unsigned EncodingTagMask = 0x3;
94 static const unsigned EncodingCounterTagAndExpansionRegionTagBits =
108 bool isZero()
const {
return Kind == Zero; }
117 return LHS.Kind == RHS.Kind && LHS.ID == RHS.ID;
121 return !(LHS == RHS);
125 return std::tie(LHS.Kind, LHS.ID) < std::tie(RHS.Kind, RHS.ID);
133 return Counter(CounterValueReference, CounterId);
139 return Counter(Expression, ExpressionId);
151 : Kind(Kind), LHS(LHS), RHS(RHS) {}
175 Term(
unsigned CounterID,
int Factor)
176 : CounterID(CounterID), Factor(Factor) {}
229 unsigned LineStart,
unsigned ColumnStart,
230 unsigned LineEnd,
unsigned ColumnEnd,
RegionKind Kind)
231 : Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),
232 LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
233 ColumnEnd(ColumnEnd), Kind(Kind) {}
237 unsigned ColumnStart,
unsigned LineEnd,
unsigned ColumnEnd) {
239 LineEnd, ColumnEnd, CodeRegion);
244 unsigned ColumnStart,
unsigned LineEnd,
unsigned ColumnEnd) {
246 ColumnStart, LineEnd, ColumnEnd,
251 makeSkipped(
unsigned FileID,
unsigned LineStart,
unsigned ColumnStart,
252 unsigned LineEnd,
unsigned ColumnEnd) {
254 LineEnd, ColumnEnd, SkippedRegion);
259 unsigned ColumnStart,
unsigned LineEnd,
unsigned ColumnEnd) {
261 LineEnd, (1U << 31) | ColumnEnd, GapRegion);
288 : Expressions(Expressions), CounterValues(CounterValues) {}
317 : Name(Name), Filenames(Filenames.
begin(), Filenames.
end()) {}
323 if (CountedRegions.empty())
324 ExecutionCount = Count;
325 CountedRegions.emplace_back(Region, Count);
332 std::forward_iterator_tag, FunctionRecord> {
338 void skipOtherFiles();
343 : Records(Records_), Current(Records.
begin()), Filename(Filename) {
350 return Current == RHS.Current && Filename == RHS.Filename;
356 assert(Current != Records.
end() &&
"incremented past end");
378 : FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}
400 : Line(Line), Col(Col), Count(0), HasCount(
false),
401 IsRegionEntry(IsRegionEntry), IsGapRegion(
false) {}
404 bool IsRegionEntry,
bool IsGapRegion =
false)
405 : Line(Line), Col(Col), Count(Count), HasCount(
true),
406 IsRegionEntry(IsRegionEntry), IsGapRegion(IsGapRegion) {}
426 std::vector<const FunctionRecord *> Instantiations;
429 std::vector<const FunctionRecord *> Instantiations)
430 : Line(Line), Col(Col), Instantiations(
std::move(Instantiations)) {}
437 size_t size()
const {
return Instantiations.size(); }
447 for (
unsigned I = 1,
E = Instantiations.size();
I <
E; ++
I)
448 if (Instantiations[
I]->
Name != Instantiations[0]->
Name)
455 assert(hasName() &&
"Instantiations don't have a shared name");
456 return Instantiations[0]->Name;
463 Count +=
F->ExecutionCount;
469 return Instantiations;
481 std::string Filename;
482 std::vector<CoverageSegment> Segments;
483 std::vector<ExpansionRecord> Expansions;
495 std::vector<CoverageSegment>::const_iterator
begin()
const {
496 return Segments.begin();
499 std::vector<CoverageSegment>::const_iterator
end()
const {
500 return Segments.end();
503 bool empty()
const {
return Segments.empty(); }
515 std::vector<FunctionRecord> Functions;
517 std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
530 getImpreciseRecordIndicesForFilename(
StringRef Filename)
const;
538 load(
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
559 return FuncHashMismatches;
564 std::vector<StringRef> getUniqueSourceFiles()
const;
596 std::vector<InstantiationGroup>
597 getInstantiationGroups(
StringRef Filename)
const;
602 uint64_t ExecutionCount;
603 bool HasMultipleRegions;
635 LineCoverageIterator, std::forward_iterator_tag, LineCoverageStats> {
641 : CD(CD), WrappedSegment(nullptr), Next(CD.
begin()), Ended(
false),
642 Line(Line), Segments(),
Stats() {
647 return &CD == &R.CD && Next == R.Next && Ended == R.Ended;
658 EndIt.Next = CD.end();
666 std::vector<CoverageSegment>::const_iterator Next;
677 auto End = Begin.getEnd();
692 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name; 697 template <support::endianness Endian> uint64_t
getFuncHash()
const {
698 return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
703 return support::endian::byte_swap<uint32_t, Endian>(DataSize);
708 return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
712 template <support::endianness Endian>
714 IntPtrT NameRef = getFuncNameRef<Endian>();
716 FuncName = ProfileNames.
getFuncName(NameRef, NameS);
717 if (NameS && FuncName.empty())
724 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name; 728 template <support::endianness Endian> uint64_t
getFuncHash()
const {
729 return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
734 return support::endian::byte_swap<uint32_t, Endian>(DataSize);
739 return support::endian::byte_swap<uint64_t, Endian>(NameRef);
743 template <support::endianness Endian>
745 uint64_t NameRef = getFuncNameRef<Endian>();
754 #define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name; 757 return support::endian::byte_swap<uint32_t, Endian>(NRecords);
761 return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
765 return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
769 return support::endian::byte_swap<uint32_t, Endian>(
Version);
803 using namespace coverage;
805 return CounterExpression(CounterExpression::ExprKind::Subtract,
811 using namespace coverage;
819 return static_cast<unsigned>(
832 #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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
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
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="")
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
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.
#define LLVM_PACKED_START
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
Mapping from FileID (i.e.
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++()