From 9c0e8875f1d2d612167589714421e433c19f2383 Mon Sep 17 00:00:00 2001 From: Philippe Sauter Date: Mon, 15 Dec 2025 15:46:09 +0100 Subject: [PATCH] opt_dff: skip convertion to dffe for keep wires --- passes/opt/opt_dff.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/passes/opt/opt_dff.cc b/passes/opt/opt_dff.cc index 04bcec835..0667bbf00 100644 --- a/passes/opt/opt_dff.cc +++ b/passes/opt/opt_dff.cc @@ -52,6 +52,7 @@ struct OptDffWorker FfInitVals initvals; dict bitusers; dict bit2mux; + pool kept_bits; typedef std::map pattern_t; typedef std::set patterns_t; @@ -69,6 +70,10 @@ struct OptDffWorker for (auto wire : module->wires()) { + if (wire->get_bool_attribute(ID::keep)) + for (auto bit : sigmap(wire)) + kept_bits.insert(bit); + if (wire->port_output) for (auto bit : sigmap(wire)) bitusers[bit]++; @@ -77,8 +82,13 @@ struct OptDffWorker for (auto cell : module->cells()) { if (cell->type.in(ID($mux), ID($pmux), ID($_MUX_))) { RTLIL::SigSpec sig_y = sigmap(cell->getPort(ID::Y)); - for (int i = 0; i < GetSize(sig_y); i++) - bit2mux[sig_y[i]] = cell_int_t(cell, i); + for (int i = 0; i < GetSize(sig_y); i++) { + SigBit bit = sig_y[i]; + // skip optimization for wires marked as 'keep' + if (kept_bits.count(bit)) + continue; + bit2mux[bit] = cell_int_t(cell, i); + } } for (auto conn : cell->connections()) {