mirror of
https://github.com/verilator/verilator.git
synced 2026-09-02 10:48:27 +02:00
+13
-8
@@ -1097,6 +1097,7 @@ public:
|
||||
class GateMergeAssignments final {
|
||||
GateGraph& m_graph;
|
||||
size_t m_statAssignMerged = 0; // Statistic tracking
|
||||
std::vector<GateLogicVertex*> m_toRemove; // Logic vertices to delete
|
||||
|
||||
// assemble two Sel into one if possible
|
||||
AstSel* merge(AstSel* prevSelp, AstSel* currSelp) {
|
||||
@@ -1146,18 +1147,16 @@ class GateMergeAssignments final {
|
||||
// replace preSel with newSel
|
||||
prevSelp->replaceWith(newSelp);
|
||||
VL_DO_DANGLING(prevSelp->deleteTree(), prevSelp);
|
||||
// create new rhs for pre assignment
|
||||
AstNode* const newRhsp = new AstConcat{prevAssignp->rhsp()->fileline(),
|
||||
prevAssignp->rhsp()->cloneTreePure(false),
|
||||
assignp->rhsp()->cloneTreePure(false)};
|
||||
AstNode* const prevRhsp = prevAssignp->rhsp();
|
||||
prevRhsp->replaceWith(newRhsp);
|
||||
VL_DO_DANGLING(prevRhsp->deleteTree(), prevRhsp);
|
||||
// Update RHS of the prev assignment, reusing existing parts (might be impure).
|
||||
prevAssignp->rhsp(new AstConcat{prevAssignp->rhsp()->fileline(),
|
||||
prevAssignp->rhsp()->unlinkFrBack(),
|
||||
assignp->rhsp()->unlinkFrBack()});
|
||||
// Why do we care about the type of an assignment?
|
||||
prevAssignp->dtypeChgWidthSigned(prevAssignp->width() + assignp->width(),
|
||||
prevAssignp->width() + assignp->width(),
|
||||
VSigning::SIGNED);
|
||||
// Don't need to delete assignp, will be handled
|
||||
// We will delete the current assignment
|
||||
m_toRemove.emplace_back(lVtxp);
|
||||
|
||||
// Update the graph
|
||||
while (V3GraphEdge* const iedgep = lVtxp->inEdges().frontp()) {
|
||||
@@ -1182,6 +1181,12 @@ class GateMergeAssignments final {
|
||||
for (V3GraphVertex& vtx : graph.vertices()) {
|
||||
if (GateVarVertex* const vVtxp = vtx.cast<GateVarVertex>()) process(vVtxp);
|
||||
}
|
||||
// Delete merged assignments
|
||||
for (GateLogicVertex* const lVtxp : m_toRemove) {
|
||||
AstNode* const nodep = lVtxp->nodep();
|
||||
VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
|
||||
VL_DO_DANGLING(lVtxp->unlinkDelete(&m_graph), lVtxp);
|
||||
}
|
||||
}
|
||||
|
||||
~GateMergeAssignments() {
|
||||
|
||||
Reference in New Issue
Block a user