From 7ba6647c4f30a4c5198289fb26b10b4c48a4ccdf Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 28 Oct 2023 20:11:28 -0400 Subject: [PATCH] Internals: Cleanup some V3Graph constructors/funcs and docs. No functional change. --- src/V3EmitCSyms.cpp | 2 +- src/V3Graph.cpp | 5 +++-- src/V3Graph.h | 31 +++++++++++++++++++++---------- src/V3GraphAcyc.cpp | 2 +- src/V3GraphAlg.cpp | 18 ++++++++++++------ src/V3LinkCells.cpp | 2 +- src/V3LinkDot.cpp | 2 +- src/V3Order.cpp | 8 ++++---- src/V3Partition.cpp | 4 ++-- src/V3Split.cpp | 4 ++-- src/V3Trace.cpp | 4 ++-- 11 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index fc197d784..bf020e06c 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -1119,5 +1119,5 @@ void EmitCSyms::emitDpiImp() { void V3EmitC::emitcSyms(bool dpiHdrOnly) { UINFO(2, __FUNCTION__ << ": " << endl); - EmitCSyms(v3Global.rootp(), dpiHdrOnly); + EmitCSyms{v3Global.rootp(), dpiHdrOnly}; } diff --git a/src/V3Graph.cpp b/src/V3Graph.cpp index e8ab00441..f77f1d056 100644 --- a/src/V3Graph.cpp +++ b/src/V3Graph.cpp @@ -266,7 +266,7 @@ void V3Graph::loopsVertexCb(V3GraphVertex* vertexp) { if (debug()) std::cerr << "-Info-Loop: " << cvtToHex(vertexp) << " " << vertexp << endl; } -void V3Graph::dump(std::ostream& os) { +void V3Graph::dump(std::ostream& os) const { // This generates a file used by graphviz, https://www.graphviz.org os << " Graph:\n"; // Print vertices @@ -284,7 +284,8 @@ void V3Graph::dump(std::ostream& os) { } } -void V3Graph::dumpEdge(std::ostream& os, const V3GraphVertex* vertexp, const V3GraphEdge* edgep) { +void V3Graph::dumpEdge(std::ostream& os, const V3GraphVertex* vertexp, + const V3GraphEdge* edgep) const { if (edgep->weight() && (edgep->fromp() == vertexp || edgep->top() == vertexp)) { os << "\t\t"; if (edgep->fromp() == vertexp) os << "-> " << edgep->top()->name(); diff --git a/src/V3Graph.h b/src/V3Graph.h index cd816bd32..c2973cae7 100644 --- a/src/V3Graph.h +++ b/src/V3Graph.h @@ -91,7 +91,7 @@ protected: // METHODS double orderDFSIterate(V3GraphVertex* vertexp) VL_MT_DISABLED; void dumpEdge(std::ostream& os, const V3GraphVertex* vertexp, - const V3GraphEdge* edgep) VL_MT_DISABLED; + const V3GraphEdge* edgep) const VL_MT_DISABLED; void verticesUnlink() { m_vertices.reset(); } // ACCESSORS @@ -102,13 +102,14 @@ public: // METHODS void clear() VL_MT_DISABLED; // Empty it of all vertices/edges, as if making a new object - void clearColors() VL_MT_DISABLED; bool empty() const { return m_vertices.empty(); } - V3GraphVertex* verticesBeginp() const { return m_vertices.begin(); } // METHODS - ALGORITHMS + /// Clears color + void clearColors() VL_MT_DISABLED; + /// Assign same color to all vertices in the same weakly connected component /// Thus different color if there's no edges between the two subgraphs void weaklyConnected(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; @@ -116,10 +117,12 @@ public: /// Assign same color to all vertices that are strongly connected /// Thus different color if there's no directional circuit within the subgraphs. /// (I.E. all loops will occur within each color, not between them.) + /// Side-effect: changes user() void stronglyConnected(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; /// Assign an ordering number to all vertexes in a tree. /// All nodes with no inputs will get rank 1 + /// Side-effect: changes user() void rank(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; void rank() VL_MT_DISABLED; @@ -131,20 +134,24 @@ public: /// Order all vertices by rank and fanout, lowest first /// Sort all vertices by rank and fanout, lowest first /// Sort all edges by weight, lowest first - /// Side-effect: assigns ranks to every node. + /// Side-effect: assigns ranks to every node, and changes user() void order() VL_MT_DISABLED; - // Similar to order() but does not assign ranks. Caller must - // ensure that the graph has been ranked ahead of the call. + /// Similar to order() but does not assign ranks. Caller must + /// ensure that the graph has been ranked ahead of the call. + /// Side-effect: assigns ranks to every node, and changes user() void orderPreRanked() VL_MT_DISABLED; /// Make acyclical (into a tree) by breaking a minimal subset of cutable edges. + /// Side-effect: changes rank(), changes user() void acyclic(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; /// Remove any redundant edges, weights become MAX of any other weight - void removeRedundantEdges(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; + /// Side-effect: changes user() + void removeRedundantEdgesMax(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; /// Remove any redundant edges, weights become SUM of any other weight + /// Side-effect: changes user() void removeRedundantEdgesSum(V3EdgeFuncP edgeFuncp) VL_MT_DISABLED; /// Remove any transitive edges. E.g. if have edges A->B, B->C, and A->C @@ -154,21 +161,25 @@ public: void removeTransitiveEdges() VL_MT_DISABLED; /// Call loopsVertexCb on any one loop starting where specified + /// Side-effect: changes user() void reportLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp) VL_MT_DISABLED; /// Build a subgraph of all loops starting where specified + /// Side-effect: changes user() void subtreeLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp, V3Graph* loopGraphp) VL_MT_DISABLED; + /// Clear user() + void userClearVertices() VL_MT_DISABLED; + void userClearEdges() VL_MT_DISABLED; + /// Debugging - void dump(std::ostream& os = std::cout) VL_MT_DISABLED; + void dump(std::ostream& os = std::cout) const VL_MT_DISABLED; void dumpDotFile(const string& filename, bool colorAsSubgraph) const VL_MT_DISABLED; void dumpDotFilePrefixed(const string& nameComment, bool colorAsSubgraph = false) const VL_MT_DISABLED; void dumpDotFilePrefixedAlways(const string& nameComment, bool colorAsSubgraph = false) const VL_MT_DISABLED; - void userClearVertices() VL_MT_DISABLED; - void userClearEdges() VL_MT_DISABLED; static void selfTest() VL_MT_DISABLED; // CALLBACKS diff --git a/src/V3GraphAcyc.cpp b/src/V3GraphAcyc.cpp index 968efd38b..4bf46a495 100644 --- a/src/V3GraphAcyc.cpp +++ b/src/V3GraphAcyc.cpp @@ -574,7 +574,7 @@ void GraphAcyc::main() { void V3Graph::acyclic(V3EdgeFuncP edgeFuncp) { UINFO(4, "Acyclic\n"); - GraphAcyc acyc(this, edgeFuncp); + GraphAcyc acyc{this, edgeFuncp}; acyc.main(); UINFO(4, "Acyclic done\n"); } diff --git a/src/V3GraphAlg.cpp b/src/V3GraphAlg.cpp index 7f00a7067..43edcb9e0 100644 --- a/src/V3GraphAlg.cpp +++ b/src/V3GraphAlg.cpp @@ -34,6 +34,7 @@ VL_DEFINE_DEBUG_FUNCTIONS; //###################################################################### //###################################################################### // Algorithms - Remove redundancies +// Changes user() and weight() class GraphRemoveRedundant final : GraphAlg<> { const bool m_sumWeights; ///< Sum, rather then maximize weights @@ -92,11 +93,11 @@ public: ~GraphRemoveRedundant() = default; }; -void V3Graph::removeRedundantEdges(V3EdgeFuncP edgeFuncp) { - GraphRemoveRedundant(this, edgeFuncp, false); +void V3Graph::removeRedundantEdgesMax(V3EdgeFuncP edgeFuncp) { + GraphRemoveRedundant{this, edgeFuncp, false}; } void V3Graph::removeRedundantEdgesSum(V3EdgeFuncP edgeFuncp) { - GraphRemoveRedundant(this, edgeFuncp, true); + GraphRemoveRedundant{this, edgeFuncp, true}; } //###################################################################### @@ -132,6 +133,7 @@ void V3Graph::removeTransitiveEdges() { GraphAlgRemoveTransitiveEdges{this}.go() //###################################################################### //###################################################################### // Algorithms - weakly connected components +// Changes color() class GraphAlgWeakly final : GraphAlg<> { private: @@ -173,6 +175,7 @@ void V3Graph::weaklyConnected(V3EdgeFuncP edgeFuncp) { GraphAlgWeakly{this, edge //###################################################################### //###################################################################### // Algorithms - strongly connected components +// Changes user() and color() class GraphAlgStrongly final : GraphAlg<> { private: @@ -263,6 +266,7 @@ void V3Graph::stronglyConnected(V3EdgeFuncP edgeFuncp) { GraphAlgStrongly{this, //###################################################################### //###################################################################### // Algorithms - ranking +// Changes user() and rank() class GraphAlgRank final : GraphAlg<> { private: @@ -317,7 +321,8 @@ void V3Graph::rank(V3EdgeFuncP edgeFuncp) { GraphAlgRank{this, edgeFuncp}; } //###################################################################### //###################################################################### -// Algorithms - ranking +// Algorithms - report loops +// Changes user() class GraphAlgRLoops final : GraphAlg<> { private: @@ -365,12 +370,13 @@ public: }; void V3Graph::reportLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp) { - GraphAlgRLoops(this, edgeFuncp, vertexp); + GraphAlgRLoops{this, edgeFuncp, vertexp}; } //###################################################################### //###################################################################### // Algorithms - subtrees +// Changes user() class GraphAlgSubtrees final : GraphAlg<> { private: @@ -414,7 +420,7 @@ public: //! Report the entire connected graph with a loop or loops void V3Graph::subtreeLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp, V3Graph* loopGraphp) { - GraphAlgSubtrees(this, loopGraphp, edgeFuncp, vertexp); + GraphAlgSubtrees{this, loopGraphp, edgeFuncp, vertexp}; } //###################################################################### diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index 14bcfee31..60647c7d2 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -164,7 +164,7 @@ private: readModNames(); iterateChildren(nodep); // Find levels in graph - m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + m_graph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); if (dumpGraphLevel()) m_graph.dumpDotFilePrefixed("linkcells"); m_graph.rank(); for (V3GraphVertex* itp = m_graph.verticesBeginp(); itp; itp = itp->verticesNextp()) { diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 2726f2e97..3e53ce387 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -3749,7 +3749,7 @@ void V3LinkDot::linkDotGuts(AstNetlist* rootp, VLinkDotStep step) { if (debug() >= 5 || dumpTreeLevel() >= 9) { v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot.tree")); } - LinkDotState state(rootp, step); + LinkDotState state{rootp, step}; const LinkDotFindVisitor visitor{rootp, &state}; if (debug() >= 5 || dumpTreeLevel() >= 9) { v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("prelinkdot-find.tree")); diff --git a/src/V3Order.cpp b/src/V3Order.cpp index 415505c0d..7b59511fc 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -1291,12 +1291,12 @@ void OrderProcess::processMTasks() { mtask_pmbg.build(); // Needed? We do this for m_pomGraph in serial mode, so do it here too: - logicGraph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + logicGraph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); // Partition logicGraph into LogicMTask's. The partitioner will annotate // each vertex in logicGraph with a 'color' which is really an mtask ID // in this context. - V3Partition partitioner(&m_graph, &logicGraph); + V3Partition partitioner{&m_graph, &logicGraph}; V3Graph mtasks; partitioner.go(&mtasks); @@ -1307,7 +1307,7 @@ void OrderProcess::processMTasks() { // This is the order we'll execute logic nodes within the MTask. // // MTasks may span scopes and domains, so sort by both here: - GraphStream emit_logic(&logicGraph); + GraphStream emit_logic{&logicGraph}; const V3GraphVertex* moveVxp; while ((moveVxp = emit_logic.nextp())) { const MTaskMoveVertex* const movep = static_cast(moveVxp); @@ -1435,7 +1435,7 @@ void OrderProcess::process(bool multiThreaded) { processMoveBuildGraph(); // Different prefix (ordermv) as it's not the same graph if (dumpGraphLevel() >= 4) m_pomGraph.dumpDotFilePrefixed(m_tag + "_ordermv_start"); - m_pomGraph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + m_pomGraph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); if (dumpGraphLevel() >= 4) m_pomGraph.dumpDotFilePrefixed(m_tag + "_ordermv_simpl"); UINFO(2, " Move...\n"); diff --git a/src/V3Partition.cpp b/src/V3Partition.cpp index 2a8c64993..26403446d 100644 --- a/src/V3Partition.cpp +++ b/src/V3Partition.cpp @@ -2586,7 +2586,7 @@ void V3Partition::debugMTaskGraphStats(const V3Graph* graphp, const string& stag // Look only at the cost of each mtask, neglect communication cost. // This will show us how much parallelism we expect, assuming cache-miss // costs are minor and the cost of running logic is the dominant cost. - PartParallelismEst vertexParEst(graphp); + PartParallelismEst vertexParEst{graphp}; vertexParEst.traverse(); vertexParEst.statsReport(stage); if (debug() >= 4) { @@ -3047,7 +3047,7 @@ static void finalizeCosts(V3Graph* execMTaskGraphp) { // Record summary stats for final m_tasks graph. // (More verbose stats are available with --debugi-V3Partition >= 3.) - PartParallelismEst parEst(execMTaskGraphp); + PartParallelismEst parEst{execMTaskGraphp}; parEst.traverse(); parEst.statsReport("final"); if (debug() >= 3) { diff --git a/src/V3Split.cpp b/src/V3Split.cpp index c543aec1d..08d39bc18 100644 --- a/src/V3Split.cpp +++ b/src/V3Split.cpp @@ -456,7 +456,7 @@ protected: void cleanupBlockGraph(AstNode* nodep) { // Transform the graph into what we need UINFO(5, "ReorderBlock " << nodep << endl); - m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + m_graph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); if (dumpGraphLevel() >= 9) m_graph.dumpDotFilePrefixed("reorderg_nodup", false); @@ -893,7 +893,7 @@ protected: void colorAlwaysGraph() { // Color the graph to indicate subsets, each of which // we can split into its own always block. - m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + m_graph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); // Some vars are primary inputs to the always block; prune // edges on those vars. Reasoning: if two statements both depend diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index a7bc4fa42..070092cd9 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -254,7 +254,7 @@ private: // Remove multiple variables connecting funcs to traces // We do this twice, as then we have fewer edges to multiply out in the below // expansion. - m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + m_graph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); // Remove all Cfunc nodes for (V3GraphVertex *nextp, *itp = m_graph.verticesBeginp(); itp; itp = nextp) { nextp = itp->verticesNextp(); @@ -266,7 +266,7 @@ private: } // Remove multiple variables connecting funcs to traces - m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); + m_graph.removeRedundantEdgesMax(&V3GraphEdge::followAlwaysTrue); // If there are any edges from a always, keep only the always for (const V3GraphVertex* itp = m_graph.verticesBeginp(); itp;