2024-03-09 13:43:09 +01:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Block code ordering
|
|
|
|
|
//
|
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2025-01-01 14:30:25 +01:00
|
|
|
// Copyright 2003-2025 by Wilson Snyder. This program is free software; you
|
2024-03-09 13:43:09 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Serial code ordering
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#include "V3PchAstNoMT.h" // VL_MT_DISABLED_CODE_UNIT
|
|
|
|
|
|
|
|
|
|
#include "V3OrderCFuncEmitter.h"
|
|
|
|
|
#include "V3OrderInternal.h"
|
|
|
|
|
|
2024-03-09 22:19:35 +01:00
|
|
|
#include <memory>
|
2024-03-09 13:43:09 +01:00
|
|
|
|
|
|
|
|
VL_DEFINE_DEBUG_FUNCTIONS;
|
|
|
|
|
|
2024-03-09 22:19:35 +01:00
|
|
|
//######################################################################
|
2024-03-17 14:15:39 +01:00
|
|
|
// OrderSerial class
|
2024-03-09 13:43:09 +01:00
|
|
|
|
2025-10-31 19:29:11 +01:00
|
|
|
AstNodeStmt* V3Order::createSerial(OrderMoveGraph& moveGraph, const std::string& tag, bool slow) {
|
2024-03-09 13:43:09 +01:00
|
|
|
|
2025-05-23 02:29:32 +02:00
|
|
|
UINFO(2, " Constructing serial code for '" + tag + "'");
|
2024-03-09 13:43:09 +01:00
|
|
|
|
2024-03-17 14:15:39 +01:00
|
|
|
// Serializer
|
2025-10-31 19:29:11 +01:00
|
|
|
OrderMoveGraphSerializer serializer{moveGraph};
|
2024-03-09 13:43:09 +01:00
|
|
|
|
2024-03-17 14:15:39 +01:00
|
|
|
// Add initially ready vertices (those with no dependencies) to the serializer as seeds
|
2025-10-31 19:29:11 +01:00
|
|
|
for (V3GraphVertex& vtx : moveGraph.vertices()) {
|
2024-03-26 00:06:25 +01:00
|
|
|
if (vtx.inEmpty()) serializer.addSeed(vtx.as<OrderMoveVertex>());
|
2024-03-09 13:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-17 14:15:39 +01:00
|
|
|
// Emit all logic as they become ready
|
|
|
|
|
V3OrderCFuncEmitter emitter{tag, slow};
|
|
|
|
|
OrderMoveDomScope* prevDomScopep = nullptr;
|
|
|
|
|
while (OrderMoveVertex* const mVtxp = serializer.getNext()) {
|
|
|
|
|
// We only really care about logic vertices
|
|
|
|
|
if (OrderLogicVertex* const logicp = mVtxp->logicp()) {
|
|
|
|
|
// Force a new function if the domain or scope changed, for better combining.
|
|
|
|
|
OrderMoveDomScope* const domScopep = &mVtxp->domScope();
|
|
|
|
|
if (domScopep != prevDomScopep) emitter.forceNewFunction();
|
|
|
|
|
prevDomScopep = domScopep;
|
|
|
|
|
// Emit the logic under this vertex
|
|
|
|
|
emitter.emitLogic(logicp);
|
2024-03-09 22:19:35 +01:00
|
|
|
}
|
|
|
|
|
// Can delete the vertex now
|
2025-10-31 19:29:11 +01:00
|
|
|
VL_DO_DANGLING(mVtxp->unlinkDelete(&moveGraph), mVtxp);
|
2024-03-09 13:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-17 14:15:39 +01:00
|
|
|
// Delete the remaining variable vertices
|
2025-10-31 19:29:11 +01:00
|
|
|
for (V3GraphVertex* const vtxp : moveGraph.vertices().unlinkable()) {
|
2024-03-17 14:15:39 +01:00
|
|
|
if (!vtxp->as<OrderMoveVertex>()->logicp()) {
|
2025-10-31 19:29:11 +01:00
|
|
|
VL_DO_DANGLING(vtxp->unlinkDelete(&moveGraph), vtxp);
|
2024-03-09 22:19:35 +01:00
|
|
|
}
|
2024-03-09 13:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-27 11:41:30 +01:00
|
|
|
return emitter.getStmts();
|
2024-03-09 13:43:09 +01:00
|
|
|
}
|