InstrProf: Handle unknown functions if they consist only of zero-regions

This comes up when we generate coverage for a function but don't end
up emitting the function at all - dead static functions or inline
functions that aren't referenced in a particular TU, for example. In
these cases we'd like to show that the function was never called,
which is trivially true.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229717 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner
2015-02-18 18:40:46 +00:00
parent a4976167c4
commit e0eae15f6c
3 changed files with 34 additions and 14 deletions

View File

@@ -184,25 +184,26 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
std::vector<uint64_t> Counts;
for (const auto &Record : CoverageReader) {
CounterMappingContext Ctx(Record.Expressions);
Counts.clear();
if (std::error_code EC = ProfileReader.getFunctionCounts(
Record.FunctionName, Record.FunctionHash, Counts)) {
if (EC != instrprof_error::hash_mismatch &&
EC != instrprof_error::unknown_function)
if (EC == instrprof_error::hash_mismatch) {
Coverage->MismatchedFunctionCount++;
continue;
} else if (EC != instrprof_error::unknown_function)
return EC;
Coverage->MismatchedFunctionCount++;
continue;
}
} else
Ctx.setCounts(Counts);
assert(Counts.size() != 0 && "Function's counts are empty");
FunctionRecord Function(Record.FunctionName, Record.Filenames,
Counts.front());
CounterMappingContext Ctx(Record.Expressions, Counts);
assert(!Record.MappingRegions.empty() && "Function has no regions");
FunctionRecord Function(Record.FunctionName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
if (!ExecutionCount)
break;
Function.CountedRegions.push_back(CountedRegion(Region, *ExecutionCount));
Function.pushRegion(Region, *ExecutionCount);
}
if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
Coverage->MismatchedFunctionCount++;