From e1fc67a693d69bfdf27d0aea1eee9cc350c8cd5e Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Wed, 5 Mar 2025 06:37:36 -0800 Subject: [PATCH] Improve the naming in instance add functions --- kernel/rtlil.cc | 103 ++++++++++++++++++++++++++---------------- kernel/yosys_common.h | 2 + 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 6bc18a3d1..c4200bb27 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -2758,10 +2758,11 @@ RTLIL::Process *RTLIL::Module::addProcess(RTLIL::IdString name, const RTLIL::Pro return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), _y_size); \ add ## _func(name, sig_a, sig_y, is_signed, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(Not, sig_a.size(), ID($not)) DEF_METHOD(Pos, sig_a.size(), ID($pos)) DEF_METHOD(Neg, sig_a.size(), ID($neg)) @@ -2783,10 +2784,11 @@ DEF_METHOD(LogicNot, 1, ID($logic_not)) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), _y_size); \ add ## _func(name, sig_a, sig_y, is_signed, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(Buf, sig_a.size(), ID($buf)) #undef DEF_METHOD @@ -2805,10 +2807,11 @@ DEF_METHOD(Buf, sig_a.size(), ID($buf)) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), _y_size); \ add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(And, max(sig_a.size(), sig_b.size()), ID($and)) DEF_METHOD(Or, max(sig_a.size(), sig_b.size()), ID($or)) DEF_METHOD(Xor, max(sig_a.size(), sig_b.size()), ID($xor)) @@ -2848,10 +2851,11 @@ DEF_METHOD(LogicOr, 1, ID($logic_or)) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), _y_size); \ add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(Shl, sig_a.size(), ID($shl)) DEF_METHOD(Shr, sig_a.size(), ID($shr)) DEF_METHOD(Sshl, sig_a.size(), ID($sshl)) @@ -2873,10 +2877,11 @@ DEF_METHOD(Sshr, sig_a.size(), ID($sshr)) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), _y_size); \ add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(Shiftx, sig_a.size(), ID($shiftx)) #undef DEF_METHOD @@ -2893,10 +2898,11 @@ DEF_METHOD(Shiftx, sig_a.size(), ID($shiftx)) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, sig_a.size()); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(!_pmux ? NEW_ID : NEW_ID4_SUFFIX("y"), sig_a.size()); \ add ## _func(name, sig_a, sig_b, sig_s, sig_y, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming (NOT IMPROVED FOR MUX!) DEF_METHOD(Mux, ID($mux), 0) DEF_METHOD(Bwmux, ID($bwmux), 0) DEF_METHOD(Pmux, ID($pmux), 1) @@ -2914,10 +2920,11 @@ DEF_METHOD(Pmux, ID($pmux), 1) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_s, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, _demux ? sig_a.size() << sig_s.size() : sig_a.size() >> sig_s.size()); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), _demux ? sig_a.size() << sig_s.size() : sig_a.size() >> sig_s.size()); \ add ## _func(name, sig_a, sig_s, sig_y, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(Bmux, ID($bmux), 0) DEF_METHOD(Demux, ID($demux), 1) #undef DEF_METHOD @@ -2933,10 +2940,11 @@ DEF_METHOD(Demux, ID($demux), 1) return cell; \ } \ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_s, const std::string &src) { \ - RTLIL::SigSpec sig_y = addWire(NEW_ID, sig_a.size()); \ + Module *module = this; \ + RTLIL::SigSpec sig_y = addWire(NEW_ID4_SUFFIX("y"), sig_a.size()); \ add ## _func(name, sig_a, sig_s, sig_y, src); \ return sig_y; \ - } + } // SILIMATE: Improve the naming DEF_METHOD(Bweqx, ID($bweqx)) #undef DEF_METHOD @@ -2949,10 +2957,11 @@ DEF_METHOD(Bweqx, ID($bweqx)) return cell; \ } \ RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const std::string &src) { \ - RTLIL::SigBit sig2 = addWire(NEW_ID); \ + Module *module = this; \ + RTLIL::SigBit sig2 = addWire(NEW_ID4_SUFFIX(#_P2)); \ add ## _func(name, sig1, sig2, src); \ return sig2; \ - } + } // SILIMATE: Improve the naming #define DEF_METHOD_3(_func, _type, _P1, _P2, _P3) \ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const std::string &src) { \ RTLIL::Cell *cell = addCell(name, _type); \ @@ -2963,11 +2972,12 @@ DEF_METHOD(Bweqx, ID($bweqx)) return cell; \ } \ RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const std::string &src) { \ - RTLIL::SigBit sig3 = addWire(NEW_ID); \ + Module *module = this; \ + RTLIL::SigBit sig3 = addWire(NEW_ID4_SUFFIX(#_P3)); \ add ## _func(name, sig1, sig2, sig3, src); \ return sig3; \ - } -#define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4) \ + } // SILIMATE: Improve the naming +#define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4, _mux) \ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const std::string &src) { \ RTLIL::Cell *cell = addCell(name, _type); \ cell->setPort("\\" #_P1, sig1); \ @@ -2978,10 +2988,11 @@ DEF_METHOD(Bweqx, ID($bweqx)) return cell; \ } \ RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const std::string &src) { \ - RTLIL::SigBit sig4 = addWire(NEW_ID); \ + Module *module = this; \ + RTLIL::SigBit sig4 = addWire(_mux ? NEW_ID : NEW_ID4_SUFFIX(#_P4)); \ add ## _func(name, sig1, sig2, sig3, sig4, src); \ return sig4; \ - } + } // SILIMATE: Improve the naming (NOT IMPROVED AT ALL!) #define DEF_METHOD_5(_func, _type, _P1, _P2, _P3, _P4, _P5) \ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const RTLIL::SigBit &sig5, const std::string &src) { \ RTLIL::Cell *cell = addCell(name, _type); \ @@ -2994,10 +3005,11 @@ DEF_METHOD(Bweqx, ID($bweqx)) return cell; \ } \ RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const std::string &src) { \ - RTLIL::SigBit sig5 = addWire(NEW_ID); \ + Module *module = this; \ + RTLIL::SigBit sig5 = addWire(NEW_ID4_SUFFIX("sig5")); \ add ## _func(name, sig1, sig2, sig3, sig4, sig5, src); \ return sig5; \ - } + } // SILIMATE: Improve the naming DEF_METHOD_2(BufGate, ID($_BUF_), A, Y) DEF_METHOD_2(NotGate, ID($_NOT_), A, Y) DEF_METHOD_3(AndGate, ID($_AND_), A, B, Y) @@ -3008,10 +3020,10 @@ DEF_METHOD_3(XorGate, ID($_XOR_), A, B, Y) DEF_METHOD_3(XnorGate, ID($_XNOR_), A, B, Y) DEF_METHOD_3(AndnotGate, ID($_ANDNOT_), A, B, Y) DEF_METHOD_3(OrnotGate, ID($_ORNOT_), A, B, Y) -DEF_METHOD_4(MuxGate, ID($_MUX_), A, B, S, Y) -DEF_METHOD_4(NmuxGate, ID($_NMUX_), A, B, S, Y) -DEF_METHOD_4(Aoi3Gate, ID($_AOI3_), A, B, C, Y) -DEF_METHOD_4(Oai3Gate, ID($_OAI3_), A, B, C, Y) +DEF_METHOD_4(MuxGate, ID($_MUX_), A, B, S, Y, 1) +DEF_METHOD_4(NmuxGate, ID($_NMUX_), A, B, S, Y, 0) +DEF_METHOD_4(Aoi3Gate, ID($_AOI3_), A, B, C, Y, 0) +DEF_METHOD_4(Oai3Gate, ID($_OAI3_), A, B, C, Y, 0) DEF_METHOD_5(Aoi4Gate, ID($_AOI4_), A, B, C, D, Y) DEF_METHOD_5(Oai4Gate, ID($_OAI4_), A, B, C, D, Y) #undef DEF_METHOD_2 @@ -3603,7 +3615,8 @@ RTLIL::Cell* RTLIL::Module::addAnyinit(RTLIL::IdString name, const RTLIL::SigSpe RTLIL::SigSpec RTLIL::Module::Anyconst(RTLIL::IdString name, int width, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, width); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), width); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($anyconst)); cell->setParam(ID::WIDTH, width); cell->setPort(ID::Y, sig); @@ -3613,7 +3626,8 @@ RTLIL::SigSpec RTLIL::Module::Anyconst(RTLIL::IdString name, int width, const st RTLIL::SigSpec RTLIL::Module::Anyseq(RTLIL::IdString name, int width, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, width); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), width); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($anyseq)); cell->setParam(ID::WIDTH, width); cell->setPort(ID::Y, sig); @@ -3623,7 +3637,8 @@ RTLIL::SigSpec RTLIL::Module::Anyseq(RTLIL::IdString name, int width, const std: RTLIL::SigSpec RTLIL::Module::Allconst(RTLIL::IdString name, int width, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, width); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), width); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($allconst)); cell->setParam(ID::WIDTH, width); cell->setPort(ID::Y, sig); @@ -3633,7 +3648,8 @@ RTLIL::SigSpec RTLIL::Module::Allconst(RTLIL::IdString name, int width, const st RTLIL::SigSpec RTLIL::Module::Allseq(RTLIL::IdString name, int width, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, width); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), width); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($allseq)); cell->setParam(ID::WIDTH, width); cell->setPort(ID::Y, sig); @@ -3643,7 +3659,8 @@ RTLIL::SigSpec RTLIL::Module::Allseq(RTLIL::IdString name, int width, const std: RTLIL::SigSpec RTLIL::Module::Initstate(RTLIL::IdString name, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y")); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($initstate)); cell->setPort(ID::Y, sig); cell->set_src_attribute(src); @@ -3652,7 +3669,8 @@ RTLIL::SigSpec RTLIL::Module::Initstate(RTLIL::IdString name, const std::string RTLIL::SigSpec RTLIL::Module::SetTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_s, const RTLIL::SigSpec &sig_c, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, sig_a.size()); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), sig_a.size()); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($set_tag)); cell->parameters[ID::WIDTH] = sig_a.size(); cell->parameters[ID::TAG] = tag; @@ -3679,7 +3697,8 @@ RTLIL::Cell* RTLIL::Module::addSetTag(RTLIL::IdString name, const std::string &t RTLIL::SigSpec RTLIL::Module::GetTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, sig_a.size()); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), sig_a.size()); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($get_tag)); cell->parameters[ID::WIDTH] = sig_a.size(); cell->parameters[ID::TAG] = tag; @@ -3703,7 +3722,8 @@ RTLIL::Cell* RTLIL::Module::addOverwriteTag(RTLIL::IdString name, const std::str RTLIL::SigSpec RTLIL::Module::OriginalTag(RTLIL::IdString name, const std::string &tag, const RTLIL::SigSpec &sig_a, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, sig_a.size()); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), sig_a.size()); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($original_tag)); cell->parameters[ID::WIDTH] = sig_a.size(); cell->parameters[ID::TAG] = tag; @@ -3715,7 +3735,8 @@ RTLIL::SigSpec RTLIL::Module::OriginalTag(RTLIL::IdString name, const std::strin RTLIL::SigSpec RTLIL::Module::FutureFF(RTLIL::IdString name, const RTLIL::SigSpec &sig_e, const std::string &src) { - RTLIL::SigSpec sig = addWire(NEW_ID, sig_e.size()); + Module *module = this; // SILIMATE: Improve the naming + RTLIL::SigSpec sig = addWire(NEW_ID4_SUFFIX("y"), sig_e.size()); // SILIMATE: Improve the naming Cell *cell = addCell(name, ID($future_ff)); cell->parameters[ID::WIDTH] = sig_e.size(); cell->setPort(ID::A, sig_e); @@ -3901,6 +3922,8 @@ void RTLIL::Module::bufNormalize() SigMap sigmap(this); new_connections({}); + Module *module = this; // SILIMATE: Improve the naming + for (auto &key : queue) { Cell *cell = key.first; @@ -3923,7 +3946,7 @@ void RTLIL::Module::bufNormalize() for (auto &chunk : sig.chunks()) if (chunk.wire) outWires.insert(chunk.wire); - Wire *wire = addWire(NEW_ID, GetSize(sig)); + Wire *wire = addWire(NEW_ID2_SUFFIX(portname.str()), GetSize(sig)); // SILIMATE: Improve the naming sigmap.add(sig, wire); cell->setPort(portname, wire); @@ -3936,7 +3959,7 @@ void RTLIL::Module::bufNormalize() for (int i = 0; i < GetSize(wire); i++) if (insig[i] == outsig[i]) insig[i] = State::Sx; - addBuf(NEW_ID, insig, outsig); + addBuf(NEW_ID4_SUFFIX("buf"), insig, outsig); // SILIMATE: Improve the naming } } } diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index 9d1fac622..9678ff965 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -340,6 +340,8 @@ RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std: #define NEW_ID3_SUFFIX(suffix) module->uniquify(cell_name.str() + "_" + suffix) #define NEW_ID4 module->uniquify(name.str()) #define NEW_ID4_SUFFIX(suffix) module->uniquify(name.str() + "_" + suffix) +#define NEW_ID5 module->uniquify(name) +#define NEW_ID5_SUFFIX(suffix) module->uniquify(name + "_" + suffix) #define NEW_MEM_ID_SUFFIX(suffix) mem.mem ? module->uniquify(stringf("%s_%s", mem.mem->name.c_str(), suffix)) : module->uniquify(stringf("\\mem_%s", suffix)) #define NEW_BLIF_ID IdString(stringf("\\boolopt_%d", autoidx++))