Skip to content
Snippets Groups Projects
Commit 78d39cf9 authored by rarbore2's avatar rarbore2
Browse files

Clone elimination pass

parent 7baa7040
No related branches found
No related tags found
1 merge request!98Clone elimination pass
extern crate hercules_ir;
use std::collections::BTreeSet;
use self::hercules_ir::ir::*;
use crate::*;
/*
* Top level function to run clone elimination.
*/
pub fn clone_elim(editor: &mut FunctionEditor) {
// Create workset (starts as all nodes).
let mut workset: BTreeSet<NodeID> = (0..editor.func().nodes.len()).map(NodeID::new).collect();
while let Some(work) = workset.pop_first() {
// Look for Write nodes with identical `collect` and `data` inputs.
let nodes = &editor.func().nodes;
if let Node::Write {
collect,
data,
ref indices,
} = nodes[work.idx()]
&& nodes[collect.idx()] == nodes[data.idx()]
{
assert!(indices.is_empty());
editor.edit(|edit| edit.replace_all_uses(work, collect)?.delete_node(work));
// Removing this write may affect downstream writes.
workset.extend(editor.get_users(work));
}
}
}
#![feature(let_chains)] #![feature(let_chains)]
pub mod ccp; pub mod ccp;
pub mod clone_elim;
pub mod dce; pub mod dce;
pub mod delete_uncalled; pub mod delete_uncalled;
pub mod editor; pub mod editor;
...@@ -21,6 +22,7 @@ pub mod unforkify; ...@@ -21,6 +22,7 @@ pub mod unforkify;
pub mod utils; pub mod utils;
pub use crate::ccp::*; pub use crate::ccp::*;
pub use crate::clone_elim::*;
pub use crate::dce::*; pub use crate::dce::*;
pub use crate::delete_uncalled::*; pub use crate::delete_uncalled::*;
pub use crate::editor::*; pub use crate::editor::*;
......
...@@ -40,6 +40,7 @@ pub enum Pass { ...@@ -40,6 +40,7 @@ pub enum Pass {
Unforkify, Unforkify,
InferSchedules, InferSchedules,
LegalizeReferenceSemantics, LegalizeReferenceSemantics,
CloneElim,
Verify, Verify,
// Parameterized over whether analyses that aid visualization are necessary. // Parameterized over whether analyses that aid visualization are necessary.
// Useful to set to false if displaying a potentially broken module. // Useful to set to false if displaying a potentially broken module.
...@@ -807,6 +808,33 @@ impl PassManager { ...@@ -807,6 +808,33 @@ impl PassManager {
break; break;
} }
}, },
Pass::CloneElim => {
self.make_def_uses();
let def_uses = self.def_uses.as_ref().unwrap();
for idx in 0..self.module.functions.len() {
let constants_ref =
RefCell::new(std::mem::take(&mut self.module.constants));
let dynamic_constants_ref =
RefCell::new(std::mem::take(&mut self.module.dynamic_constants));
let types_ref = RefCell::new(std::mem::take(&mut self.module.types));
let mut editor = FunctionEditor::new(
&mut self.module.functions[idx],
FunctionID::new(idx),
&constants_ref,
&dynamic_constants_ref,
&types_ref,
&def_uses[idx],
);
clone_elim(&mut editor);
self.module.constants = constants_ref.take();
self.module.dynamic_constants = dynamic_constants_ref.take();
self.module.types = types_ref.take();
self.module.functions[idx].delete_gravestones();
}
self.clear_analyses();
}
Pass::InferSchedules => { Pass::InferSchedules => {
self.make_def_uses(); self.make_def_uses();
self.make_fork_join_maps(); self.make_fork_join_maps();
......
...@@ -192,6 +192,8 @@ pub fn compile_ir( ...@@ -192,6 +192,8 @@ pub fn compile_ir(
add_pass!(pm, verify, GVN); add_pass!(pm, verify, GVN);
add_verified_pass!(pm, verify, DCE); add_verified_pass!(pm, verify, DCE);
add_pass!(pm, verify, LegalizeReferenceSemantics); add_pass!(pm, verify, LegalizeReferenceSemantics);
add_pass!(pm, verify, CloneElim);
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, Outline); add_pass!(pm, verify, Outline);
add_pass!(pm, verify, InterproceduralSROA); add_pass!(pm, verify, InterproceduralSROA);
add_pass!(pm, verify, SROA); add_pass!(pm, verify, SROA);
......
...@@ -17,12 +17,19 @@ fn matmul<n : usize, m : usize, l : usize>(a : i32[n, m], b : i32[m, l]) -> i32[ ...@@ -17,12 +17,19 @@ fn matmul<n : usize, m : usize, l : usize>(a : i32[n, m], b : i32[m, l]) -> i32[
#[entry] #[entry]
fn tiled_64_matmul<n : usize, m : usize, l : usize>(a : i32[n, m], b : i32[m, l]) -> i32[n, l] { fn tiled_64_matmul<n : usize, m : usize, l : usize>(a : i32[n, m], b : i32[m, l]) -> i32[n, l] {
let res : i32[n, l]; let res : i32[n, l];
let atile : i32[64, 64];
let btile : i32[64, 64];
let ctile : i32[64, 64];
for bi = 0 to n / 64 { for bi = 0 to n / 64 {
for bk = 0 to l / 64 { for bk = 0 to l / 64 {
let atile : i32[64, 64]; for ti = 0 to 64 {
let btile : i32[64, 64]; for tk = 0 to 64 {
let ctile : i32[64, 64]; atile[ti, tk] = 0;
btile[ti, tk] = 0;
ctile[ti, tk] = 0;
}
}
for tile_idx = 0 to m / 64 { for tile_idx = 0 to m / 64 {
for ti = 0 to 64 { for ti = 0 to 64 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment