From a689cdc6edc9542fbe6b758b89f49ccdc7bb5200 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Sat, 30 May 2026 01:37:49 +0200 Subject: [PATCH] patch: don't track root cell deletions for perf --- kernel/unstable/patch.cc | 8 ++++++-- kernel/unstable/patch.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/unstable/patch.cc b/kernel/unstable/patch.cc index ba06a470e..a2cf467ad 100644 --- a/kernel/unstable/patch.cc +++ b/kernel/unstable/patch.cc @@ -88,7 +88,7 @@ struct SrcCollector { } }; -void Patch::gc(Cell* old_cell) { +void Patch::gc(Cell* old_cell, bool track) { log_debug("gc %s\n", old_cell->name); if (old_cell->type.in(ID($input_port), ID($output_port), ID($public))) return; @@ -119,9 +119,13 @@ void Patch::gc(Cell* old_cell) { } } log_debug("\tremove %s\n", old_cell->name); + // Only track recursively-removed cells. The top-level patched cell is the + // caller's current iteration variable and won't be re-encountered. + if (track && removed_cells) + removed_cells->insert(old_cell); old_cell->module->remove(old_cell); for (auto input : inputs) - gc(input); + gc(input, /*track=*/true); } Wire* Patch::commit_wire(std::unique_ptr wire) { diff --git a/kernel/unstable/patch.h b/kernel/unstable/patch.h index ba38a4dcc..eea9ab685 100644 --- a/kernel/unstable/patch.h +++ b/kernel/unstable/patch.h @@ -10,7 +10,7 @@ YOSYS_NAMESPACE_BEGIN struct RTLIL::Patch : public CellAdderMixin { private: - void gc(Cell* old_cell); + void gc(Cell* old_cell, bool track = false); protected: void add(RTLIL::Wire *wire); @@ -25,6 +25,7 @@ protected: public: Module* mod; SigMap* map; + pool* removed_cells = nullptr; vector> wires_ = {}; vector> cells_ = {};