[llvm] r229723 - InstrProf: Don't combine expansion regions with code regions

Justin Bogner mail at justinbogner.com
Wed Feb 18 11:01:07 PST 2015


Author: bogner
Date: Wed Feb 18 13:01:06 2015
New Revision: 229723

URL: http://llvm.org/viewvc/llvm-project?rev=229723&view=rev
Log:
InstrProf: Don't combine expansion regions with code regions

This was leading to duplicate counts when a code region happened to
overlap exactly with an expansion. The combining behaviour only makes
sense for code regions.

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=229723&r1=229722&r2=229723&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Wed Feb 18 13:01:06 2015
@@ -314,7 +314,7 @@ public:
         popRegion();
       if (PrevRegion && PrevRegion->startLoc() == Region.startLoc() &&
           PrevRegion->endLoc() == Region.endLoc()) {
-        if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion)
+        if (Region.Kind == coverage::CounterMappingRegion::CodeRegion)
           Segments.back().addCount(Region.ExecutionCount);
       } else {
         // Add this region to the stack.

Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=229723&r1=229722&r2=229723&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Wed Feb 18 13:01:06 2015
@@ -222,4 +222,41 @@ TEST_F(CoverageMappingTest, uncovered_fu
   ASSERT_EQ(CoverageSegment(3, 4, false),   Segments[1]);
 }
 
+TEST_F(CoverageMappingTest, combine_regions) {
+  ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20, 30});
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+  addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
+  addCMR(Counter::getCounter(2), "file1", 3, 3, 4, 4);
+  loadCoverageMapping("func", 0x1234);
+
+  CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
+  std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
+  ASSERT_EQ(4U, Segments.size());
+  ASSERT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
+  ASSERT_EQ(CoverageSegment(3, 3, 50, true), Segments[1]);
+  ASSERT_EQ(CoverageSegment(4, 4, 10, false), Segments[2]);
+  ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
+}
+
+TEST_F(CoverageMappingTest, dont_combine_expansions) {
+  ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20});
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+  addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
+  addCMR(Counter::getCounter(1), "include1", 6, 6, 7, 7);
+  addExpansionCMR("file1", "include1", 3, 3, 4, 4);
+  loadCoverageMapping("func", 0x1234);
+
+  CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
+  std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
+  ASSERT_EQ(4U, Segments.size());
+  ASSERT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
+  ASSERT_EQ(CoverageSegment(3, 3, 20, true), Segments[1]);
+  ASSERT_EQ(CoverageSegment(4, 4, 10, false), Segments[2]);
+  ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
+}
+
 } // end anonymous namespace





More information about the llvm-commits mailing list