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

forkify more aggressively

parent 878956fd
No related branches found
No related tags found
No related merge requests found
Pipeline #201638 passed
...@@ -183,8 +183,7 @@ pub fn forkify_loop( ...@@ -183,8 +183,7 @@ pub fn forkify_loop(
let reductionable_phis: Vec<_> = analyze_phis(&editor, &l, &candidate_phis, &loop_nodes) let reductionable_phis: Vec<_> = analyze_phis(&editor, &l, &candidate_phis, &loop_nodes)
.into_iter() .into_iter()
.collect(); .collect();
// TODO: Handle multiple loop body lasts.
// If there are multiple candidates for loop body last, return false.
if editor if editor
.get_uses(loop_if) .get_uses(loop_if)
.filter(|id| l.control[id.idx()]) .filter(|id| l.control[id.idx()])
...@@ -417,9 +416,9 @@ nest! { ...@@ -417,9 +416,9 @@ nest! {
continue_latch: NodeID, continue_latch: NodeID,
is_associative: bool, is_associative: bool,
}, },
LoopDependant(NodeID), OutsideUse(NodeID),
ControlDependant(NodeID), // This phi is redcutionable, but its cycle might depend on internal control within the loop. NonCyclic(NodeID),
UsedByDependant(NodeID),
} }
} }
...@@ -427,9 +426,8 @@ impl LoopPHI { ...@@ -427,9 +426,8 @@ impl LoopPHI {
pub fn get_phi(&self) -> NodeID { pub fn get_phi(&self) -> NodeID {
match self { match self {
LoopPHI::Reductionable { phi, .. } => *phi, LoopPHI::Reductionable { phi, .. } => *phi,
LoopPHI::LoopDependant(node_id) => *node_id, LoopPHI::OutsideUse(node_id) => *node_id,
LoopPHI::UsedByDependant(node_id) => *node_id, LoopPHI::NonCyclic(node_id) => *node_id,
LoopPHI::ControlDependant(node_id) => *node_id,
} }
} }
} }
...@@ -500,42 +498,12 @@ pub fn analyze_phis<'a>( ...@@ -500,42 +498,12 @@ pub fn analyze_phis<'a>(
let uses = walk_all_uses_stop_on(loop_continue_latch, editor, stop_on.clone()); let uses = walk_all_uses_stop_on(loop_continue_latch, editor, stop_on.clone());
let users = walk_all_users_stop_on(*phi, editor, stop_on.clone()); let users = walk_all_users_stop_on(*phi, editor, stop_on.clone());
let other_stop_on: HashSet<NodeID> = editor
.node_ids()
.filter(|node| {
let data = &editor.func().nodes[node.idx()];
// Phi, Reduce
if data.is_phi() {
return true;
}
if data.is_reduce() {
return true;
}
// External Control
if data.is_control() {
return true;
}
return false;
})
.collect();
let mut uses_for_dependance =
walk_all_users_stop_on(loop_continue_latch, editor, other_stop_on);
let set1: HashSet<_> = HashSet::from_iter(uses); let set1: HashSet<_> = HashSet::from_iter(uses);
let set2: HashSet<_> = HashSet::from_iter(users); let set2: HashSet<_> = HashSet::from_iter(users);
let intersection: HashSet<_> = set1.intersection(&set2).cloned().collect(); let intersection: HashSet<_> = set1.intersection(&set2).cloned().collect();
// If this phi uses any other phis the node is loop dependant, 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 // 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 // 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). // by the time the reduce is triggered (at the end of the loop's internal control).
...@@ -555,7 +523,7 @@ pub fn analyze_phis<'a>( ...@@ -555,7 +523,7 @@ pub fn analyze_phis<'a>(
// 3) Split the cycle into two phis, add them or multiply them together at the end. // 3) Split the cycle into two phis, add them or multiply them together at the end.
// 4) Split the cycle into two reduces, add them or multiply them together at the end. // 4) Split the cycle into two reduces, add them or multiply them together at the end.
// Somewhere else should handle this. // Somewhere else should handle this.
return LoopPHI::LoopDependant(*phi); return LoopPHI::OutsideUse(*phi);
} }
// FIXME: Do we want to calculate associativity here, there might be a case where this information is used in forkify // FIXME: Do we want to calculate associativity here, there might be a case where this information is used in forkify
...@@ -571,7 +539,7 @@ pub fn analyze_phis<'a>( ...@@ -571,7 +539,7 @@ pub fn analyze_phis<'a>(
} }
} else { } else {
// No cycles exist, this isn't a reduction. // No cycles exist, this isn't a reduction.
LoopPHI::LoopDependant(*phi) LoopPHI::NonCyclic(*phi)
} }
}) })
} }
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