27using namespace coverage;
31 : Filenames(Filenames) {
40 std::string FilenamesStr;
43 for (
const auto &Filename : Filenames) {
45 FilenamesOS << Filename;
64 OS << (doCompression ? toStringRef(CompressedStr) :
StringRef(FilenamesStr));
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();
172 return (Kind == CounterMappingRegion::MCDCDecisionRegion
173 ? 2 * CounterMappingRegion::ExpansionRegion - 1
177 return getKindKey(
LHS.Kind) < getKindKey(
RHS.Kind);
182 for (
const auto &FileID : VirtualFileMapping)
186 CounterExpressionsMinimizer Minimizer(Expressions, MappingRegions);
187 auto MinExpressions = Minimizer.getExpressions();
189 for (
const auto &E : MinExpressions) {
197 unsigned PrevLineStart = 0;
198 unsigned CurrentFileID = ~0U;
199 for (
auto I = MappingRegions.begin(), E = MappingRegions.end();
I != E; ++
I) {
200 if (
I->FileID != CurrentFileID) {
202 assert(
I->FileID == (CurrentFileID + 1));
204 unsigned RegionCount = 1;
205 for (
auto J =
I + 1; J != E &&
I->FileID == J->FileID; ++J)
210 CurrentFileID =
I->FileID;
213 Counter Count = Minimizer.adjust(
I->Count);
214 Counter FalseCount = Minimizer.adjust(
I->FalseCount);
215 bool ParamsShouldBeNull =
true;
224 (std::numeric_limits<unsigned>::max() >>
228 unsigned EncodedTagExpandedFileID =
256 const auto &BranchParams =
I->getBranchParams();
257 ParamsShouldBeNull =
false;
258 unsigned ID1 = BranchParams.ID + 1;
259 unsigned TID1 = BranchParams.Conds[
true] + 1;
260 unsigned FID1 = BranchParams.Conds[
false] + 1;
271 const auto &DecisionParams =
I->getDecisionParams();
272 ParamsShouldBeNull =
false;
274 encodeULEB128(
static_cast<unsigned>(DecisionParams.NumConditions),
OS);
278 assert(
I->LineStart >= PrevLineStart);
284 PrevLineStart =
I->LineStart;
285 assert((!ParamsShouldBeNull || std::get_if<0>(&
I->MCDCParams)) &&
286 "MCDCParams should be empty");
287 (void)ParamsShouldBeNull;
290 assert(CurrentFileID == (VirtualFileMapping.size() - 1));
295 return support::endian::byte_swap<uint64_t, llvm::endianness::little>(
N);
300 OS.
write(
reinterpret_cast<char *
>(&Magic),
sizeof(Magic));
304 OS.
write(
reinterpret_cast<char *
>(&VersionLittle),
sizeof(VersionLittle));
309 OS << ProfileNamesData;
319 OS << CoverageMappingData;
324 OS << CoverageRecordsData;
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.
constexpr size_t size() const
size - Get the string size.
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.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
constexpr int BestSizeCompression
constexpr uint64_t TestingFormatMagic
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
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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...
@ MCDCDecisionRegion
A DecisionRegion represents a top-level boolean expression and is associated with a variable length b...
@ MCDCBranchRegion
A Branch Region can be extended to include IDs to facilitate MC/DC.
@ 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.