From 0b8cfbc6fde8e7500c5df38c74e1da2d74e588bd Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Mon, 29 Sep 2014 12:51:54 +0200 Subject: [PATCH] Added support for "keep" on modules --- README | 2 ++ kernel/rtlil.h | 5 +++++ passes/opt/opt_clean.cc | 2 +- passes/opt/opt_share.cc | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README b/README index d7f5aaa4b..32a47cbfe 100644 --- a/README +++ b/README @@ -273,6 +273,8 @@ Verilog Attributes and non-standard features - The "keep" attribute on cells and wires is used to mark objects that should never be removed by the optimizer. This is used for example for cells that have hidden connections that are not part of the netlist, such as IO pads. + Setting the "keep" attribute on a module has the same effect as setting it + on all instances of the module. - The "init" attribute on wires is set by the frontend when a register is initialized "FPGA-style" with 'reg foo = val'. It can be used during synthesis diff --git a/kernel/rtlil.h b/kernel/rtlil.h index a0ae8f082..8df0bfe19 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -857,6 +857,11 @@ public: void check(); void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false); + bool has_keep_attr() const { + return get_bool_attribute("\\keep") || (module && module->design && module->design->module(type) && + module->design->module(type)->get_bool_attribute("\\keep")); + } + template void rewrite_sigspecs(T functor); }; diff --git a/passes/opt/opt_clean.cc b/passes/opt/opt_clean.cc index d589518aa..0e5ed238f 100644 --- a/passes/opt/opt_clean.cc +++ b/passes/opt/opt_clean.cc @@ -48,7 +48,7 @@ void rmunused_module_cells(RTLIL::Module *module, bool verbose) wire2driver.insert(sig, cell); } } - if (cell->type == "$memwr" || cell->type == "$assert" || cell->get_bool_attribute("\\keep")) + if (cell->type == "$memwr" || cell->type == "$assert" || cell->has_keep_attr()) queue.insert(cell); unused.insert(cell); } diff --git a/passes/opt/opt_share.cc b/passes/opt/opt_share.cc index 33115349c..f8bc02205 100644 --- a/passes/opt/opt_share.cc +++ b/passes/opt/opt_share.cc @@ -196,7 +196,7 @@ struct OptShareWorker if (!ct.cell_known(cell1->type)) return cell1 < cell2; - if (cell1->get_bool_attribute("\\keep") || cell2->get_bool_attribute("\\keep")) + if (cell1->has_keep_attr() || cell2->has_keep_attr()) return cell1 < cell2; bool lt; -- 2.30.2