[llvm] r237298 - InstrProf: Treat functions with a coverage map but no profile as unreached

Justin Bogner mail at justinbogner.com
Wed May 13 15:03:04 PDT 2015


Author: bogner
Date: Wed May 13 17:03:04 2015
New Revision: 237298

URL: http://llvm.org/viewvc/llvm-project?rev=237298&view=rev
Log:
InstrProf: Treat functions with a coverage map but no profile as unreached

If we have a coverage mapping but no profile data for a function,
calling it mismatched is misleading. This can just as easily be
unreachable code that was stripped from the binary. Instead, treat
these the same as functions where we have an explicit "zero" coverage
map by setting the count to zero for each mapped region.

Modified:
    llvm/trunk/lib/ProfileData/CoverageMapping.cpp
    llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp

Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=237298&r1=237297&r2=237298&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Wed May 13 17:03:04 2015
@@ -209,8 +209,9 @@ CoverageMapping::load(CoverageMappingRea
         continue;
       } else if (EC != instrprof_error::unknown_function)
         return EC;
-    } else
-      Ctx.setCounts(Counts);
+      Counts.assign(Record.MappingRegions.size(), 0);
+    }
+    Ctx.setCounts(Counts);
 
     assert(!Record.MappingRegions.empty() && "Function has no regions");
 

Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=237298&r1=237297&r2=237298&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Wed May 13 17:03:04 2015
@@ -222,6 +222,21 @@ TEST_F(CoverageMappingTest, uncovered_fu
   ASSERT_EQ(CoverageSegment(3, 4, false),   Segments[1]);
 }
 
+TEST_F(CoverageMappingTest, uncovered_function_with_mapping) {
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+  addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
+  loadCoverageMapping("func", 0x1234);
+
+  CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
+  std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
+  ASSERT_EQ(3U, Segments.size());
+  ASSERT_EQ(CoverageSegment(1, 1, 0, true),  Segments[0]);
+  ASSERT_EQ(CoverageSegment(4, 7, 0, false), Segments[1]);
+  ASSERT_EQ(CoverageSegment(9, 9, false),    Segments[2]);
+}
+
 TEST_F(CoverageMappingTest, combine_regions) {
   ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20, 30});
   readProfCounts();





More information about the llvm-commits mailing list