Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/code_examples/macro_commands/opt.ys
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ do
opt_boundary (-boundary only)
opt_clean
opt_expr
while <changed design>
while <changed design in opt_dff> (up to -max_iter iterations)
29 changes: 26 additions & 3 deletions passes/opt/opt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct OptPass : public Pass {
log(" opt_boundary (-boundary only)\n");
log(" opt_clean [-purge]\n");
log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-noclkinv] [-fine] [-full] [-keepdc]\n");
log(" while <changed design>\n");
log(" while <changed design> (up to -max_iter iterations)\n");
log("\n");
log("When called with -fast the following script is used instead:\n");
log("\n");
Expand All @@ -61,11 +61,14 @@ struct OptPass : public Pass {
log(" opt_hier (-hier only)\n");
log(" opt_boundary (-boundary only)\n");
log(" opt_clean [-purge]\n");
log(" while <changed design in opt_dff>\n");
log(" while <changed design in opt_dff> (up to -max_iter iterations)\n");
log("\n");
log("Note: Options in square brackets (such as [-keepdc]) are passed through to\n");
log("the opt_* commands when given to 'opt'.\n");
log("\n");
log(" -max_iter <number>\n");
log(" only run the specified number of iterations.\n");
log(" default: 20. use 0 for unlimited.\n");
log("\n");
}
void execute(std::vector<std::string> args, RTLIL::Design *design) override
Expand All @@ -80,6 +83,8 @@ struct OptPass : public Pass {
bool noff_mode = false;
bool hier_mode = false;
bool boundary_mode = false;
int max_iter = 20;
Comment thread
akashlevy marked this conversation as resolved.
bool reached_max_iter = false;

log_header(design, "Executing OPT pass (performing simple optimizations).\n");
log_push();
Expand Down Expand Up @@ -155,13 +160,19 @@ struct OptPass : public Pass {
boundary_mode = true;
continue;
}
if (args[argidx] == "-max_iter" && argidx+1 < args.size()) {
max_iter = atoi(args[++argidx].c_str());
continue;
Comment thread
akashlevy marked this conversation as resolved.
}
break;
}
extra_args(args, argidx, design);

if (fast_mode)
{
int iter = 0;
while (1) {
iter++;
Pass::call(design, "opt_expr" + opt_expr_args);
Pass::call(design, "opt_merge" + opt_merge_args);
design->scratchpad_unset("opt.did_something");
Expand All @@ -174,6 +185,10 @@ struct OptPass : public Pass {
if (boundary_mode)
Pass::call(design, "opt_boundary");
Pass::call(design, "opt_clean" + opt_clean_args);
if (max_iter > 0 && iter >= max_iter) {
reached_max_iter = true;
break;
}
log_header(design, "Rerunning OPT passes. (Removed registers in this run.)\n");
}
Pass::call(design, "opt_clean" + opt_clean_args);
Expand All @@ -182,7 +197,9 @@ struct OptPass : public Pass {
{
Pass::call(design, "opt_expr" + opt_expr_args);
Pass::call(design, "opt_merge -nomux" + opt_merge_args);
int iter = 0;
while (1) {
iter++;
design->scratchpad_unset("opt.did_something");
Pass::call(design, "opt_muxtree");
Pass::call(design, "opt_reduce" + opt_reduce_args);
Expand All @@ -199,6 +216,10 @@ struct OptPass : public Pass {
Pass::call(design, "opt_expr" + opt_expr_args);
if (design->scratchpad_get_bool("opt.did_something") == false)
break;
if (max_iter > 0 && iter >= max_iter) {
reached_max_iter = true;
break;
}
log_header(design, "Rerunning OPT passes. (Maybe there is more to do..)\n");
}
}
Expand All @@ -207,7 +228,9 @@ struct OptPass : public Pass {
design->sort();
design->check();

log_header(design, "Finished fast OPT passes.%s\n", fast_mode ? "" : " (There is nothing left to do.)");
const char *done_reason = reached_max_iter ? " (Reached maximum number of iterations.)" :
(fast_mode ? "" : " (There is nothing left to do.)");
log_header(design, "Finished %sOPT passes.%s\n", fast_mode ? "fast " : "", done_reason);
log_pop();
}
} OptPass;
Expand Down
Loading