27using namespace coverage;
31 : Filenames(Filenames) {
40 std::string FilenamesStr;
43 for (
const auto &Filename : Filenames) {
45 FilenamesOS << Filename;
71class CounterExpressionsMinimizer {
74 std::vector<unsigned> AdjustedExpressionIDs;
79 : Expressions(Expressions) {
80 AdjustedExpressionIDs.resize(Expressions.
size(), 0);
81 for (
const auto &
I : MappingRegions) {
85 for (
const auto &
I : MappingRegions) {
87 gatherUsed(
I.FalseCount);
92 if (!
C.isExpression())
94 unsigned ID =
C.getExpressionID();
95 AdjustedExpressionIDs[
ID] = 1;
96 mark(Expressions[
ID].
LHS);
97 mark(Expressions[
ID].
RHS);
101 if (!
C.isExpression() || !AdjustedExpressionIDs[
C.getExpressionID()])
103 AdjustedExpressionIDs[
C.getExpressionID()] = UsedExpressions.
size();
104 const auto &
E = Expressions[
C.getExpressionID()];
115 if (
C.isExpression())
140 if (
C.isExpression())
141 Tag += Expressions[
C.getExpressionID()].Kind;
142 unsigned ID =
C.getCounterID();
159 "Source region does not begin before it ends");
165 if (
LHS.FileID !=
RHS.FileID)
166 return LHS.FileID <
RHS.FileID;
167 if (
LHS.startLoc() !=
RHS.startLoc())
168 return LHS.startLoc() <
RHS.startLoc();
169 return LHS.Kind <
RHS.Kind;
174 for (
const auto &FileID : VirtualFileMapping)
178 CounterExpressionsMinimizer Minimizer(Expressions, MappingRegions);
179 auto MinExpressions = Minimizer.getExpressions();
181 for (
const auto &
E : MinExpressions) {
189 unsigned PrevLineStart = 0;
190 unsigned CurrentFileID = ~0U;
191 for (
auto I = MappingRegions.begin(),
E = MappingRegions.end();
I !=
E; ++
I) {
192 if (
I->FileID != CurrentFileID) {
194 assert(
I->FileID == (CurrentFileID + 1));
196 unsigned RegionCount = 1;
197 for (
auto J =
I + 1; J !=
E &&
I->FileID == J->FileID; ++J)
202 CurrentFileID =
I->FileID;
205 Counter Count = Minimizer.adjust(
I->Count);
206 Counter FalseCount = Minimizer.adjust(
I->FalseCount);
215 (std::numeric_limits<unsigned>::max() >>
219 unsigned EncodedTagExpandedFileID =
240 assert(
I->LineStart >= PrevLineStart);
246 PrevLineStart =
I->LineStart;
249 assert(CurrentFileID == (VirtualFileMapping.size() - 1));
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static void writeCounter(ArrayRef< CounterExpression > Expressions, Counter C, raw_ostream &OS)
static unsigned encodeCounter(ArrayRef< CounterExpression > Expressions, Counter C)
Encode the counter.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
void push_back(const T &Elt)
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.
StringSet - A wrapper for StringMap that provides set-like functionality.
std::pair< typename Base::iterator, bool > insert(StringRef key)
void write(raw_ostream &OS, bool Compress=true)
Write encoded filenames to the given output stream.
CoverageFilenamesSectionWriter(ArrayRef< std::string > Filenames)
void write(raw_ostream &OS)
Write encoded coverage mapping data to the given output stream.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
constexpr int BestSizeCompression
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
cl::opt< bool > DoInstrProfNameCompression
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
A Counter mapping region associates a source range with a specific counter.
LineColPair endLoc() const
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 const unsigned EncodingCounterTagAndExpansionRegionTagBits
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.