Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame^] | 1 | //===- SourceCoverageDataManager.h - Manager for source file coverage data-===// |
| 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 class separates and merges mapping regions for a specific source file. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_COV_SOURCECOVERAGEDATAMANAGER_H |
| 15 | #define LLVM_COV_SOURCECOVERAGEDATAMANAGER_H |
| 16 | |
| 17 | #include "FunctionCoverageMapping.h" |
| 18 | #include "llvm/ProfileData/CoverageMapping.h" |
| 19 | #include "llvm/ADT/Hashing.h" |
| 20 | #include <vector> |
| 21 | #include <unordered_map> |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | /// \brief Partions mapping regions by their kind and sums |
| 26 | /// the execution counts of the regions that start at the same location. |
| 27 | class SourceCoverageDataManager { |
| 28 | public: |
| 29 | struct SourceRange { |
| 30 | unsigned LineStart, ColumnStart, LineEnd, ColumnEnd; |
| 31 | |
| 32 | SourceRange(unsigned LineStart, unsigned ColumnStart, unsigned LineEnd, |
| 33 | unsigned ColumnEnd) |
| 34 | : LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd), |
| 35 | ColumnEnd(ColumnEnd) {} |
| 36 | |
| 37 | bool operator==(const SourceRange &Other) const { |
| 38 | return LineStart == Other.LineStart && ColumnStart == Other.ColumnStart && |
| 39 | LineEnd == Other.LineEnd && ColumnEnd == Other.ColumnEnd; |
| 40 | } |
| 41 | |
| 42 | bool operator<(const SourceRange &Other) const { |
| 43 | if (LineStart == Other.LineStart) |
| 44 | return ColumnStart < Other.ColumnStart; |
| 45 | return LineStart < Other.LineStart; |
| 46 | } |
| 47 | |
| 48 | bool contains(const SourceRange &Other) { |
| 49 | if (LineStart > Other.LineStart || |
| 50 | (LineStart == Other.LineStart && ColumnStart > Other.ColumnStart)) |
| 51 | return false; |
| 52 | if (LineEnd < Other.LineEnd || |
| 53 | (LineEnd == Other.LineEnd && ColumnEnd < Other.ColumnEnd)) |
| 54 | return false; |
| 55 | return true; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | protected: |
| 60 | std::vector<std::pair<SourceRange, uint64_t>> Regions; |
| 61 | std::vector<SourceRange> SkippedRegions; |
| 62 | bool Uniqued; |
| 63 | |
| 64 | public: |
| 65 | SourceCoverageDataManager() : Uniqued(false) {} |
| 66 | |
| 67 | void insert(const MappingRegion &Region); |
| 68 | |
| 69 | /// \brief Return the source ranges and execution counts |
| 70 | /// obtained from the non-skipped mapping regions. |
| 71 | ArrayRef<std::pair<SourceRange, uint64_t>> getSourceRegions(); |
| 72 | |
| 73 | /// \brief Return the source ranges obtained from the skipped mapping regions. |
| 74 | ArrayRef<SourceRange> getSkippedRegions() const { return SkippedRegions; } |
| 75 | }; |
| 76 | |
| 77 | } // namespace llvm |
| 78 | |
| 79 | #endif // LLVM_COV_SOURCECOVERAGEDATAMANAGER_H |