mirror of
https://github.com/verilator/verilator.git
synced 2026-09-03 16:28:53 +02:00
Do not create aliases for forced port signals (#5105)
+ don't remove forced signals in V3Const and Dfg Fixes #5062
This commit is contained in:
@@ -1809,6 +1809,7 @@ class AstVar final : public AstNode {
|
||||
bool m_trace : 1; // Trace this variable
|
||||
bool m_isLatched : 1; // Not assigned in all control paths of combo always
|
||||
bool m_isForceable : 1; // May be forced/released externally from user C code
|
||||
bool m_isForcedByCode : 1; // May be forced/released from AstAssignForce/AstRelease
|
||||
bool m_isWrittenByDpi : 1; // This variable can be written by a DPI Export
|
||||
bool m_isWrittenBySuspendable : 1; // This variable can be written by a suspendable process
|
||||
|
||||
@@ -1854,6 +1855,7 @@ class AstVar final : public AstNode {
|
||||
m_trace = false;
|
||||
m_isLatched = false;
|
||||
m_isForceable = false;
|
||||
m_isForcedByCode = false;
|
||||
m_isWrittenByDpi = false;
|
||||
m_isWrittenBySuspendable = false;
|
||||
m_attrClocker = VVarAttrClocker::CLOCKER_UNKNOWN;
|
||||
@@ -2009,6 +2011,8 @@ public:
|
||||
void isLatched(bool flag) { m_isLatched = flag; }
|
||||
bool isForceable() const { return m_isForceable; }
|
||||
void setForceable() { m_isForceable = true; }
|
||||
void setForcedByCode() { m_isForcedByCode = true; }
|
||||
bool isForced() const { return m_isForceable || m_isForcedByCode; }
|
||||
bool isWrittenByDpi() const { return m_isWrittenByDpi; }
|
||||
void setWrittenByDpi() { m_isWrittenByDpi = true; }
|
||||
bool isWrittenBySuspendable() const { return m_isWrittenBySuspendable; }
|
||||
|
||||
+3
-2
@@ -3071,8 +3071,9 @@ class ConstVisitor final : public VNVisitor {
|
||||
&& varrefp // Don't do messes with BITREFs/ARRAYREFs
|
||||
&& !varrefp->varp()->hasStrengthAssignment() // Strengths are resolved in V3Tristate
|
||||
&& !varrefp->varp()->valuep() // Not already constified
|
||||
&& !varrefp->varScopep()) { // Not scoped (or each scope may have different initial
|
||||
// value)
|
||||
&& !varrefp->varScopep() // Not scoped (or each scope may have different initial val.)
|
||||
&& !varrefp->varp()->isForced() // Not forced (not really a constant)
|
||||
) {
|
||||
// ASSIGNW (VARREF, const) -> INITIAL ( ASSIGN (VARREF, const) )
|
||||
UINFO(4, "constAssignW " << nodep << endl);
|
||||
// Make a initial assignment
|
||||
|
||||
@@ -443,7 +443,7 @@ class AstToDfgVisitor final : public VNVisitor {
|
||||
// Mark variables with external references
|
||||
if (nodep->isIO() // Ports
|
||||
|| nodep->user2() // Target of a hierarchical reference
|
||||
|| nodep->isForceable() // Forceable
|
||||
|| nodep->isForced() // Forced
|
||||
) {
|
||||
getNet(nodep)->setHasExtRefs();
|
||||
}
|
||||
|
||||
+2
-2
@@ -165,8 +165,8 @@ void V3DfgPasses::inlineVars(DfgGraph& dfg) {
|
||||
const AstVar* const astVarp = driverVarp->varp();
|
||||
// If driven from a SystemC variable
|
||||
if (astVarp->isSc()) continue;
|
||||
// If the variable is forceable
|
||||
if (astVarp->isForceable()) continue;
|
||||
// If the variable is forced
|
||||
if (astVarp->isForced()) continue;
|
||||
}
|
||||
|
||||
varp->forEachSinkEdge([=](DfgEdge& edge) { edge.relinkSource(driverp); });
|
||||
|
||||
+1
-1
@@ -239,7 +239,7 @@ public:
|
||||
ASTGEN_MEMBERS_DfgVarPacked;
|
||||
|
||||
bool isDrivenFullyByDfg() const {
|
||||
return arity() == 1 && source(0)->dtypep() == dtypep() && !varp()->isForceable();
|
||||
return arity() == 1 && source(0)->dtypep() == dtypep() && !varp()->isForced();
|
||||
}
|
||||
|
||||
void addDriver(FileLine* flp, uint32_t lsb, DfgVertex* vtxp) {
|
||||
|
||||
@@ -64,15 +64,6 @@ class ForceConvertVisitor final : public VNVisitor {
|
||||
m_rdVarp->addNext(m_enVarp);
|
||||
m_rdVarp->addNext(m_valVarp);
|
||||
varp->addNextHere(m_rdVarp);
|
||||
|
||||
if (varp->isPrimaryIO()) {
|
||||
varp->v3warn(
|
||||
E_UNSUPPORTED,
|
||||
"Unsupported: Force/Release on primary input/output net "
|
||||
<< varp->prettyNameQ() << "\n"
|
||||
<< varp->warnMore()
|
||||
<< "... Suggest assign it to/from a temporary net and force/release that");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -425,8 +425,8 @@ class GateClkDecomp final {
|
||||
void visit(GateVarVertex* vVtxp, int offset) {
|
||||
AstVarScope* const vscp = vVtxp->varScp();
|
||||
|
||||
// Can't propagate if this variable is forceable
|
||||
if (vscp->varp()->isForceable()) return;
|
||||
// Can't propagate if this variable might be forced
|
||||
if (vscp->varp()->isForced()) return;
|
||||
|
||||
// Check that we haven't been here before
|
||||
if (vscp->user2SetOnce()) return;
|
||||
|
||||
+13
-3
@@ -320,8 +320,16 @@ class InlineRelinkVisitor final : public VNVisitor {
|
||||
// module, so a AstVarRef not AstVarXRef below
|
||||
exprvarrefp = exprvarrefp->cloneTree(false);
|
||||
exprvarrefp->access(VAccess::READ);
|
||||
m_modp->addStmtsp(new AstAssignAlias{
|
||||
flp, new AstVarRef{flp, nodep, VAccess::WRITE}, exprvarrefp});
|
||||
AstVarRef* const nodeVarRefp = new AstVarRef{flp, nodep, VAccess::WRITE};
|
||||
if (nodep->isForced() && nodep->direction() == VDirection::INPUT) {
|
||||
m_modp->addStmtsp(new AstAssignW{flp, nodeVarRefp, exprvarrefp});
|
||||
} else if (nodep->isForced() && nodep->direction() == VDirection::OUTPUT) {
|
||||
exprvarrefp->access(VAccess::WRITE);
|
||||
nodeVarRefp->access(VAccess::READ);
|
||||
m_modp->addStmtsp(new AstAssignW{flp, exprvarrefp, nodeVarRefp});
|
||||
} else {
|
||||
m_modp->addStmtsp(new AstAssignAlias{flp, nodeVarRefp, exprvarrefp});
|
||||
}
|
||||
FileLine* const flbp = exprvarrefp->varp()->fileline();
|
||||
flp->modifyStateInherit(flbp);
|
||||
flbp->modifyStateInherit(flp);
|
||||
@@ -370,7 +378,9 @@ class InlineRelinkVisitor final : public VNVisitor {
|
||||
if (nodep->varp()->user2p() // It's being converted to an alias.
|
||||
&& !nodep->varp()->user3()
|
||||
// Don't constant propagate aliases (we just made)
|
||||
&& !VN_IS(nodep->backp(), AssignAlias)) {
|
||||
&& !VN_IS(nodep->backp(), AssignAlias)
|
||||
// Forced signals do not use aliases
|
||||
&& !nodep->varp()->isForced()) {
|
||||
AstVar* const varp = nodep->varp();
|
||||
if (AstConst* const constp = VN_CAST(varp->user2p(), Const)) {
|
||||
nodep->replaceWith(constp->cloneTree(false));
|
||||
|
||||
+13
-5
@@ -35,6 +35,7 @@ class LinkLValueVisitor final : public VNVisitor {
|
||||
// STATE
|
||||
bool m_setContinuously = false; // Set that var has some continuous assignment
|
||||
bool m_setStrengthSpecified = false; // Set that var has assignment with strength specified.
|
||||
bool m_setForcedByCode = false; // Set that var is the target of an AstAssignForce/AstRelease
|
||||
VAccess m_setRefLvalue; // Set VarRefs to lvalues for pin assignments
|
||||
|
||||
// VISITs
|
||||
@@ -42,15 +43,16 @@ class LinkLValueVisitor final : public VNVisitor {
|
||||
void visit(AstNodeVarRef* nodep) override {
|
||||
// VarRef: LValue its reference
|
||||
if (m_setRefLvalue != VAccess::NOCHANGE) nodep->access(m_setRefLvalue);
|
||||
if (nodep->varp()) {
|
||||
if (nodep->access().isWriteOrRW() && m_setContinuously) {
|
||||
if (nodep->varp() && nodep->access().isWriteOrRW()) {
|
||||
if (m_setContinuously) {
|
||||
nodep->varp()->isContinuously(true);
|
||||
// Strength may only be specified in continuous assignment,
|
||||
// so it is needed to check only if m_setContinuously is true
|
||||
if (m_setStrengthSpecified) nodep->varp()->hasStrengthAssignment(true);
|
||||
}
|
||||
if (nodep->access().isWriteOrRW() && !nodep->varp()->isFuncLocal()
|
||||
&& nodep->varp()->isReadOnly()) {
|
||||
if (m_setForcedByCode) {
|
||||
nodep->varp()->setForcedByCode();
|
||||
} else if (!nodep->varp()->isFuncLocal() && nodep->varp()->isReadOnly()) {
|
||||
nodep->v3warn(ASSIGNIN,
|
||||
"Assigning to input/const variable: " << nodep->prettyNameQ());
|
||||
}
|
||||
@@ -79,7 +81,11 @@ class LinkLValueVisitor final : public VNVisitor {
|
||||
if (AstAssignW* assignwp = VN_CAST(nodep, AssignW)) {
|
||||
if (assignwp->strengthSpecp()) m_setStrengthSpecified = true;
|
||||
}
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
{
|
||||
VL_RESTORER(m_setForcedByCode);
|
||||
m_setForcedByCode = VN_IS(nodep, AssignForce);
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
}
|
||||
m_setRefLvalue = VAccess::NOCHANGE;
|
||||
m_setContinuously = false;
|
||||
m_setStrengthSpecified = false;
|
||||
@@ -89,9 +95,11 @@ class LinkLValueVisitor final : public VNVisitor {
|
||||
void visit(AstRelease* nodep) override {
|
||||
VL_RESTORER(m_setRefLvalue);
|
||||
VL_RESTORER(m_setContinuously);
|
||||
VL_RESTORER(m_setForcedByCode);
|
||||
{
|
||||
m_setRefLvalue = VAccess::WRITE;
|
||||
m_setContinuously = false;
|
||||
m_setForcedByCode = true;
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user