Skip to content

Commit

Permalink
Promotion Heurisitcs (subsumes #1750) (#1758)
Browse files Browse the repository at this point in the history
* first attempt

* added test cases

* clippy

* comments

* no loop setting

* compile repeat better

* rewrite tests

* support invokes

* style

* clippy

* small change
  • Loading branch information
calebmkim authored and rachitnigam committed Feb 16, 2024
1 parent cb30ead commit a086796
Show file tree
Hide file tree
Showing 12 changed files with 827 additions and 181 deletions.
11 changes: 11 additions & 0 deletions calyx-ir/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,17 @@ impl Control {
let empty = Control::empty();
std::mem::replace(self, empty)
}

/// Replaces &mut self with an empty control statement, and returns StaticControl
/// of self. Note that this only works on Control that is static
pub fn take_static_control(&mut self) -> StaticControl {
let empty = Control::empty();
let control = std::mem::replace(self, empty);
let Control::Static(static_control) = control else {
unreachable!("Called take_static_control on non-static control")
};
static_control
}
}

impl StaticControl {
Expand Down
8 changes: 8 additions & 0 deletions calyx-opt/src/passes/compile_repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl Visitor for CompileRepeat {
)
.to_vec();
init_group.borrow_mut().assignments = init_assigns;
init_group
.borrow_mut()
.attributes
.insert(ir::NumAttr::PromoteStatic, 1);
// incr_group:
// 1) writes results of idx + 1 into idx (i.e., increments idx)
// 2) writes the result of (idx + 1 < num_repeats) into cond_reg,
Expand All @@ -84,6 +88,10 @@ impl Visitor for CompileRepeat {
)
.to_vec();
incr_group.borrow_mut().assignments = idx_incr_assigns;
incr_group
.borrow_mut()
.attributes
.insert(ir::NumAttr::PromoteStatic, 1);
// create control:
// init_group; while cond_reg.out {repeat_body; incr_group;}
let while_body = ir::Control::seq(vec![
Expand Down
Loading

0 comments on commit a086796

Please sign in to comment.