From 52a1493548063ea5cc22b04538e4a6d99989b388 Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Thu, 21 Nov 2024 03:29:35 -0800 Subject: [PATCH] Naming improvements --- kernel/ff.cc | 104 +++++++++++++++++++------------------- kernel/yosys_common.h | 22 ++++---- passes/techmap/techmap.cc | 2 +- 3 files changed, 63 insertions(+), 65 deletions(-) diff --git a/kernel/ff.cc b/kernel/ff.cc index 5eef58909..499652465 100644 --- a/kernel/ff.cc +++ b/kernel/ff.cc @@ -263,7 +263,7 @@ FfData::FfData(FfInitVals *initvals, Cell *cell_) : FfData(cell_->module, initva } FfData FfData::slice(const std::vector &bits) { - FfData res(module, initvals, NEW_ID2); // SILIMATE: Improve the naming + FfData res(module, initvals, NEW_ID4); // SILIMATE: Improve the naming res.sig_clk = sig_clk; res.sig_ce = sig_ce; res.sig_aload = sig_aload; @@ -400,21 +400,21 @@ void FfData::aload_to_sr() { pol_clr = false; pol_set = true; if (pol_aload) { - sig_clr = module->Mux(NEW_ID2_SUFFIX("clr"), Const(State::S1, width), sig_ad, sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_set = module->Mux(NEW_ID2_SUFFIX("set"), Const(State::S0, width), sig_ad, sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_clr = module->Mux(NEW_ID4_SUFFIX("clr"), Const(State::S1, width), sig_ad, sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_set = module->Mux(NEW_ID4_SUFFIX("set"), Const(State::S0, width), sig_ad, sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_clr = module->Mux(NEW_ID2_SUFFIX("clr"), sig_ad, Const(State::S1, width), sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_set = module->Mux(NEW_ID2_SUFFIX("set"), sig_ad, Const(State::S0, width), sig_aload, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_clr = module->Mux(NEW_ID4_SUFFIX("clr"), sig_ad, Const(State::S1, width), sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_set = module->Mux(NEW_ID4_SUFFIX("set"), sig_ad, Const(State::S0, width), sig_aload, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } else { pol_clr = pol_aload; pol_set = pol_aload; if (pol_aload) { - sig_clr = module->AndnotGate(NEW_ID2_SUFFIX("clr"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_set = module->AndGate(NEW_ID2_SUFFIX("set"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_clr = module->AndnotGate(NEW_ID4_SUFFIX("clr"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_set = module->AndGate(NEW_ID4_SUFFIX("set"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_clr = module->OrGate(NEW_ID2_SUFFIX("clr"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_set = module->OrnotGate(NEW_ID2_SUFFIX("set"), sig_aload, sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_clr = module->OrGate(NEW_ID4_SUFFIX("clr"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_set = module->OrnotGate(NEW_ID4_SUFFIX("set"), sig_aload, sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } } @@ -427,31 +427,31 @@ void FfData::convert_ce_over_srst(bool val) { if (!is_fine) { if (pol_ce) { if (pol_srst) { - sig_ce = module->Or(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ce = module->Or(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_ce = module->Or(NEW_ID2_SUFFIX("ce"), sig_ce, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_ce = module->Or(NEW_ID4_SUFFIX("ce"), sig_ce, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } else { if (pol_srst) { - SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_ce = module->And(NEW_ID2_SUFFIX("ce"), sig_ce, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_ce = module->And(NEW_ID4_SUFFIX("ce"), sig_ce, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_ce = module->And(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ce = module->And(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } } else { if (pol_ce) { if (pol_srst) { - sig_ce = module->OrGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ce = module->OrGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_ce = module->OrnotGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ce = module->OrnotGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } else { if (pol_srst) { - sig_ce = module->AndnotGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ce = module->AndnotGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_ce = module->AndGate(NEW_ID2_SUFFIX("ce"), sig_ce, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ce = module->AndGate(NEW_ID4_SUFFIX("ce"), sig_ce, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } } @@ -460,31 +460,31 @@ void FfData::convert_ce_over_srst(bool val) { if (!is_fine) { if (pol_srst) { if (pol_ce) { - sig_srst = cell->module->And(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_srst = cell->module->And(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_srst = cell->module->And(NEW_ID2_SUFFIX("srst"), sig_srst, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_srst = cell->module->And(NEW_ID4_SUFFIX("srst"), sig_srst, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } else { if (pol_ce) { - SigSpec tmp = module->Not(NEW_ID2_SUFFIX("tmp"), sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming - sig_srst = cell->module->Or(NEW_ID2_SUFFIX("srst"), sig_srst, tmp, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + SigSpec tmp = module->Not(NEW_ID4_SUFFIX("tmp"), sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + sig_srst = cell->module->Or(NEW_ID4_SUFFIX("srst"), sig_srst, tmp, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_srst = cell->module->Or(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_srst = cell->module->Or(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } } else { if (pol_srst) { if (pol_ce) { - sig_srst = cell->module->AndGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_srst = cell->module->AndGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_srst = cell->module->AndnotGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_srst = cell->module->AndnotGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } else { if (pol_ce) { - sig_srst = cell->module->OrnotGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_srst = cell->module->OrnotGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - sig_srst = cell->module->OrGate(NEW_ID2_SUFFIX("srst"), sig_srst, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_srst = cell->module->OrGate(NEW_ID4_SUFFIX("srst"), sig_srst, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } } @@ -501,14 +501,14 @@ void FfData::unmap_ce() { if (!is_fine) { if (pol_ce) - sig_d = module->Mux(NEW_ID2_SUFFIX("d"), sig_q, sig_d, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->Mux(NEW_ID4_SUFFIX("d"), sig_q, sig_d, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming else - sig_d = module->Mux(NEW_ID2_SUFFIX("d"), sig_d, sig_q, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->Mux(NEW_ID4_SUFFIX("d"), sig_d, sig_q, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { if (pol_ce) - sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), sig_q, sig_d, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), sig_q, sig_d, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming else - sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), sig_d, sig_q, sig_ce, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), sig_d, sig_q, sig_ce, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } has_ce = false; } @@ -521,14 +521,14 @@ void FfData::unmap_srst() { if (!is_fine) { if (pol_srst) - sig_d = module->Mux(NEW_ID2_SUFFIX("d"), sig_d, val_srst, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->Mux(NEW_ID4_SUFFIX("d"), sig_d, val_srst, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming else - sig_d = module->Mux(NEW_ID2_SUFFIX("d"), val_srst, sig_d, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->Mux(NEW_ID4_SUFFIX("d"), val_srst, sig_d, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { if (pol_srst) - sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), sig_d, val_srst[0], sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), sig_d, val_srst[0], sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming else - sig_d = module->MuxGate(NEW_ID2_SUFFIX("d"), val_srst[0], sig_d, sig_srst, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->MuxGate(NEW_ID4_SUFFIX("d"), val_srst[0], sig_d, sig_srst, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } has_srst = false; } @@ -701,7 +701,7 @@ void FfData::flip_bits(const pool &bits) { flip_rst_bits(bits); - Wire *new_q = module->addWire(NEW_ID2_SUFFIX("new_q"), width); // SILIMATE: Improve the naming + Wire *new_q = module->addWire(NEW_ID4_SUFFIX("new_q"), width); // SILIMATE: Improve the naming if (has_sr && cell) { log_warning("Flipping D/Q/init and inserting priority fixup to legalize %s.%s [%s].\n", log_id(module->name), log_id(cell->name), log_id(cell->type)); @@ -713,15 +713,15 @@ void FfData::flip_bits(const pool &bits) { SigSpec new_sig_clr; if (pol_set) { if (pol_clr) { - new_sig_clr = module->AndnotGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming + new_sig_clr = module->AndnotGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - new_sig_clr = module->AndGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming + new_sig_clr = module->AndGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } else { if (pol_clr) { - new_sig_clr = module->OrGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming + new_sig_clr = module->OrGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { - new_sig_clr = module->OrnotGate(NEW_ID2_SUFFIX("new_clr"), sig_set, sig_clr, cell->get_src_attribute()); // SILIMATE: Improve the naming + new_sig_clr = module->OrnotGate(NEW_ID4_SUFFIX("new_clr"), sig_set, sig_clr, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } } pol_set = pol_clr; @@ -730,10 +730,10 @@ void FfData::flip_bits(const pool &bits) { sig_clr = new_sig_clr; } if (has_clk || has_gclk) - sig_d = module->NotGate(NEW_ID2_SUFFIX("d"), sig_d, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->NotGate(NEW_ID4_SUFFIX("d"), sig_d, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming if (has_aload) - sig_ad = module->NotGate(NEW_ID2_SUFFIX("ad"), sig_ad, cell->get_src_attribute()); // SILIMATE: Improve the naming - module->addNotGate(NEW_ID2_SUFFIX("not"), new_q, sig_q, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ad = module->NotGate(NEW_ID4_SUFFIX("ad"), sig_ad, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + module->addNotGate(NEW_ID4_SUFFIX("not"), new_q, sig_q, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } else { @@ -741,17 +741,17 @@ void FfData::flip_bits(const pool &bits) { SigSpec not_clr; if (!pol_clr) { not_clr = sig_clr; - sig_clr = module->Not(NEW_ID2_SUFFIX("clr"), sig_clr, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_clr = module->Not(NEW_ID4_SUFFIX("clr"), sig_clr, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming pol_clr = true; } else { - not_clr = module->Not(NEW_ID2_SUFFIX("not_clr"), sig_clr, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + not_clr = module->Not(NEW_ID4_SUFFIX("not_clr"), sig_clr, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } if (!pol_set) { - sig_set = module->Not(NEW_ID2_SUFFIX("set"), sig_set, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_set = module->Not(NEW_ID4_SUFFIX("set"), sig_set, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming pol_set = true; } - SigSpec masked_set = module->And(NEW_ID2_SUFFIX("masked_set"), sig_set, not_clr, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + SigSpec masked_set = module->And(NEW_ID4_SUFFIX("masked_set"), sig_set, not_clr, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming for (auto bit: bits) { sig_set[bit] = sig_clr[bit]; sig_clr[bit] = masked_set[bit]; @@ -763,10 +763,10 @@ void FfData::flip_bits(const pool &bits) { mask.bits()[bit] = State::S1; if (has_clk || has_gclk) - sig_d = module->Xor(NEW_ID2_SUFFIX("d"), sig_d, mask, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_d = module->Xor(NEW_ID4_SUFFIX("d"), sig_d, mask, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming if (has_aload) - sig_ad = module->Xor(NEW_ID2_SUFFIX("ad"), sig_ad, mask, false, cell->get_src_attribute()); // SILIMATE: Improve the naming - module->addXor(NEW_ID2_SUFFIX("xor"), new_q, mask, sig_q, false, cell->get_src_attribute()); // SILIMATE: Improve the naming + sig_ad = module->Xor(NEW_ID4_SUFFIX("ad"), sig_ad, mask, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming + module->addXor(NEW_ID4_SUFFIX("xor"), new_q, mask, sig_q, false, attributes[ID::src].decode_string()); // SILIMATE: Improve the naming } sig_q = new_q; diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index 1320505e7..3007ca694 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -358,18 +358,16 @@ RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std: YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__) #define NEW_ID_SUFFIX(suffix) \ YOSYS_NAMESPACE_PREFIX new_id_suffix(__FILE__, __LINE__, __FUNCTION__, suffix) -#define NEW_ID2 \ - module->uniquify(cell->name.str()) -#define NEW_ID2_SUFFIX(suffix) \ - module->uniquify(cell->name.str() + "_" + suffix) -#define NEW_ID3 \ - module->uniquify(cell_name.str()) -#define NEW_ID3_SUFFIX(suffix) \ - module->uniquify(cell_name.str() + "_" + suffix) -#define NEW_MEM_ID_SUFFIX(suffix) \ - mem.mem ? module->uniquify(mem.mem->name.str() + "_" + suffix) : module->uniquify(string("\\mem_") + suffix) -#define NEW_ABC_ID \ - module->uniquify(IdString("\\boolopt")) + +#define UNQ_SUFFIX "_ix" + std::to_string(autoidx++) +#define NEW_ID2 IdString(cell->name.str() + UNQ_SUFFIX) +#define NEW_ID2_SUFFIX(suffix) IdString(cell->name.str() + "_" + suffix + UNQ_SUFFIX) +#define NEW_ID3 IdString(cell_name.str() + UNQ_SUFFIX) +#define NEW_ID3_SUFFIX(suffix) IdString(cell_name.str() + "_" + suffix + UNQ_SUFFIX) +#define NEW_ID4 IdString(name.str() + UNQ_SUFFIX) +#define NEW_ID4_SUFFIX(suffix) IdString(name.str() + "_" + suffix + UNQ_SUFFIX) +#define NEW_MEM_ID_SUFFIX(suffix) mem.mem ? module->uniquify(mem.mem->name.str() + "_" + suffix) : module->uniquify(string("\\mem_") + suffix) +#define NEW_ABC_ID module->uniquify(IdString("\\boolopt")) // Create a statically allocated IdString object, using for example ID::A or ID($add). // diff --git a/passes/techmap/techmap.cc b/passes/techmap/techmap.cc index f3927a486..1ccb58b5d 100644 --- a/passes/techmap/techmap.cc +++ b/passes/techmap/techmap.cc @@ -44,7 +44,7 @@ void apply_prefix(IdString prefix, IdString &id) if (id[0] == '\\') id = stringf("%s.%s", prefix.c_str(), id.c_str()+1); else - id = stringf("$techmap%s.%s", prefix.c_str(), id.c_str()); + id = stringf("\\%s.%s", prefix.c_str(), id.c_str()); } void apply_prefix(IdString prefix, RTLIL::SigSpec &sig, RTLIL::Module *module)