llvm.org GIT mirror llvm / 798787c
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229723 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 4 years ago
2 changed file(s) with 38 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
313313 popRegion();
314314 if (PrevRegion && PrevRegion->startLoc() == Region.startLoc() &&
315315 PrevRegion->endLoc() == Region.endLoc()) {
316 if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion)
316 if (Region.Kind == coverage::CounterMappingRegion::CodeRegion)
317317 Segments.back().addCount(Region.ExecutionCount);
318318 } else {
319319 // Add this region to the stack.
221221 ASSERT_EQ(CoverageSegment(3, 4, false), Segments[1]);
222222 }
223223
224 TEST_F(CoverageMappingTest, combine_regions) {
225 ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20, 30});
226 readProfCounts();
227
228 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
229 addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
230 addCMR(Counter::getCounter(2), "file1", 3, 3, 4, 4);
231 loadCoverageMapping("func", 0x1234);
232
233 CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
234 std::vector Segments(Data.begin(), Data.end());
235 ASSERT_EQ(4U, Segments.size());
236 ASSERT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
237 ASSERT_EQ(CoverageSegment(3, 3, 50, true), Segments[1]);
238 ASSERT_EQ(CoverageSegment(4, 4, 10, false), Segments[2]);
239 ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
240 }
241
242 TEST_F(CoverageMappingTest, dont_combine_expansions) {
243 ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20});
244 readProfCounts();
245
246 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
247 addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
248 addCMR(Counter::getCounter(1), "include1", 6, 6, 7, 7);
249 addExpansionCMR("file1", "include1", 3, 3, 4, 4);
250 loadCoverageMapping("func", 0x1234);
251
252 CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
253 std::vector Segments(Data.begin(), Data.end());
254 ASSERT_EQ(4U, Segments.size());
255 ASSERT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
256 ASSERT_EQ(CoverageSegment(3, 3, 20, true), Segments[1]);
257 ASSERT_EQ(CoverageSegment(4, 4, 10, false), Segments[2]);
258 ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
259 }
260
224261 } // end anonymous namespace