28using namespace coverage;
32 : Filenames(Filenames) {
41 std::string FilenamesStr;
44 for (
const auto &Filename : Filenames) {
46 FilenamesOS << Filename;
72class CounterExpressionsMinimizer {
75 std::vector<unsigned> AdjustedExpressionIDs;
80 : Expressions(Expressions) {
81 AdjustedExpressionIDs.resize(Expressions.
size(), 0);
82 for (
const auto &
I : MappingRegions) {
86 for (
const auto &
I : MappingRegions) {
88 gatherUsed(
I.FalseCount);
93 if (!
C.isExpression())
95 unsigned ID =
C.getExpressionID();
96 AdjustedExpressionIDs[
ID] = 1;
97 mark(Expressions[
ID].
LHS);
98 mark(Expressions[
ID].
RHS);
102 if (!
C.isExpression() || !AdjustedExpressionIDs[
C.getExpressionID()])
104 AdjustedExpressionIDs[
C.getExpressionID()] = UsedExpressions.
size();
105 const auto &
E = Expressions[
C.getExpressionID()];
116 if (
C.isExpression())
141 if (
C.isExpression())
142 Tag += Expressions[
C.getExpressionID()].Kind;
143 unsigned ID =
C.getCounterID();
160 "Source region does not begin before it ends");
166 if (
LHS.FileID !=
RHS.FileID)
167 return LHS.FileID <
RHS.FileID;
168 if (
LHS.startLoc() !=
RHS.startLoc())
169 return LHS.startLoc() <
RHS.startLoc();
173 return (Kind == CounterMappingRegion::MCDCDecisionRegion
174 ? 2 * CounterMappingRegion::ExpansionRegion - 1
178 return getKindKey(
LHS.Kind) < getKindKey(
RHS.Kind);
183 for (
const auto &FileID : VirtualFileMapping)
187 CounterExpressionsMinimizer Minimizer(Expressions, MappingRegions);
188 auto MinExpressions = Minimizer.getExpressions();
190 for (
const auto &E : MinExpressions) {
198 unsigned PrevLineStart = 0;
199 unsigned CurrentFileID = ~0U;
200 for (
auto I = MappingRegions.begin(), E = MappingRegions.end();
I != E; ++
I) {
201 if (
I->FileID != CurrentFileID) {
203 assert(
I->FileID == (CurrentFileID + 1));
205 unsigned RegionCount = 1;
206 for (
auto J =
I + 1; J != E &&
I->FileID == J->FileID; ++J)
211 CurrentFileID =
I->FileID;
214 Counter Count = Minimizer.adjust(
I->Count);
215 Counter FalseCount = Minimizer.adjust(
I->FalseCount);
216 bool ParamsShouldBeNull =
true;
225 (std::numeric_limits<unsigned>::max() >>
229 unsigned EncodedTagExpandedFileID =
257 const auto &BranchParams =
I->getBranchParams();
258 ParamsShouldBeNull =
false;
259 unsigned ID1 = BranchParams.ID + 1;
260 unsigned TID1 = BranchParams.Conds[
true] + 1;
261 unsigned FID1 = BranchParams.Conds[
false] + 1;
272 const auto &DecisionParams =
I->getDecisionParams();
273 ParamsShouldBeNull =
false;
275 encodeULEB128(
static_cast<unsigned>(DecisionParams.NumConditions),
OS);
279 assert(
I->LineStart >= PrevLineStart);
285 PrevLineStart =
I->LineStart;
286 assert((!ParamsShouldBeNull || std::get_if<0>(&
I->MCDCParams)) &&
287 "MCDCParams should be empty");
288 (void)ParamsShouldBeNull;
291 assert(CurrentFileID == (VirtualFileMapping.size() - 1));
296 return support::endian::byte_swap<uint64_t, llvm::endianness::little>(
N);
301 OS.
write(
reinterpret_cast<char *
>(&Magic),
sizeof(Magic));
305 OS.
write(
reinterpret_cast<char *
>(&VersionLittle),
sizeof(VersionLittle));
310 OS << ProfileNamesData;
320 OS << CoverageMappingData;
325 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.
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
constexpr uint64_t TestingFormatMagic
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
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.