From ab5b00cf5fb79d30943a1008ff5bb79d039787f8 Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Tue, 18 Feb 2025 12:07:56 -0600 Subject: [PATCH 1/2] Loop bound canon in cava + forkify --- hercules_opt/src/loop_bound_canon.rs | 18 +----------------- juno_samples/cava/src/cpu.sch | 8 ++++++++ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/hercules_opt/src/loop_bound_canon.rs b/hercules_opt/src/loop_bound_canon.rs index e305e9db..c127c617 100644 --- a/hercules_opt/src/loop_bound_canon.rs +++ b/hercules_opt/src/loop_bound_canon.rs @@ -47,8 +47,6 @@ pub fn canonicalize_single_loop_bounds( ) -> bool { let function = editor.func(); - println!("canonicalizing {:?}", l.header); - let Some(loop_condition) = get_loop_exit_conditions(function, l, control_subgraph) else { return false; }; @@ -66,7 +64,6 @@ pub fn canonicalize_single_loop_bounds( let ivs = compute_iv_ranges(editor, l, ivs, &loop_condition); if has_canonical_iv(editor, l, &ivs).is_some() { - // println!("has canon iv!"); return false; } @@ -78,7 +75,6 @@ pub fn canonicalize_single_loop_bounds( // Assume there is only one loop bound iv. if loop_bound_ivs.len() != 1 { - // println!("has multiple iv!"); return false; } @@ -225,25 +221,15 @@ pub fn canonicalize_single_loop_bounds( // If increment is negative (how in the world do we know that...) // Increment can be DefinetlyPostiive, Unknown, DefinetlyNegative. - // // First, massage loop condition to be <, because that is normal! - // Also includes - // editor.edit(|mut edit| { - - // } - // Collect immediate IV users - let update_expr_users: Vec<_> = editor .get_users(*update_expression) .filter(|node| *node != iv.phi() && *node != condition_node) .collect(); - // println!("update_expr_users: {:?}", update_expr_users); let iv_phi_users: Vec<_> = editor .get_users(iv.phi()) .filter(|node| *node != iv.phi() && *node != *update_expression) .collect(); - // println!(" iv_phi_users: {:?}", iv_phi_users); - let result = editor.edit(|mut edit| { // 4) Second, change loop IV to go from 0..N. // we subtract off init from init and dc_bound_node, @@ -270,7 +256,6 @@ pub fn canonicalize_single_loop_bounds( edit.replace_all_uses_where(bound_id, new_condition, |usee| *usee == binop_node)?; } - // for user in update_expr_users { // let new_user = Node::Binary { // left: user, @@ -281,7 +266,7 @@ pub fn canonicalize_single_loop_bounds( // edit = edit.replace_all_uses(user, new_user)?; // } - // for + // for // Add the offset back to users of the IV update expression let new_user = Node::Binary { @@ -311,6 +296,5 @@ pub fn canonicalize_single_loop_bounds( Ok(edit) }); - println!("result: {:?}", result); return result; } diff --git a/juno_samples/cava/src/cpu.sch b/juno_samples/cava/src/cpu.sch index 4013fd27..635de17a 100644 --- a/juno_samples/cava/src/cpu.sch +++ b/juno_samples/cava/src/cpu.sch @@ -39,6 +39,13 @@ fixpoint { simpl!(fuse1); array-slf(fuse1); loop-bound-canon(fuse1); +fixpoint { + forkify(fuse1); + fork-guard-elim(fuse1); + fork-coalesce(fuse1); +} +predication(fuse1); +simpl!(fuse1); inline(fuse2); no-memset(fuse2@res); @@ -116,6 +123,7 @@ simpl!(fuse5); delete-uncalled(*); simpl!(*); +xdot[true](fuse1); simpl!(fuse1); unforkify(fuse1); -- GitLab From 518064248f79c148dddef698c33b1474c104b647 Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Tue, 18 Feb 2025 12:13:42 -0600 Subject: [PATCH 2/2] Whoops --- hercules_opt/src/gcm.rs | 7 +++---- juno_samples/cava/src/cpu.sch | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/hercules_opt/src/gcm.rs b/hercules_opt/src/gcm.rs index 446b3184..f2405893 100644 --- a/hercules_opt/src/gcm.rs +++ b/hercules_opt/src/gcm.rs @@ -486,11 +486,10 @@ fn basic_blocks( // Look between the LCA and the schedule early location to place the // node. let schedule_early = schedule_early[id.idx()].unwrap(); + // If the node has no users, then it doesn't really matter where we + // place it - just place it at the early placement. let schedule_late = lca.unwrap_or(schedule_early); - let mut chain = dom - // If the node has no users, then it doesn't really matter where we - // place it - just place it at the early placement. - .chain(schedule_late, schedule_early); + let mut chain = dom.chain(schedule_late, schedule_early); if let Some(mut location) = chain.next() { while let Some(control_node) = chain.next() { diff --git a/juno_samples/cava/src/cpu.sch b/juno_samples/cava/src/cpu.sch index 635de17a..6cd33a3b 100644 --- a/juno_samples/cava/src/cpu.sch +++ b/juno_samples/cava/src/cpu.sch @@ -123,9 +123,9 @@ simpl!(fuse5); delete-uncalled(*); simpl!(*); -xdot[true](fuse1); -simpl!(fuse1); + +fork-split(fuse1); unforkify(fuse1); fork-split(fuse2); unforkify(fuse2); -- GitLab