mirror of
https://github.com/verilator/verilator.git
synced 2026-09-02 10:48:27 +02:00
Fixes #7440
This commit is contained in:
@@ -3998,6 +3998,23 @@ class RandomizeVisitor final : public VNVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite a LogIf-of-Dist chain into nested AstConstraintIf. The outermost
|
||||
// AstLogIf shell is left for the caller's AstConstraintExpr to free; inner
|
||||
// shells are deleted here once their children are transplanted.
|
||||
AstConstraintIf* liftLogIfChainToConstraintIf(AstLogIf* logIfp) {
|
||||
FileLine* const fl = logIfp->fileline();
|
||||
AstNodeExpr* const condp = logIfp->lhsp()->unlinkFrBack();
|
||||
AstNodeExpr* const rhsp = logIfp->rhsp()->unlinkFrBack();
|
||||
AstNode* thenBodyp;
|
||||
if (AstLogIf* const innerLogIfp = VN_CAST(rhsp, LogIf)) {
|
||||
thenBodyp = liftLogIfChainToConstraintIf(innerLogIfp);
|
||||
VL_DO_DANGLING(pushDeletep(innerLogIfp), innerLogIfp);
|
||||
} else {
|
||||
thenBodyp = new AstConstraintExpr{fl, rhsp};
|
||||
}
|
||||
return new AstConstraintIf{fl, condp, thenBodyp, nullptr};
|
||||
}
|
||||
|
||||
// Replace AstDist with weighted bucket selection via AstConstraintIf chain.
|
||||
// Supports both constant and variable weight expressions.
|
||||
void lowerDistConstraints(AstTask* taskp, AstNode* constrItemsp) {
|
||||
@@ -4019,6 +4036,25 @@ class RandomizeVisitor final : public VNVisitor {
|
||||
|
||||
AstConstraintExpr* const constrExprp = VN_CAST(itemp, ConstraintExpr);
|
||||
if (!constrExprp) continue;
|
||||
|
||||
// `cond -> x dist {...}` parses as ConstraintExpr(LogIf(cond, Dist)).
|
||||
// This pass only scans ConstraintExpr/If/Foreach for Dist, so lift the
|
||||
// LogIf chain into nested ConstraintIf first. Chains like
|
||||
// `a -> b -> dist` nest accordingly.
|
||||
if (AstLogIf* const topLogIfp = VN_CAST(constrExprp->exprp(), LogIf)) {
|
||||
AstNode* chainEndp = topLogIfp->rhsp();
|
||||
while (AstLogIf* const innerp = VN_CAST(chainEndp, LogIf)) {
|
||||
chainEndp = innerp->rhsp();
|
||||
}
|
||||
if (VN_IS(chainEndp, Dist)) {
|
||||
AstConstraintIf* const liftedp = liftLogIfChainToConstraintIf(topLogIfp);
|
||||
constrExprp->replaceWith(liftedp);
|
||||
VL_DO_DANGLING(pushDeletep(constrExprp), constrExprp);
|
||||
lowerDistConstraints(taskp, liftedp->thensp());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
AstDist* const distp = VN_CAST(constrExprp->exprp(), Dist);
|
||||
if (!distp) continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user