mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 00:17:01 +00:00
InstrProf: Make CoverageMapping testable and add a basic unit test
Make CoverageMapping easier to create, so that we can write targeted unit tests for its internals, and add a some infrastructure to write these tests. Finally, add a simple unit test for basic functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229709 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -28,7 +28,7 @@ namespace llvm {
|
||||
class IndexedInstrProfReader;
|
||||
namespace coverage {
|
||||
|
||||
class ObjectFileCoverageMappingReader;
|
||||
class CoverageMappingReader;
|
||||
|
||||
class CoverageMapping;
|
||||
struct CounterExpressions;
|
||||
@@ -333,10 +333,22 @@ struct CoverageSegment {
|
||||
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
|
||||
: Line(Line), Col(Col), Count(0), HasCount(false),
|
||||
IsRegionEntry(IsRegionEntry) {}
|
||||
|
||||
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count,
|
||||
bool IsRegionEntry)
|
||||
: Line(Line), Col(Col), Count(Count), HasCount(true),
|
||||
IsRegionEntry(IsRegionEntry) {}
|
||||
|
||||
friend bool operator==(const CoverageSegment &L, const CoverageSegment &R) {
|
||||
return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry) ==
|
||||
std::tie(R.Line, R.Col, R.Count, R.HasCount, R.IsRegionEntry);
|
||||
}
|
||||
|
||||
void setCount(uint64_t NewCount) {
|
||||
Count = NewCount;
|
||||
HasCount = true;
|
||||
}
|
||||
|
||||
void addCount(uint64_t NewCount) { setCount(Count + NewCount); }
|
||||
};
|
||||
|
||||
@@ -384,7 +396,7 @@ class CoverageMapping {
|
||||
public:
|
||||
/// \brief Load the coverage mapping using the given readers.
|
||||
static ErrorOr<std::unique_ptr<CoverageMapping>>
|
||||
load(ObjectFileCoverageMappingReader &CoverageReader,
|
||||
load(CoverageMappingReader &CoverageReader,
|
||||
IndexedInstrProfReader &ProfileReader);
|
||||
|
||||
/// \brief Load the coverage mapping from the given files.
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
namespace llvm {
|
||||
namespace coverage {
|
||||
|
||||
class ObjectFileCoverageMappingReader;
|
||||
class CoverageMappingReader;
|
||||
|
||||
/// \brief Coverage mapping information for a single function.
|
||||
struct CoverageMappingRecord {
|
||||
@@ -41,15 +41,14 @@ struct CoverageMappingRecord {
|
||||
/// \brief A file format agnostic iterator over coverage mapping data.
|
||||
class CoverageMappingIterator
|
||||
: public std::iterator<std::input_iterator_tag, CoverageMappingRecord> {
|
||||
ObjectFileCoverageMappingReader *Reader;
|
||||
CoverageMappingReader *Reader;
|
||||
CoverageMappingRecord Record;
|
||||
|
||||
void increment();
|
||||
|
||||
public:
|
||||
CoverageMappingIterator() : Reader(nullptr) {}
|
||||
CoverageMappingIterator(ObjectFileCoverageMappingReader *Reader)
|
||||
: Reader(Reader) {
|
||||
CoverageMappingIterator(CoverageMappingReader *Reader) : Reader(Reader) {
|
||||
increment();
|
||||
}
|
||||
|
||||
@@ -67,6 +66,14 @@ public:
|
||||
CoverageMappingRecord *operator->() { return &Record; }
|
||||
};
|
||||
|
||||
class CoverageMappingReader {
|
||||
public:
|
||||
virtual std::error_code readNextRecord(CoverageMappingRecord &Record) = 0;
|
||||
CoverageMappingIterator begin() { return CoverageMappingIterator(this); }
|
||||
CoverageMappingIterator end() { return CoverageMappingIterator(); }
|
||||
virtual ~CoverageMappingReader() {}
|
||||
};
|
||||
|
||||
/// \brief Base class for the raw coverage mapping and filenames data readers.
|
||||
class RawCoverageReader {
|
||||
protected:
|
||||
@@ -135,7 +142,7 @@ private:
|
||||
|
||||
/// \brief Reader for the coverage mapping data that is emitted by the
|
||||
/// frontend and stored in an object file.
|
||||
class ObjectFileCoverageMappingReader {
|
||||
class ObjectFileCoverageMappingReader : public CoverageMappingReader {
|
||||
public:
|
||||
struct ProfileMappingRecord {
|
||||
CoverageMappingVersion Version;
|
||||
@@ -184,11 +191,7 @@ public:
|
||||
sys::fs::file_magic Type = sys::fs::file_magic::unknown);
|
||||
|
||||
std::error_code readHeader();
|
||||
std::error_code readNextRecord(CoverageMappingRecord &Record);
|
||||
|
||||
/// Iterator over profile data.
|
||||
CoverageMappingIterator begin() { return CoverageMappingIterator(this); }
|
||||
CoverageMappingIterator end() { return CoverageMappingIterator(); }
|
||||
std::error_code readNextRecord(CoverageMappingRecord &Record) override;
|
||||
|
||||
/// \brief Return true if the reader has finished reading the profile data.
|
||||
bool isEOF() { return LastError == instrprof_error::eof; }
|
||||
|
||||
Reference in New Issue
Block a user