mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 23:48:56 +00:00
llvm-cov: Rename MappingRegion to coverage::CountedRegion (NFC)
This name was too similar to CoverageMappingRegion, and the type really belongs in the coverage library anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217416 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
086832979b
commit
74a60259a5
@ -173,6 +173,14 @@ struct CounterMappingRegion {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// \brief Associates a source range with an execution count.
|
||||||
|
struct CountedRegion : public CounterMappingRegion {
|
||||||
|
uint64_t ExecutionCount;
|
||||||
|
|
||||||
|
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
|
||||||
|
: CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}
|
||||||
|
};
|
||||||
|
|
||||||
/// \brief A Counter mapping context is used to connect the counters,
|
/// \brief A Counter mapping context is used to connect the counters,
|
||||||
/// expressions and the obtained counter values.
|
/// expressions and the obtained counter values.
|
||||||
class CounterMappingContext {
|
class CounterMappingContext {
|
||||||
|
@ -53,14 +53,14 @@ class FunctionInstantiationSetCollector {
|
|||||||
typedef std::vector<const FunctionCoverageMapping *> SetType;
|
typedef std::vector<const FunctionCoverageMapping *> SetType;
|
||||||
std::unordered_map<uint64_t, SetType> InstantiatedFunctions;
|
std::unordered_map<uint64_t, SetType> InstantiatedFunctions;
|
||||||
|
|
||||||
static KeyType getKey(const MappingRegion &R) {
|
static KeyType getKey(const CountedRegion &R) {
|
||||||
return uint64_t(R.LineStart) | uint64_t(R.ColumnStart) << 32;
|
return uint64_t(R.LineStart) | uint64_t(R.ColumnStart) << 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void insert(const FunctionCoverageMapping &Function, unsigned FileID) {
|
void insert(const FunctionCoverageMapping &Function, unsigned FileID) {
|
||||||
KeyType Key = 0;
|
KeyType Key = 0;
|
||||||
for (const auto &R : Function.MappingRegions) {
|
for (const auto &R : Function.CountedRegions) {
|
||||||
if (R.FileID == FileID) {
|
if (R.FileID == FileID) {
|
||||||
Key = getKey(R);
|
Key = getKey(R);
|
||||||
break;
|
break;
|
||||||
@ -119,7 +119,7 @@ public:
|
|||||||
|
|
||||||
/// \brief Create a source view which shows coverage for an expansion
|
/// \brief Create a source view which shows coverage for an expansion
|
||||||
/// of a file.
|
/// of a file.
|
||||||
void createExpansionSubView(const MappingRegion &ExpandedRegion,
|
void createExpansionSubView(const CountedRegion &ExpandedRegion,
|
||||||
const FunctionCoverageMapping &Function,
|
const FunctionCoverageMapping &Function,
|
||||||
SourceCoverageView &Parent);
|
SourceCoverageView &Parent);
|
||||||
|
|
||||||
@ -197,11 +197,11 @@ findExpandedFileInterestingLineRange(unsigned FileID,
|
|||||||
const FunctionCoverageMapping &Function) {
|
const FunctionCoverageMapping &Function) {
|
||||||
unsigned LineStart = std::numeric_limits<unsigned>::max();
|
unsigned LineStart = std::numeric_limits<unsigned>::max();
|
||||||
unsigned LineEnd = 0;
|
unsigned LineEnd = 0;
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (Region.FileID != FileID)
|
if (CR.FileID != FileID)
|
||||||
continue;
|
continue;
|
||||||
LineStart = std::min(Region.LineStart, LineStart);
|
LineStart = std::min(CR.LineStart, LineStart);
|
||||||
LineEnd = std::max(Region.LineEnd, LineEnd);
|
LineEnd = std::max(CR.LineEnd, LineEnd);
|
||||||
}
|
}
|
||||||
return std::make_pair(LineStart, LineEnd);
|
return std::make_pair(LineStart, LineEnd);
|
||||||
}
|
}
|
||||||
@ -236,10 +236,10 @@ CodeCoverageTool::findMainViewFileID(StringRef SourceFile,
|
|||||||
if (equivalentFiles(SourceFile, Function.Filenames[I]))
|
if (equivalentFiles(SourceFile, Function.Filenames[I]))
|
||||||
FilenameEquivalence[I] = true;
|
FilenameEquivalence[I] = true;
|
||||||
}
|
}
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (Region.Kind == MappingRegion::ExpansionRegion &&
|
if (CR.Kind == CounterMappingRegion::ExpansionRegion &&
|
||||||
FilenameEquivalence[Region.FileID])
|
FilenameEquivalence[CR.FileID])
|
||||||
IsExpandedFile[Region.ExpandedFileID] = true;
|
IsExpandedFile[CR.ExpandedFileID] = true;
|
||||||
}
|
}
|
||||||
for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I) {
|
for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I) {
|
||||||
if (!FilenameEquivalence[I] || IsExpandedFile[I])
|
if (!FilenameEquivalence[I] || IsExpandedFile[I])
|
||||||
@ -254,9 +254,9 @@ bool
|
|||||||
CodeCoverageTool::findMainViewFileID(const FunctionCoverageMapping &Function,
|
CodeCoverageTool::findMainViewFileID(const FunctionCoverageMapping &Function,
|
||||||
unsigned &MainViewFileID) {
|
unsigned &MainViewFileID) {
|
||||||
llvm::SmallVector<bool, 8> IsExpandedFile(Function.Filenames.size(), false);
|
llvm::SmallVector<bool, 8> IsExpandedFile(Function.Filenames.size(), false);
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (Region.Kind == MappingRegion::ExpansionRegion)
|
if (CR.Kind == CounterMappingRegion::ExpansionRegion)
|
||||||
IsExpandedFile[Region.ExpandedFileID] = true;
|
IsExpandedFile[CR.ExpandedFileID] = true;
|
||||||
}
|
}
|
||||||
for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I) {
|
for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I) {
|
||||||
if (IsExpandedFile[I])
|
if (IsExpandedFile[I])
|
||||||
@ -268,7 +268,7 @@ CodeCoverageTool::findMainViewFileID(const FunctionCoverageMapping &Function,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CodeCoverageTool::createExpansionSubView(
|
void CodeCoverageTool::createExpansionSubView(
|
||||||
const MappingRegion &ExpandedRegion,
|
const CountedRegion &ExpandedRegion,
|
||||||
const FunctionCoverageMapping &Function, SourceCoverageView &Parent) {
|
const FunctionCoverageMapping &Function, SourceCoverageView &Parent) {
|
||||||
auto ExpandedLines = findExpandedFileInterestingLineRange(
|
auto ExpandedLines = findExpandedFileInterestingLineRange(
|
||||||
ExpandedRegion.ExpandedFileID, Function);
|
ExpandedRegion.ExpandedFileID, Function);
|
||||||
@ -286,9 +286,9 @@ void CodeCoverageTool::createExpansionSubView(
|
|||||||
SourceBuffer.get(), Parent.getOptions(), ExpandedLines.first,
|
SourceBuffer.get(), Parent.getOptions(), ExpandedLines.first,
|
||||||
ExpandedLines.second, ExpandedRegion);
|
ExpandedLines.second, ExpandedRegion);
|
||||||
SourceCoverageDataManager RegionManager;
|
SourceCoverageDataManager RegionManager;
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (Region.FileID == ExpandedRegion.ExpandedFileID)
|
if (CR.FileID == ExpandedRegion.ExpandedFileID)
|
||||||
RegionManager.insert(Region);
|
RegionManager.insert(CR);
|
||||||
}
|
}
|
||||||
SubView->load(RegionManager);
|
SubView->load(RegionManager);
|
||||||
createExpansionSubViews(*SubView, ExpandedRegion.ExpandedFileID, Function);
|
createExpansionSubViews(*SubView, ExpandedRegion.ExpandedFileID, Function);
|
||||||
@ -300,12 +300,12 @@ void CodeCoverageTool::createExpansionSubViews(
|
|||||||
const FunctionCoverageMapping &Function) {
|
const FunctionCoverageMapping &Function) {
|
||||||
if (!ViewOpts.ShowExpandedRegions)
|
if (!ViewOpts.ShowExpandedRegions)
|
||||||
return;
|
return;
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (Region.Kind != CounterMappingRegion::ExpansionRegion)
|
if (CR.Kind != CounterMappingRegion::ExpansionRegion)
|
||||||
continue;
|
continue;
|
||||||
if (Region.FileID != ViewFileID)
|
if (CR.FileID != ViewFileID)
|
||||||
continue;
|
continue;
|
||||||
createExpansionSubView(Region, Function, View);
|
createExpansionSubView(CR, Function, View);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,9 +317,9 @@ void CodeCoverageTool::createInstantiationSubView(
|
|||||||
if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
|
if (!gatherInterestingFileIDs(SourceFile, Function, InterestingFileIDs))
|
||||||
return;
|
return;
|
||||||
// Get the interesting regions
|
// Get the interesting regions
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (InterestingFileIDs.count(Region.FileID))
|
if (InterestingFileIDs.count(CR.FileID))
|
||||||
RegionManager.insert(Region);
|
RegionManager.insert(CR);
|
||||||
}
|
}
|
||||||
View.load(RegionManager);
|
View.load(RegionManager);
|
||||||
unsigned MainFileID;
|
unsigned MainFileID;
|
||||||
@ -346,9 +346,9 @@ bool CodeCoverageTool::createSourceFileView(
|
|||||||
InterestingFileIDs))
|
InterestingFileIDs))
|
||||||
continue;
|
continue;
|
||||||
// Get the interesting regions
|
// Get the interesting regions
|
||||||
for (const auto &Region : Function.MappingRegions) {
|
for (const auto &CR : Function.CountedRegions) {
|
||||||
if (InterestingFileIDs.count(Region.FileID))
|
if (InterestingFileIDs.count(CR.FileID))
|
||||||
RegionManager.insert(Region);
|
RegionManager.insert(CR);
|
||||||
}
|
}
|
||||||
InstantiationSetCollector.insert(Function, MainFileID);
|
InstantiationSetCollector.insert(Function, MainFileID);
|
||||||
createExpansionSubViews(View, MainFileID, Function);
|
createExpansionSubViews(View, MainFileID, Function);
|
||||||
@ -363,7 +363,7 @@ bool CodeCoverageTool::createSourceFileView(
|
|||||||
if (InstantiationSet.second.size() < 2)
|
if (InstantiationSet.second.size() < 2)
|
||||||
continue;
|
continue;
|
||||||
auto InterestingRange = findExpandedFileInterestingLineRange(
|
auto InterestingRange = findExpandedFileInterestingLineRange(
|
||||||
InstantiationSet.second.front()->MappingRegions.front().FileID,
|
InstantiationSet.second.front()->CountedRegions.front().FileID,
|
||||||
*InstantiationSet.second.front());
|
*InstantiationSet.second.front());
|
||||||
for (auto Function : InstantiationSet.second) {
|
for (auto Function : InstantiationSet.second) {
|
||||||
auto SubView = llvm::make_unique<SourceCoverageView>(
|
auto SubView = llvm::make_unique<SourceCoverageView>(
|
||||||
@ -413,7 +413,7 @@ bool CodeCoverageTool::load() {
|
|||||||
}
|
}
|
||||||
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(R.Count);
|
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(R.Count);
|
||||||
if (ExecutionCount) {
|
if (ExecutionCount) {
|
||||||
Function.MappingRegions.push_back(MappingRegion(R, *ExecutionCount));
|
Function.CountedRegions.push_back(CountedRegion(R, *ExecutionCount));
|
||||||
} else if (!RegionError) {
|
} else if (!RegionError) {
|
||||||
colored_ostream(errs(), raw_ostream::RED)
|
colored_ostream(errs(), raw_ostream::RED)
|
||||||
<< "error: Regions and counters don't match in a function '"
|
<< "error: Regions and counters don't match in a function '"
|
||||||
|
@ -21,11 +21,11 @@ FunctionCoverageSummary
|
|||||||
FunctionCoverageSummary::get(const FunctionCoverageMapping &Function) {
|
FunctionCoverageSummary::get(const FunctionCoverageMapping &Function) {
|
||||||
// Compute the region coverage
|
// Compute the region coverage
|
||||||
size_t NumCodeRegions = 0, CoveredRegions = 0;
|
size_t NumCodeRegions = 0, CoveredRegions = 0;
|
||||||
for (auto &Region : Function.MappingRegions) {
|
for (auto &CR : Function.CountedRegions) {
|
||||||
if (Region.Kind != CounterMappingRegion::CodeRegion)
|
if (CR.Kind != CounterMappingRegion::CodeRegion)
|
||||||
continue;
|
continue;
|
||||||
++NumCodeRegions;
|
++NumCodeRegions;
|
||||||
if (Region.ExecutionCount != 0)
|
if (CR.ExecutionCount != 0)
|
||||||
++CoveredRegions;
|
++CoveredRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,27 +37,27 @@ FunctionCoverageSummary::get(const FunctionCoverageMapping &Function) {
|
|||||||
// in that particular file
|
// in that particular file
|
||||||
unsigned LineStart = std::numeric_limits<unsigned>::max();
|
unsigned LineStart = std::numeric_limits<unsigned>::max();
|
||||||
unsigned LineEnd = 0;
|
unsigned LineEnd = 0;
|
||||||
for (auto &Region : Function.MappingRegions) {
|
for (auto &CR : Function.CountedRegions) {
|
||||||
if (Region.FileID != FileID)
|
if (CR.FileID != FileID)
|
||||||
continue;
|
continue;
|
||||||
LineStart = std::min(LineStart, Region.LineStart);
|
LineStart = std::min(LineStart, CR.LineStart);
|
||||||
LineEnd = std::max(LineEnd, Region.LineEnd);
|
LineEnd = std::max(LineEnd, CR.LineEnd);
|
||||||
}
|
}
|
||||||
unsigned LineCount = LineEnd - LineStart + 1;
|
unsigned LineCount = LineEnd - LineStart + 1;
|
||||||
|
|
||||||
// Get counters
|
// Get counters
|
||||||
llvm::SmallVector<uint64_t, 16> ExecutionCounts;
|
llvm::SmallVector<uint64_t, 16> ExecutionCounts;
|
||||||
ExecutionCounts.resize(LineCount, 0);
|
ExecutionCounts.resize(LineCount, 0);
|
||||||
for (auto &Region : Function.MappingRegions) {
|
for (auto &CR : Function.CountedRegions) {
|
||||||
if (Region.FileID != FileID)
|
if (CR.FileID != FileID)
|
||||||
continue;
|
continue;
|
||||||
// Ignore the lines that were skipped by the preprocessor.
|
// Ignore the lines that were skipped by the preprocessor.
|
||||||
auto ExecutionCount = Region.ExecutionCount;
|
auto ExecutionCount = CR.ExecutionCount;
|
||||||
if (Region.Kind == MappingRegion::SkippedRegion) {
|
if (CR.Kind == CounterMappingRegion::SkippedRegion) {
|
||||||
LineCount -= Region.LineEnd - Region.LineStart + 1;
|
LineCount -= CR.LineEnd - CR.LineStart + 1;
|
||||||
ExecutionCount = 1;
|
ExecutionCount = 1;
|
||||||
}
|
}
|
||||||
for (unsigned I = Region.LineStart; I <= Region.LineEnd; ++I)
|
for (unsigned I = CR.LineStart; I <= CR.LineEnd; ++I)
|
||||||
ExecutionCounts[I - LineStart] = ExecutionCount;
|
ExecutionCounts[I - LineStart] = ExecutionCount;
|
||||||
}
|
}
|
||||||
CoveredLines += LineCount - std::count(ExecutionCounts.begin(),
|
CoveredLines += LineCount - std::count(ExecutionCounts.begin(),
|
||||||
|
@ -22,21 +22,13 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
/// \brief Associates a source range with an execution count.
|
|
||||||
struct MappingRegion : public coverage::CounterMappingRegion {
|
|
||||||
uint64_t ExecutionCount;
|
|
||||||
|
|
||||||
MappingRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
|
|
||||||
: CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// \brief Stores all the required information
|
/// \brief Stores all the required information
|
||||||
/// about code coverage for a single function.
|
/// about code coverage for a single function.
|
||||||
struct FunctionCoverageMapping {
|
struct FunctionCoverageMapping {
|
||||||
/// \brief Raw function name.
|
/// \brief Raw function name.
|
||||||
std::string Name;
|
std::string Name;
|
||||||
std::vector<std::string> Filenames;
|
std::vector<std::string> Filenames;
|
||||||
std::vector<MappingRegion> MappingRegions;
|
std::vector<coverage::CountedRegion> CountedRegions;
|
||||||
|
|
||||||
FunctionCoverageMapping(StringRef Name, ArrayRef<StringRef> Filenames)
|
FunctionCoverageMapping(StringRef Name, ArrayRef<StringRef> Filenames)
|
||||||
: Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
|
: Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
|
||||||
|
@ -17,14 +17,13 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace coverage;
|
using namespace coverage;
|
||||||
|
|
||||||
void SourceCoverageDataManager::insert(const MappingRegion &Region) {
|
void SourceCoverageDataManager::insert(const CountedRegion &CR) {
|
||||||
SourceRange Range(Region.LineStart, Region.ColumnStart, Region.LineEnd,
|
SourceRange Range(CR.LineStart, CR.ColumnStart, CR.LineEnd, CR.ColumnEnd);
|
||||||
Region.ColumnEnd);
|
if (CR.Kind == CounterMappingRegion::SkippedRegion) {
|
||||||
if (Region.Kind == CounterMappingRegion::SkippedRegion) {
|
|
||||||
SkippedRegions.push_back(Range);
|
SkippedRegions.push_back(Range);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Regions.push_back(std::make_pair(Range, Region.ExecutionCount));
|
Regions.push_back(std::make_pair(Range, CR.ExecutionCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayRef<std::pair<SourceCoverageDataManager::SourceRange, uint64_t>>
|
ArrayRef<std::pair<SourceCoverageDataManager::SourceRange, uint64_t>>
|
||||||
|
@ -64,7 +64,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
SourceCoverageDataManager() : Uniqued(false) {}
|
SourceCoverageDataManager() : Uniqued(false) {}
|
||||||
|
|
||||||
void insert(const MappingRegion &Region);
|
void insert(const coverage::CountedRegion &CR);
|
||||||
|
|
||||||
/// \brief Return the source ranges and execution counts
|
/// \brief Return the source ranges and execution counts
|
||||||
/// obtained from the non-skipped mapping regions.
|
/// obtained from the non-skipped mapping regions.
|
||||||
|
Loading…
Reference in New Issue
Block a user