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

Re-write Predication to use FunctionEditor

parent 8c46d474
No related branches found
No related tags found
1 merge request!105Re-write Predication to use FunctionEditor
...@@ -25,6 +25,7 @@ pub enum Pass { ...@@ -25,6 +25,7 @@ pub enum Pass {
PhiElim, PhiElim,
Forkify, Forkify,
ForkGuardElim, ForkGuardElim,
WritePredication,
Predication, Predication,
SROA, SROA,
Inline, Inline,
...@@ -469,27 +470,58 @@ impl PassManager { ...@@ -469,27 +470,58 @@ impl PassManager {
} }
self.clear_analyses(); self.clear_analyses();
} }
Pass::WritePredication => {
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],
);
write_predication(&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::Predication => { Pass::Predication => {
self.make_def_uses(); self.make_def_uses();
self.make_reverse_postorders(); self.make_typing();
self.make_doms();
self.make_fork_join_maps();
let def_uses = self.def_uses.as_ref().unwrap(); let def_uses = self.def_uses.as_ref().unwrap();
let reverse_postorders = self.reverse_postorders.as_ref().unwrap(); let typing = self.typing.as_ref().unwrap();
let doms = self.doms.as_ref().unwrap();
let fork_join_maps = self.fork_join_maps.as_ref().unwrap();
for idx in 0..self.module.functions.len() { for idx in 0..self.module.functions.len() {
predication( 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], &mut self.module.functions[idx],
FunctionID::new(idx),
&constants_ref,
&dynamic_constants_ref,
&types_ref,
&def_uses[idx], &def_uses[idx],
&reverse_postorders[idx],
&doms[idx],
&fork_join_maps[idx],
); );
let num_nodes = self.module.functions[idx].nodes.len(); predication(&mut editor, &typing[idx]);
self.module.functions[idx]
.schedules self.module.constants = constants_ref.take();
.resize(num_nodes, vec![]); self.module.dynamic_constants = dynamic_constants_ref.take();
self.module.types = types_ref.take();
self.module.functions[idx].delete_gravestones(); self.module.functions[idx].delete_gravestones();
} }
self.clear_analyses(); self.clear_analyses();
......
This diff is collapsed.
...@@ -179,6 +179,15 @@ pub fn compile_ir( ...@@ -179,6 +179,15 @@ pub fn compile_ir(
add_pass!(pm, verify, DCE); add_pass!(pm, verify, DCE);
add_pass!(pm, verify, GVN); add_pass!(pm, verify, GVN);
add_pass!(pm, verify, DCE); add_pass!(pm, verify, DCE);
add_pass!(pm, verify, WritePredication);
add_pass!(pm, verify, PhiElim);
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, Predication);
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, CCP);
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, GVN);
add_pass!(pm, verify, DCE);
if x_dot { if x_dot {
pm.add_pass(hercules_opt::pass::Pass::Xdot(true)); pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
} }
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
fn simple_antideps(a : usize, b : usize) -> i32 { fn simple_antideps(a : usize, b : usize) -> i32 {
let arr : i32[3]; let arr : i32[3];
let r = arr[b]; let r = arr[b];
arr[a] = 5; let x : i32[1];
if a == b {
x[0] = 5;
} else {
x[0] = 7;
}
arr[a] = x[0];
return r + arr[b]; return r + arr[b];
} }
......
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