InstrProf: Strip filename prefixes from the names we display for coverage
For consumers of coverage data, any filename prefixes we store in the
profile data are just noise. Strip this prefix if it exists.
llvm-svn: 236558
diff --git a/llvm/lib/ProfileData/CoverageMapping.cpp b/llvm/lib/ProfileData/CoverageMapping.cpp
index 46d494b..5f1d94a 100644
--- a/llvm/lib/ProfileData/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/CoverageMapping.cpp
@@ -20,6 +20,7 @@
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -178,6 +179,18 @@
*this = FunctionRecordIterator();
}
+/// Get the function name from the record, removing the filename prefix if
+/// necessary.
+static StringRef getFuncNameWithoutPrefix(const CoverageMappingRecord &Record) {
+ StringRef FunctionName = Record.FunctionName;
+ if (Record.Filenames.empty())
+ return FunctionName;
+ StringRef Filename = sys::path::filename(Record.Filenames[0]);
+ if (FunctionName.startswith(Filename))
+ FunctionName = FunctionName.drop_front(Filename.size() + 1);
+ return FunctionName;
+}
+
ErrorOr<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(CoverageMappingReader &CoverageReader,
IndexedInstrProfReader &ProfileReader) {
@@ -199,7 +212,8 @@
Ctx.setCounts(Counts);
assert(!Record.MappingRegions.empty() && "Function has no regions");
- FunctionRecord Function(Record.FunctionName, Record.Filenames);
+
+ FunctionRecord Function(getFuncNameWithoutPrefix(Record), Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
if (!ExecutionCount)