LLVM  5.0.0
CoverageMappingReader.h
Go to the documentation of this file.
1 //===- CoverageMappingReader.h - Code coverage mapping reader ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for reading coverage mapping data for
11 // instrumentation based coverage.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGREADER_H
16 #define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGREADER_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Error.h"
24 #include <cstddef>
25 #include <cstdint>
26 #include <iterator>
27 #include <memory>
28 #include <vector>
29 
30 namespace llvm {
31 namespace coverage {
32 
33 class CoverageMappingReader;
34 
35 /// \brief Coverage mapping information for a single function.
38  uint64_t FunctionHash;
42 };
43 
44 /// \brief A file format agnostic iterator over coverage mapping data.
46  : public std::iterator<std::input_iterator_tag, CoverageMappingRecord> {
47  CoverageMappingReader *Reader = nullptr;
49 
50  void increment();
51 
52 public:
53  CoverageMappingIterator() = default;
54 
55  CoverageMappingIterator(CoverageMappingReader *Reader) : Reader(Reader) {
56  increment();
57  }
58 
60  increment();
61  return *this;
62  }
64  return Reader == RHS.Reader;
65  }
67  return Reader != RHS.Reader;
68  }
71 };
72 
74 public:
75  virtual ~CoverageMappingReader() = default;
76 
80 };
81 
82 /// \brief Base class for the raw coverage mapping and filenames data readers.
84 protected:
86 
87  RawCoverageReader(StringRef Data) : Data(Data) {}
88 
89  Error readULEB128(uint64_t &Result);
90  Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);
91  Error readSize(uint64_t &Result);
92  Error readString(StringRef &Result);
93 };
94 
95 /// \brief Reader for the raw coverage filenames.
97  std::vector<StringRef> &Filenames;
98 
99 public:
100  RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)
101  : RawCoverageReader(Data), Filenames(Filenames) {}
104  operator=(const RawCoverageFilenamesReader &) = delete;
105 
106  Error read();
107 };
108 
109 /// \brief Checks if the given coverage mapping data is exported for
110 /// an unused function.
112 public:
114  : RawCoverageReader(MappingData) {}
115 
117 };
118 
119 /// \brief Reader for the raw coverage mapping data.
121  ArrayRef<StringRef> TranslationUnitFilenames;
122  std::vector<StringRef> &Filenames;
123  std::vector<CounterExpression> &Expressions;
124  std::vector<CounterMappingRegion> &MappingRegions;
125 
126 public:
128  ArrayRef<StringRef> TranslationUnitFilenames,
129  std::vector<StringRef> &Filenames,
130  std::vector<CounterExpression> &Expressions,
131  std::vector<CounterMappingRegion> &MappingRegions)
132  : RawCoverageReader(MappingData),
133  TranslationUnitFilenames(TranslationUnitFilenames),
134  Filenames(Filenames), Expressions(Expressions),
135  MappingRegions(MappingRegions) {}
138  operator=(const RawCoverageMappingReader &) = delete;
139 
140  Error read();
141 
142 private:
143  Error decodeCounter(unsigned Value, Counter &C);
144  Error readCounter(Counter &C);
145  Error
146  readMappingRegionsSubArray(std::vector<CounterMappingRegion> &MappingRegions,
147  unsigned InferredFileID, size_t NumFileIDs);
148 };
149 
150 /// \brief Reader for the coverage mapping data that is emitted by the
151 /// frontend and stored in an object file.
153 public:
157  uint64_t FunctionHash;
161 
164  size_t FilenamesBegin, size_t FilenamesSize)
165  : Version(Version), FunctionName(FunctionName),
166  FunctionHash(FunctionHash), CoverageMapping(CoverageMapping),
167  FilenamesBegin(FilenamesBegin), FilenamesSize(FilenamesSize) {}
168  };
169 
170 private:
171  std::vector<StringRef> Filenames;
172  std::vector<ProfileMappingRecord> MappingRecords;
173  InstrProfSymtab ProfileNames;
174  size_t CurrentRecord = 0;
175  std::vector<StringRef> FunctionsFilenames;
176  std::vector<CounterExpression> Expressions;
177  std::vector<CounterMappingRegion> MappingRegions;
178 
179  BinaryCoverageReader() = default;
180 
181 public:
182  BinaryCoverageReader(const BinaryCoverageReader &) = delete;
184 
186  create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
187  StringRef Arch);
188 
190 };
191 
192 } // end namespace coverage
193 } // end namespace llvm
194 
195 #endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGREADER_H
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:410
Reader for the raw coverage mapping data.
RawCoverageFilenamesReader(StringRef Data, std::vector< StringRef > &Filenames)
Base class for the raw coverage mapping and filenames data readers.
CoverageMappingIterator(CoverageMappingReader *Reader)
Checks if the given coverage mapping data is exported for an unused function.
RawCoverageFilenamesReader & operator=(const RawCoverageFilenamesReader &)=delete
ArrayRef< CounterMappingRegion > MappingRegions
Reader for the coverage mapping data that is emitted by the frontend and stored in an object file...
RawCoverageMappingReader(StringRef MappingData, ArrayRef< StringRef > TranslationUnitFilenames, std::vector< StringRef > &Filenames, std::vector< CounterExpression > &Expressions, std::vector< CounterMappingRegion > &MappingRegions)
ArrayRef< CounterExpression > Expressions
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Error readIntMax(uint64_t &Result, uint64_t MaxPlus1)
Error readNextRecord(CoverageMappingRecord &Record) override
Coverage mapping information for a single function.
Reader for the raw coverage filenames.
bool operator==(const CoverageMappingIterator &RHS)
A file format agnostic iterator over coverage mapping data.
BinaryCoverageReader & operator=(const BinaryCoverageReader &)=delete
static Expected< std::unique_ptr< BinaryCoverageReader > > create(std::unique_ptr< MemoryBuffer > &ObjectBuffer, StringRef Arch)
The mapping of profile information to coverage data.
#define C
Definition: LargeTest.cpp:25
virtual Error readNextRecord(CoverageMappingRecord &Record)=0
RawCoverageMappingReader & operator=(const RawCoverageMappingReader &)=delete
ProfileMappingRecord(CovMapVersion Version, StringRef FunctionName, uint64_t FunctionHash, StringRef CoverageMapping, size_t FilenamesBegin, size_t FilenamesSize)
LLVM Value Representation.
Definition: Value.h:73
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool operator!=(const CoverageMappingIterator &RHS)
A Counter is an abstract value that describes how to compute the execution count for a region of code...