From 9f947bcb5f94bdea19bcd5c5fe3884649a648865 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 8 Mar 2020 21:09:31 -0400 Subject: [PATCH] Internals: Refactor flags in V3Undriven. No functional change intended. --- src/V3Undriven.cpp | 90 ++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/V3Undriven.cpp b/src/V3Undriven.cpp index 571b57a98..e63d1abbc 100644 --- a/src/V3Undriven.cpp +++ b/src/V3Undriven.cpp @@ -44,10 +44,9 @@ class UndrivenVarEntry { // MEMBERS - AstVar* m_varp; // Variable this tracks - bool m_usedWhole; // True if whole vector used - bool m_drivenWhole; // True if whole vector driven - std::vector m_flags; // Used/Driven on each subbit + AstVar* m_varp; // Variable this tracks + std::vector m_wholeFlags; // Used/Driven on whole vector + std::vector m_bitFlags; // Used/Driven on each subbit enum { FLAG_USED = 0, FLAG_DRIVEN = 1, FLAGS_PER_BIT = 2 }; @@ -58,31 +57,35 @@ public: explicit UndrivenVarEntry(AstVar* varp) { // Construction for when a var is used UINFO(9, "create "<width()*FLAGS_PER_BIT); - for (int i=0; iwidth()*FLAGS_PER_BIT; i++) { - m_flags[i] = false; + m_wholeFlags.resize(FLAGS_PER_BIT); + for (int i = 0; i < FLAGS_PER_BIT; i++) { + m_wholeFlags[i] = false; + } + m_bitFlags.resize(varp->width() * FLAGS_PER_BIT); + for (int i = 0; i < varp->width() * FLAGS_PER_BIT; i++) { + m_bitFlags[i] = false; } } ~UndrivenVarEntry() {} private: // METHODS - inline bool bitNumOk(int bit) const { return bit>=0 - && (bit*FLAGS_PER_BIT < static_cast(m_flags.size())); } - inline bool usedFlag(int bit) const { - return m_usedWhole || m_flags[bit*FLAGS_PER_BIT + FLAG_USED]; } - inline bool drivenFlag(int bit) const { - return m_drivenWhole || m_flags[bit*FLAGS_PER_BIT + FLAG_DRIVEN]; } + bool bitNumOk(int bit) const { + return bit >= 0 && (bit * FLAGS_PER_BIT < static_cast(m_bitFlags.size())); + } + bool usedFlag(int bit) const { + return m_wholeFlags[FLAG_USED] || m_bitFlags[bit * FLAGS_PER_BIT + FLAG_USED]; + } + bool drivenFlag(int bit) const { + return m_wholeFlags[FLAG_DRIVEN] || m_bitFlags[bit * FLAGS_PER_BIT + FLAG_DRIVEN]; + } enum BitNamesWhich { BN_UNUSED, BN_UNDRIVEN, BN_BOTH }; string bitNames(BitNamesWhich which) { string bits; bool prev = false; int msb = 0; // bit==-1 loops below; we do one extra iteration so end with prev=false - for (int bit=(m_flags.size()/FLAGS_PER_BIT)-1; bit >= -1; --bit) { + for (int bit=(m_bitFlags.size()/FLAGS_PER_BIT)-1; bit >= -1; --bit) { if (bit>=0 && ((which == BN_UNUSED && !usedFlag(bit) && drivenFlag(bit)) || (which == BN_UNDRIVEN && usedFlag(bit) && !drivenFlag(bit)) @@ -109,38 +112,39 @@ private: public: void usedWhole() { UINFO(9, "set u[*] "<name()<name()<name()<name()<isParam() && !nodep->isGenVar()) { bool allU = true; bool allD = true; - bool anyU = m_usedWhole; - bool anyD = m_drivenWhole; + bool anyU = m_wholeFlags[FLAG_USED]; + bool anyD = m_wholeFlags[FLAG_DRIVEN]; bool anyUnotD = false; bool anyDnotU = false; bool anynotDU = false; - for (unsigned bit=0; bitisIfaceRef()) { // For interface top level we don't do any tracking @@ -229,18 +233,18 @@ private: // NODE STATE // Netlist: // AstVar::user1p -> UndrivenVar* for usage var, 0=not set yet - AstUser1InUse m_inuser1; + AstUser1InUse m_inuser1; // Each always: // AstNode::user2p -> UndrivenVar* for usage var, 0=not set yet - AstUser2InUse m_inuser2; + AstUser2InUse m_inuser2; // STATE std::vector m_entryps[3]; // Nodes to delete when we are finished - bool m_inBBox; // In black box; mark as driven+used - bool m_inContAssign; // In continuous assignment - bool m_inProcAssign; // In procedural assignment - AstNodeFTask* m_taskp; // Current task - AstAlways* m_alwaysCombp; // Current always if combo, otherwise NULL + bool m_inBBox; // In black box; mark as driven+used + bool m_inContAssign; // In continuous assignment + bool m_inProcAssign; // In procedural assignment + AstNodeFTask* m_taskp; // Current task + AstAlways* m_alwaysCombp; // Current always if combo, otherwise NULL // METHODS VL_DEBUG_FUNC; // Declare debug() @@ -443,7 +447,7 @@ public: it != m_entryps[1].end(); ++it) { (*it)->reportViolations(); } - for (int usr=1; usr<3; ++usr) { + for (int usr = 1; usr < 3; ++usr) { for (std::vector::iterator it = m_entryps[usr].begin(); it != m_entryps[usr].end(); ++it) { delete (*it);