-
-
Save wwared/71cd9cf8bf7a84a5dba0d7d89f313b53 to your computer and use it in GitHub Desktop.
mem2reg blocks attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs | |
index e5fffaccd..4510ac4a1 100644 | |
--- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs | |
+++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs | |
@@ -101,6 +101,7 @@ struct PerFunctionContext<'f> { | |
post_order: PostOrder, | |
blocks: BTreeMap<BasicBlockId, Block>, | |
+ processed_blocks: BTreeSet<BasicBlockId>, | |
inserter: FunctionInserter<'f>, | |
@@ -121,6 +122,7 @@ impl<'f> PerFunctionContext<'f> { | |
post_order, | |
inserter: FunctionInserter::new(function), | |
blocks: BTreeMap::new(), | |
+ processed_blocks: BTreeSet::new(), | |
instructions_to_remove: BTreeSet::new(), | |
} | |
} | |
@@ -134,10 +136,27 @@ impl<'f> PerFunctionContext<'f> { | |
let mut block_order = PostOrder::with_function(self.inserter.function).into_vec(); | |
block_order.reverse(); | |
+ let total = block_order.len(); | |
+ let mut i = 1; | |
for block in block_order { | |
let references = self.find_starting_references(block); | |
+ // println!("==> {}", self.blocks.len()); | |
self.analyze_block(block, references); | |
+ self.processed_blocks.insert(block); | |
+ if i % 8192 == 0 { | |
+ //println!("{}/{}", i, total); | |
+ //println!("--> before: {}", self.blocks.len()); | |
+ self.blocks.retain(|&b, _| { | |
+ self.cfg.successors(b).all(|s| self.processed_blocks.contains(&s)) | |
+ }); | |
+ //println!("--> after: {}", self.blocks.len()); | |
+ } | |
+ i += 1; | |
} | |
+ println!("done\ninstr to remove: {}", self.instructions_to_remove.len()); | |
+ // self.blocks.clear(); | |
+ // self.processed_blocks.clear(); | |
+ // println!("finished"); | |
} | |
/// The value of each reference at the start of the given block is the unification | |
@@ -355,11 +374,23 @@ impl<'f> PerFunctionContext<'f> { | |
/// no longer needed. | |
fn remove_instructions(&mut self) { | |
// The order we iterate blocks in is not important | |
- for block in self.post_order.as_slice() { | |
- self.inserter.function.dfg[*block] | |
- .instructions_mut() | |
- .retain(|instruction| !self.instructions_to_remove.contains(instruction)); | |
+ println!("removing"); | |
+ use std::io::Write; | |
+ { | |
+ let mut lock = std::io::stdout().lock(); | |
+ let mut i = 0; | |
+ for block in self.post_order.as_slice() { | |
+ if i % 2048 == 0 { | |
+ write!(lock, ".").unwrap(); | |
+ lock.flush().unwrap(); | |
+ } | |
+ self.inserter.function.dfg[*block] | |
+ .instructions_mut() | |
+ .retain(|instruction| !self.instructions_to_remove.contains(instruction)); | |
+ i += 1; | |
+ } | |
} | |
+ println!("done"); | |
} | |
fn handle_terminator(&mut self, block: BasicBlockId, references: &mut Block) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment