diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index 3254806ad9..e564f32954 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -3213,7 +3213,6 @@ class AstTraceDecl final : public AstNodeStmt { const string m_showname; // Name of variable const VNumRange m_bitRange; // Property of var the trace details const VNumRange m_arrayRange; // Property of var the trace details - const uint32_t m_codeInc; // Code increment const VVarType m_varType; // Type of variable (for localparam vs. param) const VDirection m_declDirection; // Declared direction input/output etc public: @@ -3224,9 +3223,6 @@ class AstTraceDecl final : public AstNodeStmt { , m_showname{showname} , m_bitRange{bitRange} , m_arrayRange{arrayRange} - , m_codeInc( - ((arrayRange.ranged() ? arrayRange.elements() : 1) * valuep->dtypep()->widthWords() - * (VL_EDATASIZE / 32))) // A code is always 32-bits , m_varType{varp->varType()} , m_declDirection{varp->declDirection()} { dtypeFrom(valuep); @@ -3245,7 +3241,11 @@ class AstTraceDecl final : public AstNodeStmt { void code(uint32_t code) { m_code = code; } uint32_t fidx() const { return m_fidx; } void fidx(uint32_t fidx) { m_fidx = fidx; } - uint32_t codeInc() const { return m_codeInc; } + uint32_t codeInc() const { + return (m_arrayRange.ranged() ? m_arrayRange.elements() : 1) + * valuep()->dtypep()->widthWords() + * (VL_EDATASIZE / 32); // A code is always 32-bits + } const VNumRange& bitRange() const { return m_bitRange; } const VNumRange& arrayRange() const { return m_arrayRange; } VVarType varType() const { return m_varType; } @@ -3266,8 +3266,9 @@ class AstTraceInc final : public AstNodeStmt { , m_traceType{traceType} , m_declp{declp} { dtypeFrom(declp); - this->valuep( - declp->valuep()->cloneTree(true)); // TODO: maybe use reference to TraceDecl instead? + // Note: A clone is necessary (instead of using declp()->valuep()), + // for insertion of local temporaries in V3Premit + valuep(declp->valuep()->cloneTree(true)); } ASTGEN_MEMBERS_AstTraceInc; void dump(std::ostream& str) const override; diff --git a/src/V3Clean.cpp b/src/V3Clean.cpp index 833e383d41..d972c0029d 100644 --- a/src/V3Clean.cpp +++ b/src/V3Clean.cpp @@ -238,10 +238,7 @@ class CleanVisitor final : public VNVisitor { if (AstNodeExpr* const exprp = VN_CAST(argp, NodeExpr)) ensureClean(exprp); } } - void visit(AstTraceDecl* nodep) override { - // No cleaning, or would loose pointer to enum - iterateChildren(nodep); - } + void visit(AstTraceDecl* nodep) override {} // Nothing to do here void visit(AstTraceInc* nodep) override { iterateChildren(nodep); ensureCleanAndNext(nodep->valuep()); diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index ebfe22e782..ed25f5e523 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -201,40 +201,24 @@ class TraceVisitor final : public VNVisitor { UINFO(9, "Finding duplicates\n"); // Note uses user4 V3DupFinder dupFinder; // Duplicate code detection - // Hash all of the values the traceIncs need - for (const V3GraphVertex* itp = m_graph.verticesBeginp(); itp; - itp = itp->verticesNextp()) { - if (const TraceTraceVertex* const vvertexp = itp->cast()) { - const AstTraceDecl* const nodep = vvertexp->nodep(); - if (nodep->valuep()) { - UASSERT_OBJ(nodep->valuep()->backp() == nodep, nodep, - "Trace duplicate back needs consistency," - " so we can map duplicates back to TRACEINCs"); - // Just keep one node in the map and point all duplicates to this node - if (dupFinder.findDuplicate(nodep->valuep()) == dupFinder.end()) { - dupFinder.insert(nodep->valuep()); - } - } - } - } - // Find if there are any duplicates + // Hash all of the traced values and find if there are any duplicates for (V3GraphVertex* itp = m_graph.verticesBeginp(); itp; itp = itp->verticesNextp()) { if (TraceTraceVertex* const vvertexp = itp->cast()) { const AstTraceDecl* const nodep = vvertexp->nodep(); - if (nodep->valuep() && !vvertexp->duplicatep()) { - const auto dupit = dupFinder.findDuplicate(nodep->valuep()); - if (dupit != dupFinder.end()) { - const AstTraceDecl* const dupDeclp - = VN_AS(dupit->second->backp(), TraceDecl); - UASSERT_OBJ(dupDeclp, nodep, "Trace duplicate of wrong type"); - TraceTraceVertex* const dupvertexp - = dupDeclp->user1u().toGraphVertex()->cast(); - UINFO(8, " Orig " << nodep << endl); - UINFO(8, " dup " << dupDeclp << endl); - // Mark the hashed node as the original and our - // iterating node as duplicated - vvertexp->duplicatep(dupvertexp); - } + UASSERT_OBJ(!vvertexp->duplicatep(), nodep, "Should not be a duplicate"); + const auto dupit = dupFinder.findDuplicate(nodep->valuep()); + if (dupit == dupFinder.end()) { + dupFinder.insert(nodep->valuep()); + } else { + const AstTraceDecl* const dupDeclp = VN_AS(dupit->second->backp(), TraceDecl); + UASSERT_OBJ(dupDeclp, nodep, "Trace duplicate of wrong type"); + TraceTraceVertex* const dupvertexp + = dupDeclp->user1u().toGraphVertex()->cast(); + UINFO(8, " Orig " << nodep << endl); + UINFO(8, " dup " << dupDeclp << endl); + // Mark the hashed node as the original and our + // iterating node as duplicated + vvertexp->duplicatep(dupvertexp); } } } @@ -594,8 +578,9 @@ class TraceVisitor final : public VNVisitor { UASSERT_OBJ(declp->code() == 0, declp, "Canonical node should not have code assigned yet"); declp->code(m_code); - m_code += declp->codeInc(); - m_statUniqCodes += declp->codeInc(); + const uint32_t codeInc = declp->codeInc(); + m_code += codeInc; + m_statUniqCodes += codeInc; ++m_statUniqSigs; // If this is a const signal, add the AstTraceInc