aboutsummaryrefslogtreecommitdiffstats
path: root/passes
diff options
context:
space:
mode:
authorAndrew Zonenberg <azonenberg@drawersteak.com>2017-08-14 11:44:05 -0700
committerAndrew Zonenberg <azonenberg@drawersteak.com>2017-08-14 11:44:05 -0700
commit15e41d6363b9f3a71a2fe564c793296f8c1fba6d (patch)
treec47ada89c6118838681a8ecb66fc545ea2513722 /passes
parent0ee27d0226dcafad798eefdd26480dde1c186e98 (diff)
downloadyosys-15e41d6363b9f3a71a2fe564c793296f8c1fba6d.tar.gz
yosys-15e41d6363b9f3a71a2fe564c793296f8c1fba6d.tar.bz2
yosys-15e41d6363b9f3a71a2fe564c793296f8c1fba6d.zip
rmports: Now remove ports from cell instances if we optimized them out of that cell
Diffstat (limited to 'passes')
-rw-r--r--passes/opt/rmports.cc37
1 files changed, 35 insertions, 2 deletions
diff --git a/passes/opt/rmports.cc b/passes/opt/rmports.cc
index 39cef12e6..3aaa05c99 100644
--- a/passes/opt/rmports.cc
+++ b/passes/opt/rmports.cc
@@ -43,12 +43,44 @@ struct RmportsPassPass : public Pass {
{
log_header(design, "Executing RMPORTS pass (remove top level ports with no connections).\n");
+ //The set of ports we removed
+ std::map< RTLIL::IdString, std::set<RTLIL::IdString> > removed_ports;
+
+ //Find all of the unused ports, and remove them from that module
auto modules = design->selected_modules();
for(auto mod : modules)
- ProcessModule(mod);
+ ScanModule(mod, removed_ports);
+
+ //Remove the unused ports from all instances of those modules
+ for(auto mod : modules)
+ CleanupModule(mod, removed_ports);
+ }
+
+ void CleanupModule(RTLIL::Module* module, std::map< RTLIL::IdString, std::set<RTLIL::IdString> >& removed_ports)
+ {
+ log("Removing now-unused cell ports in module %s\n", module->name.c_str());
+
+ auto cells = module->cells();
+ for(auto cell : cells)
+ {
+ if(removed_ports.find(cell->type) == removed_ports.end())
+ {
+ //log(" Not touching instance \"%s\" because we didn't remove any ports from module \"%s\"\n",
+ // cell->name.c_str(), cell->type.c_str());
+ continue;
+ }
+
+ auto ports_to_remove = removed_ports[cell->type];
+ for(auto p : ports_to_remove)
+ {
+ log(" Removing port \"%s\" from instance \"%s\"\n",
+ p.c_str(), cell->type.c_str());
+ cell->unsetPort(p);
+ }
+ }
}
- void ProcessModule(RTLIL::Module* module)
+ void ScanModule(RTLIL::Module* module, std::map< RTLIL::IdString, std::set<RTLIL::IdString> >& removed_ports)
{
log("Finding unconnected ports in module %s\n", module->name.c_str());
@@ -118,6 +150,7 @@ struct RmportsPassPass : public Pass {
for(auto port : unused_ports)
{
log(" removing unused port %s\n", port.c_str());
+ removed_ports[module->name].emplace(port);
//Remove from ports list
for(size_t i=0; i<module->ports.size(); i++)