1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

[Coverage] Strip <unknown> from PGO names if no filenames are available

Patch suggested by David Li!

llvm-svn: 264586
This commit is contained in:
Vedant Kumar 2016-03-28 15:49:08 +00:00
parent 5e7b5fce65
commit 8c50bbf8c8
4 changed files with 12 additions and 7 deletions

View File

@ -188,7 +188,8 @@ StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar);
/// Given a PGO function name, remove the filename prefix and return /// Given a PGO function name, remove the filename prefix and return
/// the original (static) function name. /// the original (static) function name.
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName); StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
StringRef FileName = "<unknown>");
/// Given a vector of strings (function PGO names) \c NameStrs, the /// Given a vector of strings (function PGO names) \c NameStrs, the
/// method generates a combined string \c Result thatis ready to be /// method generates a combined string \c Result thatis ready to be

View File

@ -205,7 +205,9 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
assert(!Record.MappingRegions.empty() && "Function has no regions"); assert(!Record.MappingRegions.empty() && "Function has no regions");
StringRef OrigFuncName = Record.FunctionName; StringRef OrigFuncName = Record.FunctionName;
if (!Record.Filenames.empty()) if (Record.Filenames.empty())
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
else
OrigFuncName = OrigFuncName =
getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]); getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
FunctionRecord Function(OrigFuncName, Record.Filenames); FunctionRecord Function(OrigFuncName, Record.Filenames);

View File

@ -90,7 +90,7 @@ std::string getPGOFuncName(const Function &F, uint64_t Version) {
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) {
if (FileName.empty()) if (FileName.empty())
FileName = "<unknown>"; return PGOFuncName;
// Drop the file name including ':'. See also getPGOFuncName. // Drop the file name including ':'. See also getPGOFuncName.
if (PGOFuncName.startswith(FileName)) if (PGOFuncName.startswith(FileName))
PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1); PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1);

View File

@ -141,13 +141,15 @@ struct CoverageMappingTest : ::testing::Test {
ProfileReader = std::move(ReaderOrErr.get()); ProfileReader = std::move(ReaderOrErr.get());
} }
void loadCoverageMapping(StringRef FuncName, uint64_t Hash) { void loadCoverageMapping(StringRef FuncName, uint64_t Hash,
bool EmitFilenames = true) {
std::string Regions = writeCoverageRegions(); std::string Regions = writeCoverageRegions();
readCoverageRegions(Regions); readCoverageRegions(Regions);
SmallVector<StringRef, 8> Filenames; SmallVector<StringRef, 8> Filenames;
for (const auto &E : Files) if (EmitFilenames)
Filenames.push_back(E.getKey()); for (const auto &E : Files)
Filenames.push_back(E.getKey());
OneFunctionCoverageReader CovReader(FuncName, Hash, Filenames, OutputCMRs); OneFunctionCoverageReader CovReader(FuncName, Hash, Filenames, OutputCMRs);
auto CoverageOrErr = CoverageMapping::load(CovReader, *ProfileReader); auto CoverageOrErr = CoverageMapping::load(CovReader, *ProfileReader);
ASSERT_TRUE(NoError(CoverageOrErr.getError())); ASSERT_TRUE(NoError(CoverageOrErr.getError()));
@ -310,7 +312,7 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) {
readProfCounts(); readProfCounts();
addCMR(Counter::getCounter(0), "", 1, 1, 9, 9); addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
loadCoverageMapping("<unknown>:func", 0x1234); loadCoverageMapping("<unknown>:func", 0x1234, /*EmitFilenames=*/false);
std::vector<std::string> Names; std::vector<std::string> Names;
for (const auto &Func : LoadedCoverage->getCoveredFunctions()) for (const auto &Func : LoadedCoverage->getCoveredFunctions())