LLVM  5.0.0
CoverageMapping.h
Go to the documentation of this file.
1 //===- CoverageMapping.h - Code coverage mapping support --------*- 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 // Code coverage mapping data is generated by clang and read by
11 // llvm-cov to show code coverage statistics for a file.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
16 #define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/Hashing.h"
21 #include "llvm/ADT/None.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/StringSet.h"
24 #include "llvm/ADT/iterator.h"
27 #include "llvm/Support/Compiler.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/Endian.h"
30 #include "llvm/Support/Error.h"
32 #include <cassert>
33 #include <cstdint>
34 #include <iterator>
35 #include <memory>
36 #include <string>
37 #include <system_error>
38 #include <tuple>
39 #include <utility>
40 #include <vector>
41 
42 namespace llvm {
43 
44 class IndexedInstrProfReader;
45 
46 namespace coverage {
47 
50 
51 enum class coveragemap_error {
52  success = 0,
53  eof,
56  truncated,
57  malformed
58 };
59 
61 
62 inline std::error_code make_error_code(coveragemap_error E) {
63  return std::error_code(static_cast<int>(E), coveragemap_category());
64 }
65 
66 class CoverageMapError : public ErrorInfo<CoverageMapError> {
67 public:
69  assert(Err != coveragemap_error::success && "Not an error");
70  }
71 
72  std::string message() const override;
73 
74  void log(raw_ostream &OS) const override { OS << message(); }
75 
76  std::error_code convertToErrorCode() const override {
77  return make_error_code(Err);
78  }
79 
80  coveragemap_error get() const { return Err; }
81 
82  static char ID;
83 
84 private:
86 };
87 
88 /// \brief A Counter is an abstract value that describes how to compute the
89 /// execution count for a region of code using the collected profile count data.
90 struct Counter {
92  static const unsigned EncodingTagBits = 2;
93  static const unsigned EncodingTagMask = 0x3;
95  EncodingTagBits + 1;
96 
97 private:
98  CounterKind Kind = Zero;
99  unsigned ID = 0;
100 
101  Counter(CounterKind Kind, unsigned ID) : Kind(Kind), ID(ID) {}
102 
103 public:
104  Counter() = default;
105 
106  CounterKind getKind() const { return Kind; }
107 
108  bool isZero() const { return Kind == Zero; }
109 
110  bool isExpression() const { return Kind == Expression; }
111 
112  unsigned getCounterID() const { return ID; }
113 
114  unsigned getExpressionID() const { return ID; }
115 
116  friend bool operator==(const Counter &LHS, const Counter &RHS) {
117  return LHS.Kind == RHS.Kind && LHS.ID == RHS.ID;
118  }
119 
120  friend bool operator!=(const Counter &LHS, const Counter &RHS) {
121  return !(LHS == RHS);
122  }
123 
124  friend bool operator<(const Counter &LHS, const Counter &RHS) {
125  return std::tie(LHS.Kind, LHS.ID) < std::tie(RHS.Kind, RHS.ID);
126  }
127 
128  /// \brief Return the counter that represents the number zero.
129  static Counter getZero() { return Counter(); }
130 
131  /// \brief Return the counter that corresponds to a specific profile counter.
132  static Counter getCounter(unsigned CounterId) {
133  return Counter(CounterValueReference, CounterId);
134  }
135 
136  /// \brief Return the counter that corresponds to a specific
137  /// addition counter expression.
138  static Counter getExpression(unsigned ExpressionId) {
139  return Counter(Expression, ExpressionId);
140  }
141 };
142 
143 /// \brief A Counter expression is a value that represents an arithmetic
144 /// operation with two counters.
146  enum ExprKind { Subtract, Add };
149 
151  : Kind(Kind), LHS(LHS), RHS(RHS) {}
152 };
153 
154 /// \brief A Counter expression builder is used to construct the
155 /// counter expressions. It avoids unnecessary duplication
156 /// and simplifies algebraic expressions.
158  /// \brief A list of all the counter expressions
159  std::vector<CounterExpression> Expressions;
160 
161  /// \brief A lookup table for the index of a given expression.
162  DenseMap<CounterExpression, unsigned> ExpressionIndices;
163 
164  /// \brief Return the counter which corresponds to the given expression.
165  ///
166  /// If the given expression is already stored in the builder, a counter
167  /// that references that expression is returned. Otherwise, the given
168  /// expression is added to the builder's collection of expressions.
169  Counter get(const CounterExpression &E);
170 
171  /// Represents a term in a counter expression tree.
172  struct Term {
173  unsigned CounterID;
174  int Factor;
175 
176  Term(unsigned CounterID, int Factor)
177  : CounterID(CounterID), Factor(Factor) {}
178  };
179 
180  /// \brief Gather the terms of the expression tree for processing.
181  ///
182  /// This collects each addition and subtraction referenced by the counter into
183  /// a sequence that can be sorted and combined to build a simplified counter
184  /// expression.
185  void extractTerms(Counter C, int Sign, SmallVectorImpl<Term> &Terms);
186 
187  /// \brief Simplifies the given expression tree
188  /// by getting rid of algebraically redundant operations.
189  Counter simplify(Counter ExpressionTree);
190 
191 public:
192  ArrayRef<CounterExpression> getExpressions() const { return Expressions; }
193 
194  /// \brief Return a counter that represents the expression
195  /// that adds LHS and RHS.
196  Counter add(Counter LHS, Counter RHS);
197 
198  /// \brief Return a counter that represents the expression
199  /// that subtracts RHS from LHS.
200  Counter subtract(Counter LHS, Counter RHS);
201 };
202 
203 /// \brief A Counter mapping region associates a source range with
204 /// a specific counter.
206  enum RegionKind {
207  /// \brief A CodeRegion associates some code with a counter
209 
210  /// \brief An ExpansionRegion represents a file expansion region that
211  /// associates a source range with the expansion of a virtual source file,
212  /// such as for a macro instantiation or #include file.
214 
215  /// \brief A SkippedRegion represents a source range with code that
216  /// was skipped by a preprocessor or similar means.
218  };
219 
224 
226  unsigned LineStart, unsigned ColumnStart,
227  unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
228  : Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),
229  LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
230  ColumnEnd(ColumnEnd), Kind(Kind) {}
231 
232  static CounterMappingRegion
233  makeRegion(Counter Count, unsigned FileID, unsigned LineStart,
234  unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
235  return CounterMappingRegion(Count, FileID, 0, LineStart, ColumnStart,
236  LineEnd, ColumnEnd, CodeRegion);
237  }
238 
239  static CounterMappingRegion
240  makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart,
241  unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
242  return CounterMappingRegion(Counter(), FileID, ExpandedFileID, LineStart,
243  ColumnStart, LineEnd, ColumnEnd,
245  }
246 
247  static CounterMappingRegion
248  makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart,
249  unsigned LineEnd, unsigned ColumnEnd) {
250  return CounterMappingRegion(Counter(), FileID, 0, LineStart, ColumnStart,
251  LineEnd, ColumnEnd, SkippedRegion);
252  }
253 
254  inline std::pair<unsigned, unsigned> startLoc() const {
255  return std::pair<unsigned, unsigned>(LineStart, ColumnStart);
256  }
257 
258  inline std::pair<unsigned, unsigned> endLoc() const {
259  return std::pair<unsigned, unsigned>(LineEnd, ColumnEnd);
260  }
261 };
262 
263 /// \brief Associates a source range with an execution count.
265  uint64_t ExecutionCount;
266 
268  : CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}
269 };
270 
271 /// \brief A Counter mapping context is used to connect the counters,
272 /// expressions and the obtained counter values.
274  ArrayRef<CounterExpression> Expressions;
275  ArrayRef<uint64_t> CounterValues;
276 
277 public:
279  ArrayRef<uint64_t> CounterValues = None)
280  : Expressions(Expressions), CounterValues(CounterValues) {}
281 
282  void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }
283 
284  void dump(const Counter &C, raw_ostream &OS) const;
285  void dump(const Counter &C) const { dump(C, dbgs()); }
286 
287  /// \brief Return the number of times that a region of code associated with
288  /// this counter was executed.
289  Expected<int64_t> evaluate(const Counter &C) const;
290 };
291 
292 /// \brief Code coverage information for a single function.
294  /// \brief Raw function name.
295  std::string Name;
296  /// \brief Associated files.
297  std::vector<std::string> Filenames;
298  /// \brief Regions in the function along with their counts.
299  std::vector<CountedRegion> CountedRegions;
300  /// \brief The number of times this function was executed.
301  uint64_t ExecutionCount;
302 
304  : Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
305 
306  FunctionRecord(FunctionRecord &&FR) = default;
307  FunctionRecord &operator=(FunctionRecord &&) = default;
308 
309  void pushRegion(CounterMappingRegion Region, uint64_t Count) {
310  if (CountedRegions.empty())
311  ExecutionCount = Count;
312  CountedRegions.emplace_back(Region, Count);
313  }
314 };
315 
316 /// \brief Iterator over Functions, optionally filtered to a single file.
318  : public iterator_facade_base<FunctionRecordIterator,
319  std::forward_iterator_tag, FunctionRecord> {
320  ArrayRef<FunctionRecord> Records;
322  StringRef Filename;
323 
324  /// \brief Skip records whose primary file is not \c Filename.
325  void skipOtherFiles();
326 
327 public:
329  StringRef Filename = "")
330  : Records(Records_), Current(Records.begin()), Filename(Filename) {
331  skipOtherFiles();
332  }
333 
334  FunctionRecordIterator() : Current(Records.begin()) {}
335 
336  bool operator==(const FunctionRecordIterator &RHS) const {
337  return Current == RHS.Current && Filename == RHS.Filename;
338  }
339 
340  const FunctionRecord &operator*() const { return *Current; }
341 
343  assert(Current != Records.end() && "incremented past end");
344  ++Current;
345  skipOtherFiles();
346  return *this;
347  }
348 };
349 
350 /// \brief Coverage information for a macro expansion or #included file.
351 ///
352 /// When covered code has pieces that can be expanded for more detail, such as a
353 /// preprocessor macro use and its definition, these are represented as
354 /// expansions whose coverage can be looked up independently.
356  /// \brief The abstract file this expansion covers.
357  unsigned FileID;
358  /// \brief The region that expands to this record.
360  /// \brief Coverage for the expansion.
362 
364  const FunctionRecord &Function)
365  : FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}
366 };
367 
368 /// \brief The execution count information starting at a point in a file.
369 ///
370 /// A sequence of CoverageSegments gives execution counts for a file in format
371 /// that's simple to iterate through for processing.
373  /// \brief The line where this segment begins.
374  unsigned Line;
375  /// \brief The column where this segment begins.
376  unsigned Col;
377  /// \brief The execution count, or zero if no count was recorded.
378  uint64_t Count;
379  /// \brief When false, the segment was uninstrumented or skipped.
380  bool HasCount;
381  /// \brief Whether this enters a new region or returns to a previous count.
383 
384  CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
385  : Line(Line), Col(Col), Count(0), HasCount(false),
386  IsRegionEntry(IsRegionEntry) {}
387 
388  CoverageSegment(unsigned Line, unsigned Col, uint64_t Count,
389  bool IsRegionEntry)
390  : Line(Line), Col(Col), Count(Count), HasCount(true),
391  IsRegionEntry(IsRegionEntry) {}
392 
393  friend bool operator==(const CoverageSegment &L, const CoverageSegment &R) {
394  return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry) ==
395  std::tie(R.Line, R.Col, R.Count, R.HasCount, R.IsRegionEntry);
396  }
397 };
398 
399 /// \brief Coverage information to be processed or displayed.
400 ///
401 /// This represents the coverage of an entire file, expansion, or function. It
402 /// provides a sequence of CoverageSegments to iterate through, as well as the
403 /// list of expansions that can be further processed.
405  friend class CoverageMapping;
406 
407  std::string Filename;
408  std::vector<CoverageSegment> Segments;
409  std::vector<ExpansionRecord> Expansions;
410 
411 public:
412  CoverageData() = default;
413 
414  CoverageData(StringRef Filename) : Filename(Filename) {}
415 
416  /// \brief Get the name of the file this data covers.
417  StringRef getFilename() const { return Filename; }
418 
419  std::vector<CoverageSegment>::const_iterator begin() const {
420  return Segments.begin();
421  }
422 
423  std::vector<CoverageSegment>::const_iterator end() const {
424  return Segments.end();
425  }
426 
427  bool empty() const { return Segments.empty(); }
428 
429  /// \brief Expansions that can be further processed.
430  ArrayRef<ExpansionRecord> getExpansions() const { return Expansions; }
431 };
432 
433 /// \brief The mapping of profile information to coverage data.
434 ///
435 /// This is the main interface to get coverage information, using a profile to
436 /// fill out execution counts.
438  StringSet<> FunctionNames;
439  std::vector<FunctionRecord> Functions;
440  unsigned MismatchedFunctionCount = 0;
441 
442  CoverageMapping() = default;
443 
444  /// \brief Add a function record corresponding to \p Record.
445  Error loadFunctionRecord(const CoverageMappingRecord &Record,
446  IndexedInstrProfReader &ProfileReader);
447 
448 public:
449  CoverageMapping(const CoverageMapping &) = delete;
450  CoverageMapping &operator=(const CoverageMapping &) = delete;
451 
452  /// \brief Load the coverage mapping using the given readers.
454  load(ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
455  IndexedInstrProfReader &ProfileReader);
456 
458  load(ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
459  StringRef Arch = StringRef());
460 
461  /// \brief The number of functions that couldn't have their profiles mapped.
462  ///
463  /// This is a count of functions whose profile is out of date or otherwise
464  /// can't be associated with any coverage information.
465  unsigned getMismatchedCount() { return MismatchedFunctionCount; }
466 
467  /// \brief Returns a lexicographically sorted, unique list of files that are
468  /// covered.
469  std::vector<StringRef> getUniqueSourceFiles() const;
470 
471  /// \brief Get the coverage for a particular file.
472  ///
473  /// The given filename must be the name as recorded in the coverage
474  /// information. That is, only names returned from getUniqueSourceFiles will
475  /// yield a result.
476  CoverageData getCoverageForFile(StringRef Filename) const;
477 
478  /// \brief Gets all of the functions covered by this profile.
480  return make_range(FunctionRecordIterator(Functions),
482  }
483 
484  /// \brief Gets all of the functions in a particular file.
486  getCoveredFunctions(StringRef Filename) const {
487  return make_range(FunctionRecordIterator(Functions, Filename),
489  }
490 
491  /// \brief Get the list of function instantiations in the file.
492  ///
493  /// Functions that are instantiated more than once, such as C++ template
494  /// specializations, have distinct coverage records for each instantiation.
495  std::vector<const FunctionRecord *>
496  getInstantiations(StringRef Filename) const;
497 
498  /// \brief Get the coverage for a particular function.
500 
501  /// \brief Get the coverage for an expansion within a coverage set.
502  CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const;
503 };
504 
505 // Profile coverage map has the following layout:
506 // [CoverageMapFileHeader]
507 // [ArrayStart]
508 // [CovMapFunctionRecord]
509 // [CovMapFunctionRecord]
510 // ...
511 // [ArrayEnd]
512 // [Encoded Region Mapping Data]
514 template <class IntPtrT> struct CovMapFunctionRecordV1 {
515 #define COVMAP_V1
516 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
518 #undef COVMAP_V1
519 
520  // Return the structural hash associated with the function.
521  template <support::endianness Endian> uint64_t getFuncHash() const {
522  return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
523  }
524 
525  // Return the coverage map data size for the funciton.
526  template <support::endianness Endian> uint32_t getDataSize() const {
527  return support::endian::byte_swap<uint32_t, Endian>(DataSize);
528  }
529 
530  // Return function lookup key. The value is consider opaque.
531  template <support::endianness Endian> IntPtrT getFuncNameRef() const {
532  return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
533  }
534 
535  // Return the PGO name of the function */
536  template <support::endianness Endian>
537  Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
538  IntPtrT NameRef = getFuncNameRef<Endian>();
539  uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);
540  FuncName = ProfileNames.getFuncName(NameRef, NameS);
541  if (NameS && FuncName.empty())
542  return make_error<CoverageMapError>(coveragemap_error::malformed);
543  return Error::success();
544  }
545 };
546 
548 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
550 
551  // Return the structural hash associated with the function.
552  template <support::endianness Endian> uint64_t getFuncHash() const {
553  return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
554  }
555 
556  // Return the coverage map data size for the funciton.
557  template <support::endianness Endian> uint32_t getDataSize() const {
558  return support::endian::byte_swap<uint32_t, Endian>(DataSize);
559  }
560 
561  // Return function lookup key. The value is consider opaque.
562  template <support::endianness Endian> uint64_t getFuncNameRef() const {
563  return support::endian::byte_swap<uint64_t, Endian>(NameRef);
564  }
565 
566  // Return the PGO name of the function */
567  template <support::endianness Endian>
568  Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
569  uint64_t NameRef = getFuncNameRef<Endian>();
570  FuncName = ProfileNames.getFuncName(NameRef);
571  return Error::success();
572  }
573 };
574 
575 // Per module coverage mapping data header, i.e. CoverageMapFileHeader
576 // documented above.
577 struct CovMapHeader {
578 #define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;
580  template <support::endianness Endian> uint32_t getNRecords() const {
581  return support::endian::byte_swap<uint32_t, Endian>(NRecords);
582  }
583 
584  template <support::endianness Endian> uint32_t getFilenamesSize() const {
585  return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
586  }
587 
588  template <support::endianness Endian> uint32_t getCoverageSize() const {
589  return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
590  }
591 
592  template <support::endianness Endian> uint32_t getVersion() const {
593  return support::endian::byte_swap<uint32_t, Endian>(Version);
594  }
595 };
596 
598 
600  Version1 = 0,
601  // Function's name reference from CovMapFuncRecord is changed from raw
602  // name string pointer to MD5 to support name section compression. Name
603  // section is also compressed.
604  Version2 = 1,
605  // The current version is Version2
606  CurrentVersion = INSTR_PROF_COVMAP_VERSION
607 };
608 
609 template <int CovMapVersion, class IntPtrT> struct CovMapTraits {
611  using NameRefType = uint64_t;
612 };
613 
614 template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version1, IntPtrT> {
616  using NameRefType = IntPtrT;
617 };
618 
619 } // end namespace coverage
620 
621 /// \brief Provide DenseMapInfo for CounterExpression
622 template<> struct DenseMapInfo<coverage::CounterExpression> {
624  using namespace coverage;
625 
626  return CounterExpression(CounterExpression::ExprKind::Subtract,
627  Counter::getCounter(~0U),
628  Counter::getCounter(~0U));
629  }
630 
632  using namespace coverage;
633 
634  return CounterExpression(CounterExpression::ExprKind::Add,
635  Counter::getCounter(~0U),
636  Counter::getCounter(~0U));
637  }
638 
639  static unsigned getHashValue(const coverage::CounterExpression &V) {
640  return static_cast<unsigned>(
642  V.RHS.getKind(), V.RHS.getCounterID()));
643  }
644 
645  static bool isEqual(const coverage::CounterExpression &LHS,
646  const coverage::CounterExpression &RHS) {
647  return LHS.Kind == RHS.Kind && LHS.LHS == RHS.LHS && LHS.RHS == RHS.RHS;
648  }
649 };
650 
651 } // end namespace llvm
652 
653 #endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
MachineLoop * L
StringRef getFilename() const
Get the name of the file this data covers.
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
static coverage::CounterExpression getTombstoneKey()
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:410
bool operator==(const FunctionRecordIterator &RHS) const
static const unsigned EncodingTagMask
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:234
static Counter getZero()
Return the counter that represents the number zero.
CoverageMapping & operator=(const CoverageMapping &)=delete
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count, bool IsRegionEntry)
std::vector< const FunctionRecord * > getInstantiations(StringRef Filename) const
Get the list of function instantiations in the file.
static CounterMappingRegion makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
void setCounts(ArrayRef< uint64_t > Counts)
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
Expected< int64_t > evaluate(const Counter &C) const
Return the number of times that a region of code associated with this counter was executed...
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
CoverageData getCoverageForFunction(const FunctionRecord &Function) const
Get the coverage for a particular function.
static bool isEqual(const coverage::CounterExpression &LHS, const coverage::CounterExpression &RHS)
static int Counter
iterator_range< FunctionRecordIterator > getCoveredFunctions(StringRef Filename) const
Gets all of the functions in a particular file.
std::error_code make_error_code(coveragemap_error E)
friend bool operator==(const Counter &LHS, const Counter &RHS)
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const
Get the coverage for an expansion within a coverage set.
void pushRegion(CounterMappingRegion Region, uint64_t Count)
A Counter expression is a value that represents an arithmetic operation with two counters.
FunctionRecord(StringRef Name, ArrayRef< StringRef > Filenames)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
friend bool operator!=(const Counter &LHS, const Counter &RHS)
friend bool operator<(const Counter &LHS, const Counter &RHS)
friend bool operator==(const CoverageSegment &L, const CoverageSegment &R)
Iterator over Functions, optionally filtered to a single file.
unsigned Col
The column where this segment begins.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
const CountedRegion & Region
The region that expands to this record.
uint32_t getCoverageSize() const
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize)
Return function's PGO name from the function name's symbol address in the object file.
std::vector< CoverageSegment >::const_iterator begin() const
static Expected< std::unique_ptr< CoverageMapping > > load(ArrayRef< std::unique_ptr< CoverageMappingReader >> CoverageReaders, IndexedInstrProfReader &ProfileReader)
Load the coverage mapping using the given readers.
Coverage information to be processed or displayed.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
CoverageMapError(coveragemap_error Err)
Counter add(Counter LHS, Counter RHS)
Return a counter that represents the expression that adds LHS and RHS.
static CounterMappingRegion makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
iterator_range< FunctionRecordIterator > getCoveredFunctions() const
Gets all of the functions covered by this profile.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:68
const std::error_category & coveragemap_category()
unsigned getExpressionID() const
Function Alias Analysis false
The execution count information starting at a point in a file.
static CounterMappingRegion makeRegion(Counter Count, unsigned FileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd)
Coverage mapping information for a single function.
uint64_t ExecutionCount
The number of times this function was executed.
unsigned getMismatchedCount()
The number of functions that couldn't have their profiles mapped.
void dump(const Counter &C, raw_ostream &OS) const
CounterKind getKind() const
CoverageData getCoverageForFile(StringRef Filename) const
Get the coverage for a particular file.
A CodeRegion associates some code with a counter.
A Counter mapping context is used to connect the counters, expressions and the obtained counter value...
unsigned getCounterID() const
A Counter mapping region associates a source range with a specific counter.
bool IsRegionEntry
Whether this enters a new region or returns to a previous count.
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:74
CounterMappingRegion(Counter Count, unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
Associates a source range with an execution count.
std::pair< unsigned, unsigned > startLoc() const
static coverage::CounterExpression getEmptyKey()
Counter subtract(Counter LHS, Counter RHS)
Return a counter that represents the expression that subtracts RHS from LHS.
static unsigned getHashValue(const coverage::CounterExpression &V)
CounterExpression(ExprKind Kind, Counter LHS, Counter RHS)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Code coverage information for a single function.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
#define E
Definition: LargeTest.cpp:27
FunctionRecordIterator(ArrayRef< FunctionRecord > Records_, StringRef Filename="")
std::vector< CoverageSegment >::const_iterator end() const
ExpansionRecord(const CountedRegion &Region, const FunctionRecord &Function)
uint64_t Count
The execution count, or zero if no count was recorded.
bool HasCount
When false, the segment was uninstrumented or skipped.
An ExpansionRegion represents a file expansion region that associates a source range with the expansi...
A SkippedRegion represents a source range with code that was skipped by a preprocessor or similar mea...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
uint32_t getFilenamesSize() const
A range adaptor for a pair of iterators.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:602
Base class for user error types.
Definition: Error.h:329
static const unsigned EncodingCounterTagAndExpansionRegionTagBits
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const
The mapping of profile information to coverage data.
unsigned Line
The line where this segment begins.
CoverageData(StringRef Filename)
Basic Alias true
std::string message() const override
Return the error message as a string.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
#define C
Definition: LargeTest.cpp:25
CounterMappingContext(ArrayRef< CounterExpression > Expressions, ArrayRef< uint64_t > CounterValues=None)
std::vector< CountedRegion > CountedRegions
Regions in the function along with their counts.
#define LLVM_PACKED_START
Definition: Compiler.h:349
std::string Name
Raw function name.
unsigned FileID
The abstract file this expansion covers.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const unsigned EncodingTagBits
ArrayRef< CounterExpression > getExpressions() const
FunctionRecord & operator=(FunctionRecord &&)=default
std::vector< std::string > Filenames
Associated files.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:28
std::pair< unsigned, unsigned > endLoc() const
const FunctionRecord & operator*() const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
void dump(const Counter &C) const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Reader for the indexed binary instrprof format.
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.
A Counter expression builder is used to construct the counter expressions.
std::vector< StringRef > getUniqueSourceFiles() const
Returns a lexicographically sorted, unique list of files that are covered.
ArrayRef< ExpansionRecord > getExpansions() const
Expansions that can be further processed.
A Counter is an abstract value that describes how to compute the execution count for a region of code...
const uint64_t Version
Definition: InstrProf.h:864
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
const FunctionRecord & Function
Coverage for the expansion.
#define LLVM_PACKED_END
Definition: Compiler.h:350
Coverage information for a macro expansion or #included file.
FunctionRecordIterator & operator++()