Skip to content
Snippets Groups Projects
Commit 6f161d1e authored by Xavier Routh's avatar Xavier Routh
Browse files

canon + forkify fix

parent e8ee780c
No related branches found
No related tags found
1 merge request!207Loop bound lte
Pipeline #201949 passed
......@@ -95,6 +95,8 @@ pub fn forkify_loop(
) -> bool {
let function = editor.func();
println!("forkifying {:?}", l.header);
let Some(loop_condition) = get_loop_exit_conditions(function, l, control_subgraph) else {
return false;
};
......@@ -106,12 +108,13 @@ pub fn forkify_loop(
else {
return false;
};
// Compute loop variance
let loop_variance = compute_loop_variance(editor, l);
let ivs = compute_induction_vars(editor.func(), l, &loop_variance);
let ivs = compute_iv_ranges(editor, l, ivs, &loop_condition);
let Some(canonical_iv) = has_canonical_iv(editor, l, &ivs) else {
println!("no canonical iv");
return false;
};
......@@ -130,6 +133,7 @@ pub fn forkify_loop(
};
let Some(bound_dc_id) = bound else {
println!("no bound iv");
return false;
};
......@@ -167,6 +171,8 @@ pub fn forkify_loop(
return false;
}
println!("this one");
// Get all phis used outside of the loop, they need to be reductionable.
// For now just assume all phis will be phis used outside of the loop, except for the canonical iv.
// FIXME: We need a different definiton of `loop_nodes` to check for phis used outside hte loop than the one
......@@ -196,6 +202,9 @@ pub fn forkify_loop(
let loop_body_last = editor.get_uses(loop_if).next().unwrap();
println!("phis {:?}", reductionable_phis);
if reductionable_phis
.iter()
.any(|phi| !matches!(phi, LoopPHI::Reductionable { .. }))
......@@ -403,6 +412,7 @@ pub fn forkify_loop(
Ok(edit)
});
println!("result: {:?}", result);
return result;
}
......@@ -530,10 +540,11 @@ pub fn analyze_phis<'a>(
let intersection: HashSet<_> = set1.intersection(&set2).cloned().collect();
// If this phi uses any other phis the node is loop dependant,
// we use `phis` because this phi can actually contain the loop iv and its fine.
if uses_for_dependance.any(|node| phis.contains(&node) && node != *phi) {
LoopPHI::LoopDependant(*phi)
} else if intersection.clone().iter().next().is_some() {
// // we use `phis` because this phi can actually contain the loop iv and its fine.
// if uses_for_dependance.any(|node| phis.contains(&node) && node != *phi) {
// LoopPHI::LoopDependant(*phi)
// } else
if intersection.clone().iter().next().is_some() {
// PHIs on the frontier of the uses by the candidate phi, i.e in uses_for_dependance need
// to have headers that postdominate the loop continue latch. The value of the PHI used needs to be defined
// by the time the reduce is triggered (at the end of the loop's internal control).
......
......@@ -73,7 +73,7 @@ pub fn canonicalize_single_loop_bounds(
.into_iter()
.partition(|f| loop_bound_iv_phis.contains(&f.phi()));
println!("{:?}", loop_bound_ivs);
// println!("{:?}", loop_bound_ivs);
// Assume there is only one loop bound iv.
......@@ -248,9 +248,9 @@ pub fn canonicalize_single_loop_bounds(
} else {
None
};
println!("condition node: {:?}", condition_node);
// println!("condition node: {:?}", condition_node);
let users = editor.get_users(condition_node).collect_vec();
println!("{:?}", users);
// println!("{:?}", users);
let mut condition_node = condition_node;
......@@ -280,7 +280,7 @@ pub fn canonicalize_single_loop_bounds(
let new_binop_node = edit.add_node(Node::Binary { left, right: blah, op: BinaryOperator::LT });
edit = edit.replace_all_uses_where(binop_node, new_binop_node, |usee| *usee == if_node)?;
Some((init_id, bound_id, new_binop_node, if_node))
Some((init_id, blah, new_binop_node, if_node))
} else {guard_info};
edit = edit.replace_all_uses_where(dc_bound_node, new_dc_bound_node, |usee| *usee == new_bop)?;
......
......@@ -17,6 +17,7 @@ lift-dc-math(*);
loop-bound-canon(*);
dce(*);
lift-dc-math(*);
fixpoint {
forkify(*);
fork-guard-elim(*);
......
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