Internals: Use faster VNVisitorConst where able. No functional change intended.

This commit is contained in:
Wilson Snyder 2023-11-12 18:26:29 -05:00
parent 2882737bcd
commit ee3ba7c761
7 changed files with 44 additions and 44 deletions

View File

@ -320,7 +320,7 @@ public:
//######################################################################
class BeginRelinkVisitor final : public VNVisitor {
class BeginRelinkVisitor final : public VNVisitorConst {
// Replace tasks with new pointer
private:
// NODE STATE
@ -333,13 +333,13 @@ private:
UINFO(9, " relinkFTask " << nodep << endl);
nodep->name(nodep->taskp()->name());
}
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
void visit(AstVarRef* nodep) override {
if (nodep->varp()->user1()) { // It was converted
UINFO(9, " relinVarRef " << nodep << endl);
}
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
void visit(AstIfaceRefDType* nodep) override {
// May have changed cell names
@ -347,14 +347,14 @@ private:
UINFO(8, " IFACEREFDTYPE " << nodep << endl);
if (nodep->cellp()) nodep->cellName(nodep->cellp()->name());
UINFO(8, " rename to " << nodep << endl);
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
//--------------------
void visit(AstNode* nodep) override { iterateChildren(nodep); }
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
public:
// CONSTRUCTORS
BeginRelinkVisitor(AstNetlist* nodep, BeginState*) { iterate(nodep); }
BeginRelinkVisitor(AstNetlist* nodep, BeginState*) { iterateConst(nodep); }
~BeginRelinkVisitor() override = default;
};

View File

@ -33,7 +33,7 @@ VL_DEFINE_DEBUG_FUNCTIONS;
// Visit within a module all nodes and data types they reference, finding
// any classes so we can make sure they are defined when Verilated code
// compiles
class CUseVisitor final : public VNVisitor {
class CUseVisitor final : public VNVisitorConst {
// NODE STATE
// AstNode::user1() -> bool. True if already visited
const VNUser1InUse m_inuser1;
@ -56,44 +56,44 @@ class CUseVisitor final : public VNVisitor {
}
void visit(AstCFunc* nodep) override {
if (nodep->user1SetOnce()) return;
iterateAndNextNull(nodep->argsp());
iterateAndNextNull(nodep->stmtsp());
iterateAndNextConstNull(nodep->argsp());
iterateAndNextConstNull(nodep->stmtsp());
}
void visit(AstCCall* nodep) override { return; }
void visit(AstCReturn* nodep) override {
UASSERT(!nodep->user1SetOnce(), "Visited same return twice.");
iterate(nodep->lhsp()->dtypep());
iterateConst(nodep->lhsp()->dtypep());
}
void visit(AstNodeDType* nodep) override {
if (nodep->virtRefDTypep()) iterate(nodep->virtRefDTypep());
if (nodep->virtRefDType2p()) iterate(nodep->virtRefDType2p());
if (nodep->virtRefDTypep()) iterateConst(nodep->virtRefDTypep());
if (nodep->virtRefDType2p()) iterateConst(nodep->virtRefDType2p());
// Add a CUse for every struct that requires a declaration
AstNodeUOrStructDType* const stypep = VN_CAST(nodep->skipRefp(), NodeUOrStructDType);
if (stypep && stypep->classOrPackagep()) {
addNewUse(nodep, VUseType::INT_INCLUDE, stypep->classOrPackagep()->name());
iterateChildren(stypep);
iterateChildrenConst(stypep);
} else if (AstClassRefDType* const classp = VN_CAST(nodep->skipRefp(), ClassRefDType)) {
addNewUse(nodep, VUseType::INT_FWD_CLASS, classp->name());
}
}
void visit(AstNode* nodep) override {
if (nodep->user1SetOnce()) return; // Process once
if (nodep->dtypep()) iterate(nodep->dtypep());
iterateChildren(nodep);
if (nodep->dtypep()) iterateConst(nodep->dtypep());
iterateChildrenConst(nodep);
}
void visit(AstCell* nodep) override {
if (nodep->user1SetOnce()) return; // Process once
// Currently no IMP_INCLUDE because we include __Syms which has them all
addNewUse(nodep, VUseType::INT_FWD_CLASS, nodep->modp()->name());
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
public:
// CONSTRUCTORS
explicit CUseVisitor(AstNodeModule* modp)
: m_modp(modp) {
iterate(modp);
iterateConst(modp);
for (auto& used : m_didUse) {
AstCUse* const newp = new AstCUse{used.second.first, used.second.second, used.first};

View File

@ -37,7 +37,7 @@ VL_DEFINE_DEBUG_FUNCTIONS;
//######################################################################
// Find nodes with side effects, to mark as non-expandable
class ExpandOkVisitor final : public VNVisitor {
class ExpandOkVisitor final : public VNVisitorConst {
private:
// NODE STATE
// AstNode::user2() -> bool. Is pure (along with all children)
@ -53,7 +53,7 @@ private:
{
VL_RESTORER(m_isImpure);
m_isImpure = false;
iterateChildren(nodep);
iterateChildrenConst(nodep);
selfImpure |= m_isImpure;
nodep->user2(selfImpure);
}
@ -62,7 +62,7 @@ private:
public:
// CONSTRUCTORS
explicit ExpandOkVisitor(AstNetlist* nodep) { iterate(nodep); }
explicit ExpandOkVisitor(AstNetlist* nodep) { iterateConst(nodep); }
~ExpandOkVisitor() = default;
};

View File

@ -236,7 +236,7 @@ string V3HierBlock::commandArgsFileName(bool forCMake) const {
//######################################################################
// Collect how hierarchical blocks are used
class HierBlockUsageCollectVisitor final : public VNVisitor {
class HierBlockUsageCollectVisitor final : public VNVisitorConst {
// NODE STATE
// AstNode::user1() -> bool. Processed
const VNUser1InUse m_inuser1;
@ -266,7 +266,7 @@ class HierBlockUsageCollectVisitor final : public VNVisitor {
}
prevGParams.swap(m_gparams);
iterateChildren(nodep);
iterateChildrenConst(nodep);
if (nodep->hierBlock()) {
m_planp->add(nodep, m_gparams);
@ -280,7 +280,7 @@ class HierBlockUsageCollectVisitor final : public VNVisitor {
// Visit used module here to know that the module is hier_block or not.
// This visitor behaves almost depth first search
if (AstModule* const modp = VN_CAST(nodep->modp(), Module)) {
iterate(modp);
iterateConst(modp);
m_referred.insert(modp);
}
// Nothing to do for interface because hierarchical block does not exist
@ -294,12 +294,12 @@ class HierBlockUsageCollectVisitor final : public VNVisitor {
}
void visit(AstNodeExpr*) override {} // Accelerate
void visit(AstNode* nodep) override { iterateChildren(nodep); }
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
public:
HierBlockUsageCollectVisitor(V3HierBlockPlan* planp, AstNetlist* netlist)
: m_planp{planp} {
iterateChildren(netlist);
iterateChildrenConst(netlist);
}
};

View File

@ -30,7 +30,7 @@ VL_DEFINE_DEBUG_FUNCTIONS;
//######################################################################
// Name state, as a visitor of each AstNode
class NameVisitor final : public VNVisitor {
class NameVisitor final : public VNVisitorConst {
private:
// NODE STATE
// Cleared on Netlist
@ -69,7 +69,7 @@ private:
VL_RESTORER(m_modp);
{
m_modp = nodep;
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
}
// Add __PVT__ to names of local signals
@ -82,39 +82,39 @@ private:
}
void visit(AstCFunc* nodep) override {
if (!nodep->user1()) {
iterateChildren(nodep);
iterateChildrenConst(nodep);
rename(nodep, false);
}
}
void visit(AstVarRef* nodep) override { iterate(nodep->varp()); }
void visit(AstVarRef* nodep) override { iterateConst(nodep->varp()); }
void visit(AstCell* nodep) override {
if (!nodep->user1()) {
rename(nodep, (!nodep->modp()->modPublic() && !VN_IS(nodep->modp(), ClassPackage)));
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
}
void visit(AstMemberDType* nodep) override {
if (!nodep->user1()) {
rename(nodep, true);
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
}
void visit(AstMemberSel* nodep) override {
if (!nodep->user1()) {
rename(nodep, true);
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
}
void visit(AstStructSel* nodep) override {
if (!nodep->user1()) {
rename(nodep, true);
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
}
void visit(AstScope* nodep) override {
if (!nodep->user1SetOnce()) {
if (nodep->aboveScopep()) iterate(nodep->aboveScopep());
if (nodep->aboveCellp()) iterate(nodep->aboveCellp());
if (nodep->aboveScopep()) iterateConst(nodep->aboveScopep());
if (nodep->aboveCellp()) iterateConst(nodep->aboveCellp());
// Always recompute name (as many levels above scope may have changed)
// Same formula as V3Scope
nodep->name(nodep->isTop() ? "TOP"
@ -123,16 +123,16 @@ private:
? ("TOP." + m_modp->name())
: (nodep->aboveScopep()->name() + "." + nodep->aboveCellp()->name()));
nodep->editCountInc();
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
}
//--------------------
void visit(AstNode* nodep) override { iterateChildren(nodep); }
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
public:
// CONSTRUCTORS
explicit NameVisitor(AstNetlist* nodep) { iterate(nodep); }
explicit NameVisitor(AstNetlist* nodep) { iterateConst(nodep); }
~NameVisitor() override = default;
};

View File

@ -32,7 +32,7 @@ VL_DEFINE_DEBUG_FUNCTIONS;
//######################################################################
// Find all split variables in a block
class SplitAsFindVisitor final : public VNVisitor {
class SplitAsFindVisitor final : public VNVisitorConst {
private:
// STATE - across all visitors
AstVarScope* m_splitVscp = nullptr; // Variable we want to split
@ -49,11 +49,11 @@ private:
// This will break if the m_splitVscp is a "ref" argument to the function,
// but little we can do.
}
void visit(AstNode* nodep) override { iterateChildren(nodep); }
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
public:
// CONSTRUCTORS
explicit SplitAsFindVisitor(AstAlways* nodep) { iterate(nodep); }
explicit SplitAsFindVisitor(AstAlways* nodep) { iterateConst(nodep); }
~SplitAsFindVisitor() override = default;
// METHODS
AstVarScope* splitVscp() const { return m_splitVscp; }

View File

@ -165,7 +165,7 @@ public:
// See if any variables have changed value since we determined subst value,
// as a visitor of each AstNode
class SubstUseVisitor final : public VNVisitor {
class SubstUseVisitor final : public VNVisitorConst {
private:
// NODE STATE
// See SubstVisitor
@ -197,7 +197,7 @@ private:
void visit(AstConst*) override {} // Accelerate
void visit(AstNode* nodep) override {
if (!nodep->isPure()) m_ok = false;
iterateChildren(nodep);
iterateChildrenConst(nodep);
}
public:
@ -205,7 +205,7 @@ public:
SubstUseVisitor(AstNode* nodep, int origStep)
: m_origStep{origStep} {
UINFO(9, " SubstUseVisitor " << origStep << " " << nodep << endl);
iterate(nodep);
iterateConst(nodep);
}
~SubstUseVisitor() override = default;
// METHODS