LLVM  14.0.0git
CoverageMapping.cpp
Go to the documentation of this file.
1 //===- CoverageMapping.cpp - Code coverage mapping support ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for clang's and llvm's instrumentation based
10 // code coverage.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/None.h"
18 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/Errc.h"
26 #include "llvm/Support/Error.h"
31 #include <algorithm>
32 #include <cassert>
33 #include <cstdint>
34 #include <iterator>
35 #include <map>
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  llvm::sort(Terms, [](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()) {
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 
190  switch (C.getKind()) {
191  case Counter::Zero:
192  return 0;
194  return C.getCounterID();
195  case Counter::Expression: {
196  if (C.getExpressionID() >= Expressions.size())
197  return 0;
198  const auto &E = Expressions[C.getExpressionID()];
199  return std::max(getMaxCounterID(E.LHS), getMaxCounterID(E.RHS));
200  }
201  }
202  llvm_unreachable("Unhandled CounterKind");
203 }
204 
205 void FunctionRecordIterator::skipOtherFiles() {
206  while (Current != Records.end() && !Filename.empty() &&
207  Filename != Current->Filenames[0])
208  ++Current;
209  if (Current == Records.end())
210  *this = FunctionRecordIterator();
211 }
212 
213 ArrayRef<unsigned> CoverageMapping::getImpreciseRecordIndicesForFilename(
214  StringRef Filename) const {
215  size_t FilenameHash = hash_value(Filename);
216  auto RecordIt = FilenameHash2RecordIndices.find(FilenameHash);
217  if (RecordIt == FilenameHash2RecordIndices.end())
218  return {};
219  return RecordIt->second;
220 }
221 
222 static unsigned getMaxCounterID(const CounterMappingContext &Ctx,
223  const CoverageMappingRecord &Record) {
224  unsigned MaxCounterID = 0;
225  for (const auto &Region : Record.MappingRegions) {
226  MaxCounterID = std::max(MaxCounterID, Ctx.getMaxCounterID(Region.Count));
227  }
228  return MaxCounterID;
229 }
230 
231 Error CoverageMapping::loadFunctionRecord(
233  IndexedInstrProfReader &ProfileReader) {
234  StringRef OrigFuncName = Record.FunctionName;
235  if (OrigFuncName.empty())
236  return make_error<CoverageMapError>(coveragemap_error::malformed);
237 
238  if (Record.Filenames.empty())
239  OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
240  else
241  OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
242 
243  CounterMappingContext Ctx(Record.Expressions);
244 
245  std::vector<uint64_t> Counts;
246  if (Error E = ProfileReader.getFunctionCounts(Record.FunctionName,
247  Record.FunctionHash, Counts)) {
249  if (IPE == instrprof_error::hash_mismatch) {
250  FuncHashMismatches.emplace_back(std::string(Record.FunctionName),
251  Record.FunctionHash);
252  return Error::success();
253  } else if (IPE != instrprof_error::unknown_function)
254  return make_error<InstrProfError>(IPE);
255  Counts.assign(getMaxCounterID(Ctx, Record) + 1, 0);
256  }
257  Ctx.setCounts(Counts);
258 
259  assert(!Record.MappingRegions.empty() && "Function has no regions");
260 
261  // This coverage record is a zero region for a function that's unused in
262  // some TU, but used in a different TU. Ignore it. The coverage maps from the
263  // the other TU will either be loaded (providing full region counts) or they
264  // won't (in which case we don't unintuitively report functions as uncovered
265  // when they have non-zero counts in the profile).
266  if (Record.MappingRegions.size() == 1 &&
267  Record.MappingRegions[0].Count.isZero() && Counts[0] > 0)
268  return Error::success();
269 
270  FunctionRecord Function(OrigFuncName, Record.Filenames);
271  for (const auto &Region : Record.MappingRegions) {
272  Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
273  if (auto E = ExecutionCount.takeError()) {
275  return Error::success();
276  }
277  Expected<int64_t> AltExecutionCount = Ctx.evaluate(Region.FalseCount);
278  if (auto E = AltExecutionCount.takeError()) {
280  return Error::success();
281  }
282  Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount);
283  }
284 
285  // Don't create records for (filenames, function) pairs we've already seen.
286  auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
287  Record.Filenames.end());
288  if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
289  return Error::success();
290 
291  Functions.push_back(std::move(Function));
292 
293  // Performance optimization: keep track of the indices of the function records
294  // which correspond to each filename. This can be used to substantially speed
295  // up queries for coverage info in a file.
296  unsigned RecordIndex = Functions.size() - 1;
297  for (StringRef Filename : Record.Filenames) {
298  auto &RecordIndices = FilenameHash2RecordIndices[hash_value(Filename)];
299  // Note that there may be duplicates in the filename set for a function
300  // record, because of e.g. macro expansions in the function in which both
301  // the macro and the function are defined in the same file.
302  if (RecordIndices.empty() || RecordIndices.back() != RecordIndex)
303  RecordIndices.push_back(RecordIndex);
304  }
305 
306  return Error::success();
307 }
308 
309 // This function is for memory optimization by shortening the lifetimes
310 // of CoverageMappingReader instances.
311 Error CoverageMapping::loadFromReaders(
312  ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
313  IndexedInstrProfReader &ProfileReader, CoverageMapping &Coverage) {
314  for (const auto &CoverageReader : CoverageReaders) {
315  for (auto RecordOrErr : *CoverageReader) {
316  if (Error E = RecordOrErr.takeError())
317  return E;
318  const auto &Record = *RecordOrErr;
319  if (Error E = Coverage.loadFunctionRecord(Record, ProfileReader))
320  return E;
321  }
322  }
323  return Error::success();
324 }
325 
327  ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
328  IndexedInstrProfReader &ProfileReader) {
329  auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
330  if (Error E = loadFromReaders(CoverageReaders, ProfileReader, *Coverage))
331  return std::move(E);
332  return std::move(Coverage);
333 }
334 
335 // If E is a no_data_found error, returns success. Otherwise returns E.
337  return handleErrors(
338  std::move(E), [](const CoverageMapError &CME) {
340  return static_cast<Error>(Error::success());
341  return make_error<CoverageMapError>(CME.get());
342  });
343 }
344 
347  StringRef ProfileFilename, ArrayRef<StringRef> Arches,
348  StringRef CompilationDir) {
349  auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);
350  if (Error E = ProfileReaderOrErr.takeError())
351  return std::move(E);
352  auto ProfileReader = std::move(ProfileReaderOrErr.get());
353  auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
354  bool DataFound = false;
355 
356  for (const auto &File : llvm::enumerate(ObjectFilenames)) {
357  auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(
358  File.value(), /*IsText=*/false, /*RequiresNullTerminator=*/false);
359  if (std::error_code EC = CovMappingBufOrErr.getError())
360  return errorCodeToError(EC);
361  StringRef Arch = Arches.empty() ? StringRef() : Arches[File.index()];
362  MemoryBufferRef CovMappingBufRef =
363  CovMappingBufOrErr.get()->getMemBufferRef();
365  auto CoverageReadersOrErr = BinaryCoverageReader::create(
366  CovMappingBufRef, Arch, Buffers, CompilationDir);
367  if (Error E = CoverageReadersOrErr.takeError()) {
369  if (E)
370  return std::move(E);
371  // E == success (originally a no_data_found error).
372  continue;
373  }
374 
376  for (auto &Reader : CoverageReadersOrErr.get())
377  Readers.push_back(std::move(Reader));
378  DataFound |= !Readers.empty();
379  if (Error E = loadFromReaders(Readers, *ProfileReader, *Coverage))
380  return std::move(E);
381  }
382  // If no readers were created, either no objects were provided or none of them
383  // had coverage data. Return an error in the latter case.
384  if (!DataFound && !ObjectFilenames.empty())
385  return make_error<CoverageMapError>(coveragemap_error::no_data_found);
386  return std::move(Coverage);
387 }
388 
389 namespace {
390 
391 /// Distributes functions into instantiation sets.
392 ///
393 /// An instantiation set is a collection of functions that have the same source
394 /// code, ie, template functions specializations.
395 class FunctionInstantiationSetCollector {
396  using MapT = std::map<LineColPair, std::vector<const FunctionRecord *>>;
397  MapT InstantiatedFunctions;
398 
399 public:
400  void insert(const FunctionRecord &Function, unsigned FileID) {
401  auto I = Function.CountedRegions.begin(), E = Function.CountedRegions.end();
402  while (I != E && I->FileID != FileID)
403  ++I;
404  assert(I != E && "function does not cover the given file");
405  auto &Functions = InstantiatedFunctions[I->startLoc()];
406  Functions.push_back(&Function);
407  }
408 
409  MapT::iterator begin() { return InstantiatedFunctions.begin(); }
410  MapT::iterator end() { return InstantiatedFunctions.end(); }
411 };
412 
413 class SegmentBuilder {
414  std::vector<CoverageSegment> &Segments;
416 
417  SegmentBuilder(std::vector<CoverageSegment> &Segments) : Segments(Segments) {}
418 
419  /// Emit a segment with the count from \p Region starting at \p StartLoc.
420  //
421  /// \p IsRegionEntry: The segment is at the start of a new non-gap region.
422  /// \p EmitSkippedRegion: The segment must be emitted as a skipped region.
423  void startSegment(const CountedRegion &Region, LineColPair StartLoc,
424  bool IsRegionEntry, bool EmitSkippedRegion = false) {
425  bool HasCount = !EmitSkippedRegion &&
427 
428  // If the new segment wouldn't affect coverage rendering, skip it.
429  if (!Segments.empty() && !IsRegionEntry && !EmitSkippedRegion) {
430  const auto &Last = Segments.back();
431  if (Last.HasCount == HasCount && Last.Count == Region.ExecutionCount &&
432  !Last.IsRegionEntry)
433  return;
434  }
435 
436  if (HasCount)
437  Segments.emplace_back(StartLoc.first, StartLoc.second,
438  Region.ExecutionCount, IsRegionEntry,
440  else
441  Segments.emplace_back(StartLoc.first, StartLoc.second, IsRegionEntry);
442 
443  LLVM_DEBUG({
444  const auto &Last = Segments.back();
445  dbgs() << "Segment at " << Last.Line << ":" << Last.Col
446  << " (count = " << Last.Count << ")"
447  << (Last.IsRegionEntry ? ", RegionEntry" : "")
448  << (!Last.HasCount ? ", Skipped" : "")
449  << (Last.IsGapRegion ? ", Gap" : "") << "\n";
450  });
451  }
452 
453  /// Emit segments for active regions which end before \p Loc.
454  ///
455  /// \p Loc: The start location of the next region. If None, all active
456  /// regions are completed.
457  /// \p FirstCompletedRegion: Index of the first completed region.
458  void completeRegionsUntil(Optional<LineColPair> Loc,
459  unsigned FirstCompletedRegion) {
460  // Sort the completed regions by end location. This makes it simple to
461  // emit closing segments in sorted order.
462  auto CompletedRegionsIt = ActiveRegions.begin() + FirstCompletedRegion;
463  std::stable_sort(CompletedRegionsIt, ActiveRegions.end(),
464  [](const CountedRegion *L, const CountedRegion *R) {
465  return L->endLoc() < R->endLoc();
466  });
467 
468  // Emit segments for all completed regions.
469  for (unsigned I = FirstCompletedRegion + 1, E = ActiveRegions.size(); I < E;
470  ++I) {
471  const auto *CompletedRegion = ActiveRegions[I];
472  assert((!Loc || CompletedRegion->endLoc() <= *Loc) &&
473  "Completed region ends after start of new region");
474 
475  const auto *PrevCompletedRegion = ActiveRegions[I - 1];
476  auto CompletedSegmentLoc = PrevCompletedRegion->endLoc();
477 
478  // Don't emit any more segments if they start where the new region begins.
479  if (Loc && CompletedSegmentLoc == *Loc)
480  break;
481 
482  // Don't emit a segment if the next completed region ends at the same
483  // location as this one.
484  if (CompletedSegmentLoc == CompletedRegion->endLoc())
485  continue;
486 
487  // Use the count from the last completed region which ends at this loc.
488  for (unsigned J = I + 1; J < E; ++J)
489  if (CompletedRegion->endLoc() == ActiveRegions[J]->endLoc())
490  CompletedRegion = ActiveRegions[J];
491 
492  startSegment(*CompletedRegion, CompletedSegmentLoc, false);
493  }
494 
495  auto Last = ActiveRegions.back();
496  if (FirstCompletedRegion && Last->endLoc() != *Loc) {
497  // If there's a gap after the end of the last completed region and the
498  // start of the new region, use the last active region to fill the gap.
499  startSegment(*ActiveRegions[FirstCompletedRegion - 1], Last->endLoc(),
500  false);
501  } else if (!FirstCompletedRegion && (!Loc || *Loc != Last->endLoc())) {
502  // Emit a skipped segment if there are no more active regions. This
503  // ensures that gaps between functions are marked correctly.
504  startSegment(*Last, Last->endLoc(), false, true);
505  }
506 
507  // Pop the completed regions.
508  ActiveRegions.erase(CompletedRegionsIt, ActiveRegions.end());
509  }
510 
511  void buildSegmentsImpl(ArrayRef<CountedRegion> Regions) {
512  for (const auto &CR : enumerate(Regions)) {
513  auto CurStartLoc = CR.value().startLoc();
514 
515  // Active regions which end before the current region need to be popped.
516  auto CompletedRegions =
517  std::stable_partition(ActiveRegions.begin(), ActiveRegions.end(),
518  [&](const CountedRegion *Region) {
519  return !(Region->endLoc() <= CurStartLoc);
520  });
521  if (CompletedRegions != ActiveRegions.end()) {
522  unsigned FirstCompletedRegion =
523  std::distance(ActiveRegions.begin(), CompletedRegions);
524  completeRegionsUntil(CurStartLoc, FirstCompletedRegion);
525  }
526 
527  bool GapRegion = CR.value().Kind == CounterMappingRegion::GapRegion;
528 
529  // Try to emit a segment for the current region.
530  if (CurStartLoc == CR.value().endLoc()) {
531  // Avoid making zero-length regions active. If it's the last region,
532  // emit a skipped segment. Otherwise use its predecessor's count.
533  const bool Skipped =
534  (CR.index() + 1) == Regions.size() ||
535  CR.value().Kind == CounterMappingRegion::SkippedRegion;
536  startSegment(ActiveRegions.empty() ? CR.value() : *ActiveRegions.back(),
537  CurStartLoc, !GapRegion, Skipped);
538  // If it is skipped segment, create a segment with last pushed
539  // regions's count at CurStartLoc.
540  if (Skipped && !ActiveRegions.empty())
541  startSegment(*ActiveRegions.back(), CurStartLoc, false);
542  continue;
543  }
544  if (CR.index() + 1 == Regions.size() ||
545  CurStartLoc != Regions[CR.index() + 1].startLoc()) {
546  // Emit a segment if the next region doesn't start at the same location
547  // as this one.
548  startSegment(CR.value(), CurStartLoc, !GapRegion);
549  }
550 
551  // This region is active (i.e not completed).
552  ActiveRegions.push_back(&CR.value());
553  }
554 
555  // Complete any remaining active regions.
556  if (!ActiveRegions.empty())
557  completeRegionsUntil(None, 0);
558  }
559 
560  /// Sort a nested sequence of regions from a single file.
561  static void sortNestedRegions(MutableArrayRef<CountedRegion> Regions) {
562  llvm::sort(Regions, [](const CountedRegion &LHS, const CountedRegion &RHS) {
563  if (LHS.startLoc() != RHS.startLoc())
564  return LHS.startLoc() < RHS.startLoc();
565  if (LHS.endLoc() != RHS.endLoc())
566  // When LHS completely contains RHS, we sort LHS first.
567  return RHS.endLoc() < LHS.endLoc();
568  // If LHS and RHS cover the same area, we need to sort them according
569  // to their kinds so that the most suitable region will become "active"
570  // in combineRegions(). Because we accumulate counter values only from
571  // regions of the same kind as the first region of the area, prefer
572  // CodeRegion to ExpansionRegion and ExpansionRegion to SkippedRegion.
573  static_assert(CounterMappingRegion::CodeRegion <
577  "Unexpected order of region kind values");
578  return LHS.Kind < RHS.Kind;
579  });
580  }
581 
582  /// Combine counts of regions which cover the same area.
584  combineRegions(MutableArrayRef<CountedRegion> Regions) {
585  if (Regions.empty())
586  return Regions;
587  auto Active = Regions.begin();
588  auto End = Regions.end();
589  for (auto I = Regions.begin() + 1; I != End; ++I) {
590  if (Active->startLoc() != I->startLoc() ||
591  Active->endLoc() != I->endLoc()) {
592  // Shift to the next region.
593  ++Active;
594  if (Active != I)
595  *Active = *I;
596  continue;
597  }
598  // Merge duplicate region.
599  // If CodeRegions and ExpansionRegions cover the same area, it's probably
600  // a macro which is fully expanded to another macro. In that case, we need
601  // to accumulate counts only from CodeRegions, or else the area will be
602  // counted twice.
603  // On the other hand, a macro may have a nested macro in its body. If the
604  // outer macro is used several times, the ExpansionRegion for the nested
605  // macro will also be added several times. These ExpansionRegions cover
606  // the same source locations and have to be combined to reach the correct
607  // value for that area.
608  // We add counts of the regions of the same kind as the active region
609  // to handle the both situations.
610  if (I->Kind == Active->Kind)
611  Active->ExecutionCount += I->ExecutionCount;
612  }
613  return Regions.drop_back(std::distance(++Active, End));
614  }
615 
616 public:
617  /// Build a sorted list of CoverageSegments from a list of Regions.
618  static std::vector<CoverageSegment>
619  buildSegments(MutableArrayRef<CountedRegion> Regions) {
620  std::vector<CoverageSegment> Segments;
621  SegmentBuilder Builder(Segments);
622 
623  sortNestedRegions(Regions);
624  ArrayRef<CountedRegion> CombinedRegions = combineRegions(Regions);
625 
626  LLVM_DEBUG({
627  dbgs() << "Combined regions:\n";
628  for (const auto &CR : CombinedRegions)
629  dbgs() << " " << CR.LineStart << ":" << CR.ColumnStart << " -> "
630  << CR.LineEnd << ":" << CR.ColumnEnd
631  << " (count=" << CR.ExecutionCount << ")\n";
632  });
633 
634  Builder.buildSegmentsImpl(CombinedRegions);
635 
636 #ifndef NDEBUG
637  for (unsigned I = 1, E = Segments.size(); I < E; ++I) {
638  const auto &L = Segments[I - 1];
639  const auto &R = Segments[I];
640  if (!(L.Line < R.Line) && !(L.Line == R.Line && L.Col < R.Col)) {
641  if (L.Line == R.Line && L.Col == R.Col && !L.HasCount)
642  continue;
643  LLVM_DEBUG(dbgs() << " ! Segment " << L.Line << ":" << L.Col
644  << " followed by " << R.Line << ":" << R.Col << "\n");
645  assert(false && "Coverage segments not unique or sorted");
646  }
647  }
648 #endif
649 
650  return Segments;
651  }
652 };
653 
654 } // end anonymous namespace
655 
656 std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {
657  std::vector<StringRef> Filenames;
658  for (const auto &Function : getCoveredFunctions())
659  llvm::append_range(Filenames, Function.Filenames);
660  llvm::sort(Filenames);
661  auto Last = std::unique(Filenames.begin(), Filenames.end());
662  Filenames.erase(Last, Filenames.end());
663  return Filenames;
664 }
665 
667  const FunctionRecord &Function) {
668  SmallBitVector FilenameEquivalence(Function.Filenames.size(), false);
669  for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I)
670  if (SourceFile == Function.Filenames[I])
671  FilenameEquivalence[I] = true;
672  return FilenameEquivalence;
673 }
674 
675 /// Return the ID of the file where the definition of the function is located.
677  SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
678  for (const auto &CR : Function.CountedRegions)
680  IsNotExpandedFile[CR.ExpandedFileID] = false;
681  int I = IsNotExpandedFile.find_first();
682  if (I == -1)
683  return None;
684  return I;
685 }
686 
687 /// Check if SourceFile is the file that contains the definition of
688 /// the Function. Return the ID of the file in that case or None otherwise.
690  const FunctionRecord &Function) {
692  if (I && SourceFile == Function.Filenames[*I])
693  return I;
694  return None;
695 }
696 
697 static bool isExpansion(const CountedRegion &R, unsigned FileID) {
698  return R.Kind == CounterMappingRegion::ExpansionRegion && R.FileID == FileID;
699 }
700 
702  CoverageData FileCoverage(Filename);
703  std::vector<CountedRegion> Regions;
704 
705  // Look up the function records in the given file. Due to hash collisions on
706  // the filename, we may get back some records that are not in the file.
707  ArrayRef<unsigned> RecordIndices =
708  getImpreciseRecordIndicesForFilename(Filename);
709  for (unsigned RecordIndex : RecordIndices) {
710  const FunctionRecord &Function = Functions[RecordIndex];
711  auto MainFileID = findMainViewFileID(Filename, Function);
712  auto FileIDs = gatherFileIDs(Filename, Function);
713  for (const auto &CR : Function.CountedRegions)
714  if (FileIDs.test(CR.FileID)) {
715  Regions.push_back(CR);
716  if (MainFileID && isExpansion(CR, *MainFileID))
717  FileCoverage.Expansions.emplace_back(CR, Function);
718  }
719  // Capture branch regions specific to the function (excluding expansions).
720  for (const auto &CR : Function.CountedBranchRegions)
721  if (FileIDs.test(CR.FileID) && (CR.FileID == CR.ExpandedFileID))
722  FileCoverage.BranchRegions.push_back(CR);
723  }
724 
725  LLVM_DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
726  FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
727 
728  return FileCoverage;
729 }
730 
731 std::vector<InstantiationGroup>
733  FunctionInstantiationSetCollector InstantiationSetCollector;
734  // Look up the function records in the given file. Due to hash collisions on
735  // the filename, we may get back some records that are not in the file.
736  ArrayRef<unsigned> RecordIndices =
737  getImpreciseRecordIndicesForFilename(Filename);
738  for (unsigned RecordIndex : RecordIndices) {
739  const FunctionRecord &Function = Functions[RecordIndex];
740  auto MainFileID = findMainViewFileID(Filename, Function);
741  if (!MainFileID)
742  continue;
743  InstantiationSetCollector.insert(Function, *MainFileID);
744  }
745 
746  std::vector<InstantiationGroup> Result;
747  for (auto &InstantiationSet : InstantiationSetCollector) {
748  InstantiationGroup IG{InstantiationSet.first.first,
749  InstantiationSet.first.second,
750  std::move(InstantiationSet.second)};
751  Result.emplace_back(std::move(IG));
752  }
753  return Result;
754 }
755 
758  auto MainFileID = findMainViewFileID(Function);
759  if (!MainFileID)
760  return CoverageData();
761 
762  CoverageData FunctionCoverage(Function.Filenames[*MainFileID]);
763  std::vector<CountedRegion> Regions;
764  for (const auto &CR : Function.CountedRegions)
765  if (CR.FileID == *MainFileID) {
766  Regions.push_back(CR);
767  if (isExpansion(CR, *MainFileID))
768  FunctionCoverage.Expansions.emplace_back(CR, Function);
769  }
770  // Capture branch regions specific to the function (excluding expansions).
771  for (const auto &CR : Function.CountedBranchRegions)
772  if (CR.FileID == *MainFileID)
773  FunctionCoverage.BranchRegions.push_back(CR);
774 
775  LLVM_DEBUG(dbgs() << "Emitting segments for function: " << Function.Name
776  << "\n");
777  FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
778 
779  return FunctionCoverage;
780 }
781 
783  const ExpansionRecord &Expansion) const {
784  CoverageData ExpansionCoverage(
785  Expansion.Function.Filenames[Expansion.FileID]);
786  std::vector<CountedRegion> Regions;
787  for (const auto &CR : Expansion.Function.CountedRegions)
788  if (CR.FileID == Expansion.FileID) {
789  Regions.push_back(CR);
790  if (isExpansion(CR, Expansion.FileID))
791  ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function);
792  }
793  for (const auto &CR : Expansion.Function.CountedBranchRegions)
794  // Capture branch regions that only pertain to the corresponding expansion.
795  if (CR.FileID == Expansion.FileID)
796  ExpansionCoverage.BranchRegions.push_back(CR);
797 
798  LLVM_DEBUG(dbgs() << "Emitting segments for expansion of file "
799  << Expansion.FileID << "\n");
800  ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
801 
802  return ExpansionCoverage;
803 }
804 
805 LineCoverageStats::LineCoverageStats(
807  const CoverageSegment *WrappedSegment, unsigned Line)
808  : ExecutionCount(0), HasMultipleRegions(false), Mapped(false), Line(Line),
809  LineSegments(LineSegments), WrappedSegment(WrappedSegment) {
810  // Find the minimum number of regions which start in this line.
811  unsigned MinRegionCount = 0;
812  auto isStartOfRegion = [](const CoverageSegment *S) {
813  return !S->IsGapRegion && S->HasCount && S->IsRegionEntry;
814  };
815  for (unsigned I = 0; I < LineSegments.size() && MinRegionCount < 2; ++I)
816  if (isStartOfRegion(LineSegments[I]))
817  ++MinRegionCount;
818 
819  bool StartOfSkippedRegion = !LineSegments.empty() &&
820  !LineSegments.front()->HasCount &&
821  LineSegments.front()->IsRegionEntry;
822 
823  HasMultipleRegions = MinRegionCount > 1;
824  Mapped =
825  !StartOfSkippedRegion &&
826  ((WrappedSegment && WrappedSegment->HasCount) || (MinRegionCount > 0));
827 
828  if (!Mapped)
829  return;
830 
831  // Pick the max count from the non-gap, region entry segments and the
832  // wrapped count.
833  if (WrappedSegment)
834  ExecutionCount = WrappedSegment->Count;
835  if (!MinRegionCount)
836  return;
837  for (const auto *LS : LineSegments)
838  if (isStartOfRegion(LS))
839  ExecutionCount = std::max(ExecutionCount, LS->Count);
840 }
841 
843  if (Next == CD.end()) {
844  Stats = LineCoverageStats();
845  Ended = true;
846  return *this;
847  }
848  if (Segments.size())
849  WrappedSegment = Segments.back();
850  Segments.clear();
851  while (Next != CD.end() && Next->Line == Line)
852  Segments.push_back(&*Next++);
853  Stats = LineCoverageStats(Segments, WrappedSegment, Line);
854  ++Line;
855  return *this;
856 }
857 
859  switch (Err) {
861  return "Success";
863  return "End of File";
865  return "No coverage data found";
867  return "Unsupported coverage format version";
869  return "Truncated coverage data";
871  return "Malformed coverage data";
873  return "Failed to decompress coverage data (zlib)";
875  return "`-arch` specifier is invalid or missing for universal binary";
876  }
877  llvm_unreachable("A value of coveragemap_error has no message.");
878 }
879 
880 namespace {
881 
882 // FIXME: This class is only here to support the transition to llvm::Error. It
883 // will be removed once this transition is complete. Clients should prefer to
884 // deal with the Error value directly, rather than converting to error_code.
885 class CoverageMappingErrorCategoryType : public std::error_category {
886  const char *name() const noexcept override { return "llvm.coveragemap"; }
887  std::string message(int IE) const override {
888  return getCoverageMapErrString(static_cast<coveragemap_error>(IE));
889  }
890 };
891 
892 } // end anonymous namespace
893 
894 std::string CoverageMapError::message() const {
895  return getCoverageMapErrString(Err);
896 }
897 
899 
901  return *ErrorCategory;
902 }
903 
904 char CoverageMapError::ID = 0;
llvm::coverage::Counter::getExpression
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.
Definition: CoverageMapping.h:142
llvm::coverage::coveragemap_error::success
@ success
MemoryBuffer.h
llvm::coverage::CounterExpression
A Counter expression is a value that represents an arithmetic operation with two counters.
Definition: CoverageMapping.h:149
llvm::coverage::CoverageMapping::getCoverageForExpansion
CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion) const
Get the coverage for an expansion within a coverage set.
Definition: CoverageMapping.cpp:782
llvm::coverage::CoverageMapping::getInstantiationGroups
std::vector< InstantiationGroup > getInstantiationGroups(StringRef Filename) const
Get the list of function instantiation groups in a particular file.
Definition: CoverageMapping.cpp:732
llvm::coverage::CoverageData::end
std::vector< CoverageSegment >::const_iterator end() const
Definition: CoverageMapping.h:553
llvm::coverage::FunctionRecord::Filenames
std::vector< std::string > Filenames
Mapping from FileID (i.e.
Definition: CoverageMapping.h:351
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::SmallVectorImpl::erase
iterator erase(const_iterator CI)
Definition: SmallVector.h:705
llvm::sys::path::const_iterator::end
friend const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::handleErrors
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition: Error.h:935
llvm::coverage::CounterMappingRegion::endLoc
LineColPair endLoc() const
Definition: CoverageMapping.h:299
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
Optional.h
llvm::coverage::CoverageMapError
Definition: CoverageMapping.h:68
llvm::coverage::CounterExpressionBuilder::subtract
Counter subtract(Counter LHS, Counter RHS)
Return a counter that represents the expression that subtracts RHS from LHS.
Definition: CoverageMapping.cpp:130
llvm::coverage::CoverageMapError::get
coveragemap_error get() const
Definition: CoverageMapping.h:82
llvm::Function::end
iterator end()
Definition: Function.h:735
llvm::coverage::coveragemap_error::no_data_found
@ no_data_found
llvm::coverage::FunctionRecordIterator::FunctionRecordIterator
FunctionRecordIterator()
Definition: CoverageMapping.h:399
llvm::Function
Definition: Function.h:61
llvm::coverage::CounterExpression::Subtract
@ Subtract
Definition: CoverageMapping.h:150
StringRef.h
handleMaybeNoDataFoundError
static Error handleMaybeNoDataFoundError(Error E)
Definition: CoverageMapping.cpp:336
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::coverage::LineCoverageIterator
An iterator over the LineCoverageStats objects for lines described by a CoverageData instance.
Definition: CoverageMapping.h:695
llvm::enumerate
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
Definition: STLExtras.h:1977
llvm::coverage::Counter::Expression
@ Expression
Definition: CoverageMapping.h:95
ErrorHandling.h
ManagedStatic.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
Error.h
llvm::coverage::Counter::getCounter
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
Definition: CoverageMapping.h:136
llvm::coverage::CounterExpressionBuilder::add
Counter add(Counter LHS, Counter RHS)
Return a counter that represents the expression that adds LHS and RHS.
Definition: CoverageMapping.cpp:126
llvm::coverage::Counter::CounterValueReference
@ CounterValueReference
Definition: CoverageMapping.h:95
Errc.h
llvm::SmallBitVector::find_first
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
Definition: SmallBitVector.h:229
DenseMap.h
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::coverage::coveragemap_error
coveragemap_error
Definition: CoverageMapping.h:51
llvm::coverage::CoverageSegment::IsRegionEntry
bool IsRegionEntry
Whether this enters a new region or returns to a previous count.
Definition: CoverageMapping.h:447
llvm::Optional
Definition: APInt.h:33
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::coverage::CounterMappingRegion::ExpansionRegion
@ ExpansionRegion
An ExpansionRegion represents a file expansion region that associates a source range with the expansi...
Definition: CoverageMapping.h:216
llvm::coverage::CounterExpression::Add
@ Add
Definition: CoverageMapping.h:150
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
isExpansion
static bool isExpansion(const CountedRegion &R, unsigned FileID)
Definition: CoverageMapping.cpp:697
llvm::coverage::coveragemap_error::unsupported_version
@ unsupported_version
llvm::coverage::CounterMappingRegion::Kind
RegionKind Kind
Definition: CoverageMapping.h:240
llvm::hash_value
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4827
llvm::coverage::CoverageMapError::message
std::string message() const override
Return the error message as a string.
Definition: CoverageMapping.cpp:894
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1035
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::coverage::coveragemap_error::decompression_failed
@ decompression_failed
llvm::coverage::ExpansionRecord::Function
const FunctionRecord & Function
Coverage for the expansion.
Definition: CoverageMapping.h:426
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:193
findMainViewFileID
static Optional< unsigned > findMainViewFileID(const FunctionRecord &Function)
Return the ID of the file where the definition of the function is located.
Definition: CoverageMapping.cpp:676
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
ErrorCategory
static ManagedStatic< CoverageMappingErrorCategoryType > ErrorCategory
Definition: CoverageMapping.cpp:898
llvm::SmallBitVector
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
Definition: SmallBitVector.h:34
llvm::coverage::coveragemap_error::eof
@ eof
llvm::coverage::LineCoverageIterator::operator++
LineCoverageIterator & operator++()
Definition: CoverageMapping.cpp:842
llvm::errc::argument_out_of_domain
@ argument_out_of_domain
llvm::MutableArrayRef::end
iterator end() const
Definition: ArrayRef.h:357
llvm::coverage::LineColPair
std::pair< unsigned, unsigned > LineColPair
Definition: CoverageMapping.h:205
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
llvm::coverage::coveragemap_error::malformed
@ malformed
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
llvm::coverage::CoverageMapping::getCoverageForFunction
CoverageData getCoverageForFunction(const FunctionRecord &Function) const
Get the coverage for a particular function.
Definition: CoverageMapping.cpp:757
llvm::coverage::FunctionRecord::CountedBranchRegions
std::vector< CountedRegion > CountedBranchRegions
Branch Regions in the function along with their counts.
Definition: CoverageMapping.h:355
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
false
Definition: StackSlotColoring.cpp:142
llvm::coverage::CoverageMapping::getUniqueSourceFiles
std::vector< StringRef > getUniqueSourceFiles() const
Returns a lexicographically sorted, unique list of files that are covered.
Definition: CoverageMapping.cpp:656
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::coverage::coveragemap_error::invalid_or_missing_arch_specifier
@ invalid_or_missing_arch_specifier
llvm::IndexedInstrProfReader::getFunctionCounts
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash, std::vector< uint64_t > &Counts)
Fill Counts with the profile data for the given function name.
Definition: InstrProfReader.cpp:936
llvm::coverage::CounterMappingContext::dump
void dump(const Counter &C, raw_ostream &OS) const
Definition: CoverageMapping.cpp:135
llvm::None
const NoneType None
Definition: None.h:23
llvm::M68kBeads::Term
@ Term
Definition: M68kBaseInfo.h:71
llvm::coverage::CounterMappingContext::evaluate
Expected< int64_t > evaluate(const Counter &C) const
Return the number of times that a region of code associated with this counter was executed.
Definition: CoverageMapping.cpp:165
llvm::InstrProfError::take
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:327
llvm::coverage::CoverageSegment::HasCount
bool HasCount
When false, the segment was uninstrumented or skipped.
Definition: CoverageMapping.h:445
llvm::coverage::BinaryCoverageReader::create
static Expected< std::vector< std::unique_ptr< BinaryCoverageReader > > > create(MemoryBufferRef ObjectBuffer, StringRef Arch, SmallVectorImpl< std::unique_ptr< MemoryBuffer >> &ObjectFileBuffers, StringRef CompilationDir="")
Definition: CoverageMappingReader.cpp:1072
llvm::coverage::coveragemap_error::truncated
@ truncated
llvm::ARM_PROC::IE
@ IE
Definition: ARMBaseInfo.h:27
llvm::coverage::FunctionRecord
Code coverage information for a single function.
Definition: CoverageMapping.h:342
CoverageMappingReader.h
InstrProfReader.h
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::IndexedInstrProfReader
Reader for the indexed binary instrprof format.
Definition: InstrProfReader.h:458
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::MemoryBuffer::getFileOrSTDIN
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
Definition: MemoryBuffer.cpp:144
llvm::coverage::Counter
A Counter is an abstract value that describes how to compute the execution count for a region of code...
Definition: CoverageMapping.h:92
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::instrprof_error
instrprof_error
Definition: InstrProf.h:282
ArrayRef.h
llvm::coverage::coveragemap_category
const std::error_category & coveragemap_category()
Definition: CoverageMapping.cpp:900
llvm::MutableArrayRef::drop_back
MutableArrayRef< T > drop_back(size_t N=1) const
Definition: ArrayRef.h:392
message
message(STATUS "Targeting ${t}") add_subdirectory($
Definition: CMakeLists.txt:33
llvm::sys::path::const_iterator::begin
friend const_iterator begin(StringRef path, Style style)
Get begin iterator over path.
Definition: Path.cpp:224
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::coverage::CounterMappingRegion::startLoc
LineColPair startLoc() const
Definition: CoverageMapping.h:295
llvm::instrprof_error::unknown_function
@ unknown_function
llvm::IndexedInstrProf::HashT::Last
@ Last
llvm::pdb::PDB_TableType::Segments
@ Segments
llvm::MutableArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:356
llvm::Record
Definition: Record.h:1472
llvm::IndexedInstrProfReader::create
static Expected< std::unique_ptr< IndexedInstrProfReader > > create(const Twine &Path, const Twine &RemappingPath="")
Factory method to create an indexed reader.
Definition: InstrProfReader.cpp:93
llvm::coverage::CounterMappingRegion::GapRegion
@ GapRegion
A GapRegion is like a CodeRegion, but its count is only set as the line execution count when its the ...
Definition: CoverageMapping.h:224
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:650
llvm::ArrayRef< unsigned >
None.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::coverage::CoverageMapping
The mapping of profile information to coverage data.
Definition: CoverageMapping.h:570
llvm::coverage::CoverageMapping::getCoverageForFile
CoverageData getCoverageForFile(StringRef Filename) const
Get the coverage for a particular file.
Definition: CoverageMapping.cpp:701
gatherFileIDs
static SmallBitVector gatherFileIDs(StringRef SourceFile, const FunctionRecord &Function)
Definition: CoverageMapping.cpp:666
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1744
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::instrprof_error::hash_mismatch
@ hash_mismatch
llvm::ArrayRef::front
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:168
llvm::Function::begin
iterator begin()
Definition: Function.h:733
CoverageMapping.h
llvm::coverage::CoverageSegment::Count
uint64_t Count
The execution count, or zero if no count was recorded.
Definition: CoverageMapping.h:443
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::coverage::CoverageData
Coverage information to be processed or displayed.
Definition: CoverageMapping.h:531
llvm::coverage::LineCoverageStats
Coverage statistics for a single line.
Definition: CoverageMapping.h:663
llvm::stable_sort
void stable_sort(R &&Range)
Definition: STLExtras.h:1682
llvm::coverage::CoverageMapError::ID
static char ID
Definition: CoverageMapping.h:84
getMaxCounterID
static unsigned getMaxCounterID(const CounterMappingContext &Ctx, const CoverageMappingRecord &Record)
Definition: CoverageMapping.cpp:222
llvm::coverage::ExpansionRecord::FileID
unsigned FileID
The abstract file this expansion covers.
Definition: CoverageMapping.h:422
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:264
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1488
llvm::unique
auto unique(Range &&R, Predicate P)
Definition: STLExtras.h:1700
llvm::coverage::CoverageMapping::load
static Expected< std::unique_ptr< CoverageMapping > > load(ArrayRef< std::unique_ptr< CoverageMappingReader >> CoverageReaders, IndexedInstrProfReader &ProfileReader)
Load the coverage mapping using the given readers.
Definition: CoverageMapping.cpp:326
llvm::coverage::CounterMappingContext
A Counter mapping context is used to connect the counters, expressions and the obtained counter value...
Definition: CoverageMapping.h:320
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:589
llvm::coverage::Counter::Zero
@ Zero
Definition: CoverageMapping.h:95
SmallVector.h
SmallBitVector.h
llvm::hash_combine_range
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:482
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::coverage::Counter::getZero
static Counter getZero()
Return the counter that represents the number zero.
Definition: CoverageMapping.h:133
llvm::getFuncNameWithoutPrefix
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:286
llvm::coverage::CounterMappingRegion::CodeRegion
@ CodeRegion
A CodeRegion associates some code with a counter.
Definition: CoverageMapping.h:211
llvm::coverage::CounterMappingContext::getMaxCounterID
unsigned getMaxCounterID(const Counter &C) const
Definition: CoverageMapping.cpp:189
llvm::coverage::CoverageMapping::getCoveredFunctions
iterator_range< FunctionRecordIterator > getCoveredFunctions() const
Gets all of the functions covered by this profile.
Definition: CoverageMapping.h:642
llvm::coverage::ExpansionRecord
Coverage information for a macro expansion or #included file.
Definition: CoverageMapping.h:420
llvm::Region
Definition: RegionInfo.h:889
raw_ostream.h
error_category
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:76
llvm::coverage::CoverageSegment
The execution count information starting at a point in a file.
Definition: CoverageMapping.h:437
llvm::coverage::InstantiationGroup
An instantiation group contains a FunctionRecord list, such that each record corresponds to a distinc...
Definition: CoverageMapping.h:474
getCoverageMapErrString
static std::string getCoverageMapErrString(coveragemap_error Err)
Definition: CoverageMapping.cpp:858
llvm::coverage::CountedRegion
Associates a source range with an execution count.
Definition: CoverageMapping.h:303
llvm::coverage::CoverageMappingRecord
Coverage mapping information for a single function.
Definition: CoverageMappingReader.h:35
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
Debug.h
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::coverage::CounterMappingRegion::SkippedRegion
@ SkippedRegion
A SkippedRegion represents a source range with code that was skipped by a preprocessor or similar mea...
Definition: CoverageMapping.h:220
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:908
llvm::Function::size
size_t size() const
Definition: Function.h:738
llvm::coverage::FunctionRecord::CountedRegions
std::vector< CountedRegion > CountedRegions
Regions in the function along with their counts.
Definition: CoverageMapping.h:353