Skip to content

chore(ssa refactor): Add pass to simplify the control flow graph#1373

Merged
joss-aztec merged 5 commits intomasterfrom
jf/simplify-cfg
May 22, 2023
Merged

chore(ssa refactor): Add pass to simplify the control flow graph#1373
joss-aztec merged 5 commits intomasterfrom
jf/simplify-cfg

Conversation

@jfecher
Copy link
Copy Markdown
Contributor

@jfecher jfecher commented May 18, 2023

Related issue(s)

Resolves #

Description

Summary of changes

Adds a simple pass to simplify a function's CFG by inlining a block into its predecessor if that block only has 1 predecessor and that predecessor's only successor is that block. Example before this pass:

fn main {
  b0():
    jmp b1(Field 7)
  b1(v0: Field):
    jmp b2(v0)
  b2(v1: Field):
    return v1
}

And after the pass:

fn main {
  b0():
    return Field 7
}

In the future this pass is expected to perform some other quick tasks like unreachable block elimination. I favored getting this PR out earlier and smaller so that each extra feature could be a separate, easier to review PR.
This pass' name and functionality was inspired by llvm's pass of the same name: https://llvm.org/docs/Passes.html#simplifycfg-simplify-the-cfg.

Dependency additions / changes

Test additions / changes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

  • This PR requires documentation updates when merged.

Additional context

@jfecher jfecher requested review from joss-aztec and kevaundray May 18, 2023 17:07
Comment thread crates/noirc_evaluator/src/ssa_refactor/ir/dfg.rs
Copy link
Copy Markdown
Contributor

@joss-aztec joss-aztec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code seems to imply that there should be some sort of try_inline_into_predecessor failure handling, but currently ignores it. Were you maybe intending to add some info logging?

Comment thread crates/noirc_evaluator/src/ssa_refactor/opt/simplify_cfg.rs Outdated
@joss-aztec joss-aztec enabled auto-merge May 22, 2023 16:16
@joss-aztec joss-aztec added this pull request to the merge queue May 22, 2023
Merged via the queue into master with commit c4d8858 May 22, 2023
@joss-aztec joss-aztec deleted the jf/simplify-cfg branch May 22, 2023 17:41
TomAFrench added a commit that referenced this pull request May 24, 2023
* master:
  chore(ssa refactor): Add loop unrolling pass (#1364)
  chore: Add terms added in ssa refactor to `cspell` (#1385)
  chore(ssa refactor): Optimize constant `jmpif`s into `jmp`s (#1374)
  feat: Allow warnings by default (#1383)
  chore(github): Update GitHub Pull Request Template (#1370)
  chore(github): Update GitHub Bug Report Template (#1368)
  chore(ssa refactor): Update mem2reg pass to work with multiple functions and blocks (#1375)
  chore(ssa refactor): Add pass to simplify the control flow graph (#1373)
  chore(github): Update GitHub Feature Request Template (#1369)
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.

2 participants