2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* 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.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-06-11 04:47:13 -05:00
|
|
|
#include "kernel/log.h"
|
2013-01-05 04:13:26 -06:00
|
|
|
#include "kernel/register.h"
|
2019-06-11 04:47:13 -05:00
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/satgen.h"
|
2013-01-05 04:13:26 -06:00
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include <stdio.h>
|
2019-06-11 04:47:13 -05:00
|
|
|
#include <stdlib.h>
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
SigMap assign_map, dff_init_map;
|
|
|
|
SigSet<RTLIL::Cell*> mux_drivers;
|
2019-06-20 06:44:21 -05:00
|
|
|
dict<SigBit, RTLIL::Cell*> bit2driver;
|
2015-08-18 06:50:15 -05:00
|
|
|
dict<SigBit, pool<SigBit>> init_attributes;
|
2019-06-13 12:35:37 -05:00
|
|
|
|
2016-09-30 10:02:38 -05:00
|
|
|
bool keepdc;
|
2019-05-28 01:48:21 -05:00
|
|
|
bool sat;
|
2015-08-18 06:50:15 -05:00
|
|
|
|
|
|
|
void remove_init_attr(SigSpec sig)
|
|
|
|
{
|
|
|
|
for (auto bit : assign_map(sig))
|
|
|
|
if (init_attributes.count(bit))
|
|
|
|
for (auto wbit : init_attributes.at(bit))
|
2019-08-09 11:58:14 -05:00
|
|
|
wbit.wire->attributes.at(ID(init))[wbit.offset] = State::Sx;
|
2015-08-18 06:50:15 -05:00
|
|
|
}
|
2014-09-27 09:17:53 -05:00
|
|
|
|
2017-08-09 06:29:52 -05:00
|
|
|
bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
|
|
|
|
{
|
|
|
|
SigSpec sig_set, sig_clr;
|
|
|
|
State pol_set, pol_clr;
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->hasPort(ID(S)))
|
|
|
|
sig_set = cell->getPort(ID(S));
|
2017-08-09 06:29:52 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->hasPort(ID(R)))
|
|
|
|
sig_clr = cell->getPort(ID(R));
|
2017-08-09 06:29:52 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->hasPort(ID(SET)))
|
|
|
|
sig_set = cell->getPort(ID(SET));
|
2017-08-09 06:29:52 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->hasPort(ID(CLR)))
|
|
|
|
sig_clr = cell->getPort(ID(CLR));
|
2017-08-09 06:29:52 -05:00
|
|
|
|
|
|
|
log_assert(GetSize(sig_set) == GetSize(sig_clr));
|
|
|
|
|
2019-08-06 18:42:25 -05:00
|
|
|
if (cell->type.begins_with("$_DFFSR_")) {
|
2017-08-09 06:29:52 -05:00
|
|
|
pol_set = cell->type[9] == 'P' ? State::S1 : State::S0;
|
|
|
|
pol_clr = cell->type[10] == 'P' ? State::S1 : State::S0;
|
|
|
|
} else
|
2019-08-06 18:42:25 -05:00
|
|
|
if (cell->type.begins_with("$_DLATCHSR_")) {
|
2017-08-09 06:29:52 -05:00
|
|
|
pol_set = cell->type[12] == 'P' ? State::S1 : State::S0;
|
|
|
|
pol_clr = cell->type[13] == 'P' ? State::S1 : State::S0;
|
|
|
|
} else
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type.in(ID($dffsr), ID($dlatchsr))) {
|
|
|
|
pol_set = cell->parameters[ID(SET_POLARITY)].as_bool() ? State::S1 : State::S0;
|
|
|
|
pol_clr = cell->parameters[ID(CLR_POLARITY)].as_bool() ? State::S1 : State::S0;
|
2017-08-09 06:29:52 -05:00
|
|
|
} else
|
|
|
|
log_abort();
|
|
|
|
|
|
|
|
State npol_set = pol_set == State::S0 ? State::S1 : State::S0;
|
|
|
|
State npol_clr = pol_clr == State::S0 ? State::S1 : State::S0;
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
SigSpec sig_d = cell->getPort(ID(D));
|
|
|
|
SigSpec sig_q = cell->getPort(ID(Q));
|
2017-08-09 06:29:52 -05:00
|
|
|
|
|
|
|
bool did_something = false;
|
|
|
|
bool proper_sr = false;
|
|
|
|
bool used_pol_set = false;
|
|
|
|
bool used_pol_clr = false;
|
|
|
|
bool hasreset = false;
|
|
|
|
Const reset_val;
|
|
|
|
SigSpec sig_reset;
|
|
|
|
|
|
|
|
for (int i = 0; i < GetSize(sig_set); i++)
|
|
|
|
{
|
|
|
|
SigBit s = sig_set[i], c = sig_clr[i];
|
|
|
|
|
|
|
|
if (s != npol_set || c != npol_clr)
|
|
|
|
hasreset = true;
|
|
|
|
|
|
|
|
if (s == pol_set || c == pol_clr)
|
|
|
|
{
|
|
|
|
log("Constantly %s Q bit %s for SR cell %s (%s) from module %s.\n",
|
|
|
|
s == pol_set ? "set" : "cleared", log_signal(sig_q[i]),
|
|
|
|
log_id(cell), log_id(cell->type), log_id(mod));
|
|
|
|
|
|
|
|
remove_init_attr(sig_q[i]);
|
|
|
|
mod->connect(sig_q[i], s == pol_set ? State::S1 : State::S0);
|
|
|
|
sig_set.remove(i);
|
|
|
|
sig_clr.remove(i);
|
|
|
|
sig_d.remove(i);
|
|
|
|
sig_q.remove(i--);
|
|
|
|
did_something = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sig_reset.empty() && s.wire != nullptr) sig_reset = s;
|
|
|
|
if (sig_reset.empty() && c.wire != nullptr) sig_reset = c;
|
|
|
|
|
|
|
|
if (s.wire != nullptr && s != sig_reset) proper_sr = true;
|
|
|
|
if (c.wire != nullptr && c != sig_reset) proper_sr = true;
|
|
|
|
|
|
|
|
if ((s.wire == nullptr) != (c.wire == nullptr)) {
|
|
|
|
if (s.wire != nullptr) used_pol_set = true;
|
|
|
|
if (c.wire != nullptr) used_pol_clr = true;
|
|
|
|
reset_val.bits.push_back(c.wire == nullptr ? State::S1 : State::S0);
|
|
|
|
} else
|
|
|
|
proper_sr = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasreset)
|
|
|
|
proper_sr = false;
|
|
|
|
|
|
|
|
if (GetSize(sig_set) == 0)
|
|
|
|
{
|
|
|
|
log("Removing %s (%s) from module %s.\n", log_id(cell), log_id(cell->type), log_id(mod));
|
|
|
|
mod->remove(cell);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type.in(ID($dffsr), ID($dlatchsr)))
|
2017-08-09 06:29:52 -05:00
|
|
|
{
|
2019-08-09 11:58:14 -05:00
|
|
|
cell->setParam(ID(WIDTH), GetSize(sig_d));
|
|
|
|
cell->setPort(ID(SET), sig_set);
|
|
|
|
cell->setPort(ID(CLR), sig_clr);
|
|
|
|
cell->setPort(ID(D), sig_d);
|
|
|
|
cell->setPort(ID(Q), sig_q);
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-09 11:58:14 -05:00
|
|
|
cell->setPort(ID(S), sig_set);
|
|
|
|
cell->setPort(ID(R), sig_clr);
|
|
|
|
cell->setPort(ID(D), sig_d);
|
|
|
|
cell->setPort(ID(Q), sig_q);
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proper_sr)
|
|
|
|
return did_something;
|
|
|
|
|
|
|
|
if (used_pol_set && used_pol_clr && pol_set != pol_clr)
|
|
|
|
return did_something;
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type == ID($dlatchsr))
|
2018-02-26 04:46:05 -06:00
|
|
|
return did_something;
|
|
|
|
|
2017-08-09 06:29:52 -05:00
|
|
|
State unified_pol = used_pol_set ? pol_set : pol_clr;
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type == ID($dffsr))
|
2017-08-09 06:29:52 -05:00
|
|
|
{
|
|
|
|
if (hasreset)
|
|
|
|
{
|
|
|
|
log("Converting %s (%s) to %s in module %s.\n", log_id(cell), log_id(cell->type), "$adff", log_id(mod));
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
cell->type = ID($adff);
|
|
|
|
cell->setParam(ID(ARST_POLARITY), unified_pol);
|
|
|
|
cell->setParam(ID(ARST_VALUE), reset_val);
|
|
|
|
cell->setPort(ID(ARST), sig_reset);
|
2017-08-09 06:29:52 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
cell->unsetParam(ID(SET_POLARITY));
|
|
|
|
cell->unsetParam(ID(CLR_POLARITY));
|
|
|
|
cell->unsetPort(ID(SET));
|
|
|
|
cell->unsetPort(ID(CLR));
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log("Converting %s (%s) to %s in module %s.\n", log_id(cell), log_id(cell->type), "$dff", log_id(mod));
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
cell->type = ID($dff);
|
|
|
|
cell->unsetParam(ID(SET_POLARITY));
|
|
|
|
cell->unsetParam(ID(CLR_POLARITY));
|
|
|
|
cell->unsetPort(ID(SET));
|
|
|
|
cell->unsetPort(ID(CLR));
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
2019-02-21 06:48:23 -06:00
|
|
|
|
|
|
|
return true;
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
2019-02-21 06:48:23 -06:00
|
|
|
|
|
|
|
if (!hasreset)
|
2017-08-09 06:29:52 -05:00
|
|
|
{
|
|
|
|
IdString new_type;
|
|
|
|
|
2019-08-06 18:42:25 -05:00
|
|
|
if (cell->type.begins_with("$_DFFSR_"))
|
2017-08-09 06:29:52 -05:00
|
|
|
new_type = stringf("$_DFF_%c_", cell->type[8]);
|
2019-08-06 18:42:25 -05:00
|
|
|
else if (cell->type.begins_with("$_DLATCHSR_"))
|
2017-08-09 06:29:52 -05:00
|
|
|
new_type = stringf("$_DLATCH_%c_", cell->type[11]);
|
|
|
|
else
|
|
|
|
log_abort();
|
|
|
|
|
|
|
|
log("Converting %s (%s) to %s in module %s.\n", log_id(cell), log_id(cell->type), log_id(new_type), log_id(mod));
|
|
|
|
|
|
|
|
cell->type = new_type;
|
2019-08-09 11:58:14 -05:00
|
|
|
cell->unsetPort(ID(S));
|
|
|
|
cell->unsetPort(ID(R));
|
2017-08-09 06:29:52 -05:00
|
|
|
|
2019-02-21 06:48:23 -06:00
|
|
|
return true;
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
2019-02-21 06:48:23 -06:00
|
|
|
|
|
|
|
return did_something;
|
2017-08-09 06:29:52 -05:00
|
|
|
}
|
|
|
|
|
2015-05-23 02:45:48 -05:00
|
|
|
bool handle_dlatch(RTLIL::Module *mod, RTLIL::Cell *dlatch)
|
|
|
|
{
|
2017-01-31 03:15:04 -06:00
|
|
|
SigSpec sig_e;
|
|
|
|
State on_state, off_state;
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dlatch->type == ID($dlatch)) {
|
|
|
|
sig_e = assign_map(dlatch->getPort(ID(EN)));
|
|
|
|
on_state = dlatch->getParam(ID(EN_POLARITY)).as_bool() ? State::S1 : State::S0;
|
|
|
|
off_state = dlatch->getParam(ID(EN_POLARITY)).as_bool() ? State::S0 : State::S1;
|
2017-01-31 03:15:04 -06:00
|
|
|
} else
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dlatch->type == ID($_DLATCH_P_)) {
|
|
|
|
sig_e = assign_map(dlatch->getPort(ID(E)));
|
2017-01-31 03:15:04 -06:00
|
|
|
on_state = State::S1;
|
|
|
|
off_state = State::S0;
|
|
|
|
} else
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dlatch->type == ID($_DLATCH_N_)) {
|
|
|
|
sig_e = assign_map(dlatch->getPort(ID(E)));
|
2017-01-31 03:15:04 -06:00
|
|
|
on_state = State::S0;
|
|
|
|
off_state = State::S1;
|
|
|
|
} else
|
|
|
|
log_abort();
|
2015-05-23 02:45:48 -05:00
|
|
|
|
2017-01-31 03:15:04 -06:00
|
|
|
if (sig_e == off_state)
|
2015-05-23 02:45:48 -05:00
|
|
|
{
|
|
|
|
RTLIL::Const val_init;
|
2019-08-09 11:58:14 -05:00
|
|
|
for (auto bit : dff_init_map(dlatch->getPort(ID(Q))))
|
2015-05-23 02:45:48 -05:00
|
|
|
val_init.bits.push_back(bit.wire == NULL ? bit.data : State::Sx);
|
2019-08-09 11:58:14 -05:00
|
|
|
mod->connect(dlatch->getPort(ID(Q)), val_init);
|
2015-05-23 02:45:48 -05:00
|
|
|
goto delete_dlatch;
|
|
|
|
}
|
|
|
|
|
2017-01-31 03:15:04 -06:00
|
|
|
if (sig_e == on_state)
|
2015-05-23 02:45:48 -05:00
|
|
|
{
|
2019-08-09 11:58:14 -05:00
|
|
|
mod->connect(dlatch->getPort(ID(Q)), dlatch->getPort(ID(D)));
|
2015-05-23 02:45:48 -05:00
|
|
|
goto delete_dlatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
delete_dlatch:
|
2016-08-29 18:34:04 -05:00
|
|
|
log("Removing %s (%s) from module %s.\n", log_id(dlatch), log_id(dlatch->type), log_id(mod));
|
2019-08-09 11:58:14 -05:00
|
|
|
remove_init_attr(dlatch->getPort(ID(Q)));
|
2015-05-23 02:45:48 -05:00
|
|
|
mod->remove(dlatch);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-13 12:35:37 -05:00
|
|
|
bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2019-05-23 13:26:18 -05:00
|
|
|
RTLIL::SigSpec sig_d, sig_q, sig_c, sig_r, sig_e;
|
|
|
|
RTLIL::Const val_cp, val_rp, val_rv, val_ep;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dff->type == ID($_FF_)) {
|
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
2016-10-14 06:02:36 -05:00
|
|
|
}
|
2019-08-09 11:58:14 -05:00
|
|
|
else if (dff->type == ID($_DFF_N_) || dff->type == ID($_DFF_P_)) {
|
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
|
|
|
sig_c = dff->getPort(ID(C));
|
|
|
|
val_cp = RTLIL::Const(dff->type == ID($_DFF_P_), 1);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2019-08-07 14:20:08 -05:00
|
|
|
else if (dff->type.begins_with("$_DFF_") && dff->type.compare(9, 1, "_") == 0 &&
|
2013-01-05 04:13:26 -06:00
|
|
|
(dff->type[6] == 'N' || dff->type[6] == 'P') &&
|
|
|
|
(dff->type[7] == 'N' || dff->type[7] == 'P') &&
|
|
|
|
(dff->type[8] == '0' || dff->type[8] == '1')) {
|
2019-08-09 11:58:14 -05:00
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
|
|
|
sig_c = dff->getPort(ID(C));
|
|
|
|
sig_r = dff->getPort(ID(R));
|
2013-01-05 04:13:26 -06:00
|
|
|
val_cp = RTLIL::Const(dff->type[6] == 'P', 1);
|
|
|
|
val_rp = RTLIL::Const(dff->type[7] == 'P', 1);
|
|
|
|
val_rv = RTLIL::Const(dff->type[8] == '1', 1);
|
|
|
|
}
|
2019-08-07 14:20:08 -05:00
|
|
|
else if (dff->type.begins_with("$_DFFE_") && dff->type.compare(9, 1, "_") == 0 &&
|
2019-05-23 13:26:18 -05:00
|
|
|
(dff->type[7] == 'N' || dff->type[7] == 'P') &&
|
|
|
|
(dff->type[8] == 'N' || dff->type[8] == 'P')) {
|
2019-08-09 11:58:14 -05:00
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
|
|
|
sig_c = dff->getPort(ID(C));
|
|
|
|
sig_e = dff->getPort(ID(E));
|
2019-06-05 16:08:14 -05:00
|
|
|
val_cp = RTLIL::Const(dff->type[7] == 'P', 1);
|
|
|
|
val_ep = RTLIL::Const(dff->type[8] == 'P', 1);
|
2019-05-23 13:26:18 -05:00
|
|
|
}
|
2019-08-09 11:58:14 -05:00
|
|
|
else if (dff->type == ID($ff)) {
|
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
2016-10-14 06:02:36 -05:00
|
|
|
}
|
2019-08-09 11:58:14 -05:00
|
|
|
else if (dff->type == ID($dff)) {
|
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
|
|
|
sig_c = dff->getPort(ID(CLK));
|
|
|
|
val_cp = RTLIL::Const(dff->parameters[ID(CLK_POLARITY)].as_bool(), 1);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2019-08-09 11:58:14 -05:00
|
|
|
else if (dff->type == ID($dffe)) {
|
|
|
|
sig_e = dff->getPort(ID(EN));
|
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
|
|
|
sig_c = dff->getPort(ID(CLK));
|
|
|
|
val_cp = RTLIL::Const(dff->parameters[ID(CLK_POLARITY)].as_bool(), 1);
|
|
|
|
val_ep = RTLIL::Const(dff->parameters[ID(EN_POLARITY)].as_bool(), 1);
|
2019-05-23 13:26:18 -05:00
|
|
|
}
|
2019-08-09 11:58:14 -05:00
|
|
|
else if (dff->type == ID($adff)) {
|
|
|
|
sig_d = dff->getPort(ID(D));
|
|
|
|
sig_q = dff->getPort(ID(Q));
|
|
|
|
sig_c = dff->getPort(ID(CLK));
|
|
|
|
sig_r = dff->getPort(ID(ARST));
|
|
|
|
val_cp = RTLIL::Const(dff->parameters[ID(CLK_POLARITY)].as_bool(), 1);
|
|
|
|
val_rp = RTLIL::Const(dff->parameters[ID(ARST_POLARITY)].as_bool(), 1);
|
|
|
|
val_rv = dff->parameters[ID(ARST_VALUE)];
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
else
|
2013-05-24 05:32:06 -05:00
|
|
|
log_abort();
|
2013-05-23 00:48:18 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
assign_map.apply(sig_d);
|
|
|
|
assign_map.apply(sig_q);
|
|
|
|
assign_map.apply(sig_c);
|
|
|
|
assign_map.apply(sig_r);
|
|
|
|
|
2014-02-04 16:00:32 -06:00
|
|
|
bool has_init = false;
|
2014-02-04 05:02:47 -06:00
|
|
|
RTLIL::Const val_init;
|
|
|
|
for (auto bit : dff_init_map(sig_q).to_sigbit_vector()) {
|
2016-09-30 10:02:38 -05:00
|
|
|
if (bit.wire == NULL || keepdc)
|
2014-02-04 05:02:47 -06:00
|
|
|
has_init = true;
|
|
|
|
val_init.bits.push_back(bit.wire == NULL ? bit.data : RTLIL::State::Sx);
|
|
|
|
}
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dff->type.in(ID($ff), ID($dff)) && mux_drivers.has(sig_d)) {
|
2013-05-23 00:48:18 -05:00
|
|
|
std::set<RTLIL::Cell*> muxes;
|
|
|
|
mux_drivers.find(sig_d, muxes);
|
|
|
|
for (auto mux : muxes) {
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = assign_map(mux->getPort(ID::A));
|
|
|
|
RTLIL::SigSpec sig_b = assign_map(mux->getPort(ID::B));
|
2015-04-18 01:04:31 -05:00
|
|
|
if (sig_a == sig_q && sig_b.is_fully_const() && (!has_init || val_init == sig_b.as_const())) {
|
|
|
|
mod->connect(sig_q, sig_b);
|
2013-05-23 00:48:18 -05:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
2015-04-18 01:04:31 -05:00
|
|
|
if (sig_b == sig_q && sig_a.is_fully_const() && (!has_init || val_init == sig_a.as_const())) {
|
|
|
|
mod->connect(sig_q, sig_a);
|
2013-05-23 00:48:18 -05:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:33:10 -05:00
|
|
|
// If clock is driven by a constant and (i) no reset signal
|
|
|
|
// (ii) Q has no initial value
|
|
|
|
// (iii) initial value is same as reset value
|
2016-10-14 06:02:36 -05:00
|
|
|
if (!sig_c.empty() && sig_c.is_fully_const() && (!sig_r.size() || !has_init || val_init == val_rv)) {
|
2014-02-02 14:09:08 -06:00
|
|
|
if (val_rv.bits.size() == 0)
|
2014-02-04 05:02:47 -06:00
|
|
|
val_rv = val_init;
|
2019-05-24 18:33:10 -05:00
|
|
|
// Q is permanently reset value or initial value
|
2015-07-25 05:01:25 -05:00
|
|
|
mod->connect(sig_q, val_rv);
|
2014-02-02 14:09:08 -06:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:33:10 -05:00
|
|
|
// If D is fully undefined and reset signal present and (i) Q has no initial value
|
|
|
|
// (ii) initial value is same as reset value
|
2015-04-18 01:04:31 -05:00
|
|
|
if (sig_d.is_fully_undef() && sig_r.size() && (!has_init || val_init == val_rv)) {
|
2019-05-24 18:33:10 -05:00
|
|
|
// Q is permanently reset value
|
2015-07-25 05:01:25 -05:00
|
|
|
mod->connect(sig_q, val_rv);
|
2014-01-17 09:42:40 -06:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:33:10 -05:00
|
|
|
// If D is fully undefined and no reset signal and Q has an initial value
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_d.is_fully_undef() && !sig_r.size() && has_init) {
|
2019-05-24 18:33:10 -05:00
|
|
|
// Q is permanently initial value
|
2015-07-25 05:01:25 -05:00
|
|
|
mod->connect(sig_q, val_init);
|
2014-02-04 05:02:47 -06:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:33:10 -05:00
|
|
|
// If D is fully constant and (i) no reset signal
|
|
|
|
// (ii) reset value is same as constant D
|
2019-05-24 20:30:51 -05:00
|
|
|
// and (a) has no initial value
|
2019-05-24 18:33:10 -05:00
|
|
|
// (b) initial value same as constant D
|
2019-05-25 14:55:57 -05:00
|
|
|
if (sig_d.is_fully_const() && (!sig_r.size() || val_rv == sig_d.as_const()) && (!has_init || val_init == sig_d.as_const())) {
|
2019-05-24 18:33:10 -05:00
|
|
|
// Q is permanently D
|
2015-07-25 05:01:25 -05:00
|
|
|
mod->connect(sig_q, sig_d);
|
2013-01-05 04:13:26 -06:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:33:10 -05:00
|
|
|
// If D input is same as Q output and (i) no reset signal
|
|
|
|
// (ii) no initial signal
|
|
|
|
// (iii) initial value is same as reset value
|
2017-08-06 06:27:18 -05:00
|
|
|
if (sig_d == sig_q && (sig_r.empty() || !has_init || val_init == val_rv)) {
|
2019-05-24 18:33:10 -05:00
|
|
|
// Q is permanently reset value or initial value
|
2015-07-25 05:01:25 -05:00
|
|
|
if (sig_r.size())
|
|
|
|
mod->connect(sig_q, val_rv);
|
2019-05-24 18:33:10 -05:00
|
|
|
else if (has_init)
|
2015-07-25 05:01:25 -05:00
|
|
|
mod->connect(sig_q, val_init);
|
2013-01-05 04:13:26 -06:00
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:33:10 -05:00
|
|
|
// If reset signal is present, and is fully constant
|
2017-08-06 06:27:18 -05:00
|
|
|
if (!sig_r.empty() && sig_r.is_fully_const())
|
|
|
|
{
|
2019-05-24 20:30:51 -05:00
|
|
|
// If reset value is permanently active or if reset is undefined
|
2017-08-06 06:27:18 -05:00
|
|
|
if (sig_r == val_rp || sig_r.is_fully_undef()) {
|
2019-05-24 18:33:10 -05:00
|
|
|
// Q is permanently reset value
|
2017-08-06 06:27:18 -05:00
|
|
|
mod->connect(sig_q, val_rv);
|
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
|
|
|
log("Removing unused reset from %s (%s) from module %s.\n", log_id(dff), log_id(dff->type), log_id(mod));
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dff->type == ID($adff)) {
|
|
|
|
dff->type = ID($dff);
|
|
|
|
dff->unsetPort(ID(ARST));
|
|
|
|
dff->unsetParam(ID(ARST_POLARITY));
|
|
|
|
dff->unsetParam(ID(ARST_VALUE));
|
2017-08-06 06:27:18 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:42:25 -05:00
|
|
|
log_assert(dff->type.begins_with("$_DFF_"));
|
2017-08-06 06:27:18 -05:00
|
|
|
dff->type = stringf("$_DFF_%c_", + dff->type[6]);
|
2019-08-09 11:58:14 -05:00
|
|
|
dff->unsetPort(ID(R));
|
2017-08-06 06:27:18 -05:00
|
|
|
}
|
|
|
|
|
2019-05-24 20:30:51 -05:00
|
|
|
// If enable signal is present, and is fully constant
|
|
|
|
if (!sig_e.empty() && sig_e.is_fully_const())
|
|
|
|
{
|
|
|
|
// If enable value is permanently inactive
|
|
|
|
if (sig_e != val_ep) {
|
|
|
|
// Q is permanently initial value
|
|
|
|
mod->connect(sig_q, val_init);
|
|
|
|
goto delete_dff;
|
|
|
|
}
|
|
|
|
|
|
|
|
log("Removing unused enable from %s (%s) from module %s.\n", log_id(dff), log_id(dff->type), log_id(mod));
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (dff->type == ID($dffe)) {
|
|
|
|
dff->type = ID($dff);
|
|
|
|
dff->unsetPort(ID(EN));
|
|
|
|
dff->unsetParam(ID(EN_POLARITY));
|
2019-05-24 20:30:51 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:42:25 -05:00
|
|
|
log_assert(dff->type.begins_with("$_DFFE_"));
|
2019-05-24 20:30:51 -05:00
|
|
|
dff->type = stringf("$_DFF_%c_", + dff->type[7]);
|
2019-08-09 11:58:14 -05:00
|
|
|
dff->unsetPort(ID(E));
|
2019-05-24 20:30:51 -05:00
|
|
|
}
|
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
if (sat && has_init && (!sig_r.size() || val_init == val_rv))
|
|
|
|
{
|
2019-06-14 04:35:45 -05:00
|
|
|
bool removed_sigbits = false;
|
2019-05-28 01:48:21 -05:00
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
ezSatPtr ez;
|
|
|
|
SatGen satgen(ez.get(), &assign_map);
|
|
|
|
pool<Cell*> sat_cells;
|
|
|
|
|
|
|
|
std::function<void(Cell*)> sat_import_cell = [&](Cell *c) {
|
|
|
|
if (!sat_cells.insert(c).second)
|
|
|
|
return;
|
|
|
|
if (!satgen.importCell(c))
|
|
|
|
return;
|
|
|
|
for (auto &conn : c->connections()) {
|
|
|
|
if (!c->input(conn.first))
|
|
|
|
continue;
|
|
|
|
for (auto bit : assign_map(conn.second))
|
|
|
|
if (bit2driver.count(bit))
|
|
|
|
sat_import_cell(bit2driver.at(bit));
|
|
|
|
}
|
|
|
|
};
|
2019-06-14 04:35:45 -05:00
|
|
|
|
|
|
|
// For each register bit, try to prove that it cannot change from the initial value. If so, remove it
|
2019-06-11 04:47:13 -05:00
|
|
|
for (int position = 0; position < GetSize(sig_d); position += 1) {
|
2019-05-28 01:48:21 -05:00
|
|
|
RTLIL::SigBit q_sigbit = sig_q[position];
|
|
|
|
RTLIL::SigBit d_sigbit = sig_d[position];
|
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
if ((!q_sigbit.wire) || (!d_sigbit.wire))
|
2019-05-28 01:48:21 -05:00
|
|
|
continue;
|
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
if (!bit2driver.count(d_sigbit))
|
|
|
|
continue;
|
2019-06-11 04:47:13 -05:00
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
sat_import_cell(bit2driver.at(d_sigbit));
|
2019-06-11 04:47:13 -05:00
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
RTLIL::State sigbit_init_val = val_init[position];
|
|
|
|
if (sigbit_init_val != State::S0 && sigbit_init_val != State::S1)
|
|
|
|
continue;
|
2019-06-11 04:47:13 -05:00
|
|
|
|
2019-06-20 06:44:21 -05:00
|
|
|
int init_sat_pi = satgen.importSigSpec(sigbit_init_val).front();
|
2019-06-12 12:35:05 -05:00
|
|
|
int q_sat_pi = satgen.importSigBit(q_sigbit);
|
|
|
|
int d_sat_pi = satgen.importSigBit(d_sigbit);
|
2019-06-11 04:47:13 -05:00
|
|
|
|
2019-06-14 04:35:45 -05:00
|
|
|
// Try to find out whether the register bit can change under some circumstances
|
2019-06-12 12:35:05 -05:00
|
|
|
bool counter_example_found = ez->solve(ez->IFF(q_sat_pi, init_sat_pi), ez->NOT(ez->IFF(d_sat_pi, init_sat_pi)));
|
2019-06-11 04:47:13 -05:00
|
|
|
|
2019-06-14 04:35:45 -05:00
|
|
|
// If the register bit cannot change, we can replace it with a constant
|
2019-06-20 06:44:21 -05:00
|
|
|
if (!counter_example_found)
|
|
|
|
{
|
|
|
|
log("Setting constant %d-bit at position %d on %s (%s) from module %s.\n", sigbit_init_val ? 1 : 0,
|
|
|
|
position, log_id(dff), log_id(dff->type), log_id(mod));
|
2019-06-13 12:35:37 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
SigSpec tmp = dff->getPort(ID(D));
|
2019-06-20 06:44:21 -05:00
|
|
|
tmp[position] = sigbit_init_val;
|
2019-08-09 11:58:14 -05:00
|
|
|
dff->setPort(ID(D), tmp);
|
2019-06-13 12:35:37 -05:00
|
|
|
|
2019-06-14 04:35:45 -05:00
|
|
|
removed_sigbits = true;
|
2019-05-28 01:48:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 04:35:45 -05:00
|
|
|
if (removed_sigbits) {
|
2019-06-20 06:44:21 -05:00
|
|
|
handle_dff(mod, dff);
|
2019-05-28 01:48:21 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 12:35:05 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
delete_dff:
|
2016-08-29 18:34:04 -05:00
|
|
|
log("Removing %s (%s) from module %s.\n", log_id(dff), log_id(dff->type), log_id(mod));
|
2019-08-09 11:58:14 -05:00
|
|
|
remove_init_attr(dff->getPort(ID(Q)));
|
2014-07-25 08:05:18 -05:00
|
|
|
mod->remove(dff);
|
2019-06-27 15:02:12 -05:00
|
|
|
|
|
|
|
for (auto &entry : bit2driver)
|
|
|
|
if (entry.second == dff)
|
|
|
|
bit2driver.erase(entry.first);
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct OptRmdffPass : public Pass {
|
2013-03-01 01:58:55 -06:00
|
|
|
OptRmdffPass() : Pass("opt_rmdff", "remove DFFs with constant inputs") { }
|
2018-07-21 01:41:18 -05:00
|
|
|
void help() YS_OVERRIDE
|
2013-03-01 01:58:55 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2019-05-28 01:48:21 -05:00
|
|
|
log(" opt_rmdff [-keepdc] [-sat] [selection]\n");
|
2013-03-01 01:58:55 -06:00
|
|
|
log("\n");
|
|
|
|
log("This pass identifies flip-flops with constant inputs and replaces them with\n");
|
|
|
|
log("a constant driver.\n");
|
|
|
|
log("\n");
|
2019-06-27 15:06:23 -05:00
|
|
|
log(" -sat\n");
|
|
|
|
log(" additionally invoke SAT solver to detect and remove flip-flops (with \n");
|
|
|
|
log(" non-constant inputs) that can also be replaced with a constant driver\n");
|
|
|
|
log("\n");
|
2013-03-01 01:58:55 -06:00
|
|
|
}
|
2018-07-21 01:41:18 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2016-08-29 18:34:04 -05:00
|
|
|
int total_count = 0, total_initdrv = 0;
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing OPT_RMDFF pass (remove dff with constant values).\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2016-09-30 10:02:38 -05:00
|
|
|
keepdc = false;
|
2019-05-28 01:48:21 -05:00
|
|
|
sat = false;
|
2016-09-30 10:02:38 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
|
|
|
if (args[argidx] == "-keepdc") {
|
|
|
|
keepdc = true;
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-28 01:48:21 -05:00
|
|
|
if (args[argidx] == "-sat") {
|
|
|
|
sat = true;
|
|
|
|
continue;
|
|
|
|
}
|
2016-09-30 10:02:38 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-06-12 12:35:05 -05:00
|
|
|
for (auto module : design->selected_modules()) {
|
2016-08-29 18:34:04 -05:00
|
|
|
pool<SigBit> driven_bits;
|
|
|
|
dict<SigBit, State> init_bits;
|
|
|
|
|
|
|
|
assign_map.set(module);
|
|
|
|
dff_init_map.set(module);
|
2017-10-26 11:02:15 -05:00
|
|
|
mux_drivers.clear();
|
2019-06-20 06:44:21 -05:00
|
|
|
bit2driver.clear();
|
2017-10-26 11:02:15 -05:00
|
|
|
init_attributes.clear();
|
2016-08-29 18:34:04 -05:00
|
|
|
|
|
|
|
for (auto wire : module->wires())
|
|
|
|
{
|
2019-08-09 11:58:14 -05:00
|
|
|
if (wire->attributes.count(ID(init)) != 0) {
|
|
|
|
Const initval = wire->attributes.at(ID(init));
|
2017-02-09 09:06:58 -06:00
|
|
|
for (int i = 0; i < GetSize(initval) && i < GetSize(wire); i++)
|
|
|
|
if (initval[i] == State::S0 || initval[i] == State::S1)
|
|
|
|
dff_init_map.add(SigBit(wire, i), initval[i]);
|
2016-08-29 18:34:04 -05:00
|
|
|
for (int i = 0; i < GetSize(wire); i++) {
|
|
|
|
SigBit wire_bit(wire, i), mapped_bit = assign_map(wire_bit);
|
|
|
|
if (mapped_bit.wire) {
|
2015-08-18 06:50:15 -05:00
|
|
|
init_attributes[mapped_bit].insert(wire_bit);
|
2016-08-29 18:34:04 -05:00
|
|
|
if (i < GetSize(initval))
|
|
|
|
init_bits[mapped_bit] = initval[i];
|
|
|
|
}
|
2015-08-18 06:50:15 -05:00
|
|
|
}
|
|
|
|
}
|
2016-08-29 18:34:04 -05:00
|
|
|
|
|
|
|
if (wire->port_input) {
|
|
|
|
for (auto bit : assign_map(wire))
|
|
|
|
driven_bits.insert(bit);
|
|
|
|
}
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-08-02 06:11:01 -05:00
|
|
|
std::vector<RTLIL::IdString> dff_list;
|
2017-08-09 06:29:52 -05:00
|
|
|
std::vector<RTLIL::IdString> dffsr_list;
|
2015-05-23 02:45:48 -05:00
|
|
|
std::vector<RTLIL::IdString> dlatch_list;
|
2016-08-29 18:34:04 -05:00
|
|
|
for (auto cell : module->cells())
|
|
|
|
{
|
2019-06-20 06:44:21 -05:00
|
|
|
for (auto &conn : cell->connections()) {
|
|
|
|
bool is_output = cell->output(conn.first);
|
|
|
|
if (is_output || !cell->known())
|
|
|
|
for (auto bit : assign_map(conn.second)) {
|
|
|
|
if (is_output)
|
|
|
|
bit2driver[bit] = cell;
|
2016-08-29 18:34:04 -05:00
|
|
|
driven_bits.insert(bit);
|
2019-06-20 06:44:21 -05:00
|
|
|
}
|
|
|
|
}
|
2016-08-29 18:34:04 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type.in(ID($mux), ID($pmux))) {
|
2019-08-15 16:50:10 -05:00
|
|
|
if (cell->getPort(ID::A).size() == cell->getPort(ID::B).size())
|
|
|
|
mux_drivers.insert(assign_map(cell->getPort(ID::Y)), cell);
|
2013-05-23 00:48:18 -05:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-29 18:34:04 -05:00
|
|
|
|
|
|
|
if (!design->selected(module, cell))
|
2013-03-01 01:58:55 -06:00
|
|
|
continue;
|
2016-08-29 18:34:04 -05:00
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type.in(ID($_DFFSR_NNN_), ID($_DFFSR_NNP_), ID($_DFFSR_NPN_), ID($_DFFSR_NPP_),
|
|
|
|
ID($_DFFSR_PNN_), ID($_DFFSR_PNP_), ID($_DFFSR_PPN_), ID($_DFFSR_PPP_), ID($dffsr),
|
|
|
|
ID($_DLATCHSR_NNN_), ID($_DLATCHSR_NNP_), ID($_DLATCHSR_NPN_), ID($_DLATCHSR_NPP_),
|
|
|
|
ID($_DLATCHSR_PNN_), ID($_DLATCHSR_PNP_), ID($_DLATCHSR_PPN_), ID($_DLATCHSR_PPP_), ID($dlatchsr)))
|
2017-08-09 06:29:52 -05:00
|
|
|
dffsr_list.push_back(cell->name);
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type.in(ID($_FF_), ID($_DFF_N_), ID($_DFF_P_),
|
|
|
|
ID($_DFF_NN0_), ID($_DFF_NN1_), ID($_DFF_NP0_), ID($_DFF_NP1_),
|
|
|
|
ID($_DFF_PN0_), ID($_DFF_PN1_), ID($_DFF_PP0_), ID($_DFF_PP1_),
|
|
|
|
ID($_DFFE_NN_), ID($_DFFE_NP_), ID($_DFFE_PN_), ID($_DFFE_PP_),
|
|
|
|
ID($ff), ID($dff), ID($dffe), ID($adff)))
|
2016-08-29 18:34:04 -05:00
|
|
|
dff_list.push_back(cell->name);
|
|
|
|
|
2019-08-09 11:58:14 -05:00
|
|
|
if (cell->type.in(ID($dlatch), ID($_DLATCH_P_), ID($_DLATCH_N_)))
|
2016-08-29 18:34:04 -05:00
|
|
|
dlatch_list.push_back(cell->name);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2017-08-09 06:29:52 -05:00
|
|
|
for (auto &id : dffsr_list) {
|
|
|
|
if (module->cell(id) != nullptr &&
|
|
|
|
handle_dffsr(module, module->cells_[id]))
|
|
|
|
total_count++;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
for (auto &id : dff_list) {
|
2016-08-29 18:34:04 -05:00
|
|
|
if (module->cell(id) != nullptr &&
|
2019-06-13 12:35:37 -05:00
|
|
|
handle_dff(module, module->cells_[id]))
|
2013-01-05 04:13:26 -06:00
|
|
|
total_count++;
|
|
|
|
}
|
2015-05-23 02:45:48 -05:00
|
|
|
|
|
|
|
for (auto &id : dlatch_list) {
|
2016-08-29 18:34:04 -05:00
|
|
|
if (module->cell(id) != nullptr &&
|
|
|
|
handle_dlatch(module, module->cells_[id]))
|
2015-05-23 02:45:48 -05:00
|
|
|
total_count++;
|
|
|
|
}
|
2016-08-29 18:34:04 -05:00
|
|
|
|
|
|
|
SigSpec const_init_sigs;
|
|
|
|
|
|
|
|
for (auto bit : init_bits)
|
|
|
|
if (!driven_bits.count(bit.first))
|
|
|
|
const_init_sigs.append(bit.first);
|
|
|
|
|
|
|
|
const_init_sigs.sort_and_unify();
|
|
|
|
|
|
|
|
for (SigSpec sig : const_init_sigs.chunks())
|
|
|
|
{
|
|
|
|
Const val;
|
|
|
|
|
|
|
|
for (auto bit : sig)
|
|
|
|
val.bits.push_back(init_bits.at(bit));
|
|
|
|
|
|
|
|
log("Promoting init spec %s = %s to constant driver in module %s.\n",
|
|
|
|
log_signal(sig), log_signal(val), log_id(module));
|
|
|
|
|
|
|
|
module->connect(sig, val);
|
|
|
|
remove_init_attr(sig);
|
|
|
|
total_initdrv++;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
assign_map.clear();
|
2013-05-23 00:48:18 -05:00
|
|
|
mux_drivers.clear();
|
2019-06-20 06:44:21 -05:00
|
|
|
bit2driver.clear();
|
2017-10-26 11:02:15 -05:00
|
|
|
init_attributes.clear();
|
2014-08-30 12:37:12 -05:00
|
|
|
|
2016-08-29 18:34:04 -05:00
|
|
|
if (total_count || total_initdrv)
|
2014-08-30 12:37:12 -05:00
|
|
|
design->scratchpad_set_bool("opt.did_something", true);
|
2016-08-29 18:34:04 -05:00
|
|
|
|
|
|
|
if (total_initdrv)
|
|
|
|
log("Promoted %d init specs to constant drivers.\n", total_initdrv);
|
|
|
|
|
|
|
|
if (total_count)
|
|
|
|
log("Replaced %d DFF cells.\n", total_count);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
} OptRmdffPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|