Skip to content

Commit

Permalink
[Coverage] Strip <unknown> from PGO names if no filenames are available
Browse files Browse the repository at this point in the history
Patch suggested by David Li!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264586 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vedantk committed Mar 28, 2016
1 parent 3fb5c43 commit ab3787a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<unknown>");

/// Given a vector of strings (function PGO names) \c NameStrs, the
/// method generates a combined string \c Result thatis ready to be
Expand Down
4 changes: 3 additions & 1 deletion lib/ProfileData/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::string getPGOFuncName(const Function &F, uint64_t Version) {

StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) {
if (FileName.empty())
FileName = "<unknown>";
return PGOFuncName;
// Drop the file name including ':'. See also getPGOFuncName.
if (PGOFuncName.startswith(FileName))
PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1);
Expand Down
10 changes: 6 additions & 4 deletions unittests/ProfileData/CoverageMappingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringRef, 8> 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()));
Expand Down Expand Up @@ -310,7 +312,7 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) {
readProfCounts();

addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
loadCoverageMapping("<unknown>:func", 0x1234);
loadCoverageMapping("<unknown>:func", 0x1234, /*EmitFilenames=*/false);

std::vector<std::string> Names;
for (const auto &Func : LoadedCoverage->getCoveredFunctions())
Expand Down

0 comments on commit ab3787a

Please sign in to comment.