Simplify V3SenTree.h. No functional change intended.

- Remove unused headers
- Simplify container functors
- SenTreeFinder need not be a Visitor
- Update comments

Line coverage should now be 100%
This commit is contained in:
Geza Lore 2020-06-06 17:25:20 +01:00
parent 4862916f39
commit dea0e6793f
3 changed files with 31 additions and 71 deletions

View File

@ -54,7 +54,7 @@ private:
// VISITORS // VISITORS
virtual void visit(AstTopScope* nodep) VL_OVERRIDE { virtual void visit(AstTopScope* nodep) VL_OVERRIDE {
m_topscopep = nodep; m_topscopep = nodep;
m_finder.main(m_topscopep); m_finder.init(m_topscopep);
iterateChildren(nodep); iterateChildren(nodep);
m_topscopep = NULL; m_topscopep = NULL;
} }

View File

@ -965,8 +965,8 @@ private:
m_activep = NULL; m_activep = NULL;
m_topScopep = nodep; m_topScopep = nodep;
m_scopetopp = nodep->scopep(); m_scopetopp = nodep->scopep();
// Find sentree's // Find global SenTrees
m_finder.main(m_topScopep); m_finder.init(m_topScopep);
// ProcessDomainsIterate will use these when it needs to move // ProcessDomainsIterate will use these when it needs to move
// something to a combodomain. This saves a ton of find() operations. // something to a combodomain. This saves a ton of find() operations.
AstSenTree* combp AstSenTree* combp

View File

@ -13,17 +13,7 @@
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
// //
//************************************************************************* //*************************************************************************
// V3Block's Transformations: // AstSenTree related utilities.
//
// Note this can be called multiple times.
// Create a IBLOCK(initial), SBLOCK(combo)
// ALWAYS: Remove any-edges from sense list
// If no POS/NEG in senselist, Fold into SBLOCK(combo)
// Else fold into SBLOCK(sequent).
// OPTIMIZE: When support async clocks, fold into that block if possible
// INITIAL: Move into IBLOCK
// WIRE: Move into SBLOCK(combo)
//
//************************************************************************* //*************************************************************************
#ifndef _V3SENTREE_H_ #ifndef _V3SENTREE_H_
@ -32,14 +22,9 @@
#include "config_build.h" #include "config_build.h"
#include "verilatedos.h" #include "verilatedos.h"
#include "V3Global.h"
#include "V3Ast.h" #include "V3Ast.h"
#include "V3Hashed.h" #include "V3Hashed.h"
#include <cstdarg>
#include <map>
#include <algorithm>
#include <vector>
#include VL_INCLUDE_UNORDERED_SET #include VL_INCLUDE_UNORDERED_SET
//###################################################################### //######################################################################
@ -50,22 +35,16 @@ class SenTreeSet {
// Hash table of sensitive blocks. // Hash table of sensitive blocks.
private: private:
// TYPES // TYPES
class HashSenTree { struct HashSenTree {
public:
HashSenTree() {}
size_t operator()(const AstSenTree* kp) const { size_t operator()(const AstSenTree* kp) const {
return V3Hashed::uncachedHash(kp).fullValue(); return V3Hashed::uncachedHash(kp).fullValue();
} }
// Copying required for OSX's libc++
}; };
class EqSenTree { struct EqSenTree {
public:
EqSenTree() {}
bool operator()(const AstSenTree* ap, const AstSenTree* bp) const { bool operator()(const AstSenTree* ap, const AstSenTree* bp) const {
return ap->sameTree(bp); return ap->sameTree(bp);
} }
// Copying required for OSX's libc++
}; };
// MEMBERS // MEMBERS
@ -78,76 +57,57 @@ public:
// METHODS // METHODS
void add(AstSenTree* nodep) { m_trees.insert(nodep); } void add(AstSenTree* nodep) { m_trees.insert(nodep); }
AstSenTree* find(AstSenTree* likep) { AstSenTree* find(AstSenTree* likep) {
AstSenTree* resultp = NULL; AstSenTree* resultp = NULL;
Set::iterator it = m_trees.find(likep); Set::iterator it = m_trees.find(likep);
if (it != m_trees.end()) resultp = *it; if (it != m_trees.end()) resultp = *it;
return resultp; return resultp;
} }
void clear() { m_trees.clear(); } void clear() { m_trees.clear(); }
private: private:
VL_UNCOPYABLE(SenTreeSet); VL_UNCOPYABLE(SenTreeSet);
}; };
class SenTreeFinder : public AstNVisitor { class SenTreeFinder {
private: private:
// STATE // STATE
AstTopScope* m_topscopep; // Top scope to add statement to AstTopScope* m_topScopep; // Top scope to add global SenTrees to
SenTreeSet m_trees; // Set of sensitive blocks, for folding SenTreeSet m_trees; // Set of global SenTrees
// VISITORS VL_UNCOPYABLE(SenTreeFinder);
VL_DEBUG_FUNC; // Declare debug()
virtual void visit(AstNodeModule* nodep) VL_OVERRIDE { public:
// Only do the top // CONSTRUCTORS
if (nodep->isTop()) iterateChildren(nodep); SenTreeFinder()
} : m_topScopep(NULL) {}
virtual void visit(AstTopScope* nodep) VL_OVERRIDE {
m_topscopep = nodep;
iterateChildren(nodep);
// Don't clear topscopep, the namer persists beyond this visit
}
virtual void visit(AstScope* nodep) VL_OVERRIDE {
// But no SenTrees under TopScope's scope
}
// Memorize existing block names
virtual void visit(AstActive* nodep) VL_OVERRIDE {
// Don't grab SenTrees under Actives, only those that are global (under Scope directly)
iterateChildren(nodep);
}
virtual void visit(AstSenTree* nodep) VL_OVERRIDE { //
m_trees.add(nodep);
}
virtual void visit(AstNodeStmt*) VL_OVERRIDE {} // Accelerate
virtual void visit(AstNode* nodep) VL_OVERRIDE { iterateChildren(nodep); }
// METHODS // METHODS
public: AstSenTree* getSenTree(AstSenTree* senTreep) {
void clear() { // Return a global SenTree that matches given SenTree. If no such global
m_topscopep = NULL; // SenTree exists, create one and add it to the stored TopScope.
m_trees.clear(); AstSenTree* treep = m_trees.find(senTreep);
}
AstSenTree* getSenTree(AstSenTree* sensesp) {
// Return a global sentree that matches given sense list.
AstSenTree* treep = m_trees.find(sensesp);
// Not found, form a new one // Not found, form a new one
if (!treep) { if (!treep) {
UASSERT(m_topscopep, "Never called main()"); UASSERT(m_topScopep, "Never called init()");
treep = sensesp->cloneTree(false); treep = senTreep->cloneTree(false);
m_topscopep->addStmtsp(treep); m_topScopep->addStmtsp(treep);
UINFO(8, " New SENTREE " << treep << endl); UINFO(8, " New SENTREE " << treep << endl);
m_trees.add(treep); m_trees.add(treep);
// Note blocks may have also been added above in the Active visitor
} }
return treep; return treep;
} }
public: void init(AstTopScope* topScopep) {
// CONSTRUCTORS // Keep hold of top scope so we can add global SenTrees later
SenTreeFinder() { clear(); } m_topScopep = topScopep;
virtual ~SenTreeFinder() {} // Gather existing global SenTrees
void main(AstTopScope* nodep) { iterate(nodep); } for (AstNode* nodep = topScopep->stmtsp(); nodep; nodep = nodep->nextp()) {
if (AstSenTree* senTreep = VN_CAST(nodep, SenTree)) m_trees.add(senTreep);
}
}
}; };
#endif // Guard #endif // Guard