Skip to content

opt -max_iter#166

Merged
akashlevy merged 3 commits into
mainfrom
opt_max_iters
May 26, 2026
Merged

opt -max_iter#166
akashlevy merged 3 commits into
mainfrom
opt_max_iters

Conversation

@akashlevy
Copy link
Copy Markdown

If your work is part of a larger effort, please discuss your general plans on Discourse first to align your vision with maintainers.

What are the reasons/motivation for this change?

Explain how this is achieved.

Make sure your change comes with tests. If not possible, share how a reviewer might evaluate it.

These template prompts can be deleted when you're done responding to them.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 26, 2026

Greptile Summary

This PR adds a -max_iter <number> option to the opt pass that caps the number of optimization loop iterations, defaulting to 20 (with 0 meaning unlimited). It also fixes a pre-existing bug where the finish log message always said "Finished fast OPT passes." regardless of mode.

  • Behavioral change: max_iter now defaults to 20, whereas previously opt ran until convergence with no iteration limit. Designs that previously needed more than 20 iterations will now stop early with only a log-header notification and no hard warning or non-zero exit.
  • atoi for argument parsing (line 165): invalid non-numeric input silently becomes 0 (unlimited) rather than producing an error message.
  • Double blank line in the help block (lines 72–73): an extra log(\"\ \") produces an unnecessary gap in --help output.

Confidence Score: 3/5

The PR introduces a default iteration cap of 20 on a pass that previously ran until convergence, which is a silent behavioral change for existing users whose designs may need more iterations.

The default of 20 iterations changes the long-standing unconditional convergence behavior of opt. Any design that previously required more than 20 loop passes will now stop early; the only signal is a log header, with no hard warning or error. This could go unnoticed in automated flows and leave netlists in a less-optimised state without the user realising it.

passes/opt/opt.cc — specifically the default value of max_iter and the absence of a louder warning when the limit is reached.

Important Files Changed

Filename Overview
passes/opt/opt.cc Adds -max_iter option to the opt pass with a default of 20; introduces a breaking behavioral change (previously unlimited iterations), uses atoi without error checking, and contains a redundant opt_clean call in the fast_mode max-iter exit path.
docs/source/code_examples/macro_commands/opt.ys Documentation example updated to reflect the new -max_iter loop-termination condition; change is accurate and consistent with the implementation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[opt execute] --> B{fast_mode?}

    B -- yes --> FM_START[iter = 0]
    FM_START --> FM_LOOP[iter++\nopt_expr\nopt_merge\nscratchpad_unset\nopt_dff]
    FM_LOOP --> FM_CHK{did_something?}
    FM_CHK -- no --> FM_POST[opt_clean after loop]
    FM_CHK -- yes --> FM_CLEAN[opt_hier / opt_boundary\nopt_clean]
    FM_CLEAN --> FM_MAX{max_iter > 0\nand iter >= max_iter?}
    FM_MAX -- yes --> FM_REACHED[reached_max_iter = true]
    FM_REACHED --> FM_POST
    FM_MAX -- no --> FM_LOG[log Rerunning...]
    FM_LOG --> FM_LOOP
    FM_POST --> END

    B -- no --> NF_INIT[opt_expr\nopt_merge -nomux\niter = 0]
    NF_INIT --> NF_LOOP[iter++\nscratchpad_unset\nopt_muxtree/reduce/merge\nopt_share/dff/hier/boundary\nopt_clean\nopt_expr]
    NF_LOOP --> NF_CHK{did_something?}
    NF_CHK -- no --> END
    NF_CHK -- yes --> NF_MAX{max_iter > 0\nand iter >= max_iter?}
    NF_MAX -- yes --> NF_REACHED[reached_max_iter = true]
    NF_REACHED --> END
    NF_MAX -- no --> NF_LOG[log Rerunning...]
    NF_LOG --> NF_LOOP

    END[design.optimize/sort/check\nlog Finished OPT passes]
Loading

Reviews (1): Last reviewed commit: "opt -max_iter" | Re-trigger Greptile

Comment thread passes/opt/opt.cc
Comment thread passes/opt/opt.cc
Comment thread passes/opt/opt.cc Outdated
akashlevy and others added 2 commits May 26, 2026 06:38
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@akashlevy akashlevy merged commit e8cfc9b into main May 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant