Skip to content

Commit

Permalink
Minor cleanup of trace internals
Browse files Browse the repository at this point in the history
  • Loading branch information
gezalore committed Dec 12, 2023
1 parent 6012ec8 commit c5ba6e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 44 deletions.
15 changes: 8 additions & 7 deletions src/V3AstNodeOther.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
Expand All @@ -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; }
Expand All @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/V3Clean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
51 changes: 18 additions & 33 deletions src/V3Trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 TraceTraceVertex>()) {
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<TraceTraceVertex>()) {
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<TraceTraceVertex>();
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<TraceTraceVertex>();
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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c5ba6e2

Please sign in to comment.