Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ssa): Post dominator tree #7595

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Mar 5, 2025

Description

Problem*

Resolves #7571

Summary*

This PR is mostly contained to tests as it will be the basis for further control dependence analysis.

  1. Logic for reversing the CFG
  2. Switched post order computation to use the CFG rather than the function definition. The major difference here is that the CFG store's its successors in an ordered set, while the function's successors are specified as written in the SSA (e.g. the else block will follow the then block).
  3. ID normalization had to be updated to account for the changes to the post order to pass CI. When we populate blocks in normalization, we do it based off of the ordered set of all function blocks. Blocks used to be populated by following the reverse post order (RPO).

Step 3 being necessary can be illustrated by the following example (test_jmpif under parser/tests.rs):

acir(inline) fn main f0 {
    b0(v0: Field):
      jmpif v0 then: b2, else: b1
    b1():
      return
    b2():
      return
  }

The RPO for the above function (following this PR's CFG updates) is [0, 2, 1]. This means during normalization b2 will map to b1. Trying to call the assert_ssa_roundtrip test method on this code will fail. This should not happen. In fact, having to update normalization to account for the new RPO exposed a greater error in our post-order calculation.

On master the above program only works with the specified terminator. Switching b2 and b1, jmpif v0 then: b1, else: b2, will also fail to perform an SSA roundtrip. This discrepancy is due to the current post order computation using successors ordered as specified in the SSA. Specifying successors in an ordered set lets us more accurately test SSA as the ordering of terminator arguments no longer determines our resulting SSA. I have expanded test_jmpif to account for the above.

  1. Add a test to show using the the reversed CFG and updated post order provides an accurate post-dominator tree

Additional Context

The new reverse and with_function_post_dom methods are only used in tests. The #[cfg(test)] attribute will be removed as these methods are used by later work.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm requested a review from a team March 5, 2025 17:25
@vezenovm vezenovm marked this pull request as draft March 5, 2025 18:37
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 853a355 Previous: 1fa0dd9 Ratio
AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 51 s 42 s 1.21

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@vezenovm vezenovm marked this pull request as ready for review March 10, 2025 18:44
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.

Post-Dominator Tree
1 participant