Internals: Make AstCAwait an AstNodeStmt (#6280) (#7078)

AstCAwait is only ever uses in statement position, so model it as a
statement. We should never ever have a coroutine that returns a value.
There is no need for it in SV, nor should we rely on it for internals.

Also reworks the fix for V3Life incorrectly constant propagating the
beforeTrig functions (#7072). The property that upsets V3Life is that
a function:
1. Is called from multiple static call sites (multiple AstCCall)
2. Reads model state directly (AstVarRef to non-locals/arguments)

Such function can only be created internally after scheduling (V3Task
throws an unsupported error on a non-inlined function that reads model
state), so added a flag to AstCFunc to mark the dangerous ones for
V3Life.
This commit is contained in:
Geza Lore
2026-02-14 20:15:32 +00:00
committed by GitHub
parent be27811a10
commit a0b89dde8e
9 changed files with 53 additions and 64 deletions
+5 -9
View File
@@ -859,6 +859,9 @@ class AwaitBeforeTrigVisitor final : public VNVisitor {
AstVar* const tmpVarp = tmpp->varp()->unlinkFrBack();
funcp->user1p(tmpp);
funcp->addVarsp(tmpVarp);
// This function can be called multiple times, and accesses model state, which
// violates the assumption made in V3Life that there is no such function.
funcp->noLife(true);
tmpVarp->funcLocal(true);
tmpVarp->noReset(true);
@@ -884,20 +887,13 @@ class AwaitBeforeTrigVisitor final : public VNVisitor {
if (cMethodHardp->method() == VCMethod::SCHED_TRIGGER) {
AstCCall* const beforeTrigp = getBeforeTriggerStmt(nodep->sentreep());
FileLine* const flp = nodep->fileline();
// Add eventDescription argument value to a CCall - it is used for --runtime-debug
AstNode* const pinp = cMethodHardp->pinsp()->nextp()->nextp();
UASSERT_OBJ(pinp, cMethodHardp, "No event description");
beforeTrigp->addArgsp(VN_AS(pinp, NodeExpr)->cloneTree(false));
// Change CAwait Expression into StmtExpr that calls to a before-trigger function
// first and then return CAwait
VNRelinker relinker;
nodep->unlinkFrBack(&relinker);
AstExprStmt* const exprstmtp
= new AstExprStmt{flp, beforeTrigp->makeStmt(), nodep};
exprstmtp->setTimingControl();
relinker.relink(exprstmtp);
// Call the before-trigger function before the CAwait
nodep->addHereThisAsNext(beforeTrigp->makeStmt());
m_senTreeToSched.emplace(nodep->sentreep(), cMethodHardp->fromp());
}
}