3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-19 12:23:39 +00:00

Reapply "Reapply "Reapply "Add fanoutlimit"""

This reverts commit e50bca4d98.
This commit is contained in:
Akash Levy 2024-08-27 17:36:34 -07:00
parent e50bca4d98
commit cf6c4ec6e4
3 changed files with 32 additions and 9 deletions

View file

@ -67,7 +67,7 @@ struct SplitfanoutWorker
} }
} }
int split(Cell *cell) int split(Cell *cell, int fanoutlimit)
{ {
// Get output signal/port // Get output signal/port
SigSpec outsig; SigSpec outsig;
@ -93,8 +93,8 @@ struct SplitfanoutWorker
} }
} }
// Skip if output signal has only one user // Skip if output signal has only one user or too many users
if (GetSize(bit_users) <= 1) if (GetSize(bit_users) <= 1 || GetSize(bit_users) > fanoutlimit)
return 0; return 0;
// Iterate over bit users and create a new cell for each one // Iterate over bit users and create a new cell for each one
@ -148,7 +148,7 @@ struct SplitfanoutPass : public Pass {
{ {
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n"); log("\n");
log(" splitfanout [selection]\n"); log(" splitfanout [options] [selection]\n");
log("\n"); log("\n");
log("This command copies selected cells with >1 fanout into cells with fanout 1. It\n"); log("This command copies selected cells with >1 fanout into cells with fanout 1. It\n");
log("is effectively the opposite of the opt_merge pass.\n"); log("is effectively the opposite of the opt_merge pass.\n");
@ -156,16 +156,23 @@ struct SplitfanoutPass : public Pass {
log("This command operates only on cells with 1 output and no \"bit split\" on that\n"); log("This command operates only on cells with 1 output and no \"bit split\" on that\n");
log("output.\n"); log("output.\n");
log("\n"); log("\n");
log(" -fanoutlimit\n");
log(" fanout limit for splitfanout, beyond which no split (default: 10)\n");
log("\n");
} }
void execute(std::vector<std::string> args, RTLIL::Design *design) override void execute(std::vector<std::string> args, RTLIL::Design *design) override
{ {
int fanoutlimit = 10;
log_header(design, "Executing SPLITFANOUT pass (splitting up cells with >1 fanout into copies).\n"); log_header(design, "Executing SPLITFANOUT pass (splitting up cells with >1 fanout into copies).\n");
size_t argidx; size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++) for (argidx = 1; argidx < args.size(); argidx++)
{ {
// No options currently. When adding in the future make sure to update docstring with [options] if ((args[argidx] == "-fanoutlimit") && ((argidx + 1) < args.size())) {
break; fanoutlimit = std::stoi(args[++argidx]);
continue;
}
} }
extra_args(args, argidx, design); extra_args(args, argidx, design);
@ -178,7 +185,7 @@ struct SplitfanoutPass : public Pass {
SplitfanoutWorker worker(module); SplitfanoutWorker worker(module);
bool did_something = false; bool did_something = false;
for (auto cell : module->selected_cells()) { for (auto cell : module->selected_cells()) {
int n = worker.split(cell); int n = worker.split(cell, fanoutlimit);
did_something |= (n != 0); did_something |= (n != 0);
count_split_pre += (n != 0); count_split_pre += (n != 0);
count_split_post += n; count_split_post += n;

View file

@ -344,6 +344,9 @@ struct MuxpackPass : public Pass {
log(" -splitfanout\n"); log(" -splitfanout\n");
log(" run splitfanout pass first\n"); log(" run splitfanout pass first\n");
log("\n"); log("\n");
log(" -fanoutlimit\n");
log(" fanout limit for splitfanout, beyond which no split (default: 10)\n");
log("\n");
log(" -assume_excl\n"); log(" -assume_excl\n");
log(" assume mutually exclusive constraint when packing (may result in inequivalence)\n"); log(" assume mutually exclusive constraint when packing (may result in inequivalence)\n");
log("\n"); log("\n");
@ -352,6 +355,7 @@ struct MuxpackPass : public Pass {
{ {
bool splitfanout = false; bool splitfanout = false;
bool assume_excl = false; bool assume_excl = false;
int fanoutlimit = 10;
log_header(design, "Executing MUXPACK pass ($mux cell cascades to $pmux).\n"); log_header(design, "Executing MUXPACK pass ($mux cell cascades to $pmux).\n");
@ -362,6 +366,10 @@ struct MuxpackPass : public Pass {
splitfanout = true; splitfanout = true;
continue; continue;
} }
if ((args[argidx] == "-fanoutlimit") && ((argidx + 1) < args.size())) {
fanoutlimit = std::stoi(args[++argidx]);
continue;
}
if (args[argidx] == "-assume_excl") { if (args[argidx] == "-assume_excl") {
assume_excl = true; assume_excl = true;
continue; continue;
@ -371,7 +379,7 @@ struct MuxpackPass : public Pass {
extra_args(args, argidx, design); extra_args(args, argidx, design);
if (splitfanout) if (splitfanout)
Pass::call(design, "splitfanout t:$mux t:$pmux"); Pass::call(design, stringf("splitfanout -fanoutlimit %d t:$mux t:$pmux", fanoutlimit));
int mux_count = 0; int mux_count = 0;
int pmux_count = 0; int pmux_count = 0;

View file

@ -314,9 +314,13 @@ struct OptBalanceTreePass : public Pass {
log(" -splitfanout\n"); log(" -splitfanout\n");
log(" run splitfanout pass first\n"); log(" run splitfanout pass first\n");
log("\n"); log("\n");
log(" -fanoutlimit\n");
log(" fanout limit for splitfanout, beyond which no split (default: 10)\n");
log("\n");
} }
void execute(std::vector<std::string> args, RTLIL::Design *design) override { void execute(std::vector<std::string> args, RTLIL::Design *design) override {
bool splitfanout = false; bool splitfanout = false;
int fanoutlimit = 10;
log_header(design, "Executing OPT_BALANCE_TREE pass (cell cascades to trees).\n"); log_header(design, "Executing OPT_BALANCE_TREE pass (cell cascades to trees).\n");
@ -327,13 +331,17 @@ struct OptBalanceTreePass : public Pass {
splitfanout = true; splitfanout = true;
continue; continue;
} }
if ((args[argidx] == "-fanoutlimit") && ((argidx + 1) < args.size())) {
fanoutlimit = std::stoi(args[++argidx]);
continue;
}
break; break;
} }
extra_args(args, argidx, design); extra_args(args, argidx, design);
// Run splitfanout pass first // Run splitfanout pass first
if (splitfanout) if (splitfanout)
Pass::call(design, "splitfanout t:$and t:$or t:$xor t:$add t:$mul"); Pass::call(design, stringf("splitfanout -fanoutlimit %d t:$and t:$or t:$xor t:$add t:$mul", fanoutlimit));
// Count of all cells that were packed // Count of all cells that were packed
dict<IdString, int> cell_count; dict<IdString, int> cell_count;