aboutsummaryrefslogtreecommitdiffstats
path: root/passes/opt/opt_rmdff.cc
diff options
context:
space:
mode:
Diffstat (limited to 'passes/opt/opt_rmdff.cc')
-rw-r--r--passes/opt/opt_rmdff.cc264
1 files changed, 132 insertions, 132 deletions
diff --git a/passes/opt/opt_rmdff.cc b/passes/opt/opt_rmdff.cc
index be6ac2d30..4ba61e512 100644
--- a/passes/opt/opt_rmdff.cc
+++ b/passes/opt/opt_rmdff.cc
@@ -41,7 +41,7 @@ void remove_init_attr(SigSpec sig)
for (auto bit : assign_map(sig))
if (init_attributes.count(bit))
for (auto wbit : init_attributes.at(bit))
- wbit.wire->attributes.at("\\init")[wbit.offset] = State::Sx;
+ wbit.wire->attributes.at(ID(init))[wbit.offset] = State::Sx;
}
bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
@@ -49,39 +49,39 @@ bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
SigSpec sig_set, sig_clr;
State pol_set, pol_clr;
- if (cell->hasPort("\\S"))
- sig_set = cell->getPort("\\S");
+ if (cell->hasPort(ID(S)))
+ sig_set = cell->getPort(ID(S));
- if (cell->hasPort("\\R"))
- sig_clr = cell->getPort("\\R");
+ if (cell->hasPort(ID(R)))
+ sig_clr = cell->getPort(ID(R));
- if (cell->hasPort("\\SET"))
- sig_set = cell->getPort("\\SET");
+ if (cell->hasPort(ID(SET)))
+ sig_set = cell->getPort(ID(SET));
- if (cell->hasPort("\\CLR"))
- sig_clr = cell->getPort("\\CLR");
+ if (cell->hasPort(ID(CLR)))
+ sig_clr = cell->getPort(ID(CLR));
log_assert(GetSize(sig_set) == GetSize(sig_clr));
- if (cell->type.substr(0,8) == "$_DFFSR_") {
+ if (cell->type.begins_with("$_DFFSR_")) {
pol_set = cell->type[9] == 'P' ? State::S1 : State::S0;
pol_clr = cell->type[10] == 'P' ? State::S1 : State::S0;
} else
- if (cell->type.substr(0,11) == "$_DLATCHSR_") {
+ if (cell->type.begins_with("$_DLATCHSR_")) {
pol_set = cell->type[12] == 'P' ? State::S1 : State::S0;
pol_clr = cell->type[13] == 'P' ? State::S1 : State::S0;
} else
- if (cell->type == "$dffsr" || cell->type == "$dlatchsr") {
- pol_set = cell->parameters["\\SET_POLARITY"].as_bool() ? State::S1 : State::S0;
- pol_clr = cell->parameters["\\CLR_POLARITY"].as_bool() ? State::S1 : State::S0;
+ 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;
} 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;
- SigSpec sig_d = cell->getPort("\\D");
- SigSpec sig_q = cell->getPort("\\Q");
+ SigSpec sig_d = cell->getPort(ID(D));
+ SigSpec sig_q = cell->getPort(ID(Q));
bool did_something = false;
bool proper_sr = false;
@@ -137,20 +137,20 @@ bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
return true;
}
- if (cell->type == "$dffsr" || cell->type == "$dlatchsr")
+ if (cell->type.in(ID($dffsr), ID($dlatchsr)))
{
- cell->setParam("\\WIDTH", GetSize(sig_d));
- cell->setPort("\\SET", sig_set);
- cell->setPort("\\CLR", sig_clr);
- cell->setPort("\\D", sig_d);
- cell->setPort("\\Q", sig_q);
+ 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);
}
else
{
- cell->setPort("\\S", sig_set);
- cell->setPort("\\R", sig_clr);
- cell->setPort("\\D", sig_d);
- cell->setPort("\\Q", sig_q);
+ cell->setPort(ID(S), sig_set);
+ cell->setPort(ID(R), sig_clr);
+ cell->setPort(ID(D), sig_d);
+ cell->setPort(ID(Q), sig_q);
}
if (proper_sr)
@@ -159,36 +159,36 @@ bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
if (used_pol_set && used_pol_clr && pol_set != pol_clr)
return did_something;
- if (cell->type == "$dlatchsr")
+ if (cell->type == ID($dlatchsr))
return did_something;
State unified_pol = used_pol_set ? pol_set : pol_clr;
- if (cell->type == "$dffsr")
+ if (cell->type == ID($dffsr))
{
if (hasreset)
{
log("Converting %s (%s) to %s in module %s.\n", log_id(cell), log_id(cell->type), "$adff", log_id(mod));
- cell->type = "$adff";
- cell->setParam("\\ARST_POLARITY", unified_pol);
- cell->setParam("\\ARST_VALUE", reset_val);
- cell->setPort("\\ARST", sig_reset);
+ cell->type = ID($adff);
+ cell->setParam(ID(ARST_POLARITY), unified_pol);
+ cell->setParam(ID(ARST_VALUE), reset_val);
+ cell->setPort(ID(ARST), sig_reset);
- cell->unsetParam("\\SET_POLARITY");
- cell->unsetParam("\\CLR_POLARITY");
- cell->unsetPort("\\SET");
- cell->unsetPort("\\CLR");
+ cell->unsetParam(ID(SET_POLARITY));
+ cell->unsetParam(ID(CLR_POLARITY));
+ cell->unsetPort(ID(SET));
+ cell->unsetPort(ID(CLR));
}
else
{
log("Converting %s (%s) to %s in module %s.\n", log_id(cell), log_id(cell->type), "$dff", log_id(mod));
- cell->type = "$dff";
- cell->unsetParam("\\SET_POLARITY");
- cell->unsetParam("\\CLR_POLARITY");
- cell->unsetPort("\\SET");
- cell->unsetPort("\\CLR");
+ cell->type = ID($dff);
+ cell->unsetParam(ID(SET_POLARITY));
+ cell->unsetParam(ID(CLR_POLARITY));
+ cell->unsetPort(ID(SET));
+ cell->unsetPort(ID(CLR));
}
return true;
@@ -198,9 +198,9 @@ bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
{
IdString new_type;
- if (cell->type.substr(0,8) == "$_DFFSR_")
+ if (cell->type.begins_with("$_DFFSR_"))
new_type = stringf("$_DFF_%c_", cell->type[8]);
- else if (cell->type.substr(0,11) == "$_DLATCHSR_")
+ else if (cell->type.begins_with("$_DLATCHSR_"))
new_type = stringf("$_DLATCH_%c_", cell->type[11]);
else
log_abort();
@@ -208,8 +208,8 @@ bool handle_dffsr(RTLIL::Module *mod, RTLIL::Cell *cell)
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;
- cell->unsetPort("\\S");
- cell->unsetPort("\\R");
+ cell->unsetPort(ID(S));
+ cell->unsetPort(ID(R));
return true;
}
@@ -222,18 +222,18 @@ bool handle_dlatch(RTLIL::Module *mod, RTLIL::Cell *dlatch)
SigSpec sig_e;
State on_state, off_state;
- if (dlatch->type == "$dlatch") {
- sig_e = assign_map(dlatch->getPort("\\EN"));
- on_state = dlatch->getParam("\\EN_POLARITY").as_bool() ? State::S1 : State::S0;
- off_state = dlatch->getParam("\\EN_POLARITY").as_bool() ? State::S0 : State::S1;
+ 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;
} else
- if (dlatch->type == "$_DLATCH_P_") {
- sig_e = assign_map(dlatch->getPort("\\E"));
+ if (dlatch->type == ID($_DLATCH_P_)) {
+ sig_e = assign_map(dlatch->getPort(ID(E)));
on_state = State::S1;
off_state = State::S0;
} else
- if (dlatch->type == "$_DLATCH_N_") {
- sig_e = assign_map(dlatch->getPort("\\E"));
+ if (dlatch->type == ID($_DLATCH_N_)) {
+ sig_e = assign_map(dlatch->getPort(ID(E)));
on_state = State::S0;
off_state = State::S1;
} else
@@ -242,15 +242,15 @@ bool handle_dlatch(RTLIL::Module *mod, RTLIL::Cell *dlatch)
if (sig_e == off_state)
{
RTLIL::Const val_init;
- for (auto bit : dff_init_map(dlatch->getPort("\\Q")))
+ for (auto bit : dff_init_map(dlatch->getPort(ID(Q))))
val_init.bits.push_back(bit.wire == NULL ? bit.data : State::Sx);
- mod->connect(dlatch->getPort("\\Q"), val_init);
+ mod->connect(dlatch->getPort(ID(Q)), val_init);
goto delete_dlatch;
}
if (sig_e == on_state)
{
- mod->connect(dlatch->getPort("\\Q"), dlatch->getPort("\\D"));
+ mod->connect(dlatch->getPort(ID(Q)), dlatch->getPort(ID(D)));
goto delete_dlatch;
}
@@ -258,7 +258,7 @@ bool handle_dlatch(RTLIL::Module *mod, RTLIL::Cell *dlatch)
delete_dlatch:
log("Removing %s (%s) from module %s.\n", log_id(dlatch), log_id(dlatch->type), log_id(mod));
- remove_init_attr(dlatch->getPort("\\Q"));
+ remove_init_attr(dlatch->getPort(ID(Q)));
mod->remove(dlatch);
return true;
}
@@ -268,64 +268,64 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
RTLIL::SigSpec sig_d, sig_q, sig_c, sig_r, sig_e;
RTLIL::Const val_cp, val_rp, val_rv, val_ep;
- if (dff->type == "$_FF_") {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
+ if (dff->type == ID($_FF_)) {
+ sig_d = dff->getPort(ID(D));
+ sig_q = dff->getPort(ID(Q));
}
- else if (dff->type == "$_DFF_N_" || dff->type == "$_DFF_P_") {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
- sig_c = dff->getPort("\\C");
- val_cp = RTLIL::Const(dff->type == "$_DFF_P_", 1);
+ 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);
}
- else if (dff->type.substr(0,6) == "$_DFF_" && dff->type.substr(9) == "_" &&
+ else if (dff->type.begins_with("$_DFF_") && dff->type.compare(9, 1, "_") == 0 &&
(dff->type[6] == 'N' || dff->type[6] == 'P') &&
(dff->type[7] == 'N' || dff->type[7] == 'P') &&
(dff->type[8] == '0' || dff->type[8] == '1')) {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
- sig_c = dff->getPort("\\C");
- sig_r = dff->getPort("\\R");
+ sig_d = dff->getPort(ID(D));
+ sig_q = dff->getPort(ID(Q));
+ sig_c = dff->getPort(ID(C));
+ sig_r = dff->getPort(ID(R));
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);
}
- else if (dff->type.substr(0,7) == "$_DFFE_" && dff->type.substr(9) == "_" &&
+ else if (dff->type.begins_with("$_DFFE_") && dff->type.compare(9, 1, "_") == 0 &&
(dff->type[7] == 'N' || dff->type[7] == 'P') &&
(dff->type[8] == 'N' || dff->type[8] == 'P')) {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
- sig_c = dff->getPort("\\C");
- sig_e = dff->getPort("\\E");
+ sig_d = dff->getPort(ID(D));
+ sig_q = dff->getPort(ID(Q));
+ sig_c = dff->getPort(ID(C));
+ sig_e = dff->getPort(ID(E));
val_cp = RTLIL::Const(dff->type[7] == 'P', 1);
val_ep = RTLIL::Const(dff->type[8] == 'P', 1);
}
- else if (dff->type == "$ff") {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
+ else if (dff->type == ID($ff)) {
+ sig_d = dff->getPort(ID(D));
+ sig_q = dff->getPort(ID(Q));
}
- else if (dff->type == "$dff") {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
- sig_c = dff->getPort("\\CLK");
- val_cp = RTLIL::Const(dff->parameters["\\CLK_POLARITY"].as_bool(), 1);
+ 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);
}
- else if (dff->type == "$dffe") {
- sig_e = dff->getPort("\\EN");
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
- sig_c = dff->getPort("\\CLK");
- val_cp = RTLIL::Const(dff->parameters["\\CLK_POLARITY"].as_bool(), 1);
- val_ep = RTLIL::Const(dff->parameters["\\EN_POLARITY"].as_bool(), 1);
+ 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);
}
- else if (dff->type == "$adff") {
- sig_d = dff->getPort("\\D");
- sig_q = dff->getPort("\\Q");
- sig_c = dff->getPort("\\CLK");
- sig_r = dff->getPort("\\ARST");
- val_cp = RTLIL::Const(dff->parameters["\\CLK_POLARITY"].as_bool(), 1);
- val_rp = RTLIL::Const(dff->parameters["\\ARST_POLARITY"].as_bool(), 1);
- val_rv = dff->parameters["\\ARST_VALUE"];
+ 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)];
}
else
log_abort();
@@ -343,12 +343,12 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
val_init.bits.push_back(bit.wire == NULL ? bit.data : RTLIL::State::Sx);
}
- if (dff->type.in("$ff", "$dff") && mux_drivers.has(sig_d)) {
+ if (dff->type.in(ID($ff), ID($dff)) && mux_drivers.has(sig_d)) {
std::set<RTLIL::Cell*> muxes;
mux_drivers.find(sig_d, muxes);
for (auto mux : muxes) {
- RTLIL::SigSpec sig_a = assign_map(mux->getPort("\\A"));
- RTLIL::SigSpec sig_b = assign_map(mux->getPort("\\B"));
+ RTLIL::SigSpec sig_a = assign_map(mux->getPort(ID(A)));
+ RTLIL::SigSpec sig_b = assign_map(mux->getPort(ID(B)));
if (sig_a == sig_q && sig_b.is_fully_const() && (!has_init || val_init == sig_b.as_const())) {
mod->connect(sig_q, sig_b);
goto delete_dff;
@@ -420,17 +420,17 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
log("Removing unused reset from %s (%s) from module %s.\n", log_id(dff), log_id(dff->type), log_id(mod));
- if (dff->type == "$adff") {
- dff->type = "$dff";
- dff->unsetPort("\\ARST");
- dff->unsetParam("\\ARST_POLARITY");
- dff->unsetParam("\\ARST_VALUE");
+ if (dff->type == ID($adff)) {
+ dff->type = ID($dff);
+ dff->unsetPort(ID(ARST));
+ dff->unsetParam(ID(ARST_POLARITY));
+ dff->unsetParam(ID(ARST_VALUE));
return true;
}
- log_assert(dff->type.substr(0,6) == "$_DFF_");
+ log_assert(dff->type.begins_with("$_DFF_"));
dff->type = stringf("$_DFF_%c_", + dff->type[6]);
- dff->unsetPort("\\R");
+ dff->unsetPort(ID(R));
}
// If enable signal is present, and is fully constant
@@ -445,16 +445,16 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
log("Removing unused enable from %s (%s) from module %s.\n", log_id(dff), log_id(dff->type), log_id(mod));
- if (dff->type == "$dffe") {
- dff->type = "$dff";
- dff->unsetPort("\\EN");
- dff->unsetParam("\\EN_POLARITY");
+ if (dff->type == ID($dffe)) {
+ dff->type = ID($dff);
+ dff->unsetPort(ID(EN));
+ dff->unsetParam(ID(EN_POLARITY));
return true;
}
- log_assert(dff->type.substr(0,7) == "$_DFFE_");
+ log_assert(dff->type.begins_with("$_DFFE_"));
dff->type = stringf("$_DFF_%c_", + dff->type[7]);
- dff->unsetPort("\\E");
+ dff->unsetPort(ID(E));
}
if (sat && has_init && (!sig_r.size() || val_init == val_rv))
@@ -509,9 +509,9 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
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));
- SigSpec tmp = dff->getPort("\\D");
+ SigSpec tmp = dff->getPort(ID(D));
tmp[position] = sigbit_init_val;
- dff->setPort("\\D", tmp);
+ dff->setPort(ID(D), tmp);
removed_sigbits = true;
}
@@ -528,7 +528,7 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
delete_dff:
log("Removing %s (%s) from module %s.\n", log_id(dff), log_id(dff->type), log_id(mod));
- remove_init_attr(dff->getPort("\\Q"));
+ remove_init_attr(dff->getPort(ID(Q)));
mod->remove(dff);
for (auto &entry : bit2driver)
@@ -588,8 +588,8 @@ struct OptRmdffPass : public Pass {
for (auto wire : module->wires())
{
- if (wire->attributes.count("\\init") != 0) {
- Const initval = wire->attributes.at("\\init");
+ if (wire->attributes.count(ID(init)) != 0) {
+ Const initval = wire->attributes.at(ID(init));
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]);
@@ -624,29 +624,29 @@ struct OptRmdffPass : public Pass {
}
}
- if (cell->type == "$mux" || cell->type == "$pmux") {
- if (cell->getPort("\\A").size() == cell->getPort("\\B").size())
- mux_drivers.insert(assign_map(cell->getPort("\\Y")), cell);
+ if (cell->type.in(ID($mux), ID($pmux))) {
+ if (cell->getPort(ID(A)).size() == cell->getPort(ID(B)).size())
+ mux_drivers.insert(assign_map(cell->getPort(ID(Y))), cell);
continue;
}
if (!design->selected(module, cell))
continue;
- if (cell->type.in("$_DFFSR_NNN_", "$_DFFSR_NNP_", "$_DFFSR_NPN_", "$_DFFSR_NPP_",
- "$_DFFSR_PNN_", "$_DFFSR_PNP_", "$_DFFSR_PPN_", "$_DFFSR_PPP_", "$dffsr",
- "$_DLATCHSR_NNN_", "$_DLATCHSR_NNP_", "$_DLATCHSR_NPN_", "$_DLATCHSR_NPP_",
- "$_DLATCHSR_PNN_", "$_DLATCHSR_PNP_", "$_DLATCHSR_PPN_", "$_DLATCHSR_PPP_", "$dlatchsr"))
+ 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)))
dffsr_list.push_back(cell->name);
- if (cell->type.in("$_FF_", "$_DFF_N_", "$_DFF_P_",
- "$_DFF_NN0_", "$_DFF_NN1_", "$_DFF_NP0_", "$_DFF_NP1_",
- "$_DFF_PN0_", "$_DFF_PN1_", "$_DFF_PP0_", "$_DFF_PP1_",
- "$_DFFE_NN_", "$_DFFE_NP_", "$_DFFE_PN_", "$_DFFE_PP_",
- "$ff", "$dff", "$dffe", "$adff"))
+ 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)))
dff_list.push_back(cell->name);
- if (cell->type.in("$dlatch", "$_DLATCH_P_", "$_DLATCH_N_"))
+ if (cell->type.in(ID($dlatch), ID($_DLATCH_P_), ID($_DLATCH_N_)))
dlatch_list.push_back(cell->name);
}