diff options
author | Xinliang David Li <davidxl@google.com> | 2015-12-15 19:44:45 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-12-15 19:44:45 +0000 |
commit | 4ec401406e3d71aae58fa210b727175022937cf2 (patch) | |
tree | 9ea74205732b8b00206be578616d4c801e26c4b0 | |
parent | 843fb204b7102bc1abd7fdadf39f3ac2e0acb479 (diff) | |
download | bcm5719-llvm-4ec401406e3d71aae58fa210b727175022937cf2.tar.gz bcm5719-llvm-4ec401406e3d71aae58fa210b727175022937cf2.zip |
Coverage code refactoring /NFC
llvm-svn: 255670
-rw-r--r-- | llvm/include/llvm/ProfileData/InstrProf.h | 4 | ||||
-rw-r--r-- | llvm/lib/ProfileData/CoverageMapping.cpp | 18 | ||||
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 9 |
3 files changed, 18 insertions, 13 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index 98cb5b8e25a..a1d5ed97e0b 100644 --- a/llvm/include/llvm/ProfileData/InstrProf.h +++ b/llvm/include/llvm/ProfileData/InstrProf.h @@ -156,6 +156,10 @@ GlobalVariable *createPGOFuncNameVar(Module &M, GlobalValue::LinkageTypes Linkage, StringRef FuncName); +/// Given a PGO function name, remove the filename prefix and return +/// the original (static) function name. +StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName); + const std::error_category &instrprof_category(); enum class instrprof_error { diff --git a/llvm/lib/ProfileData/CoverageMapping.cpp b/llvm/lib/ProfileData/CoverageMapping.cpp index cf04fea8491..55c0fb4792e 100644 --- a/llvm/lib/ProfileData/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/CoverageMapping.cpp @@ -181,18 +181,6 @@ void FunctionRecordIterator::skipOtherFiles() { *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) { @@ -216,7 +204,11 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader, assert(!Record.MappingRegions.empty() && "Function has no regions"); - FunctionRecord Function(getFuncNameWithoutPrefix(Record), Record.Filenames); + StringRef OrigFuncName = Record.FunctionName; + if (!Record.Filenames.empty()) + OrigFuncName = + getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]); + FunctionRecord Function(OrigFuncName, Record.Filenames); for (const auto &Region : Record.MappingRegions) { ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count); if (!ExecutionCount) diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 40617171f09..723408b1c2a 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -102,6 +102,15 @@ std::string getPGOFuncName(const Function &F, uint64_t Version) { Version); } +StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { + if (FileName.empty()) + return PGOFuncName; + // Drop the file name including ':'. See also getPGOFuncName. + if (PGOFuncName.startswith(FileName)) + PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1); + return PGOFuncName; +} + // \p FuncName is the string used as profile lookup key for the function. A // symbol is created to hold the name. Return the legalized symbol name. static std::string getPGOFuncNameVarName(StringRef FuncName, |