Skip to content

Commit

Permalink
fix: Implement new mem2reg pass (#2420)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
  • Loading branch information
jfecher and vezenovm authored Aug 25, 2023
1 parent 84fdc55 commit 7714cd0
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ fn regression_2218_loop(x: Field, y: Field) {
assert(*q1 == 20);
}
assert(*q1 == 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "references"
type = "bin"
authors = [""]
compiler_version = "0.5.1"

[dependencies]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn increment(mut r: &mut Field) {
*r = *r + 1;
}

fn main() {
let mut x = 100;
let mut xref = &mut x;
increment(xref);
assert(*xref == 101);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
H4sIAAAAAAAA/+1c8ZONVRh+WCKykYqIiFRE37f37u5dkY2IEEJEtLv2bkJKQkpCSkJKIjLGNE3TmJqpmZqpmZrRH9L/Uu907szZzfjlPO+Z98yc88u+w8yz3/O853ue93zf3fsXgL/x/zXY/ex0P4uwVQ7ysCpFW7Vab2+pl5Wyu2jp6Km1FtXWnrZaWStba629LbVKpV6r1to7ejrai46yWqmXfa0dlT4HNpiAVe/7bzX9izHoJvwHkfkP5mEV/vU2efWQAb3z//82BU4Y8HsG6th8k3+j/nKNJjUp4A4Bb/Nr8R7C71HhQZrXtLEsG99QpGd8Q6FjfLd5dTa+QMyhSkINg23jE97D+D1SNT62po1l2fiGIz3jGw4d47vdq7PxBWIOd4KycUfAtvEJ7xH8HqkaH1vTxrJsfCORnvGNhI7x3eHV2fgCMUc6Qdm4o2Db+IT3KH6PVI2PrWljWTa+ZtCMrxbL+JqhY3x3enU2vkDMZicoG3c0bBuf8B7N71EyhjIGLEOp12MZyhjoGMpdXp0NJRBzjBOUjTsWtg1FeI/l9+iWhhKqA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30QUeZ5UTujyBOQ3+SfU3cPc3m7c8LTqlwPt36NzX7BP6RaKWxF6XWvpZHqi/gu28lgy4qHCv/AHbHiF5dUGB959IwyMuEbUk9rpk68feN3I/X1LYNzcQZ98UQausdhE5Xyb25QbhumJ/1zWRf78D7ddenQ+0gZiXnaBs3CuwfaAV3lf4PVL9rmumpoMGXKO//gGokXOuaucAAA==
Binary file not shown.
738 changes: 434 additions & 304 deletions crates/noirc_evaluator/src/ssa/opt/mem2reg.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/noirc_evaluator/src/ssa/opt/unrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Ssa {
}
}

pub(crate) struct Loop {
struct Loop {
/// The header block of a loop is the block which dominates all the
/// other blocks in the loop.
header: BasicBlockId,
Expand All @@ -57,20 +57,20 @@ pub(crate) struct Loop {
pub(crate) blocks: HashSet<BasicBlockId>,
}

pub(crate) struct Loops {
struct Loops {
/// The loops that failed to be unrolled so that we do not try to unroll them again.
/// Each loop is identified by its header block id.
failed_to_unroll: HashSet<BasicBlockId>,

pub(crate) yet_to_unroll: Vec<Loop>,
yet_to_unroll: Vec<Loop>,
modified_blocks: HashSet<BasicBlockId>,
cfg: ControlFlowGraph,
dom_tree: DominatorTree,
}

/// Find a loop in the program by finding a node that dominates any predecessor node.
/// The edge where this happens will be the back-edge of the loop.
pub(crate) fn find_all_loops(function: &Function) -> Loops {
fn find_all_loops(function: &Function) -> Loops {
let cfg = ControlFlowGraph::with_function(function);
let post_order = PostOrder::with_function(function);
let mut dom_tree = DominatorTree::with_cfg_and_post_order(&cfg, &post_order);
Expand Down

0 comments on commit 7714cd0

Please sign in to comment.