[llvm] r339194 - [Coverage] Ignore 'unused' functions with non-zero execution counts
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 7 15:25:36 PDT 2018
Author: vedantk
Date: Tue Aug 7 15:25:36 2018
New Revision: 339194
URL: http://llvm.org/viewvc/llvm-project?rev=339194&view=rev
Log:
[Coverage] Ignore 'unused' functions with non-zero execution counts
Frontends emit 'unused' coverage mapping records for functions which are
provably unused in a TU. These unused records contain a single counter
with CounterKind::Zero. However, a function may be unused in one TU and
used in another. When this happens, prefer the records with a full set
of counters instead of arbitrarily picking the first loaded record.
There is no impact on the single-TU case. In the multiple-TU case, this
resolves issues causing a function to appear unused when it's not.
Testing: check-{llvm,clang,compiler-rt}
rdar://42981322
Modified:
llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp
Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp?rev=339194&r1=339193&r2=339194&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp Tue Aug 7 15:25:36 2018
@@ -207,12 +207,6 @@ Error CoverageMapping::loadFunctionRecor
else
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
- // Don't load records for (filenames, function) pairs we've already seen.
- auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
- Record.Filenames.end());
- if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
- return Error::success();
-
CounterMappingContext Ctx(Record.Expressions);
std::vector<uint64_t> Counts;
@@ -230,6 +224,15 @@ Error CoverageMapping::loadFunctionRecor
assert(!Record.MappingRegions.empty() && "Function has no regions");
+ // This coverage record is a zero region for a function that's unused in
+ // some TU, but used in a different TU. Ignore it. The coverage maps from the
+ // the other TU will either be loaded (providing full region counts) or they
+ // won't (in which case we don't unintuitively report functions as uncovered
+ // when they have non-zero counts in the profile).
+ if (Record.MappingRegions.size() == 1 &&
+ Record.MappingRegions[0].Count.isZero() && Counts[0] > 0)
+ return Error::success();
+
FunctionRecord Function(OrigFuncName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
@@ -240,6 +243,12 @@ Error CoverageMapping::loadFunctionRecor
Function.pushRegion(Region, *ExecutionCount);
}
+ // Don't create records for (filenames, function) pairs we've already seen.
+ auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
+ Record.Filenames.end());
+ if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
+ return Error::success();
+
Functions.push_back(std::move(Function));
return Error::success();
}
More information about the llvm-commits
mailing list