Improve Loop unrolling (#6480) (#6493)

This patch implements #6480. All loop statements are represented using
AstLoop and AstLoopTest.

This necessitates rework of the loop unroller to handle loops of
arbitrary form. To enable this, I have split the old unroller used for
'generate for' statements and moved it into V3Param, and subsequently
rewrote V3Unroll to handle the new representation. V3Unroll can now
unroll more complex loops, including with loop conditions containing
multiple variable references or inlined functions.

Handling the more generic code also requires some restrictions. If a
loop contains any of the following, it cannot be unrolled:
- A timing control that might suspend the loop
- A non-inlined call to a non-pure function

These constructs can change the values of variables in the loop, so are
generally not safe to unroll if they are present. (We could still unroll
if all the variables needed for unrolling are automatic, however we
don't do that right now.)

These restrictions seem ok in the benchmark suite, where the new
unroller can generally unroll many more loops than before.
This commit is contained in:
Geza Lore
2025-09-29 15:25:25 +01:00
committed by GitHub
parent 5c72b45975
commit 603f4c615a
59 changed files with 3151 additions and 2891 deletions
+1 -2
View File
@@ -338,8 +338,7 @@ protected:
void visit(AstAlways* nodep) override = 0;
void visit(AstNodeIf* nodep) override = 0;
// We don't do AstWhile loops, due to the standard question
// of what is before vs. after
// We don't do AstLoop, due to the standard question of what is before vs. after
void visit(AstAssignDly* nodep) override {
VL_RESTORER(m_inDly);