2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include "kernel/celltypes.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <set>
|
|
|
|
|
2013-03-03 06:18:37 -06:00
|
|
|
using RTLIL::id2cstr;
|
|
|
|
|
2014-02-07 16:50:17 -06:00
|
|
|
static CellTypes ct, ct_reg, ct_all;
|
2013-08-08 03:53:37 -05:00
|
|
|
static int count_rm_cells, count_rm_wires;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-08-08 03:53:37 -05:00
|
|
|
static void rmunused_module_cells(RTLIL::Module *module, bool verbose)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
SigMap assign_map(module);
|
2014-08-14 19:40:46 -05:00
|
|
|
std::set<RTLIL::Cell*, RTLIL::sort_by_name_id<RTLIL::Cell>> queue, unused;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
SigSet<RTLIL::Cell*> wire2driver;
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : module->cells_) {
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Cell *cell = it.second;
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it2 : cell->connections()) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!ct.cell_input(cell->type, it2.first)) {
|
|
|
|
RTLIL::SigSpec sig = it2.second;
|
|
|
|
assign_map.apply(sig);
|
|
|
|
wire2driver.insert(sig, cell);
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 07:03:40 -06:00
|
|
|
if (cell->type == "$memwr" || cell->type == "$assert" || cell->get_bool_attribute("\\keep"))
|
2013-01-05 04:13:26 -06:00
|
|
|
queue.insert(cell);
|
|
|
|
unused.insert(cell);
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_) {
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Wire *wire = it.second;
|
2013-11-07 22:20:15 -06:00
|
|
|
if (wire->port_output || wire->get_bool_attribute("\\keep")) {
|
2013-01-05 04:13:26 -06:00
|
|
|
std::set<RTLIL::Cell*> cell_list;
|
|
|
|
RTLIL::SigSpec sig = RTLIL::SigSpec(wire);
|
|
|
|
assign_map.apply(sig);
|
|
|
|
wire2driver.find(sig, cell_list);
|
|
|
|
for (auto cell : cell_list)
|
|
|
|
queue.insert(cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (queue.size() > 0)
|
|
|
|
{
|
2014-08-14 19:40:46 -05:00
|
|
|
std::set<RTLIL::Cell*, RTLIL::sort_by_name_id<RTLIL::Cell>> new_queue;
|
2013-01-05 04:13:26 -06:00
|
|
|
for (auto cell : queue)
|
|
|
|
unused.erase(cell);
|
|
|
|
for (auto cell : queue) {
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it : cell->connections()) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!ct.cell_output(cell->type, it.first)) {
|
|
|
|
std::set<RTLIL::Cell*> cell_list;
|
|
|
|
RTLIL::SigSpec sig = it.second;
|
|
|
|
assign_map.apply(sig);
|
|
|
|
wire2driver.find(sig, cell_list);
|
|
|
|
for (auto cell : cell_list) {
|
|
|
|
if (unused.count(cell) > 0)
|
|
|
|
new_queue.insert(cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
queue.swap(new_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cell : unused) {
|
2013-08-08 03:53:37 -05:00
|
|
|
if (verbose)
|
|
|
|
log(" removing unused `%s' cell `%s'.\n", cell->type.c_str(), cell->name.c_str());
|
2014-08-30 12:37:12 -05:00
|
|
|
module->design->scratchpad_set_bool("opt.did_something", true);
|
2014-07-25 08:05:18 -05:00
|
|
|
module->remove(cell);
|
2013-08-08 03:53:37 -05:00
|
|
|
count_rm_cells++;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-08 07:21:04 -06:00
|
|
|
static int count_nontrivial_wire_attrs(RTLIL::Wire *w)
|
|
|
|
{
|
|
|
|
int count = w->attributes.size();
|
|
|
|
count -= w->attributes.count("\\src");
|
|
|
|
count -= w->attributes.count("\\unused_bits");
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
static bool compare_signals(RTLIL::SigBit &s1, RTLIL::SigBit &s2, SigPool ®s, SigPool &conns, std::set<RTLIL::Wire*> &direct_wires)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-24 15:47:57 -05:00
|
|
|
RTLIL::Wire *w1 = s1.wire;
|
|
|
|
RTLIL::Wire *w2 = s2.wire;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
if (w1 == NULL || w2 == NULL)
|
|
|
|
return w2 == NULL;
|
|
|
|
|
|
|
|
if (w1->port_input != w2->port_input)
|
|
|
|
return w2->port_input;
|
|
|
|
|
2013-10-17 15:10:55 -05:00
|
|
|
if (w1->name[0] == '\\' && w2->name[0] == '\\') {
|
|
|
|
if (regs.check_any(s1) != regs.check_any(s2))
|
|
|
|
return regs.check_any(s2);
|
2014-02-07 16:50:17 -06:00
|
|
|
if (direct_wires.count(w1) != direct_wires.count(w2))
|
|
|
|
return direct_wires.count(w2);
|
2013-10-17 15:10:55 -05:00
|
|
|
if (conns.check_any(s1) != conns.check_any(s2))
|
|
|
|
return conns.check_any(s2);
|
|
|
|
}
|
2013-10-17 13:48:40 -05:00
|
|
|
|
2013-10-16 19:41:59 -05:00
|
|
|
if (w1->port_output != w2->port_output)
|
|
|
|
return w2->port_output;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (w1->name[0] != w2->name[0])
|
|
|
|
return w2->name[0] == '\\';
|
|
|
|
|
2014-02-08 07:21:04 -06:00
|
|
|
int attrs1 = count_nontrivial_wire_attrs(w1);
|
|
|
|
int attrs2 = count_nontrivial_wire_attrs(w2);
|
|
|
|
|
|
|
|
if (attrs1 != attrs2)
|
|
|
|
return attrs2 > attrs1;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
return w2->name < w1->name;
|
|
|
|
}
|
|
|
|
|
2013-03-08 02:16:25 -06:00
|
|
|
static bool check_public_name(RTLIL::IdString id)
|
|
|
|
{
|
2014-08-02 06:11:01 -05:00
|
|
|
const std::string &id_str = id.str();
|
|
|
|
if (id_str[0] == '$')
|
2013-03-08 02:16:25 -06:00
|
|
|
return false;
|
2014-08-02 06:11:01 -05:00
|
|
|
if (id_str.substr(0, 2) == "\\_" && (id_str[id_str.size()-1] == '_' || id_str.find("_[") != std::string::npos))
|
2013-08-07 11:39:49 -05:00
|
|
|
return false;
|
2014-08-02 06:11:01 -05:00
|
|
|
if (id_str.find(".$") != std::string::npos)
|
2013-03-10 08:20:03 -05:00
|
|
|
return false;
|
|
|
|
return true;
|
2013-03-08 02:16:25 -06:00
|
|
|
}
|
|
|
|
|
2013-08-08 03:53:37 -05:00
|
|
|
static void rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbose)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2013-10-17 13:48:40 -05:00
|
|
|
SigPool register_signals;
|
|
|
|
SigPool connected_signals;
|
|
|
|
|
|
|
|
if (!purge_mode)
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : module->cells_) {
|
2013-10-17 13:48:40 -05:00
|
|
|
RTLIL::Cell *cell = it.second;
|
|
|
|
if (ct_reg.cell_known(cell->type))
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it2 : cell->connections())
|
2013-10-17 13:48:40 -05:00
|
|
|
if (ct_reg.cell_output(cell->type, it2.first))
|
|
|
|
register_signals.add(it2.second);
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it2 : cell->connections())
|
2013-10-17 13:48:40 -05:00
|
|
|
connected_signals.add(it2.second);
|
|
|
|
}
|
2014-02-07 16:50:17 -06:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
SigMap assign_map(module);
|
2014-02-07 16:50:17 -06:00
|
|
|
std::set<RTLIL::SigSpec> direct_sigs;
|
|
|
|
std::set<RTLIL::Wire*> direct_wires;
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : module->cells_) {
|
2014-02-07 16:50:17 -06:00
|
|
|
RTLIL::Cell *cell = it.second;
|
|
|
|
if (ct_all.cell_known(cell->type))
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it2 : cell->connections())
|
2014-02-07 16:50:17 -06:00
|
|
|
if (ct_all.cell_output(cell->type, it2.first))
|
|
|
|
direct_sigs.insert(assign_map(it2.second));
|
|
|
|
}
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_) {
|
2014-02-07 16:50:17 -06:00
|
|
|
if (direct_sigs.count(assign_map(it.second)) || it.second->port_input)
|
|
|
|
direct_wires.insert(it.second);
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_) {
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Wire *wire = it.second;
|
|
|
|
for (int i = 0; i < wire->width; i++) {
|
2014-07-24 15:47:57 -05:00
|
|
|
RTLIL::SigBit s1 = RTLIL::SigBit(wire, i), s2 = assign_map(s1);
|
2014-02-07 16:50:17 -06:00
|
|
|
if (!compare_signals(s1, s2, register_signals, connected_signals, direct_wires))
|
2013-01-05 04:13:26 -06:00
|
|
|
assign_map.add(s1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
module->connections_.clear();
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
SigPool used_signals;
|
|
|
|
SigPool used_signals_nodrivers;
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : module->cells_) {
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Cell *cell = it.second;
|
2014-07-26 08:57:57 -05:00
|
|
|
for (auto &it2 : cell->connections_) {
|
2013-01-05 04:13:26 -06:00
|
|
|
assign_map.apply(it2.second);
|
|
|
|
used_signals.add(it2.second);
|
|
|
|
if (!ct.cell_output(cell->type, it2.first))
|
|
|
|
used_signals_nodrivers.add(it2.second);
|
|
|
|
}
|
|
|
|
}
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_) {
|
2013-02-27 09:27:20 -06:00
|
|
|
RTLIL::Wire *wire = it.second;
|
|
|
|
if (wire->port_id > 0) {
|
|
|
|
RTLIL::SigSpec sig = RTLIL::SigSpec(wire);
|
|
|
|
assign_map.apply(sig);
|
|
|
|
used_signals.add(sig);
|
|
|
|
if (!wire->port_input)
|
|
|
|
used_signals_nodrivers.add(sig);
|
|
|
|
}
|
2013-11-05 08:52:29 -06:00
|
|
|
if (wire->get_bool_attribute("\\keep")) {
|
|
|
|
RTLIL::SigSpec sig = RTLIL::SigSpec(wire);
|
|
|
|
assign_map.apply(sig);
|
|
|
|
used_signals.add(sig);
|
|
|
|
}
|
2013-02-27 09:27:20 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
std::vector<RTLIL::Wire*> maybe_del_wires;
|
2014-07-27 06:19:05 -05:00
|
|
|
for (auto wire : module->wires())
|
|
|
|
{
|
2014-02-16 14:58:27 -06:00
|
|
|
if ((!purge_mode && check_public_name(wire->name)) || wire->port_id != 0 || wire->get_bool_attribute("\\keep")) {
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigSpec s1 = RTLIL::SigSpec(wire), s2 = s1;
|
|
|
|
assign_map.apply(s2);
|
2014-02-16 14:58:27 -06:00
|
|
|
if (!used_signals.check_any(s2) && wire->port_id == 0 && !wire->get_bool_attribute("\\keep")) {
|
2014-07-26 13:12:50 -05:00
|
|
|
maybe_del_wires.push_back(wire);
|
2013-01-05 04:13:26 -06:00
|
|
|
} else {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(SIZE(s1) == SIZE(s2));
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigSig new_conn;
|
2014-07-23 09:09:27 -05:00
|
|
|
for (int i = 0; i < SIZE(s1); i++)
|
|
|
|
if (s1[i] != s2[i]) {
|
|
|
|
new_conn.first.append_bit(s1[i]);
|
|
|
|
new_conn.second.append_bit(s2[i]);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-07-22 13:15:14 -05:00
|
|
|
if (new_conn.first.size() > 0) {
|
2013-05-23 06:19:28 -05:00
|
|
|
used_signals.add(new_conn.first);
|
|
|
|
used_signals.add(new_conn.second);
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(new_conn);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!used_signals.check_any(RTLIL::SigSpec(wire)))
|
2014-07-26 13:12:50 -05:00
|
|
|
maybe_del_wires.push_back(wire);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-07-27 06:19:05 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigSpec sig = assign_map(RTLIL::SigSpec(wire));
|
|
|
|
if (!used_signals_nodrivers.check_any(sig)) {
|
|
|
|
std::string unused_bits;
|
2014-07-23 09:09:27 -05:00
|
|
|
for (int i = 0; i < SIZE(sig); i++) {
|
|
|
|
if (sig[i].wire == NULL)
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
2014-07-27 08:38:02 -05:00
|
|
|
if (!used_signals_nodrivers.check(sig[i])) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!unused_bits.empty())
|
|
|
|
unused_bits += " ";
|
2014-07-27 08:38:02 -05:00
|
|
|
unused_bits += stringf("%d", i);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (unused_bits.empty() || wire->port_id != 0)
|
|
|
|
wire->attributes.erase("\\unused_bits");
|
|
|
|
else
|
|
|
|
wire->attributes["\\unused_bits"] = RTLIL::Const(unused_bits);
|
|
|
|
} else {
|
|
|
|
wire->attributes.erase("\\unused_bits");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
|
|
|
|
std::set<RTLIL::Wire*> del_wires;
|
|
|
|
|
2013-05-23 06:19:28 -05:00
|
|
|
int del_wires_count = 0;
|
2014-07-27 06:19:05 -05:00
|
|
|
for (auto wire : maybe_del_wires)
|
2013-05-23 06:19:28 -05:00
|
|
|
if (!used_signals.check_any(RTLIL::SigSpec(wire))) {
|
2013-08-08 03:53:37 -05:00
|
|
|
if (check_public_name(wire->name) && verbose) {
|
2013-05-23 06:19:28 -05:00
|
|
|
log(" removing unused non-port wire %s.\n", wire->name.c_str());
|
|
|
|
del_wires_count++;
|
|
|
|
}
|
2014-07-26 13:12:50 -05:00
|
|
|
del_wires.insert(wire);
|
2013-05-23 06:19:28 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
module->remove(del_wires);
|
|
|
|
count_rm_wires += del_wires.size();;
|
|
|
|
|
2013-05-23 06:19:28 -05:00
|
|
|
if (del_wires_count > 0)
|
|
|
|
log(" removed %d unused temporary wires.\n", del_wires_count);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2013-08-08 03:53:37 -05:00
|
|
|
static void rmunused_module(RTLIL::Module *module, bool purge_mode, bool verbose)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2013-08-08 03:53:37 -05:00
|
|
|
if (verbose)
|
|
|
|
log("Finding unused cells or wires in module %s..\n", module->name.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-08-08 03:53:37 -05:00
|
|
|
rmunused_module_cells(module, verbose);
|
|
|
|
rmunused_module_signals(module, purge_mode, verbose);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2013-06-05 00:07:31 -05:00
|
|
|
struct OptCleanPass : public Pass {
|
|
|
|
OptCleanPass() : Pass("opt_clean", "remove unused cells and wires") { }
|
2013-03-01 01:58:55 -06:00
|
|
|
virtual void help()
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2013-07-07 05:59:30 -05:00
|
|
|
log(" opt_clean [options] [selection]\n");
|
2013-03-01 01:58:55 -06:00
|
|
|
log("\n");
|
|
|
|
log("This pass identifies wires and cells that are unused and removes them. Other\n");
|
2013-03-17 16:02:30 -05:00
|
|
|
log("passes often remove cells but leave the wires in the design or reconnect the\n");
|
|
|
|
log("wires but leave the old cells in the design. This pass can be used to clean up\n");
|
|
|
|
log("after the passes that do the actual work.\n");
|
2013-03-01 01:58:55 -06:00
|
|
|
log("\n");
|
|
|
|
log("This pass only operates on completely selected modules without processes.\n");
|
|
|
|
log("\n");
|
2013-07-07 05:59:30 -05:00
|
|
|
log(" -purge\n");
|
|
|
|
log(" also remove internal nets if they have a public name\n");
|
|
|
|
log("\n");
|
2013-03-01 01:58:55 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
|
|
|
|
{
|
2013-07-07 05:59:30 -05:00
|
|
|
bool purge_mode = false;
|
|
|
|
|
2013-06-05 00:07:31 -05:00
|
|
|
log_header("Executing OPT_CLEAN pass (remove unused cells and wires).\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
log_push();
|
|
|
|
|
2013-07-07 05:59:30 -05:00
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
if (args[argidx] == "-purge") {
|
|
|
|
purge_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-11 06:59:14 -05:00
|
|
|
break;
|
2013-07-07 05:59:30 -05:00
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
ct.setup_internals();
|
|
|
|
ct.setup_internals_mem();
|
|
|
|
ct.setup_stdcells();
|
|
|
|
ct.setup_stdcells_mem();
|
|
|
|
|
2013-10-17 13:48:40 -05:00
|
|
|
ct_reg.setup_internals_mem();
|
|
|
|
ct_reg.setup_stdcells_mem();
|
|
|
|
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto &mod_it : design->modules_) {
|
2013-03-01 01:58:55 -06:00
|
|
|
if (!design->selected_whole_module(mod_it.first)) {
|
|
|
|
if (design->selected(mod_it.second))
|
|
|
|
log("Skipping module %s as it is only partially selected.\n", id2cstr(mod_it.second->name));
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
if (mod_it.second->processes.size() > 0) {
|
|
|
|
log("Skipping module %s as it contains processes.\n", mod_it.second->name.c_str());
|
|
|
|
} else {
|
2013-08-08 03:53:37 -05:00
|
|
|
rmunused_module(mod_it.second, purge_mode, true);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ct.clear();
|
2013-10-17 13:48:40 -05:00
|
|
|
ct_reg.clear();
|
2013-01-05 04:13:26 -06:00
|
|
|
log_pop();
|
|
|
|
}
|
2013-06-05 00:07:31 -05:00
|
|
|
} OptCleanPass;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-08-08 03:53:37 -05:00
|
|
|
struct CleanPass : public Pass {
|
|
|
|
CleanPass() : Pass("clean", "remove unused cells and wires") { }
|
|
|
|
virtual void help()
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2013-08-11 06:59:14 -05:00
|
|
|
log(" clean [options] [selection]\n");
|
2013-08-08 03:53:37 -05:00
|
|
|
log("\n");
|
2013-08-11 06:59:14 -05:00
|
|
|
log("This is identical to 'opt_clean', but less verbose.\n");
|
2013-08-08 03:53:37 -05:00
|
|
|
log("\n");
|
2014-09-06 01:47:06 -05:00
|
|
|
log("When commands are separated using the ';;' token, this command will be executed\n");
|
2013-08-11 06:33:38 -05:00
|
|
|
log("between the commands.\n");
|
|
|
|
log("\n");
|
2014-09-06 01:47:06 -05:00
|
|
|
log("When commands are separated using the ';;;' token, this command will be executed\n");
|
2013-08-11 06:59:14 -05:00
|
|
|
log("in -purge mode between the commands.\n");
|
|
|
|
log("\n");
|
2013-08-08 03:53:37 -05:00
|
|
|
}
|
|
|
|
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
|
|
|
|
{
|
2013-08-11 06:59:14 -05:00
|
|
|
bool purge_mode = false;
|
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
if (args[argidx] == "-purge") {
|
|
|
|
purge_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (argidx < args.size())
|
|
|
|
extra_args(args, argidx, design);
|
2013-08-08 03:53:37 -05:00
|
|
|
|
|
|
|
ct.setup_internals();
|
|
|
|
ct.setup_internals_mem();
|
|
|
|
ct.setup_stdcells();
|
|
|
|
ct.setup_stdcells_mem();
|
|
|
|
|
2013-10-17 13:48:40 -05:00
|
|
|
ct_reg.setup_internals_mem();
|
|
|
|
ct_reg.setup_stdcells_mem();
|
|
|
|
|
2014-02-07 16:50:17 -06:00
|
|
|
ct_all.setup(design);
|
|
|
|
|
2013-08-08 03:53:37 -05:00
|
|
|
count_rm_cells = 0;
|
|
|
|
count_rm_wires = 0;
|
|
|
|
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto &mod_it : design->modules_) {
|
2013-08-08 03:53:37 -05:00
|
|
|
if (design->selected_whole_module(mod_it.first) && mod_it.second->processes.size() == 0)
|
|
|
|
do {
|
2014-08-30 12:37:12 -05:00
|
|
|
design->scratchpad_unset("opt.did_something");
|
2013-08-11 06:59:14 -05:00
|
|
|
rmunused_module(mod_it.second, purge_mode, false);
|
2014-08-30 12:37:12 -05:00
|
|
|
} while (design->scratchpad_get_bool("opt.did_something"));
|
2013-08-08 03:53:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count_rm_cells > 0 || count_rm_wires > 0)
|
|
|
|
log("Removed %d unused cells and %d unused wires.\n", count_rm_cells, count_rm_wires);
|
|
|
|
|
|
|
|
ct.clear();
|
2013-10-17 13:48:40 -05:00
|
|
|
ct_reg.clear();
|
2014-02-07 16:50:17 -06:00
|
|
|
ct_all.clear();
|
2013-08-08 03:53:37 -05:00
|
|
|
}
|
|
|
|
} CleanPass;
|
|
|
|
|