LLVM  4.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_COVERAGEMAPPING_H_
16 #define LLVM_PROFILEDATA_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/StringSet.h"
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/ADT/iterator.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/Endian.h"
28 #include <system_error>
29 #include <tuple>
30 
31 namespace llvm {
32 namespace coverage {
33 
34 enum class coveragemap_error {
35  success = 0,
36  eof,
39  truncated,
40  malformed
41 };
42 
44 
45 inline std::error_code make_error_code(coveragemap_error E) {
46  return std::error_code(static_cast<int>(E), coveragemap_category());
47 }
48 
49 class CoverageMapError : public ErrorInfo<CoverageMapError> {
50 public:
52  assert(Err != coveragemap_error::success && "Not an error");
53  }
54 
55  std::string message() const override;
56 
57  void log(raw_ostream &OS) const override { OS << message(); }
58 
59  std::error_code convertToErrorCode() const override {
60  return make_error_code(Err);
61  }
62 
63  coveragemap_error get() const { return Err; }
64 
65  static char ID;
66 
67 private:
69 };
70 
71 } // end of coverage namespace.
72 } // end of llvm namespace
73 
74 namespace llvm {
75 class IndexedInstrProfReader;
76 namespace coverage {
77 
78 class CoverageMappingReader;
79 struct CoverageMappingRecord;
80 
81 class CoverageMapping;
82 struct CounterExpressions;
83 
84 /// \brief A Counter is an abstract value that describes how to compute the
85 /// execution count for a region of code using the collected profile count data.
86 struct Counter {
88  static const unsigned EncodingTagBits = 2;
89  static const unsigned EncodingTagMask = 0x3;
91  EncodingTagBits + 1;
92 
93 private:
94  CounterKind Kind;
95  unsigned ID;
96 
97  Counter(CounterKind Kind, unsigned ID) : Kind(Kind), ID(ID) {}
98 
99 public:
100  Counter() : Kind(Zero), ID(0) {}
101 
102  CounterKind getKind() const { return Kind; }
103 
104  bool isZero() const { return Kind == Zero; }
105 
106  bool isExpression() const { return Kind == Expression; }
107 
108  unsigned getCounterID() const { return ID; }
109 
110  unsigned getExpressionID() const { return ID; }
111 
112  friend bool operator==(const Counter &LHS, const Counter &RHS) {
113  return LHS.Kind == RHS.Kind && LHS.ID == RHS.ID;
114  }
115 
116  friend bool operator!=(const Counter &LHS, const Counter &RHS) {
117  return !(LHS == RHS);
118  }
119 
120  friend bool operator<(const Counter &LHS, const Counter &RHS) {
121  return std::tie(LHS.Kind, LHS.ID) < std::tie(RHS.Kind, RHS.ID);
122  }
123 
124  /// \brief Return the counter that represents the number zero.
125  static Counter getZero() { return Counter(); }
126 
127  /// \brief Return the counter that corresponds to a specific profile counter.
128  static Counter getCounter(unsigned CounterId) {
129  return Counter(CounterValueReference, CounterId);
130  }
131 
132  /// \brief Return the counter that corresponds to a specific
133  /// addition counter expression.
134  static Counter getExpression(unsigned ExpressionId) {
135  return Counter(Expression, ExpressionId);
136  }
137 };
138 
139 /// \brief A Counter expression is a value that represents an arithmetic
140 /// operation with two counters.
142  enum ExprKind { Subtract, Add };
145 
147  : Kind(Kind), LHS(LHS), RHS(RHS) {}
148 };
149 
150 /// \brief A Counter expression builder is used to construct the
151 /// counter expressions. It avoids unnecessary duplication
152 /// and simplifies algebraic expressions.
154  /// \brief A list of all the counter expressions
155  std::vector<CounterExpression> Expressions;
156  /// \brief A lookup table for the index of a given expression.
158 
159  /// \brief Return the counter which corresponds to the given expression.
160  ///
161  /// If the given expression is already stored in the builder, a counter
162  /// that references that expression is returned. Otherwise, the given
163  /// expression is added to the builder's collection of expressions.
164  Counter get(const CounterExpression &E);
165 
166  /// \brief Gather the terms of the expression tree for processing.
167  ///
168  /// This collects each addition and subtraction referenced by the counter into
169  /// a sequence that can be sorted and combined to build a simplified counter
170  /// expression.
171  void extractTerms(Counter C, int Sign,
172  SmallVectorImpl<std::pair<unsigned, int>> &Terms);
173 
174  /// \brief Simplifies the given expression tree
175  /// by getting rid of algebraically redundant operations.
176  Counter simplify(Counter ExpressionTree);
177 
178 public:
179  ArrayRef<CounterExpression> getExpressions() const { return Expressions; }
180 
181  /// \brief Return a counter that represents the expression
182  /// that adds LHS and RHS.
183  Counter add(Counter LHS, Counter RHS);
184 
185  /// \brief Return a counter that represents the expression
186  /// that subtracts RHS from LHS.
187  Counter subtract(Counter LHS, Counter RHS);
188 };
189 
190 /// \brief A Counter mapping region associates a source range with
191 /// a specific counter.
193  enum RegionKind {
194  /// \brief A CodeRegion associates some code with a counter
196 
197  /// \brief An ExpansionRegion represents a file expansion region that
198  /// associates a source range with the expansion of a virtual source file,
199  /// such as for a macro instantiation or #include file.
201 
202  /// \brief A SkippedRegion represents a source range with code that
203  /// was skipped by a preprocessor or similar means.
205  };
206 
211 
213  unsigned LineStart, unsigned ColumnStart,
214  unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
215  : Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),
216  LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
217  ColumnEnd(ColumnEnd), Kind(Kind) {}
218 
219  static CounterMappingRegion
220  makeRegion(Counter Count, unsigned FileID, unsigned LineStart,
221  unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
222  return CounterMappingRegion(Count, FileID, 0, LineStart, ColumnStart,
223  LineEnd, ColumnEnd, CodeRegion);
224  }
225 
226  static CounterMappingRegion
227  makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart,
228  unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {
229  return CounterMappingRegion(Counter(), FileID, ExpandedFileID, LineStart,
230  ColumnStart, LineEnd, ColumnEnd,
232  }
233 
234  static CounterMappingRegion
235  makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart,
236  unsigned LineEnd, unsigned ColumnEnd) {
237  return CounterMappingRegion(Counter(), FileID, 0, LineStart, ColumnStart,
238  LineEnd, ColumnEnd, SkippedRegion);
239  }
240 
241 
242  inline std::pair<unsigned, unsigned> startLoc() const {
243  return std::pair<unsigned, unsigned>(LineStart, ColumnStart);
244  }
245 
246  inline std::pair<unsigned, unsigned> endLoc() const {
247  return std::pair<unsigned, unsigned>(LineEnd, ColumnEnd);
248  }
249 };
250 
251 /// \brief Associates a source range with an execution count.
253  uint64_t ExecutionCount;
254 
256  : CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}
257 };
258 
259 /// \brief A Counter mapping context is used to connect the counters,
260 /// expressions and the obtained counter values.
262  ArrayRef<CounterExpression> Expressions;
263  ArrayRef<uint64_t> CounterValues;
264 
265 public:
267  ArrayRef<uint64_t> CounterValues = None)
268  : Expressions(Expressions), CounterValues(CounterValues) {}
269 
270  void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }
271 
272  void dump(const Counter &C, llvm::raw_ostream &OS) const;
273  void dump(const Counter &C) const { dump(C, dbgs()); }
274 
275  /// \brief Return the number of times that a region of code associated with
276  /// this counter was executed.
277  Expected<int64_t> evaluate(const Counter &C) const;
278 };
279 
280 /// \brief Code coverage information for a single function.
282  /// \brief Raw function name.
283  std::string Name;
284  /// \brief Associated files.
285  std::vector<std::string> Filenames;
286  /// \brief Regions in the function along with their counts.
287  std::vector<CountedRegion> CountedRegions;
288  /// \brief The number of times this function was executed.
289  uint64_t ExecutionCount;
290 
292  : Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
293 
294  FunctionRecord(FunctionRecord &&FR) = default;
295  FunctionRecord &operator=(FunctionRecord &&) = default;
296 
297  void pushRegion(CounterMappingRegion Region, uint64_t Count) {
298  if (CountedRegions.empty())
299  ExecutionCount = Count;
300  CountedRegions.emplace_back(Region, Count);
301  }
302 };
303 
304 /// \brief Iterator over Functions, optionally filtered to a single file.
306  : public iterator_facade_base<FunctionRecordIterator,
307  std::forward_iterator_tag, FunctionRecord> {
308  ArrayRef<FunctionRecord> Records;
310  StringRef Filename;
311 
312  /// \brief Skip records whose primary file is not \c Filename.
313  void skipOtherFiles();
314 
315 public:
317  StringRef Filename = "")
318  : Records(Records_), Current(Records.begin()), Filename(Filename) {
319  skipOtherFiles();
320  }
321 
322  FunctionRecordIterator() : Current(Records.begin()) {}
323 
324  bool operator==(const FunctionRecordIterator &RHS) const {
325  return Current == RHS.Current && Filename == RHS.Filename;
326  }
327 
328  const FunctionRecord &operator*() const { return *Current; }
329 
331  assert(Current != Records.end() && "incremented past end");
332  ++Current;
333  skipOtherFiles();
334  return *this;
335  }
336 };
337 
338 /// \brief Coverage information for a macro expansion or #included file.
339 ///
340 /// When covered code has pieces that can be expanded for more detail, such as a
341 /// preprocessor macro use and its definition, these are represented as
342 /// expansions whose coverage can be looked up independently.
344  /// \brief The abstract file this expansion covers.
345  unsigned FileID;
346  /// \brief The region that expands to this record.
348  /// \brief Coverage for the expansion.
350 
352  const FunctionRecord &Function)
353  : FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}
354 };
355 
356 /// \brief The execution count information starting at a point in a file.
357 ///
358 /// A sequence of CoverageSegments gives execution counts for a file in format
359 /// that's simple to iterate through for processing.
361  /// \brief The line where this segment begins.
362  unsigned Line;
363  /// \brief The column where this segment begins.
364  unsigned Col;
365  /// \brief The execution count, or zero if no count was recorded.
366  uint64_t Count;
367  /// \brief When false, the segment was uninstrumented or skipped.
368  bool HasCount;
369  /// \brief Whether this enters a new region or returns to a previous count.
371 
372  CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
373  : Line(Line), Col(Col), Count(0), HasCount(false),
374  IsRegionEntry(IsRegionEntry) {}
375 
376  CoverageSegment(unsigned Line, unsigned Col, uint64_t Count,
377  bool IsRegionEntry)
378  : Line(Line), Col(Col), Count(Count), HasCount(true),
379  IsRegionEntry(IsRegionEntry) {}
380 
381  friend bool operator==(const CoverageSegment &L, const CoverageSegment &R) {
382  return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry) ==
383  std::tie(R.Line, R.Col, R.Count, R.HasCount, R.IsRegionEntry);
384  }
385 };
386 
387 /// \brief Coverage information to be processed or displayed.
388 ///
389 /// This represents the coverage of an entire file, expansion, or function. It
390 /// provides a sequence of CoverageSegments to iterate through, as well as the
391 /// list of expansions that can be further processed.
393  std::string Filename;
394  std::vector<CoverageSegment> Segments;
395  std::vector<ExpansionRecord> Expansions;
396  friend class CoverageMapping;
397 
398 public:
400 
401  CoverageData(StringRef Filename) : Filename(Filename) {}
402 
403  /// \brief Get the name of the file this data covers.
404  StringRef getFilename() const { return Filename; }
405 
406  std::vector<CoverageSegment>::const_iterator begin() const {
407  return Segments.begin();
408  }
409  std::vector<CoverageSegment>::const_iterator end() const {
410  return Segments.end();
411  }
412  bool empty() const { return Segments.empty(); }
413 
414  /// \brief Expansions that can be further processed.
415  ArrayRef<ExpansionRecord> getExpansions() const { return Expansions; }
416 };
417 
418 /// \brief The mapping of profile information to coverage data.
419 ///
420 /// This is the main interface to get coverage information, using a profile to
421 /// fill out execution counts.
423  StringSet<> FunctionNames;
424  std::vector<FunctionRecord> Functions;
425  unsigned MismatchedFunctionCount;
426 
427  CoverageMapping() : MismatchedFunctionCount(0) {}
428 
429  CoverageMapping(const CoverageMapping &) = delete;
430  const CoverageMapping &operator=(const CoverageMapping &) = delete;
431 
432  /// \brief Add a function record corresponding to \p Record.
433  Error loadFunctionRecord(const CoverageMappingRecord &Record,
434  IndexedInstrProfReader &ProfileReader);
435 
436 public:
437  /// \brief Load the coverage mapping using the given readers.
439  load(CoverageMappingReader &CoverageReader,
440  IndexedInstrProfReader &ProfileReader);
441 
443  load(ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
444  IndexedInstrProfReader &ProfileReader);
445 
446  /// \brief Load the coverage mapping from the given files.
448  load(StringRef ObjectFilename, StringRef ProfileFilename,
449  StringRef Arch = StringRef()) {
450  return load(ArrayRef<StringRef>(ObjectFilename), ProfileFilename, Arch);
451  }
452 
454  load(ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
455  StringRef Arch = StringRef());
456 
457  /// \brief The number of functions that couldn't have their profiles mapped.
458  ///
459  /// This is a count of functions whose profile is out of date or otherwise
460  /// can't be associated with any coverage information.
461  unsigned getMismatchedCount() { return MismatchedFunctionCount; }
462 
463  /// \brief Returns a lexicographically sorted, unique list of files that are
464  /// covered.
465  std::vector<StringRef> getUniqueSourceFiles() const;
466 
467  /// \brief Get the coverage for a particular file.
468  ///
469  /// The given filename must be the name as recorded in the coverage
470  /// information. That is, only names returned from getUniqueSourceFiles will
471  /// yield a result.
472  CoverageData getCoverageForFile(StringRef Filename) const;
473 
474  /// \brief Gets all of the functions covered by this profile.
476  return make_range(FunctionRecordIterator(Functions),
478  }
479 
480  /// \brief Gets all of the functions in a particular file.
482  getCoveredFunctions(StringRef Filename) const {
483  return make_range(FunctionRecordIterator(Functions, Filename),
485  }
486 
487  /// \brief Get the list of function instantiations in the file.
488  ///
489  /// Functions that are instantiated more than once, such as C++ template
490  /// specializations, have distinct coverage records for each instantiation.
491  std::vector<const FunctionRecord *>
492  getInstantiations(StringRef Filename) const;
493 
494  /// \brief Get the coverage for a particular function.
496 
497  /// \brief Get the coverage for an expansion within a coverage set.
498  CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const;
499 };
500 
501 // Profile coverage map has the following layout:
502 // [CoverageMapFileHeader]
503 // [ArrayStart]
504 // [CovMapFunctionRecord]
505 // [CovMapFunctionRecord]
506 // ...
507 // [ArrayEnd]
508 // [Encoded Region Mapping Data]
510 template <class IntPtrT> struct CovMapFunctionRecordV1 {
511 #define COVMAP_V1
512 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
514 #undef COVMAP_V1
515 
516  // Return the structural hash associated with the function.
517  template <support::endianness Endian> uint64_t getFuncHash() const {
518  return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
519  }
520  // Return the coverage map data size for the funciton.
521  template <support::endianness Endian> uint32_t getDataSize() const {
522  return support::endian::byte_swap<uint32_t, Endian>(DataSize);
523  }
524  // Return function lookup key. The value is consider opaque.
525  template <support::endianness Endian> IntPtrT getFuncNameRef() const {
526  return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
527  }
528  // Return the PGO name of the function */
529  template <support::endianness Endian>
530  Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
531  IntPtrT NameRef = getFuncNameRef<Endian>();
532  uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);
533  FuncName = ProfileNames.getFuncName(NameRef, NameS);
534  if (NameS && FuncName.empty())
535  return make_error<CoverageMapError>(coveragemap_error::malformed);
536  return Error::success();
537  }
538 };
539 
541 #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;
543 
544  // Return the structural hash associated with the function.
545  template <support::endianness Endian> uint64_t getFuncHash() const {
546  return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
547  }
548  // Return the coverage map data size for the funciton.
549  template <support::endianness Endian> uint32_t getDataSize() const {
550  return support::endian::byte_swap<uint32_t, Endian>(DataSize);
551  }
552  // Return function lookup key. The value is consider opaque.
553  template <support::endianness Endian> uint64_t getFuncNameRef() const {
554  return support::endian::byte_swap<uint64_t, Endian>(NameRef);
555  }
556  // Return the PGO name of the function */
557  template <support::endianness Endian>
558  Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
559  uint64_t NameRef = getFuncNameRef<Endian>();
560  FuncName = ProfileNames.getFuncName(NameRef);
561  return Error::success();
562  }
563 };
564 
565 // Per module coverage mapping data header, i.e. CoverageMapFileHeader
566 // documented above.
567 struct CovMapHeader {
568 #define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;
570  template <support::endianness Endian> uint32_t getNRecords() const {
571  return support::endian::byte_swap<uint32_t, Endian>(NRecords);
572  }
573  template <support::endianness Endian> uint32_t getFilenamesSize() const {
574  return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
575  }
576  template <support::endianness Endian> uint32_t getCoverageSize() const {
577  return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
578  }
579  template <support::endianness Endian> uint32_t getVersion() const {
580  return support::endian::byte_swap<uint32_t, Endian>(Version);
581  }
582 };
583 
585 
587  Version1 = 0,
588  // Function's name reference from CovMapFuncRecord is changed from raw
589  // name string pointer to MD5 to support name section compression. Name
590  // section is also compressed.
591  Version2 = 1,
592  // The current version is Version2
593  CurrentVersion = INSTR_PROF_COVMAP_VERSION
594 };
595 
596 template <int CovMapVersion, class IntPtrT> struct CovMapTraits {
598  typedef uint64_t NameRefType;
599 };
600 
601 template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version1, IntPtrT> {
603  typedef IntPtrT NameRefType;
604 };
605 
606 } // end namespace coverage
607 
608 /// \brief Provide DenseMapInfo for CounterExpression
609 template<> struct DenseMapInfo<coverage::CounterExpression> {
611  using namespace coverage;
612  return CounterExpression(CounterExpression::ExprKind::Subtract,
613  Counter::getCounter(~0U),
614  Counter::getCounter(~0U));
615  }
616 
618  using namespace coverage;
619  return CounterExpression(CounterExpression::ExprKind::Add,
620  Counter::getCounter(~0U),
621  Counter::getCounter(~0U));
622  }
623 
624  static unsigned getHashValue(const coverage::CounterExpression &V) {
625  return static_cast<unsigned>(
627  V.RHS.getKind(), V.RHS.getCounterID()));
628  }
629 
630  static bool isEqual(const coverage::CounterExpression &LHS,
631  const coverage::CounterExpression &RHS) {
632  return LHS.Kind == RHS.Kind && LHS.LHS == RHS.LHS && LHS.RHS == RHS.RHS;
633  }
634 };
635 
636 } // end namespace llvm
637 
638 #endif // LLVM_PROFILEDATA_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:241
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:416
bool operator==(const FunctionRecordIterator &RHS) const
static const unsigned EncodingTagMask
static Counter getZero()
Return the counter that represents the number zero.
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...
CovMapFunctionRecord CovMapFuncRecordType
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)
const_iterator begin(StringRef path)
Get begin iterator over path.
Definition: Path.cpp:233
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)
static Expected< std::unique_ptr< CoverageMapping > > load(StringRef ObjectFilename, StringRef ProfileFilename, StringRef Arch=StringRef())
Load the coverage mapping from the given files.
Iterator over Functions, optionally filtered to a single file.
static Expected< std::unique_ptr< CoverageMapping > > load(CoverageMappingReader &CoverageReader, IndexedInstrProfReader &ProfileReader)
Load the coverage mapping using the given readers.
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:32
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
Tagged union holding either a T or a Error.
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
Function Alias Analysis false
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:65
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
const std::error_category & coveragemap_category()
unsigned getExpressionID() const
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, llvm::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
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.
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...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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.
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.
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:353
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.
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:23
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:47
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:799
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:354
Coverage information for a macro expansion or #included file.
FunctionRecordIterator & operator++()