Skip to content

Commit ab3cd07

Browse files
committed
Revert "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)"
This reverts commit 618a221. Buildbots failing on windows and one other issue.
1 parent 7f34674 commit ab3cd07

33 files changed

+22
-2216
lines changed

llvm/docs/CommandGuide/llvm-cov.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ OPTIONS
222222
Show coverage for branch conditions in terms of either count or percentage.
223223
The supported views are: "count", "percent".
224224

225-
.. option:: -show-mcdc
226-
227-
Show modified condition/decision coverage (MC/DC) for each complex condition.
228-
This should be used in addition to branch coverage.
229-
230225
.. option:: -show-line-counts
231226

232227
Show the execution counts for each line. Defaults to true, unless another
@@ -431,11 +426,6 @@ OPTIONS
431426

432427
Show statistics for all branch conditions. Defaults to true.
433428

434-
.. option:: -show-mcdc-summary
435-
436-
Show modified condition/decision coverage (MC/DC) statistics for complex
437-
conditions. Defaults to false.
438-
439429
.. option:: -show-functions
440430

441431
Show coverage summaries for each function. Defaults to false.

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 8 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
1616

1717
#include "llvm/ADT/ArrayRef.h"
18-
#include "llvm/ADT/BitVector.h"
1918
#include "llvm/ADT/DenseMap.h"
2019
#include "llvm/ADT/DenseSet.h"
2120
#include "llvm/ADT/Hashing.h"
@@ -34,7 +33,6 @@
3433
#include <cstdint>
3534
#include <iterator>
3635
#include <memory>
37-
#include <sstream>
3836
#include <string>
3937
#include <system_error>
4038
#include <tuple>
@@ -239,28 +237,7 @@ struct CounterMappingRegion {
239237
/// A BranchRegion represents leaf-level boolean expressions and is
240238
/// associated with two counters, each representing the number of times the
241239
/// expression evaluates to true or false.
242-
BranchRegion,
243-
244-
/// A DecisionRegion represents a top-level boolean expression and is
245-
/// associated with a variable length bitmap index and condition number.
246-
MCDCDecisionRegion,
247-
248-
/// A Branch Region can be extended to include IDs to facilitate MC/DC.
249-
MCDCBranchRegion
250-
};
251-
252-
using MCDCConditionID = unsigned int;
253-
struct MCDCParameters {
254-
/// Byte Index of Bitmap Coverage Object for a Decision Region (MC/DC
255-
/// only).
256-
unsigned BitmapIdx = 0;
257-
258-
/// Number of Conditions used for a Decision Region (MC/DC only).
259-
unsigned NumConditions = 0;
260-
261-
/// IDs used to represent a branch region and other branch regions
262-
/// evaluated based on True and False branches (MC/DC only).
263-
MCDCConditionID ID = 0, TrueID = 0, FalseID = 0;
240+
BranchRegion
264241
};
265242

266243
/// Primary Counter that is also used for Branch Regions (TrueCount).
@@ -269,13 +246,8 @@ struct CounterMappingRegion {
269246
/// Secondary Counter used for Branch Regions (FalseCount).
270247
Counter FalseCount;
271248

272-
/// Parameters used for Modified Condition/Decision Coverage
273-
MCDCParameters MCDCParams;
274-
275-
unsigned FileID = 0;
276-
unsigned ExpandedFileID = 0;
249+
unsigned FileID, ExpandedFileID;
277250
unsigned LineStart, ColumnStart, LineEnd, ColumnEnd;
278-
279251
RegionKind Kind;
280252

281253
CounterMappingRegion(Counter Count, unsigned FileID, unsigned ExpandedFileID,
@@ -285,24 +257,15 @@ struct CounterMappingRegion {
285257
LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
286258
ColumnEnd(ColumnEnd), Kind(Kind) {}
287259

288-
CounterMappingRegion(Counter Count, Counter FalseCount,
289-
MCDCParameters MCDCParams, unsigned FileID,
260+
CounterMappingRegion(Counter Count, Counter FalseCount, unsigned FileID,
290261
unsigned ExpandedFileID, unsigned LineStart,
291262
unsigned ColumnStart, unsigned LineEnd,
292263
unsigned ColumnEnd, RegionKind Kind)
293-
: Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
294-
FileID(FileID), ExpandedFileID(ExpandedFileID), LineStart(LineStart),
264+
: Count(Count), FalseCount(FalseCount), FileID(FileID),
265+
ExpandedFileID(ExpandedFileID), LineStart(LineStart),
295266
ColumnStart(ColumnStart), LineEnd(LineEnd), ColumnEnd(ColumnEnd),
296267
Kind(Kind) {}
297268

298-
CounterMappingRegion(MCDCParameters MCDCParams, unsigned FileID,
299-
unsigned ExpandedFileID, unsigned LineStart,
300-
unsigned ColumnStart, unsigned LineEnd,
301-
unsigned ColumnEnd, RegionKind Kind)
302-
: MCDCParams(MCDCParams), ExpandedFileID(ExpandedFileID),
303-
LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
304-
ColumnEnd(ColumnEnd), Kind(Kind) {}
305-
306269
static CounterMappingRegion
307270
makeRegion(Counter Count, unsigned FileID, unsigned LineStart,
308271
unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
@@ -336,27 +299,8 @@ struct CounterMappingRegion {
336299
makeBranchRegion(Counter Count, Counter FalseCount, unsigned FileID,
337300
unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
338301
unsigned ColumnEnd) {
339-
return CounterMappingRegion(Count, FalseCount, MCDCParameters(), FileID, 0,
340-
LineStart, ColumnStart, LineEnd, ColumnEnd,
341-
BranchRegion);
342-
}
343-
344-
static CounterMappingRegion
345-
makeBranchRegion(Counter Count, Counter FalseCount, MCDCParameters MCDCParams,
346-
unsigned FileID, unsigned LineStart, unsigned ColumnStart,
347-
unsigned LineEnd, unsigned ColumnEnd) {
348-
return CounterMappingRegion(Count, FalseCount, MCDCParams, FileID, 0,
349-
LineStart, ColumnStart, LineEnd, ColumnEnd,
350-
MCDCParams.ID == 0 ? BranchRegion
351-
: MCDCBranchRegion);
352-
}
353-
354-
static CounterMappingRegion
355-
makeDecisionRegion(MCDCParameters MCDCParams, unsigned FileID,
356-
unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
357-
unsigned ColumnEnd) {
358-
return CounterMappingRegion(MCDCParams, FileID, 0, LineStart, ColumnStart,
359-
LineEnd, ColumnEnd, MCDCDecisionRegion);
302+
return CounterMappingRegion(Count, FalseCount, FileID, 0, LineStart,
303+
ColumnStart, LineEnd, ColumnEnd, BranchRegion);
360304
}
361305

362306
inline LineColPair startLoc() const {
@@ -382,177 +326,18 @@ struct CountedRegion : public CounterMappingRegion {
382326
FalseExecutionCount(FalseExecutionCount), Folded(false) {}
383327
};
384328

385-
/// MCDC Record grouping all information together.
386-
struct MCDCRecord {
387-
enum CondState { MCDC_DontCare = -1, MCDC_False = 0, MCDC_True = 1 };
388-
389-
using TestVector = llvm::SmallVector<CondState>;
390-
using TestVectors = llvm::SmallVector<TestVector>;
391-
using BoolVector = llvm::SmallVector<bool>;
392-
using TVRowPair = std::pair<unsigned, unsigned>;
393-
using TVPairMap = llvm::DenseMap<unsigned, TVRowPair>;
394-
using CondIDMap = llvm::DenseMap<unsigned, unsigned>;
395-
using LineColPairMap = llvm::DenseMap<unsigned, LineColPair>;
396-
397-
private:
398-
CounterMappingRegion Region;
399-
TestVectors TV;
400-
TVPairMap IndependencePairs;
401-
BoolVector Folded;
402-
CondIDMap PosToID;
403-
LineColPairMap CondLoc;
404-
405-
public:
406-
MCDCRecord(CounterMappingRegion Region, TestVectors TV,
407-
TVPairMap IndependencePairs, BoolVector Folded, CondIDMap PosToID,
408-
LineColPairMap CondLoc)
409-
: Region(Region), TV(TV), IndependencePairs(IndependencePairs),
410-
Folded(Folded), PosToID(PosToID), CondLoc(CondLoc){};
411-
412-
CounterMappingRegion getDecisionRegion() const { return Region; }
413-
unsigned getNumConditions() const { return Region.MCDCParams.NumConditions; }
414-
unsigned getNumTestVectors() const { return TV.size(); }
415-
bool isCondFolded(unsigned Condition) const { return Folded[Condition]; }
416-
417-
CondState getTVCondition(unsigned TestVectorIndex, unsigned Condition) {
418-
// Accessing conditions in the TestVectors requires a translation from a
419-
// ordinal position to actual condition ID. This is done via PosToID[].
420-
return TV[TestVectorIndex][PosToID[Condition]];
421-
}
422-
423-
CondState getTVResult(unsigned TestVectorIndex) {
424-
// The last value for a Test Vector, after its constituent conditions, is
425-
// always the Result. See MCDCRecordProcessor::RecordTestVector().
426-
return TV[TestVectorIndex][getNumConditions()];
427-
}
428-
429-
bool isConditionIndependencePairCovered(unsigned Condition) const {
430-
// Accessing conditions in the TestVector Row Pairs requires a translation
431-
// from a ordinal position to actual condition ID. This is done via
432-
// PosToID[].
433-
auto It = PosToID.find(Condition);
434-
if (It != PosToID.end())
435-
return (IndependencePairs.find(It->second) != IndependencePairs.end());
436-
llvm_unreachable("Condition ID without an Ordinal mapping");
437-
}
438-
439-
TVRowPair getConditionIndependencePair(unsigned Condition) {
440-
// Accessing conditions in the TestVector Row Pairs requires a translation
441-
// from a ordinal position to actual condition ID. This is done via
442-
// PosToID[].
443-
assert(isConditionIndependencePairCovered(Condition));
444-
return IndependencePairs[PosToID[Condition]];
445-
}
446-
447-
float getPercentCovered() const {
448-
unsigned Folded = 0;
449-
unsigned Covered = 0;
450-
for (unsigned C = 0; C < getNumConditions(); C++) {
451-
if (isCondFolded(C))
452-
Folded++;
453-
else if (isConditionIndependencePairCovered(C))
454-
Covered++;
455-
}
456-
457-
unsigned Total = getNumConditions() - Folded;
458-
if (Total == 0)
459-
return 0.0;
460-
return (static_cast<double>(Covered) / static_cast<double>(Total)) * 100.0;
461-
}
462-
463-
std::string getConditionHeaderString(unsigned Condition) {
464-
std::ostringstream OS;
465-
OS << "Condition C" << Condition + 1 << " --> (";
466-
OS << CondLoc[Condition].first << ":" << CondLoc[Condition].second;
467-
OS << ")\n";
468-
return OS.str();
469-
}
470-
471-
std::string getTestVectorHeaderString() {
472-
std::ostringstream OS;
473-
if (getNumTestVectors() == 0) {
474-
OS << "None.\n";
475-
return OS.str();
476-
}
477-
for (unsigned I = 0; I < getNumConditions(); I++) {
478-
OS << "C" << I + 1;
479-
if (I != getNumConditions() - 1)
480-
OS << ", ";
481-
}
482-
OS << " Result\n";
483-
return OS.str();
484-
}
485-
486-
std::string getTestVectorString(unsigned TestVectorIndex) {
487-
assert(TestVectorIndex < getNumTestVectors() &&
488-
"TestVector index out of bounds!");
489-
std::ostringstream OS;
490-
// Add individual condition values to the string.
491-
OS << " " << TestVectorIndex + 1 << " { ";
492-
for (unsigned Condition = 0; Condition < getNumConditions(); Condition++) {
493-
if (isCondFolded(Condition))
494-
OS << "C";
495-
else {
496-
switch (getTVCondition(TestVectorIndex, Condition)) {
497-
case MCDCRecord::MCDC_DontCare:
498-
OS << "-";
499-
break;
500-
case MCDCRecord::MCDC_True:
501-
OS << "T";
502-
break;
503-
case MCDCRecord::MCDC_False:
504-
OS << "F";
505-
break;
506-
}
507-
}
508-
if (Condition != getNumConditions() - 1)
509-
OS << ", ";
510-
}
511-
512-
// Add result value to the string.
513-
OS << " = ";
514-
if (getTVResult(TestVectorIndex) == MCDC_True)
515-
OS << "T";
516-
else
517-
OS << "F";
518-
OS << " }\n";
519-
520-
return OS.str();
521-
}
522-
523-
std::string getConditionCoverageString(unsigned Condition) {
524-
assert(Condition < getNumConditions() &&
525-
"Condition index is out of bounds!");
526-
std::ostringstream OS;
527-
528-
OS << " C" << Condition + 1 << "-Pair: ";
529-
if (isCondFolded(Condition)) {
530-
OS << "constant folded\n";
531-
} else if (isConditionIndependencePairCovered(Condition)) {
532-
TVRowPair rows = getConditionIndependencePair(Condition);
533-
OS << "covered: (" << rows.first << ",";
534-
OS << rows.second << ")\n";
535-
} else
536-
OS << "not covered\n";
537-
538-
return OS.str();
539-
}
540-
};
541-
542329
/// A Counter mapping context is used to connect the counters, expressions
543330
/// and the obtained counter values.
544331
class CounterMappingContext {
545332
ArrayRef<CounterExpression> Expressions;
546333
ArrayRef<uint64_t> CounterValues;
547-
ArrayRef<uint8_t> BitmapBytes;
548334

549335
public:
550336
CounterMappingContext(ArrayRef<CounterExpression> Expressions,
551337
ArrayRef<uint64_t> CounterValues = std::nullopt)
552338
: Expressions(Expressions), CounterValues(CounterValues) {}
553339

554340
void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }
555-
void setBitmapBytes(ArrayRef<uint8_t> Bytes) { BitmapBytes = Bytes; }
556341

557342
void dump(const Counter &C, raw_ostream &OS) const;
558343
void dump(const Counter &C) const { dump(C, dbgs()); }
@@ -561,17 +346,6 @@ class CounterMappingContext {
561346
/// counter was executed.
562347
Expected<int64_t> evaluate(const Counter &C) const;
563348

564-
/// Return the number of times that a region of code associated with this
565-
/// counter was executed.
566-
Expected<BitVector>
567-
evaluateBitmap(const CounterMappingRegion *MCDCDecision) const;
568-
569-
/// Return an MCDC record that indicates executed test vectors and condition
570-
/// pairs.
571-
Expected<MCDCRecord>
572-
evaluateMCDCRegion(CounterMappingRegion Region, BitVector Bitmap,
573-
ArrayRef<CounterMappingRegion> Branches);
574-
575349
unsigned getMaxCounterID(const Counter &C) const;
576350
};
577351

@@ -590,8 +364,6 @@ struct FunctionRecord {
590364
std::vector<CountedRegion> CountedRegions;
591365
/// Branch Regions in the function along with their counts.
592366
std::vector<CountedRegion> CountedBranchRegions;
593-
/// MCDC Records record a DecisionRegion and associated BranchRegions.
594-
std::vector<MCDCRecord> MCDCRecords;
595367
/// The number of times this function was executed.
596368
uint64_t ExecutionCount = 0;
597369

@@ -601,12 +373,9 @@ struct FunctionRecord {
601373
FunctionRecord(FunctionRecord &&FR) = default;
602374
FunctionRecord &operator=(FunctionRecord &&) = default;
603375

604-
void pushMCDCRecord(MCDCRecord Record) { MCDCRecords.push_back(Record); }
605-
606376
void pushRegion(CounterMappingRegion Region, uint64_t Count,
607377
uint64_t FalseCount) {
608-
if (Region.Kind == CounterMappingRegion::BranchRegion ||
609-
Region.Kind == CounterMappingRegion::MCDCBranchRegion) {
378+
if (Region.Kind == CounterMappingRegion::BranchRegion) {
610379
CountedBranchRegions.emplace_back(Region, Count, FalseCount);
611380
// If both counters are hard-coded to zero, then this region represents a
612381
// constant-folded branch.
@@ -777,7 +546,6 @@ class CoverageData {
777546
std::vector<CoverageSegment> Segments;
778547
std::vector<ExpansionRecord> Expansions;
779548
std::vector<CountedRegion> BranchRegions;
780-
std::vector<MCDCRecord> MCDCRecords;
781549

782550
public:
783551
CoverageData() = default;
@@ -804,9 +572,6 @@ class CoverageData {
804572

805573
/// Branches that can be further processed.
806574
ArrayRef<CountedRegion> getBranches() const { return BranchRegions; }
807-
808-
/// MCDC Records that can be further processed.
809-
ArrayRef<MCDCRecord> getMCDCRecords() const { return MCDCRecords; }
810575
};
811576

812577
/// The mapping of profile information to coverage data.

0 commit comments

Comments
 (0)