mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
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:
+6
-4
@@ -55,6 +55,8 @@
|
||||
#include "V3Hasher.h"
|
||||
#include "V3Os.h"
|
||||
#include "V3Parse.h"
|
||||
#include "V3Simulate.h"
|
||||
#include "V3Stats.h"
|
||||
#include "V3Unroll.h"
|
||||
#include "V3Width.h"
|
||||
|
||||
@@ -1267,7 +1269,7 @@ class ParamVisitor final : public VNVisitor {
|
||||
// STATE - across all visitors
|
||||
ParamState& m_state; // Common state
|
||||
ParamProcessor m_processor; // De-parameterize a cell, build modules
|
||||
UnrollStateful m_unroller; // Loop unroller
|
||||
GenForUnroller m_unroller; // Unroller for AstGenFor
|
||||
|
||||
bool m_iterateModule = false; // Iterating module body
|
||||
string m_unlinkedTxt; // Text for AstUnlinkedRef
|
||||
@@ -1632,10 +1634,10 @@ class ParamVisitor final : public VNVisitor {
|
||||
// a BEGIN("zzz__BRA__{loop#}__KET__")
|
||||
const string beginName = nodep->name();
|
||||
// Leave the original Begin, as need a container for the (possible) GENVAR
|
||||
// Note V3Unroll will replace some AstVarRef's to the loop variable with constants
|
||||
// Note m_unroller will replace some AstVarRef's to the loop variable with constants
|
||||
// Don't remove any deleted nodes in m_unroller until whole process finishes,
|
||||
// (are held in m_unroller), as some AstXRefs may still point to old nodes.
|
||||
VL_DO_DANGLING(m_unroller.unrollGen(forp, beginName), forp);
|
||||
// as some AstXRefs may still point to old nodes.
|
||||
VL_DO_DANGLING(m_unroller.unroll(forp, beginName), forp);
|
||||
// Blocks were constructed under the special begin, move them up
|
||||
// Note forp is null, so grab statements again
|
||||
if (AstNode* const stmtsp = nodep->genforp()) {
|
||||
|
||||
Reference in New Issue
Block a user