From ecd2ac43027889e3561d65288b64f6262b68347a Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Wed, 26 Feb 2025 16:51:39 -0800 Subject: [PATCH] fixes --- passes/silimate/annotate_cell_fanout.cc | 87 ++++++++++++++++--------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/passes/silimate/annotate_cell_fanout.cc b/passes/silimate/annotate_cell_fanout.cc index 4a1ddc98f..dd10c123b 100644 --- a/passes/silimate/annotate_cell_fanout.cc +++ b/passes/silimate/annotate_cell_fanout.cc @@ -68,11 +68,11 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dictname.c_str() << std::endl; - std::cout << "Fanout: " << fanout << std::endl; + std::cout << "Nothing to do for: " << cell->name.c_str() << std::endl; + std::cout << "Fanout: " << fanout << std::endl; return; // No need to insert buffers } else { - std::cout << "Something to do for: " << cell->name.c_str() << std::endl; + std::cout << "Something to do for: " << cell->name.c_str() << std::endl; std::cout << "Fanout: " << fanout << std::endl; } @@ -83,19 +83,17 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict buffer_outputs; - std::vector buffers; - std::cout << "HERE1\n" << std::flush; + std::vector buffers; std::cout << "CELL: " << cell->name.c_str() << "\n" << std::flush; RTLIL::SigSpec cellOutSig; for (auto &conn : cell->connections()) { - IdString portName = conn.first; - RTLIL::SigSpec actual = conn.second; - if (cell->output(portName)) { - cellOutSig = sigmap(actual); - break; - } + IdString portName = conn.first; + RTLIL::SigSpec actual = conn.second; + if (cell->output(portName)) { + cellOutSig = sigmap(actual); + break; + } } - std::cout << "HERE2\n" << std::flush; for (int i = 0; i < num_buffers; ++i) { RTLIL::Cell *buffer = module->addCell(NEW_ID2_SUFFIX("fbuf"), ID($buf)); // Assuming BUF is defined RTLIL::SigSpec buffer_output = module->addWire(NEW_ID2_SUFFIX("fbuf")); @@ -104,35 +102,66 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict cells = sig2CellsInFanout[cellOutSig]; - std::cout << "Lookup OK\n" << std::flush; int indexCurrentBuffer = 0; int indexFanout = 0; - std::map bufferActualFanout; + std::map bufferActualFanout; for (Cell *c : cells) { for (auto &conn : c->connections()) { IdString portName = conn.first; RTLIL::SigSpec actual = conn.second; if (c->input(portName)) { - if (sigmap(actual) == cellOutSig) { - c->setPort(portName, buffer_outputs[indexCurrentBuffer]); - sig2CellsInFanout[sigmap(buffer_outputs[indexCurrentBuffer])].insert(c); - indexFanout++; - bufferActualFanout[buffers[indexCurrentBuffer]] = indexFanout; - if (indexFanout >= max_output_per_buffer) { - indexFanout = 0; - indexCurrentBuffer++; + if (actual.is_chunk()) { + if (sigmap(actual) == cellOutSig) { + std::cout << "vector size: " << buffer_outputs.size() << std::endl; + std::cout << "index : " << indexCurrentBuffer << std::endl; + c->setPort(portName, buffer_outputs[indexCurrentBuffer]); + sig2CellsInFanout[sigmap(buffer_outputs[indexCurrentBuffer])].insert(c); + indexFanout++; + bufferActualFanout[buffers[indexCurrentBuffer]] = indexFanout; + if (indexFanout >= max_output_per_buffer) { + indexFanout = 0; + indexCurrentBuffer++; + } + break; + } + } else { + bool match = false; + for (SigChunk chunk : actual.chunks()) { + if (sigmap(SigSpec(chunk)) == cellOutSig) { + match = true; + break; + } + } + if (match) { + std::vector newChunks; + for (SigChunk chunk : actual.chunks()) { + if (sigmap(SigSpec(chunk)) == cellOutSig) { + newChunks.push_back(buffer_outputs[indexCurrentBuffer].as_wire()); + } else { + newChunks.push_back(chunk); + } + } + c->setPort(portName, newChunks); + sig2CellsInFanout[sigmap(buffer_outputs[indexCurrentBuffer])].insert(c); + indexFanout++; + bufferActualFanout[buffers[indexCurrentBuffer]] = indexFanout; + if (indexFanout >= max_output_per_buffer) { + indexFanout = 0; + indexCurrentBuffer++; + } + break; } } } } } - + // Recursively fix the fanout of the newly created buffers - for (std::map::iterator itr = bufferActualFanout.begin(); itr != bufferActualFanout.end(); itr++) { + for (std::map::iterator itr = bufferActualFanout.begin(); itr != bufferActualFanout.end(); itr++) { if (itr->second == 1) { - std::cout << "Buffer of 1" << std::endl; + // Remove newly created buffers with a fanout of 1 + std::cout << "Buffer of 1" << std::endl; for (Cell *c : cells) { for (auto &conn : c->connections()) { IdString portName = conn.first; @@ -142,7 +171,7 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dictsetPort(portName, cellOutSig); std::cout << "Remove buffer of 1" << std::endl; module->remove(buffers[indexCurrentBuffer]); - //module->remove({buffer_outputs[indexCurrentBuffer].as_wire()}); + // module->remove({buffer_outputs[indexCurrentBuffer].as_wire()}); break; } } @@ -154,7 +183,7 @@ void fixfanout(RTLIL::Module *module, SigMap &sigmap, dict>& sig2CellsInFanout, dict &cellFanout) +void calculateFanout(RTLIL::Module *module, SigMap &sigmap, dict> &sig2CellsInFanout, dict &cellFanout) { // Precompute cell output sigspec to cell map dict> sig2CellsInFanin; @@ -234,7 +263,7 @@ struct AnnotateCellFanout : public ScriptPass { break; } extra_args(args, argidx, design); - if (limit < 2) { + if ((limit != -1) && (limit < 2)) { log_error("Fanout cannot be limited to less than 2\n"); return; }