From ab3787a57492caf7f577d80de8bd848d715c716d Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 28 Mar 2016 15:49:08 +0000 Subject: [PATCH] [Coverage] Strip from PGO names if no filenames are available Patch suggested by David Li! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264586 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ProfileData/InstrProf.h | 3 ++- lib/ProfileData/CoverageMapping.cpp | 4 +++- lib/ProfileData/InstrProf.cpp | 2 +- unittests/ProfileData/CoverageMappingTest.cpp | 10 ++++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index 4e4d1cb6a22..3bf0aa38510 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -188,7 +188,8 @@ StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar); /// Given a PGO function name, remove the filename prefix and return /// the original (static) function name. -StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName); +StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, + StringRef FileName = ""); /// Given a vector of strings (function PGO names) \c NameStrs, the /// method generates a combined string \c Result thatis ready to be diff --git a/lib/ProfileData/CoverageMapping.cpp b/lib/ProfileData/CoverageMapping.cpp index f5d477bd139..aa43019a899 100644 --- a/lib/ProfileData/CoverageMapping.cpp +++ b/lib/ProfileData/CoverageMapping.cpp @@ -205,7 +205,9 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader, assert(!Record.MappingRegions.empty() && "Function has no regions"); StringRef OrigFuncName = Record.FunctionName; - if (!Record.Filenames.empty()) + if (Record.Filenames.empty()) + OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName); + else OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]); FunctionRecord Function(OrigFuncName, Record.Filenames); diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 045ba1a7b34..2446521a5bc 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -90,7 +90,7 @@ std::string getPGOFuncName(const Function &F, uint64_t Version) { StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { if (FileName.empty()) - FileName = ""; + return PGOFuncName; // Drop the file name including ':'. See also getPGOFuncName. if (PGOFuncName.startswith(FileName)) PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1); diff --git a/unittests/ProfileData/CoverageMappingTest.cpp b/unittests/ProfileData/CoverageMappingTest.cpp index 7f80384c63a..e1f0647e76e 100644 --- a/unittests/ProfileData/CoverageMappingTest.cpp +++ b/unittests/ProfileData/CoverageMappingTest.cpp @@ -141,13 +141,15 @@ struct CoverageMappingTest : ::testing::Test { 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(); readCoverageRegions(Regions); SmallVector Filenames; - for (const auto &E : Files) - Filenames.push_back(E.getKey()); + if (EmitFilenames) + for (const auto &E : Files) + Filenames.push_back(E.getKey()); OneFunctionCoverageReader CovReader(FuncName, Hash, Filenames, OutputCMRs); auto CoverageOrErr = CoverageMapping::load(CovReader, *ProfileReader); ASSERT_TRUE(NoError(CoverageOrErr.getError())); @@ -310,7 +312,7 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) { readProfCounts(); addCMR(Counter::getCounter(0), "", 1, 1, 9, 9); - loadCoverageMapping(":func", 0x1234); + loadCoverageMapping(":func", 0x1234, /*EmitFilenames=*/false); std::vector Names; for (const auto &Func : LoadedCoverage->getCoveredFunctions()) -- 2.11.0