From 8bffb8c39149bc908d9ef079ab19ea7b4163ecde Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 2 Jul 2024 09:22:32 -0400 Subject: [PATCH] Fix table optimizing logic with side effect (#5137 prep) --- src/V3Simulate.h | 8 ++++---- src/V3Table.cpp | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/V3Simulate.h b/src/V3Simulate.h index 559d30613..c491f9905 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -107,7 +107,7 @@ private: bool m_anyAssignDly; ///< True if found a delayed assignment bool m_anyAssignComb; ///< True if found a non-delayed assignment bool m_inDlyAssign; ///< Under delayed assignment - bool m_isOutputter; // Creates output + bool m_isImpure; // Not pure int m_instrCount; ///< Number of nodes int m_dataCount; ///< Bytes of data AstJumpGo* m_jumpp = nullptr; ///< Jump label we're branching from @@ -214,7 +214,7 @@ public: AstNode* whyNotNodep() const { return m_whyNotNodep; } bool isAssignDly() const { return m_anyAssignDly; } - bool isOutputter() const { return m_isOutputter; } + bool isImpure() const { return m_isImpure; } int instrCount() const { return m_instrCount; } int dataCount() const { return m_dataCount; } @@ -359,7 +359,7 @@ private: // UINFO(9, " !predictopt " << nodep << endl); clearOptimizable(nodep, "Isn't predictable"); } - if (nodep->isOutputter()) m_isOutputter = true; + if (!nodep->isPure()) m_isImpure = true; } void knownBadNodeType(AstNode* nodep) { @@ -1231,7 +1231,7 @@ public: m_anyAssignComb = false; m_anyAssignDly = false; m_inDlyAssign = false; - m_isOutputter = false; + m_isImpure = false; m_instrCount = 0; m_dataCount = 0; m_jumpp = nullptr; diff --git a/src/V3Table.cpp b/src/V3Table.cpp index cbba13680..a7bddd93e 100644 --- a/src/V3Table.cpp +++ b/src/V3Table.cpp @@ -209,6 +209,10 @@ private: // Instruction count bytes (ok, it's space also not time :) const double time // max(_, 1), so we won't divide by zero = std::max(chkvis.instrCount() * TABLE_BYTES_PER_INST + chkvis.dataCount(), 1); + if (chkvis.isImpure()) chkvis.clearOptimizable(nodep, "Table creates side effects"); + if (!m_outWidthBytes || !m_inWidthBits) { + chkvis.clearOptimizable(nodep, "Table has no outputs"); + } if (chkvis.instrCount() < TABLE_MIN_NODE_COUNT) { chkvis.clearOptimizable(nodep, "Table has too few nodes involved"); } @@ -221,12 +225,6 @@ private: if (m_totalBytes > TABLE_TOTAL_BYTES) { chkvis.clearOptimizable(nodep, "Table out of memory"); } - if (!m_outWidthBytes || !m_inWidthBits) { - chkvis.clearOptimizable(nodep, "Table has no outputs"); - } - if (chkvis.isOutputter()) { - chkvis.clearOptimizable(nodep, "Table creates display output"); - } UINFO(4, " Test: Opt=" << (chkvis.optimizable() ? "OK" : "NO") << ", Instrs=" << chkvis.instrCount() << " Data=" << chkvis.dataCount() << " in width (bits)=" << m_inWidthBits << " out width (bytes)="