2012-04-13 01:08:20 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2008-12-12 20:34:02 +00:00
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Netlist (top level) functions
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2008-12-12 20:34:02 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2020-03-21 15:24:24 +00:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you
|
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2008-12-12 20:34:02 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// COVERAGEJOIN TRANSFORMATIONS:
|
2019-05-19 20:13:13 +00:00
|
|
|
// If two COVERTOGGLEs have same VARSCOPE, combine them
|
2008-12-12 20:34:02 +00:00
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2008-12-12 20:34:02 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
#include "V3CoverageJoin.h"
|
|
|
|
#include "V3Hashed.h"
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2008-12-12 20:34:02 +00:00
|
|
|
//######################################################################
|
|
|
|
// CoverageJoin state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
class CoverageJoinVisitor : public AstNVisitor {
|
|
|
|
private:
|
|
|
|
// NODE STATE
|
|
|
|
// V3Hashed
|
2019-05-19 20:13:13 +00:00
|
|
|
// AstCoverToggle->VarRef::user4() // V3Hashed calculation
|
2008-12-12 20:34:02 +00:00
|
|
|
|
2020-04-14 02:51:35 +00:00
|
|
|
// AstUser4InUse In V3Hashed
|
2008-12-12 20:34:02 +00:00
|
|
|
|
|
|
|
// TYPES
|
2018-02-02 02:24:41 +00:00
|
|
|
typedef std::vector<AstCoverToggle*> ToggleList;
|
2008-12-12 20:34:02 +00:00
|
|
|
|
|
|
|
// STATE
|
2020-04-14 02:51:35 +00:00
|
|
|
ToggleList m_toggleps; // List of of all AstCoverToggle's
|
2008-12-12 20:34:02 +00:00
|
|
|
|
2020-04-14 02:51:35 +00:00
|
|
|
VDouble0 m_statToggleJoins; // Statistic tracking
|
2008-12-12 20:34:02 +00:00
|
|
|
|
|
|
|
// METHODS
|
2018-05-14 10:50:47 +00:00
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
2009-01-21 21:56:50 +00:00
|
|
|
|
2008-12-12 20:34:02 +00:00
|
|
|
void detectDuplicates() {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(9, "Finding duplicates\n");
|
2019-05-19 20:13:13 +00:00
|
|
|
// Note uses user4
|
2020-04-14 02:51:35 +00:00
|
|
|
V3Hashed hashed; // Duplicate code detection
|
2019-05-19 20:13:13 +00:00
|
|
|
// Hash all of the original signals we toggle cover
|
|
|
|
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
|
|
|
|
AstCoverToggle* nodep = *it;
|
|
|
|
hashed.hashAndInsert(nodep->origp());
|
|
|
|
}
|
|
|
|
// Find if there are any duplicates
|
|
|
|
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
|
|
|
|
AstCoverToggle* nodep = *it;
|
|
|
|
// nodep->backp() is null if we already detected it's a duplicate and unlinked it.
|
|
|
|
if (nodep->backp()) {
|
|
|
|
// Want to choose a base node, and keep finding duplicates that are identical.
|
|
|
|
// This prevents making chains where a->b, then c->d, then b->c, as we'll
|
|
|
|
// find a->b, a->c, a->d directly.
|
2020-04-04 02:31:54 +00:00
|
|
|
while (true) {
|
2019-05-19 20:13:13 +00:00
|
|
|
V3Hashed::iterator dupit = hashed.findDuplicate(nodep->origp());
|
|
|
|
if (dupit == hashed.end()) break;
|
|
|
|
//
|
|
|
|
AstNode* duporigp = hashed.iteratorNodep(dupit);
|
|
|
|
// Note hashed will point to the original variable (what's
|
|
|
|
// duplicated), not the covertoggle, but we need to get back to the
|
|
|
|
// covertoggle which is immediately above, so:
|
2018-02-02 02:32:58 +00:00
|
|
|
AstCoverToggle* removep = VN_CAST(duporigp->backp(), CoverToggle);
|
2019-07-06 16:57:50 +00:00
|
|
|
UASSERT_OBJ(removep, nodep, "CoverageJoin duplicate of wrong type");
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(8, " Orig " << nodep << " -->> " << nodep->incp()->declp() << endl);
|
|
|
|
UINFO(8, " dup " << removep << " -->> " << removep->incp()->declp() << endl);
|
2019-05-19 20:13:13 +00:00
|
|
|
// The CoverDecl the duplicate pointed to now needs to point to the
|
|
|
|
// original's data. I.e. the duplicate will get the coverage number
|
|
|
|
// from the non-duplicate
|
|
|
|
AstCoverDecl* datadeclp = nodep->incp()->declp()->dataDeclThisp();
|
2018-08-25 13:52:45 +00:00
|
|
|
removep->incp()->declp()->dataDeclp(datadeclp);
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(8, " new " << removep->incp()->declp() << endl);
|
2019-05-19 20:13:13 +00:00
|
|
|
// Mark the found node as a duplicate of the first node
|
|
|
|
// (Not vice-versa as we have the iterator for the found node)
|
2020-04-14 02:51:35 +00:00
|
|
|
removep->unlinkFrBack();
|
|
|
|
VL_DO_DANGLING(pushDeletep(removep), removep);
|
2019-05-19 20:13:13 +00:00
|
|
|
// Remove node from comparison so don't hit it again
|
|
|
|
hashed.erase(dupit);
|
|
|
|
++m_statToggleJoins;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-12 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// VISITORS
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstNetlist* nodep) override {
|
2019-05-19 20:13:13 +00:00
|
|
|
// Find all Coverage's
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
// Simplify
|
|
|
|
detectDuplicates();
|
2008-12-12 20:34:02 +00:00
|
|
|
}
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstCoverToggle* nodep) override {
|
2019-05-19 20:13:13 +00:00
|
|
|
m_toggleps.push_back(nodep);
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2008-12-12 20:34:02 +00:00
|
|
|
}
|
|
|
|
//--------------------
|
2020-08-15 14:03:34 +00:00
|
|
|
virtual void visit(AstNodeMath*) override {} // Accelerate
|
|
|
|
virtual void visit(AstNode* nodep) override { iterateChildren(nodep); }
|
2008-12-12 20:34:02 +00:00
|
|
|
|
|
|
|
public:
|
2019-09-12 11:22:22 +00:00
|
|
|
// CONSTRUCTORS
|
2020-04-14 02:51:35 +00:00
|
|
|
explicit CoverageJoinVisitor(AstNetlist* nodep) { iterate(nodep); }
|
2020-08-15 15:44:10 +00:00
|
|
|
virtual ~CoverageJoinVisitor() override {
|
2019-05-19 20:13:13 +00:00
|
|
|
V3Stats::addStat("Coverage, Toggle points joined", m_statToggleJoins);
|
2008-12-12 20:34:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Coverage class functions
|
|
|
|
|
|
|
|
void V3CoverageJoin::coverageJoin(AstNetlist* rootp) {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(2, __FUNCTION__ << ": " << endl);
|
|
|
|
{ CoverageJoinVisitor visitor(rootp); } // Destruct before checking
|
2017-09-18 02:52:57 +00:00
|
|
|
V3Global::dumpCheckGlobalTree("coveragejoin", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2008-12-12 20:34:02 +00:00
|
|
|
}
|