2012-04-13 01:08:20 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Break always into sensitivity active domains
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2025-01-01 13:30:25 +00:00
|
|
|
// Copyright 2003-2025 by Wilson Snyder. This program is free software; you
|
2020-03-21 15:24:24 +00:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// V3Active's Transformations:
|
2008-06-10 01:25:10 +00:00
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
// Note this can be called multiple times.
|
|
|
|
// Across all ACTIVES
|
2019-05-19 20:13:13 +00:00
|
|
|
// SenTrees are now under each ACTIVE statement, we want them global:
|
|
|
|
// Find SenTree in under global TopScope, or create it there
|
|
|
|
// Move SenTree the global SenTree
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2023-10-18 10:37:46 +00:00
|
|
|
#include "V3PchAstNoMT.h" // VL_MT_DISABLED_CODE_UNIT
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
#include "V3ActiveTop.h"
|
2022-08-05 09:56:57 +00:00
|
|
|
|
2009-01-07 14:37:59 +00:00
|
|
|
#include "V3Const.h"
|
2022-08-05 09:56:57 +00:00
|
|
|
#include "V3SenTree.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2022-09-18 19:53:42 +00:00
|
|
|
VL_DEFINE_DEBUG_FUNCTIONS;
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
//######################################################################
|
|
|
|
// Active class functions
|
|
|
|
|
2022-01-02 18:56:40 +00:00
|
|
|
class ActiveTopVisitor final : public VNVisitor {
|
2006-08-26 11:35:28 +00:00
|
|
|
// STATE
|
2021-10-17 09:29:17 +00:00
|
|
|
SenTreeFinder m_finder; // Find global sentree's / add them under the AstTopScope
|
2009-01-21 21:56:50 +00:00
|
|
|
|
|
|
|
// METHODS
|
2006-08-26 11:35:28 +00:00
|
|
|
|
2022-05-15 15:03:32 +00:00
|
|
|
static bool isInitial(AstNode* nodep) {
|
|
|
|
const VNUser1InUse user1InUse;
|
|
|
|
// Return true if no variables that read.
|
2022-10-20 12:48:44 +00:00
|
|
|
return nodep->forall([&](const AstVarRef* refp) -> bool {
|
2022-05-15 15:03:32 +00:00
|
|
|
AstVarScope* const vscp = refp->varScopep();
|
|
|
|
// Note: Use same heuristic as ordering does to ignore written variables
|
|
|
|
// TODO: Use live variable analysis.
|
|
|
|
if (refp->access().isWriteOnly()) {
|
|
|
|
vscp->user1(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Read or ReadWrite: OK if written before
|
|
|
|
return vscp->user1();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
// VISITORS
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstNodeModule* nodep) override {
|
2019-05-19 20:13:13 +00:00
|
|
|
// Create required actives and add to module
|
|
|
|
// We can start ordering at a module, or a scope
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " MOD " << nodep << endl);
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstActive* nodep) override {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " ACTIVE " << nodep << endl);
|
|
|
|
// Remove duplicate clocks and such; sensesp() may change!
|
|
|
|
V3Const::constifyExpensiveEdit(nodep);
|
2024-05-08 12:36:24 +00:00
|
|
|
AstSenTree* sensesp = nodep->sensesp();
|
2020-08-15 14:12:55 +00:00
|
|
|
UASSERT_OBJ(sensesp, nodep, "nullptr");
|
2021-10-22 16:36:58 +00:00
|
|
|
if (sensesp->sensesp() && sensesp->sensesp()->isNever()) {
|
2019-05-19 20:13:13 +00:00
|
|
|
// Never executing. Kill it.
|
2019-07-06 16:57:50 +00:00
|
|
|
UASSERT_OBJ(!sensesp->sensesp()->nextp(), nodep,
|
|
|
|
"Never senitem should be alone, else the never should be eliminated.");
|
2020-01-17 01:17:11 +00:00
|
|
|
VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
|
2019-05-19 20:13:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-03-16 10:35:56 +00:00
|
|
|
|
|
|
|
// Delete empty procedures
|
|
|
|
for (AstNode *stmtp = nodep->stmtsp(), *nextp; stmtp; stmtp = nextp) {
|
|
|
|
nextp = stmtp->nextp();
|
|
|
|
if (AstNodeProcedure* const procp = VN_CAST(stmtp, NodeProcedure)) {
|
|
|
|
if (!procp->stmtsp()) VL_DO_DANGLING(pushDeletep(procp->unlinkFrBack()), stmtp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete empty actives
|
|
|
|
if (!nodep->stmtsp()) {
|
|
|
|
VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
// Move the SENTREE for each active up to the global level.
|
|
|
|
// This way we'll easily see what clock domains are identical
|
2021-11-13 18:50:44 +00:00
|
|
|
AstSenTree* const wantp = m_finder.getSenTree(sensesp);
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " lookdone\n");
|
2019-05-19 20:13:13 +00:00
|
|
|
if (wantp != sensesp) {
|
|
|
|
// Move the active's contents to the other active
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(4, " merge active " << sensesp << " into " << wantp << endl);
|
2019-05-19 20:13:13 +00:00
|
|
|
if (nodep->sensesStorep()) {
|
2019-07-06 16:57:50 +00:00
|
|
|
UASSERT_OBJ(sensesp == nodep->sensesStorep(), nodep,
|
|
|
|
"sensesStore should have been deleted earlier if different");
|
2019-05-19 20:13:13 +00:00
|
|
|
sensesp->unlinkFrBack();
|
|
|
|
// There may be other references to same sense tree,
|
|
|
|
// we'll be removing all references when we get to them,
|
|
|
|
// but don't dangle our pointer yet!
|
2024-05-08 12:36:24 +00:00
|
|
|
VL_DO_DANGLING(pushDeletep(sensesp), sensesp);
|
2019-05-19 20:13:13 +00:00
|
|
|
}
|
|
|
|
nodep->sensesp(wantp);
|
|
|
|
}
|
2022-05-15 15:03:32 +00:00
|
|
|
|
|
|
|
// If this is combinational logic that does not read any variables, then it really is an
|
|
|
|
// initial block in disguise, so move such logic under an Initial AstActive, V3Order would
|
|
|
|
// prune these otherwise.
|
|
|
|
// TODO: we should warn for these if they were 'always @*' as some (including strictly
|
|
|
|
// compliant) simulators will never execute these.
|
|
|
|
if (nodep->sensesp()->hasCombo()) {
|
|
|
|
FileLine* const flp = nodep->fileline();
|
|
|
|
AstActive* initialp = nullptr;
|
|
|
|
for (AstNode *logicp = nodep->stmtsp(), *nextp; logicp; logicp = nextp) {
|
|
|
|
nextp = logicp->nextp();
|
|
|
|
if (!isInitial(logicp)) continue;
|
|
|
|
if (!initialp) initialp = new AstActive{flp, "", m_finder.getInitial()};
|
|
|
|
initialp->addStmtsp(logicp->unlinkFrBack());
|
|
|
|
}
|
|
|
|
if (initialp) nodep->addHereThisAsNext(initialp);
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstNodeProcedure* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstAssignAlias* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstAssignW* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstAlwaysPublic* nodep) override { // LCOV_EXCL_LINE
|
2019-05-19 20:13:13 +00:00
|
|
|
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
2010-04-06 00:01:17 +00:00
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
//--------------------
|
2022-10-12 09:19:21 +00:00
|
|
|
void visit(AstNodeExpr*) override {} // Accelerate
|
2022-09-16 10:22:11 +00:00
|
|
|
void visit(AstVarScope*) override {} // Accelerate
|
|
|
|
void visit(AstNode* nodep) override { iterateChildren(nodep); }
|
2020-04-04 02:31:54 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
public:
|
2019-09-12 11:22:22 +00:00
|
|
|
// CONSTRUCTORS
|
2020-08-15 17:11:27 +00:00
|
|
|
explicit ActiveTopVisitor(AstNetlist* nodep) { iterate(nodep); }
|
2022-09-16 10:22:11 +00:00
|
|
|
~ActiveTopVisitor() override = default;
|
2006-08-26 11:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Active class functions
|
|
|
|
|
|
|
|
void V3ActiveTop::activeTopAll(AstNetlist* nodep) {
|
2020-04-14 02:51:35 +00:00
|
|
|
UINFO(2, __FUNCTION__ << ": " << endl);
|
2021-11-26 15:52:36 +00:00
|
|
|
{ ActiveTopVisitor{nodep}; } // Destruct before checking
|
2024-01-09 15:35:13 +00:00
|
|
|
V3Global::dumpCheckGlobalTree("activetop", 0, dumpTreeEitherLevel() >= 3);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|