LLVM  5.0.0
CoverageMapping.cpp
Go to the documentation of this file.
1 //===- CoverageMapping.cpp - Code coverage mapping support ----------------===//
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 clang's and llvm's instrumentation based
11 // code coverage.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/None.h"
19 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/Errc.h"
27 #include "llvm/Support/Error.h"
32 #include <algorithm>
33 #include <cassert>
34 #include <cstdint>
35 #include <iterator>
36 #include <memory>
37 #include <string>
38 #include <system_error>
39 #include <utility>
40 #include <vector>
41 
42 using namespace llvm;
43 using namespace coverage;
44 
45 #define DEBUG_TYPE "coverage-mapping"
46 
47 Counter CounterExpressionBuilder::get(const CounterExpression &E) {
48  auto It = ExpressionIndices.find(E);
49  if (It != ExpressionIndices.end())
50  return Counter::getExpression(It->second);
51  unsigned I = Expressions.size();
52  Expressions.push_back(E);
53  ExpressionIndices[E] = I;
54  return Counter::getExpression(I);
55 }
56 
57 void CounterExpressionBuilder::extractTerms(Counter C, int Factor,
58  SmallVectorImpl<Term> &Terms) {
59  switch (C.getKind()) {
60  case Counter::Zero:
61  break;
63  Terms.emplace_back(C.getCounterID(), Factor);
64  break;
66  const auto &E = Expressions[C.getExpressionID()];
67  extractTerms(E.LHS, Factor, Terms);
68  extractTerms(
69  E.RHS, E.Kind == CounterExpression::Subtract ? -Factor : Factor, Terms);
70  break;
71  }
72 }
73 
74 Counter CounterExpressionBuilder::simplify(Counter ExpressionTree) {
75  // Gather constant terms.
77  extractTerms(ExpressionTree, +1, Terms);
78 
79  // If there are no terms, this is just a zero. The algorithm below assumes at
80  // least one term.
81  if (Terms.size() == 0)
82  return Counter::getZero();
83 
84  // Group the terms by counter ID.
85  std::sort(Terms.begin(), Terms.end(), [](const Term &LHS, const Term &RHS) {
86  return LHS.CounterID < RHS.CounterID;
87  });
88 
89  // Combine terms by counter ID to eliminate counters that sum to zero.
90  auto Prev = Terms.begin();
91  for (auto I = Prev + 1, E = Terms.end(); I != E; ++I) {
92  if (I->CounterID == Prev->CounterID) {
93  Prev->Factor += I->Factor;
94  continue;
95  }
96  ++Prev;
97  *Prev = *I;
98  }
99  Terms.erase(++Prev, Terms.end());
100 
101  Counter C;
102  // Create additions. We do this before subtractions to avoid constructs like
103  // ((0 - X) + Y), as opposed to (Y - X).
104  for (auto T : Terms) {
105  if (T.Factor <= 0)
106  continue;
107  for (int I = 0; I < T.Factor; ++I)
108  if (C.isZero())
109  C = Counter::getCounter(T.CounterID);
110  else
112  Counter::getCounter(T.CounterID)));
113  }
114 
115  // Create subtractions.
116  for (auto T : Terms) {
117  if (T.Factor >= 0)
118  continue;
119  for (int I = 0; I < -T.Factor; ++I)
121  Counter::getCounter(T.CounterID)));
122  }
123  return C;
124 }
125 
127  return simplify(get(CounterExpression(CounterExpression::Add, LHS, RHS)));
128 }
129 
131  return simplify(
133 }
134 
136  switch (C.getKind()) {
137  case Counter::Zero:
138  OS << '0';
139  return;
141  OS << '#' << C.getCounterID();
142  break;
143  case Counter::Expression: {
144  if (C.getExpressionID() >= Expressions.size())
145  return;
146  const auto &E = Expressions[C.getExpressionID()];
147  OS << '(';
148  dump(E.LHS, OS);
149  OS << (E.Kind == CounterExpression::Subtract ? " - " : " + ");
150  dump(E.RHS, OS);
151  OS << ')';
152  break;
153  }
154  }
155  if (CounterValues.empty())
156  return;
158  if (auto E = Value.takeError()) {
159  consumeError(std::move(E));
160  return;
161  }
162  OS << '[' << *Value << ']';
163 }
164 
166  switch (C.getKind()) {
167  case Counter::Zero:
168  return 0;
170  if (C.getCounterID() >= CounterValues.size())
172  return CounterValues[C.getCounterID()];
173  case Counter::Expression: {
174  if (C.getExpressionID() >= Expressions.size())
176  const auto &E = Expressions[C.getExpressionID()];
177  Expected<int64_t> LHS = evaluate(E.LHS);
178  if (!LHS)
179  return LHS;
180  Expected<int64_t> RHS = evaluate(E.RHS);
181  if (!RHS)
182  return RHS;
183  return E.Kind == CounterExpression::Subtract ? *LHS - *RHS : *LHS + *RHS;
184  }
185  }
186  llvm_unreachable("Unhandled CounterKind");
187 }
188 
189 void FunctionRecordIterator::skipOtherFiles() {
190  while (Current != Records.end() && !Filename.empty() &&
191  Filename != Current->Filenames[0])
192  ++Current;
193  if (Current == Records.end())
194  *this = FunctionRecordIterator();
195 }
196 
197 Error CoverageMapping::loadFunctionRecord(
199  IndexedInstrProfReader &ProfileReader) {
200  StringRef OrigFuncName = Record.FunctionName;
201  if (OrigFuncName.empty())
202  return make_error<CoverageMapError>(coveragemap_error::malformed);
203 
204  if (Record.Filenames.empty())
205  OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
206  else
207  OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
208 
209  // Don't load records for functions we've already seen.
210  if (!FunctionNames.insert(OrigFuncName).second)
211  return Error::success();
212 
214 
215  std::vector<uint64_t> Counts;
216  if (Error E = ProfileReader.getFunctionCounts(Record.FunctionName,
217  Record.FunctionHash, Counts)) {
218  instrprof_error IPE = InstrProfError::take(std::move(E));
219  if (IPE == instrprof_error::hash_mismatch) {
220  MismatchedFunctionCount++;
221  return Error::success();
222  } else if (IPE != instrprof_error::unknown_function)
223  return make_error<InstrProfError>(IPE);
224  Counts.assign(Record.MappingRegions.size(), 0);
225  }
226  Ctx.setCounts(Counts);
227 
228  assert(!Record.MappingRegions.empty() && "Function has no regions");
229 
230  FunctionRecord Function(OrigFuncName, Record.Filenames);
231  for (const auto &Region : Record.MappingRegions) {
232  Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
233  if (auto E = ExecutionCount.takeError()) {
234  consumeError(std::move(E));
235  return Error::success();
236  }
237  Function.pushRegion(Region, *ExecutionCount);
238  }
239  if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
240  MismatchedFunctionCount++;
241  return Error::success();
242  }
243 
244  Functions.push_back(std::move(Function));
245  return Error::success();
246 }
247 
249  ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
250  IndexedInstrProfReader &ProfileReader) {
251  auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
252 
253  for (const auto &CoverageReader : CoverageReaders)
254  for (const auto &Record : *CoverageReader)
255  if (Error E = Coverage->loadFunctionRecord(Record, ProfileReader))
256  return std::move(E);
257 
258  return std::move(Coverage);
259 }
260 
263  StringRef ProfileFilename, StringRef Arch) {
264  auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);
265  if (Error E = ProfileReaderOrErr.takeError())
266  return std::move(E);
267  auto ProfileReader = std::move(ProfileReaderOrErr.get());
268 
271  for (StringRef ObjectFilename : ObjectFilenames) {
272  auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
273  if (std::error_code EC = CovMappingBufOrErr.getError())
274  return errorCodeToError(EC);
275  auto CoverageReaderOrErr =
276  BinaryCoverageReader::create(CovMappingBufOrErr.get(), Arch);
277  if (Error E = CoverageReaderOrErr.takeError())
278  return std::move(E);
279  Readers.push_back(std::move(CoverageReaderOrErr.get()));
280  Buffers.push_back(std::move(CovMappingBufOrErr.get()));
281  }
282  return load(Readers, *ProfileReader);
283 }
284 
285 namespace {
286 
287 /// \brief Distributes functions into instantiation sets.
288 ///
289 /// An instantiation set is a collection of functions that have the same source
290 /// code, ie, template functions specializations.
291 class FunctionInstantiationSetCollector {
293  std::vector<const FunctionRecord *>>;
294  MapT InstantiatedFunctions;
295 
296 public:
297  void insert(const FunctionRecord &Function, unsigned FileID) {
298  auto I = Function.CountedRegions.begin(), E = Function.CountedRegions.end();
299  while (I != E && I->FileID != FileID)
300  ++I;
301  assert(I != E && "function does not cover the given file");
302  auto &Functions = InstantiatedFunctions[I->startLoc()];
303  Functions.push_back(&Function);
304  }
305 
306  MapT::iterator begin() { return InstantiatedFunctions.begin(); }
307  MapT::iterator end() { return InstantiatedFunctions.end(); }
308 };
309 
310 class SegmentBuilder {
311  std::vector<CoverageSegment> &Segments;
313 
314  SegmentBuilder(std::vector<CoverageSegment> &Segments) : Segments(Segments) {}
315 
316  /// Start a segment with no count specified.
317  void startSegment(unsigned Line, unsigned Col) {
318  DEBUG(dbgs() << "Top level segment at " << Line << ":" << Col << "\n");
319  Segments.emplace_back(Line, Col, /*IsRegionEntry=*/false);
320  }
321 
322  /// Start a segment with the given Region's count.
323  void startSegment(unsigned Line, unsigned Col, bool IsRegionEntry,
324  const CountedRegion &Region) {
325  // Avoid creating empty regions.
326  if (!Segments.empty() && Segments.back().Line == Line &&
327  Segments.back().Col == Col)
328  Segments.pop_back();
329  DEBUG(dbgs() << "Segment at " << Line << ":" << Col);
330  // Set this region's count.
332  DEBUG(dbgs() << " with count " << Region.ExecutionCount);
333  Segments.emplace_back(Line, Col, Region.ExecutionCount, IsRegionEntry);
334  } else
335  Segments.emplace_back(Line, Col, IsRegionEntry);
336  DEBUG(dbgs() << "\n");
337  }
338 
339  /// Start a segment for the given region.
340  void startSegment(const CountedRegion &Region) {
341  startSegment(Region.LineStart, Region.ColumnStart, true, Region);
342  }
343 
344  /// Pop the top region off of the active stack, starting a new segment with
345  /// the containing Region's count.
346  void popRegion() {
347  const CountedRegion *Active = ActiveRegions.back();
348  unsigned Line = Active->LineEnd, Col = Active->ColumnEnd;
349  ActiveRegions.pop_back();
350  if (ActiveRegions.empty())
351  startSegment(Line, Col);
352  else
353  startSegment(Line, Col, false, *ActiveRegions.back());
354  }
355 
356  void buildSegmentsImpl(ArrayRef<CountedRegion> Regions) {
357  for (const auto &Region : Regions) {
358  // Pop any regions that end before this one starts.
359  while (!ActiveRegions.empty() &&
360  ActiveRegions.back()->endLoc() <= Region.startLoc())
361  popRegion();
362  // Add this region to the stack.
363  ActiveRegions.push_back(&Region);
364  startSegment(Region);
365  }
366  // Pop any regions that are left in the stack.
367  while (!ActiveRegions.empty())
368  popRegion();
369  }
370 
371  /// Sort a nested sequence of regions from a single file.
372  static void sortNestedRegions(MutableArrayRef<CountedRegion> Regions) {
373  std::sort(Regions.begin(), Regions.end(), [](const CountedRegion &LHS,
374  const CountedRegion &RHS) {
375  if (LHS.startLoc() != RHS.startLoc())
376  return LHS.startLoc() < RHS.startLoc();
377  if (LHS.endLoc() != RHS.endLoc())
378  // When LHS completely contains RHS, we sort LHS first.
379  return RHS.endLoc() < LHS.endLoc();
380  // If LHS and RHS cover the same area, we need to sort them according
381  // to their kinds so that the most suitable region will become "active"
382  // in combineRegions(). Because we accumulate counter values only from
383  // regions of the same kind as the first region of the area, prefer
384  // CodeRegion to ExpansionRegion and ExpansionRegion to SkippedRegion.
385  static_assert(CounterMappingRegion::CodeRegion <
389  "Unexpected order of region kind values");
390  return LHS.Kind < RHS.Kind;
391  });
392  }
393 
394  /// Combine counts of regions which cover the same area.
396  combineRegions(MutableArrayRef<CountedRegion> Regions) {
397  if (Regions.empty())
398  return Regions;
399  auto Active = Regions.begin();
400  auto End = Regions.end();
401  for (auto I = Regions.begin() + 1; I != End; ++I) {
402  if (Active->startLoc() != I->startLoc() ||
403  Active->endLoc() != I->endLoc()) {
404  // Shift to the next region.
405  ++Active;
406  if (Active != I)
407  *Active = *I;
408  continue;
409  }
410  // Merge duplicate region.
411  // If CodeRegions and ExpansionRegions cover the same area, it's probably
412  // a macro which is fully expanded to another macro. In that case, we need
413  // to accumulate counts only from CodeRegions, or else the area will be
414  // counted twice.
415  // On the other hand, a macro may have a nested macro in its body. If the
416  // outer macro is used several times, the ExpansionRegion for the nested
417  // macro will also be added several times. These ExpansionRegions cover
418  // the same source locations and have to be combined to reach the correct
419  // value for that area.
420  // We add counts of the regions of the same kind as the active region
421  // to handle the both situations.
422  if (I->Kind == Active->Kind)
423  Active->ExecutionCount += I->ExecutionCount;
424  }
425  return Regions.drop_back(std::distance(++Active, End));
426  }
427 
428 public:
429  /// Build a list of CoverageSegments from a list of Regions.
430  static std::vector<CoverageSegment>
431  buildSegments(MutableArrayRef<CountedRegion> Regions) {
432  std::vector<CoverageSegment> Segments;
433  SegmentBuilder Builder(Segments);
434 
435  sortNestedRegions(Regions);
436  ArrayRef<CountedRegion> CombinedRegions = combineRegions(Regions);
437 
438  Builder.buildSegmentsImpl(CombinedRegions);
439  return Segments;
440  }
441 };
442 
443 } // end anonymous namespace
444 
445 std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {
446  std::vector<StringRef> Filenames;
447  for (const auto &Function : getCoveredFunctions())
448  Filenames.insert(Filenames.end(), Function.Filenames.begin(),
449  Function.Filenames.end());
450  std::sort(Filenames.begin(), Filenames.end());
451  auto Last = std::unique(Filenames.begin(), Filenames.end());
452  Filenames.erase(Last, Filenames.end());
453  return Filenames;
454 }
455 
457  const FunctionRecord &Function) {
458  SmallBitVector FilenameEquivalence(Function.Filenames.size(), false);
459  for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I)
460  if (SourceFile == Function.Filenames[I])
461  FilenameEquivalence[I] = true;
462  return FilenameEquivalence;
463 }
464 
465 /// Return the ID of the file where the definition of the function is located.
467  SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
468  for (const auto &CR : Function.CountedRegions)
470  IsNotExpandedFile[CR.ExpandedFileID] = false;
471  int I = IsNotExpandedFile.find_first();
472  if (I == -1)
473  return None;
474  return I;
475 }
476 
477 /// Check if SourceFile is the file that contains the definition of
478 /// the Function. Return the ID of the file in that case or None otherwise.
480  const FunctionRecord &Function) {
482  if (I && SourceFile == Function.Filenames[*I])
483  return I;
484  return None;
485 }
486 
487 static bool isExpansion(const CountedRegion &R, unsigned FileID) {
488  return R.Kind == CounterMappingRegion::ExpansionRegion && R.FileID == FileID;
489 }
490 
492  CoverageData FileCoverage(Filename);
493  std::vector<CountedRegion> Regions;
494 
495  for (const auto &Function : Functions) {
496  auto MainFileID = findMainViewFileID(Filename, Function);
497  auto FileIDs = gatherFileIDs(Filename, Function);
498  for (const auto &CR : Function.CountedRegions)
499  if (FileIDs.test(CR.FileID)) {
500  Regions.push_back(CR);
501  if (MainFileID && isExpansion(CR, *MainFileID))
502  FileCoverage.Expansions.emplace_back(CR, Function);
503  }
504  }
505 
506  DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
507  FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
508 
509  return FileCoverage;
510 }
511 
512 std::vector<const FunctionRecord *>
514  FunctionInstantiationSetCollector InstantiationSetCollector;
515  for (const auto &Function : Functions) {
516  auto MainFileID = findMainViewFileID(Filename, Function);
517  if (!MainFileID)
518  continue;
519  InstantiationSetCollector.insert(Function, *MainFileID);
520  }
521 
522  std::vector<const FunctionRecord *> Result;
523  for (const auto &InstantiationSet : InstantiationSetCollector) {
524  if (InstantiationSet.second.size() < 2)
525  continue;
526  Result.insert(Result.end(), InstantiationSet.second.begin(),
527  InstantiationSet.second.end());
528  }
529  return Result;
530 }
531 
534  auto MainFileID = findMainViewFileID(Function);
535  if (!MainFileID)
536  return CoverageData();
537 
538  CoverageData FunctionCoverage(Function.Filenames[*MainFileID]);
539  std::vector<CountedRegion> Regions;
540  for (const auto &CR : Function.CountedRegions)
541  if (CR.FileID == *MainFileID) {
542  Regions.push_back(CR);
543  if (isExpansion(CR, *MainFileID))
544  FunctionCoverage.Expansions.emplace_back(CR, Function);
545  }
546 
547  DEBUG(dbgs() << "Emitting segments for function: " << Function.Name << "\n");
548  FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
549 
550  return FunctionCoverage;
551 }
552 
554  const ExpansionRecord &Expansion) const {
555  CoverageData ExpansionCoverage(
556  Expansion.Function.Filenames[Expansion.FileID]);
557  std::vector<CountedRegion> Regions;
558  for (const auto &CR : Expansion.Function.CountedRegions)
559  if (CR.FileID == Expansion.FileID) {
560  Regions.push_back(CR);
561  if (isExpansion(CR, Expansion.FileID))
562  ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function);
563  }
564 
565  DEBUG(dbgs() << "Emitting segments for expansion of file " << Expansion.FileID
566  << "\n");
567  ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
568 
569  return ExpansionCoverage;
570 }
571 
573  switch (Err) {
575  return "Success";
577  return "End of File";
579  return "No coverage data found";
581  return "Unsupported coverage format version";
583  return "Truncated coverage data";
585  return "Malformed coverage data";
586  }
587  llvm_unreachable("A value of coveragemap_error has no message.");
588 }
589 
590 namespace {
591 
592 // FIXME: This class is only here to support the transition to llvm::Error. It
593 // will be removed once this transition is complete. Clients should prefer to
594 // deal with the Error value directly, rather than converting to error_code.
595 class CoverageMappingErrorCategoryType : public std::error_category {
596  const char *name() const noexcept override { return "llvm.coveragemap"; }
597  std::string message(int IE) const override {
598  return getCoverageMapErrString(static_cast<coveragemap_error>(IE));
599  }
600 };
601 
602 } // end anonymous namespace
603 
604 std::string CoverageMapError::message() const {
605  return getCoverageMapErrString(Err);
606 }
607 
609 
611  return *ErrorCategory;
612 }
613 
614 char CoverageMapError::ID = 0;
const NoneType None
Definition: None.h:24
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
MutableArrayRef< T > drop_back(size_t N=1) const
Definition: ArrayRef.h:367
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:234
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
static Counter getZero()
Return the counter that represents the number zero.
std::vector< const FunctionRecord * > getInstantiations(StringRef Filename) const
Get the list of function instantiations in the file.
Expected< int64_t > evaluate(const Counter &C) const
Return the number of times that a region of code associated with this counter was executed...
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:323
CoverageData getCoverageForFunction(const FunctionRecord &Function) const
Get the coverage for a particular function.
static SmallBitVector gatherFileIDs(StringRef SourceFile, const FunctionRecord &Function)
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const
Get the coverage for an expansion within a coverage set.
A Counter expression is a value that represents an arithmetic operation with two counters.
Error takeError()
Take ownership of the stored error.
Definition: Error.h:764
ArrayRef< CounterMappingRegion > MappingRegions
ArrayRef< CounterExpression > Expressions
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
friend const_iterator begin(StringRef path, Style style)
Get begin iterator over path.
Definition: Path.cpp:234
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName="<unknown>")
Given a PGO function name, remove the filename prefix and return the original (static) function name...
Definition: InstrProf.cpp:273
iterator begin() const
Definition: ArrayRef.h:331
Coverage information to be processed or displayed.
static Expected< std::unique_ptr< CoverageMapping > > load(ArrayRef< std::unique_ptr< CoverageMappingReader >> CoverageReaders, IndexedInstrProfReader &ProfileReader)
Load the coverage mapping using the given readers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Counter add(Counter LHS, Counter RHS)
Return a counter that represents the expression that adds LHS and RHS.
iterator_range< FunctionRecordIterator > getCoveredFunctions() const
Gets all of the functions covered by this profile.
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
const std::error_category & coveragemap_category()
unsigned getExpressionID() const
friend const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:291
Coverage mapping information for a single function.
void dump(const Counter &C, raw_ostream &OS) const
CounterKind getKind() const
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:78
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
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
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:74
static const unsigned End
size_t size() const
Definition: Function.h:585
static ManagedStatic< CoverageMappingErrorCategoryType > ErrorCategory
Associates a source range with an execution count.
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
std::pair< unsigned, unsigned > startLoc() const
iterator erase(const_iterator CI)
Definition: SmallVector.h:446
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:593
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
Counter subtract(Counter LHS, Counter RHS)
Return a counter that represents the expression that subtracts RHS from LHS.
Code coverage information for a single function.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
#define E
Definition: LargeTest.cpp:27
static std::string getCoverageMapErrString(coveragemap_error Err)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
static bool isExpansion(const CountedRegion &R, unsigned FileID)
static Expected< std::unique_ptr< BinaryCoverageReader > > create(std::unique_ptr< MemoryBuffer > &ObjectBuffer, StringRef Arch)
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
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
llvm_unreachable("Unknown RegBank!")
The mapping of profile information to coverage data.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
void emplace_back(ArgTypes &&...Args)
Definition: SmallVector.h:653
std::string message() const override
Return the error message as a string.
instrprof_error
Definition: InstrProf.h:280
#define C
Definition: LargeTest.cpp:25
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
static Optional< unsigned > findMainViewFileID(const FunctionRecord &Function)
Return the ID of the file where the definition of the function is located.
std::vector< CountedRegion > CountedRegions
Regions in the function along with their counts.
std::string Name
Raw function name.
unsigned FileID
The abstract file this expansion covers.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
aarch64 promote const
LLVM Value Representation.
Definition: Value.h:73
static const char * name
std::vector< std::string > Filenames
Associated files.
static Expected< std::unique_ptr< IndexedInstrProfReader > > create(const Twine &Path)
Factory method to create an indexed reader.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
std::pair< unsigned, unsigned > endLoc() const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
#define DEBUG(X)
Definition: Debug.h:118
iterator end() const
Definition: ArrayRef.h:332
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Reader for the indexed binary instrprof format.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
Definition: Parallel.h:201
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.
std::vector< StringRef > getUniqueSourceFiles() const
Returns a lexicographically sorted, unique list of files that are covered.
A Counter is an abstract value that describes how to compute the execution count for a region of code...
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
const FunctionRecord & Function
Coverage for the expansion.
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash, std::vector< uint64_t > &Counts)
Fill Counts with the profile data for the given function name.
Coverage information for a macro expansion or #included file.