-
Notifications
You must be signed in to change notification settings - Fork 225
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 refactor): dominator tree #1253
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some preliminary comments
Last, | ||
} | ||
|
||
// Calculates the post-order of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting the unfinished sentence here (for when it comes out of draft)
@@ -0,0 +1,136 @@ | |||
use std::collections::HashSet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you put a paragraph at the top of this using //! ...
to explain what post-order is and why it is needed?
@@ -0,0 +1,443 @@ | |||
use std::{cmp::Ordering, collections::HashMap}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here for dominator tree -- ie why it is needed and other useful information that would help someone understand the codebase. See at the top of some of Cranelifts files for inspiration on how this is done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good so far. The tests looks good as well.
DomNode { reverse_post_order_idx: 0, immediate_dominator: None }, | ||
); | ||
for (i, &block_id) in entry_free_post_order.iter().rev().enumerate() { | ||
// Indices have been displaced by 1 by to the removal of the entry node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here, "by 1 by to the removal"
|
||
use crate::ssa_refactor::ir::{basic_block::BasicBlockId, function::Function}; | ||
|
||
/// DFT stack state marker for computing the cfg post-order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we spell out the acronym here?
// Stack successors for visiting. Because items are taken from the top of the | ||
// stack, we push the item that's due for a visit first to the top. | ||
for successor_id in | ||
func.dfg[block_id].successors().collect::<Vec<_>>().into_iter().rev() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
successors
should already be an iterator so we should be able to do:
func.dfg[block_id].successors().rev()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add DoubleEndedIterator
to successors
return type.
let cfg = ControlFlowGraph::with_function(&func); | ||
let post_order = PostOrder::with_function(&func); | ||
let dom_tree = DominatorTree::with_cfg_and_post_order(&cfg, &post_order); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is a common operation. Are we expected to keep around the cfg and post_order blocks without the dominator tree? If not we can have a helper function to create the first two and pass them into the third instead of creating all three separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I'd come across a use case of post order independent of dom trees - but possibly I imagined it. What cranelift does is to have the dom tree compute and take ownership of the post order. It then has an accessor for when the two are used in conjunction. Would that be preferred?
Either way I'll add a helper for the cfg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not my imagination - cranelift's dead code elimination pass iterates over post-order without any need for dom trees.
immediate_dominator: Option<BasicBlockId>, | ||
} | ||
|
||
impl DomNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're spelling out DominatorTree I think we should spell out DominatorNode or DominatorTreeNode as well.
- Comment tweaks - rm unneeded collect iter into vec - clippy changes - DominatorTree::with_function helper - rename DomNode DominatorTreeNode
* Implement first-class functions * Update crates/noirc_evaluator/src/ssa_refactor/ir/dfg.rs Co-authored-by: kevaundray <[email protected]> * Implement intrinsics * Fix no return & duplicate main * bad git. remove duplicated functions * Remove Option<Function> in builder * Undo debug printing in driver * Fix loading from mutable parameters * Grammar * Fix storing to mutable arrays * Fix unused variable * Fix array loading * Change terminology --------- Co-authored-by: kevaundray <[email protected]>
* chore(ci): Utilize new workflow to build binaries * Update release.yml --------- Co-authored-by: Tom French <[email protected]>
* chore(noir): Release 0.5.0 * chore: Update lockfile
#1226) * chore: replace `aztec_backend` with `acvm-backend-barretenberg` * feat: update to ACVM 0.10.0 * chore: move `ComputeMerkleRoot` to same match arm as `HashToField128Security` * chore: bump backend commit * feat: update stdlib to use new merkle black box function * fix: bump commit of barretenberg to match acvm-backend-barretenberg * feat: update `merkle_insert` to use new `compute_merkle_root` function * chore: update to use ACVM 0.10.3 * chore: bump backend commit
add poseidon examples into nargo_cli
* chore(noir): Release 0.5.1 * chore: Update lockfile
… pass (#1256) * Add remaining doc comments * Update crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs Co-authored-by: kevaundray <[email protected]> * Update crates/noirc_evaluator/src/ssa_refactor/ir/cfg.rs Co-authored-by: kevaundray <[email protected]> * Address PR feedback --------- Co-authored-by: kevaundray <[email protected]>
* chore(noir): constrain expr; -> assert(expr); * chore(noir): replace remaining `constrain` with `assert(expr)` --------- Co-authored-by: Tom French <[email protected]>
Whoops, I merged master into this branch and fixed the issue in f8a8933. My version of this branch turned out to be a little behind so I |
The file diff has exploded. I'm gonna close and cherry-pick into a new branch/PR. |
Replacement PR: #1278 |
Related issue(s)
Resolves #1116
Description
Summary of changes
PostOrder
for calculating the post-order of a function reachable blocksDominatorTree
for querying one block's dominance over anotherSsa
's function collection accessible so that theFunctionBuilder
can be used in unit testsDependency additions / changes
Test additions / changes
Unit test for both of the above
Checklist
cargo fmt
with default settings.Documentation needs
Additional context