Internals: Misc cleanups in V3Graph and V3Dead. No functional change.

This commit is contained in:
Wilson Snyder 2023-11-12 22:08:08 -05:00
parent ee3ba7c761
commit c8063e5732
7 changed files with 46 additions and 31 deletions

View File

@ -64,9 +64,9 @@ static std::string doubleToTimescale(double value) VL_PURE {
const char* suffixp = "s";
// clang-format off
if (value >= 1e0) { suffixp = "s"; value *= 1e0; }
else if (value >= 1e-3 ) { suffixp = "ms"; value *= 1e3; }
else if (value >= 1e-6 ) { suffixp = "us"; value *= 1e6; }
else if (value >= 1e-9 ) { suffixp = "ns"; value *= 1e9; }
else if (value >= 1e-3) { suffixp = "ms"; value *= 1e3; }
else if (value >= 1e-6) { suffixp = "us"; value *= 1e6; }
else if (value >= 1e-9) { suffixp = "ns"; value *= 1e9; }
else if (value >= 1e-12) { suffixp = "ps"; value *= 1e12; }
else if (value >= 1e-15) { suffixp = "fs"; value *= 1e15; }
else if (value >= 1e-18) { suffixp = "as"; value *= 1e18; }

View File

@ -1986,7 +1986,7 @@ void AstPackageExport::dump(std::ostream& str) const {
this->AstNode::dump(str);
str << " -> " << packagep();
}
const char* AstPackageExport ::broken() const {
const char* AstPackageExport::broken() const {
BROKEN_RTN(!m_packagep || !m_packagep->brokeExists());
return nullptr;
}

View File

@ -79,6 +79,11 @@ private:
// METHODS
void deleting(AstNode* nodep) {
UINFO(9, " deleting " << nodep << endl);
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
}
void checkAll(AstNode* nodep) {
if (nodep != nodep->dtypep()) { // NodeDTypes reference themselves
if (AstNode* const subnodep = nodep->dtypep()) subnodep->user1Inc();
@ -239,7 +244,7 @@ private:
iterateChildren(nodep);
if (m_elimCells) {
if (!nodep->varsp()) {
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
deleting(nodep);
return;
}
}
@ -316,7 +321,7 @@ private:
void deadCheckTypedefs() {
for (AstTypedef* typedefp : m_typedefsp) {
if (shouldDeleteTypedef(typedefp)) {
VL_DO_DANGLING(pushDeletep(typedefp->unlinkFrBack()), typedefp);
deleting(typedefp);
continue;
}
checkAll(typedefp);
@ -349,7 +354,7 @@ private:
cellp->modp()->user1Inc(-1);
});
}
VL_DO_DANGLING(modp->unlinkFrBack()->deleteTree(), modp);
deleting(modp);
retry = true;
}
}
@ -373,7 +378,7 @@ private:
UINFO(4, " Dead AstScope " << scp << endl);
scp->aboveScopep()->user1Inc(-1);
if (scp->dtypep()) scp->dtypep()->user1Inc(-1);
VL_DO_DANGLING(scp->unlinkFrBack()->deleteTree(), scp);
deleting(scp);
*it = nullptr;
retry = true;
}
@ -385,7 +390,7 @@ private:
for (AstCell* cellp : m_cellsp) {
if (cellp->user1() == 0 && !cellp->modp()->stmtsp()) {
cellp->modp()->user1Inc(-1);
VL_DO_DANGLING(cellp->unlinkFrBack()->deleteTree(), cellp);
deleting(cellp);
}
}
}
@ -397,7 +402,7 @@ private:
if (nodep->user1() == 0) {
if (nodep->extendsp()) nodep->extendsp()->user1Inc(-1);
if (nodep->classOrPackagep()) nodep->classOrPackagep()->user1Inc(-1);
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
deleting(nodep);
itr = nullptr;
retry = true;
}
@ -417,11 +422,11 @@ private:
AstNodeAssign* const assp = itr->second;
UINFO(4, " Dead assign " << assp << endl);
assp->dtypep()->user1Inc(-1);
VL_DO_DANGLING(assp->unlinkFrBack()->deleteTree(), assp);
deleting(assp);
}
if (vscp->scopep()) vscp->scopep()->user1Inc(-1);
vscp->dtypep()->user1Inc(-1);
VL_DO_DANGLING(vscp->unlinkFrBack()->deleteTree(), vscp);
deleting(vscp);
}
}
for (bool retry = true; retry;) {
@ -432,7 +437,7 @@ private:
if (varp->user1() == 0) {
UINFO(4, " Dead " << varp << endl);
if (varp->dtypep()) varp->dtypep()->user1Inc(-1);
VL_DO_DANGLING(varp->unlinkFrBack()->deleteTree(), varp);
deleting(varp);
*it = nullptr;
retry = true;
}
@ -440,11 +445,11 @@ private:
}
for (std::vector<AstNode*>::iterator it = m_dtypesp.begin(); it != m_dtypesp.end(); ++it) {
if ((*it)->user1() == 0) {
const AstNodeUOrStructDType* classp;
// It's possible that there if a reference to each individual member, but
// not to the dtype itself. Check and don't remove the parent dtype if
// members are still alive.
if ((classp = VN_CAST((*it), NodeUOrStructDType))) {
if (const AstNodeUOrStructDType* const classp
= VN_CAST((*it), NodeUOrStructDType)) {
bool cont = true;
for (AstMemberDType* memberp = classp->membersp(); memberp;
memberp = VN_AS(memberp->nextp(), MemberDType)) {
@ -455,7 +460,7 @@ private:
}
if (!cont) continue;
}
VL_DO_DANGLING((*it)->unlinkFrBack()->deleteTree(), *it);
deleting(*it);
}
}
}

View File

@ -294,6 +294,12 @@ void V3Graph::dumpEdge(std::ostream& os, const V3GraphVertex* vertexp,
os << '\n';
}
}
void V3Graph::dumpEdges(std::ostream& os, const V3GraphVertex* vertexp) const {
for (const V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp())
dumpEdge(os, vertexp, edgep);
for (const V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp())
dumpEdge(os, vertexp, edgep);
}
void V3Graph::dumpDotFilePrefixed(const string& nameComment, bool colorAsSubgraph) const {
dumpDotFile(v3Global.debugFilename(nameComment) + ".dot", colorAsSubgraph);

View File

@ -180,6 +180,7 @@ public:
bool colorAsSubgraph = false) const VL_MT_DISABLED;
void dumpDotFilePrefixedAlways(const string& nameComment,
bool colorAsSubgraph = false) const VL_MT_DISABLED;
void dumpEdges(std::ostream& os, const V3GraphVertex* vertexp) const VL_MT_DISABLED;
static void selfTest() VL_MT_DISABLED;
// CALLBACKS

View File

@ -149,22 +149,22 @@ class V3GraphTestVars final : public V3GraphTest {
public:
string name() override { return "vars"; }
void runTest() override {
V3Graph* gp = &m_graph;
V3Graph* const gp = &m_graph;
V3GraphTestVertex* clk = new V3GraphTestVarVertex{gp, "$clk"};
V3GraphTestVertex* const clk = new V3GraphTestVarVertex{gp, "$clk"};
V3GraphTestVertex* a = new V3GraphTestVarVertex{gp, "$a"};
V3GraphTestVertex* a_dly = new V3GraphTestVarVertex{gp, "$a_dly"};
V3GraphTestVertex* a_dlyblk = new V3GraphTestVarVertex{gp, "$a_dlyblk"};
V3GraphTestVertex* b = new V3GraphTestVarVertex{gp, "$b"};
V3GraphTestVertex* b_dly = new V3GraphTestVarVertex{gp, "$b_dly"};
V3GraphTestVertex* b_dlyblk = new V3GraphTestVarVertex{gp, "$b_dlyblk"};
V3GraphTestVertex* c = new V3GraphTestVarVertex{gp, "$c"};
V3GraphTestVertex* i = new V3GraphTestVarVertex{gp, "$i"};
V3GraphTestVertex* const a = new V3GraphTestVarVertex{gp, "$a"};
V3GraphTestVertex* const a_dly = new V3GraphTestVarVertex{gp, "$a_dly"};
V3GraphTestVertex* const a_dlyblk = new V3GraphTestVarVertex{gp, "$a_dlyblk"};
V3GraphTestVertex* const b = new V3GraphTestVarVertex{gp, "$b"};
V3GraphTestVertex* const b_dly = new V3GraphTestVarVertex{gp, "$b_dly"};
V3GraphTestVertex* const b_dlyblk = new V3GraphTestVarVertex{gp, "$b_dlyblk"};
V3GraphTestVertex* const c = new V3GraphTestVarVertex{gp, "$c"};
V3GraphTestVertex* const i = new V3GraphTestVarVertex{gp, "$i"};
V3GraphTestVertex* ap = new V3GraphTestVarVertex{gp, "$a_pre"};
V3GraphTestVertex* bp = new V3GraphTestVarVertex{gp, "$b_pre"};
V3GraphTestVertex* cp = new V3GraphTestVarVertex{gp, "$c_pre"};
V3GraphTestVertex* const ap = new V3GraphTestVarVertex{gp, "$a_pre"};
V3GraphTestVertex* const bp = new V3GraphTestVarVertex{gp, "$b_pre"};
V3GraphTestVertex* const cp = new V3GraphTestVarVertex{gp, "$c_pre"};
V3GraphTestVertex* n;
@ -185,7 +185,7 @@ public:
new V3GraphEdge{gp, n, i, 2};
}
V3GraphTestVertex* posedge = n = new V3GraphTestVertex{gp, "*posedge clk*"};
V3GraphTestVertex* const posedge = n = new V3GraphTestVertex{gp, "*posedge clk*"};
{ new V3GraphEdge{gp, clk, n, 2}; }
// AssignPre's VarRefs on LHS: generate special BLK
@ -258,6 +258,9 @@ public:
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
gp->order();
// Test debug function
gp->dumpEdges(std::cout, ap);
dumpSelf();
}
};

View File

@ -1414,7 +1414,7 @@ void OrderProcess::process(bool multiThreaded) {
// edges) will have its own color, and corresponds to a loop in the
// original graph. However the new graph will be acyclic (the removed
// edges are actually still there, just with weight 0).
UINFO(2, " Acyclic & Order...\n");
UINFO(2, " Acyclic and Order...\n");
m_graph.acyclic(&V3GraphEdge::followAlwaysTrue);
if (dumpGraphLevel()) m_graph.dumpDotFilePrefixed(m_tag + "_orderg_acyc");