From fda3028ce05cedd01744e934a881d025e3d5f5e8 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Mon, 20 Jan 2025 15:51:32 +0100 Subject: [PATCH] Remove duplicates in verilator_coverage Signed-off-by: Ryszard Rozak --- src/VlcSource.h | 8 ++++---- src/VlcTop.cpp | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/VlcSource.h b/src/VlcSource.h index 35a99a0659..1027d89bdb 100644 --- a/src/VlcSource.h +++ b/src/VlcSource.h @@ -35,7 +35,7 @@ class VlcPoint; class VlcSourceCount final { // TYPES - using PointsSet = std::set; + using PointsSet = std::set; // MEMBERS const int m_lineno; ///< Line number @@ -55,12 +55,12 @@ class VlcSourceCount final { uint64_t minCount() const { return m_minCount; } // METHODS - void insertPoint(const VlcPoint* pointp) { + void insertPoint(VlcPoint* pointp) { m_maxCount = std::max(m_maxCount, pointp->count()); m_minCount = std::min(m_minCount, pointp->count()); m_points.emplace(pointp); } - const PointsSet& points() { return m_points; } + PointsSet& points() { return m_points; } }; //******************************************************************** @@ -90,7 +90,7 @@ class VlcSource final { LinenoMap& lines() { return m_lines; } // METHODS - void insertPoint(int lineno, const VlcPoint* pointp) { + void insertPoint(int lineno, VlcPoint* pointp) { VlcSourceCount& sc = m_lines.emplace(lineno, lineno).first->second; sc.insertPoint(pointp); } diff --git a/src/VlcTop.cpp b/src/VlcTop.cpp index cafb7ec14b..ca0e35a165 100644 --- a/src/VlcTop.cpp +++ b/src/VlcTop.cpp @@ -80,6 +80,28 @@ void VlcTop::writeCoverage(const string& filename) { os << "C '" << point.name() << "' " << point.count() << '\n'; } } +std::string getKey(VlcPoint* const point) { + std::string comment = point->comment().substr(0, point->comment().find("=")); + if (comment.find("toggle") != std::string::npos) { + return comment; + } else { + return std::to_string(point->lineno()) + std::to_string(point->column()); + } +} +void processPoints(VlcSourceCount& sc) { + std::map pointsMap; + std::set toErase; + for (auto& point : sc.points()) { + std::string key = getKey(point); + if (pointsMap.find(key) == pointsMap.end()) { + pointsMap[key] = point; + } else { + pointsMap[key]->countInc(point->count()); + toErase.insert(point); + } + } + for (auto& point : toErase) { sc.points().erase(point); } +} void VlcTop::writeInfo(const string& filename) { UINFO(2, "writeInfo " << filename << endl); @@ -120,6 +142,7 @@ void VlcTop::writeInfo(const string& filename) { int branchesHit = 0; for (auto& li : lines) { VlcSourceCount& sc = li.second; + processPoints(sc); os << "DA:" << sc.lineno() << "," << sc.maxCount() << "\n"; int num_branches = sc.points().size(); if (num_branches == 1) continue; @@ -129,9 +152,13 @@ void VlcTop::writeInfo(const string& filename) { os << "BRDA:" << sc.lineno() << ","; os << "0,"; const string cmt = point->comment().substr(0, point->comment().find("=")); - os << cmt; - if (cmt.rfind("toggle_", 0) != 0) { os << "_" << point_num; } + if (cmt.rfind("toggle_", 0) != 0) { + std::string typeStr = cmt.substr(0, cmt.find("_")); + os << typeStr << "_" << point_num; + } else { + os << cmt; + } os << ","; os << point->count() << "\n"; @@ -212,7 +239,7 @@ void VlcTop::rank() { void VlcTop::annotateCalc() { // Calculate per-line information into filedata structure for (const auto& i : m_points) { - const VlcPoint& point = m_points.pointNumber(i.second); + VlcPoint& point = m_points.pointNumber(i.second); const string filename = point.filename(); const int lineno = point.lineno(); if (!filename.empty() && lineno != 0) {