[llvm] r218185 - llvm-cov: Allow creating CoverageMappings from filenames

Justin Bogner mail at justinbogner.com
Sat Sep 20 10:19:53 PDT 2014


Author: bogner
Date: Sat Sep 20 12:19:52 2014
New Revision: 218185

URL: http://llvm.org/viewvc/llvm-project?rev=218185&view=rev
Log:
llvm-cov: Allow creating CoverageMappings from filenames

Modified:
    llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
    llvm/trunk/lib/ProfileData/CoverageMapping.cpp
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp

Modified: llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/CoverageMapping.h?rev=218185&r1=218184&r2=218185&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/CoverageMapping.h Sat Sep 20 12:19:52 2014
@@ -318,11 +318,15 @@ class CoverageMapping {
   CoverageMapping() : MismatchedFunctionCount(0) {}
 
 public:
-  /// Load the coverage mapping using the given readers.
+  /// \brief Load the coverage mapping using the given readers.
   static ErrorOr<std::unique_ptr<CoverageMapping>>
   load(ObjectFileCoverageMappingReader &CoverageReader,
        IndexedInstrProfReader &ProfileReader);
 
+  /// \brief Load the coverage mapping from the given files.
+  static ErrorOr<std::unique_ptr<CoverageMapping>>
+  load(StringRef ObjectFilename, StringRef ProfileFilename);
+
   /// \brief The number of functions that couldn't have their profiles mapped.
   ///
   /// This is a count of functions whose profile is out of date or otherwise

Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=218185&r1=218184&r2=218185&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Sat Sep 20 12:19:52 2014
@@ -183,6 +183,20 @@ CoverageMapping::load(ObjectFileCoverage
   return std::move(Coverage);
 }
 
+ErrorOr<std::unique_ptr<CoverageMapping>>
+CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename) {
+  auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
+  if (auto EC = CounterMappingBuff.getError())
+    return EC;
+  ObjectFileCoverageMappingReader CoverageReader(CounterMappingBuff.get());
+  if (auto EC = CoverageReader.readHeader())
+    return EC;
+  std::unique_ptr<IndexedInstrProfReader> ProfileReader;
+  if (auto EC = IndexedInstrProfReader::create(ProfileFilename, ProfileReader))
+    return EC;
+  return load(CoverageReader, *ProfileReader);
+}
+
 namespace {
 /// \brief Distributes functions into instantiation sets.
 ///

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=218185&r1=218184&r2=218185&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Sat Sep 20 12:19:52 2014
@@ -196,24 +196,7 @@ CodeCoverageTool::createSourceFileView(S
 }
 
 std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
-  auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
-  if (auto EC = CounterMappingBuff.getError()) {
-    error(EC.message(), ObjectFilename);
-    return nullptr;
-  }
-  ObjectFileCoverageMappingReader MappingReader(CounterMappingBuff.get());
-  if (auto EC = MappingReader.readHeader()) {
-    error(EC.message(), ObjectFilename);
-    return nullptr;
-  }
-
-  std::unique_ptr<IndexedInstrProfReader> PGOReader;
-  if (auto EC = IndexedInstrProfReader::create(PGOFilename, PGOReader)) {
-    error(EC.message(), PGOFilename);
-    return nullptr;
-  }
-
-  auto CoverageOrErr = CoverageMapping::load(MappingReader, *PGOReader);
+  auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename);
   if (std::error_code EC = CoverageOrErr.getError()) {
     colored_ostream(errs(), raw_ostream::RED)
         << "error: Failed to load coverage: " << EC.message();





More information about the llvm-commits mailing list