-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): Remove redundant inc rc without instructions between (#6183)
# Description ## Problem\* Part of general effort to reduce Brillig bytecode sizes. ## Summary\* We often have patterns like such (example from `brillig_rc_regression_6123`): ``` brillig fn main f0 { b0(): inc_rc [Field 0, Field 0] inc_rc [Field 0, Field 0] inc_rc [Field 0, Field 0] inc_rc [Field 0, Field 0] inc_rc [Field 0, Field 0] v4 = allocate store [Field 0, Field 0] at v4 v5 = allocate store u32 0 at v5 inc_rc [Field 0, Field 0] v7 = allocate store [Field 0, Field 0] at v7 inc_rc [Field 0, Field 0] inc_rc [Field 0, Field 0] jmp b1(u32 0) ``` It is usually due to each impl method that mutably borrows self placing inc RCs on the internal arrays of the struct for which it is implementing the method. Without any instructions in between these `inc_rc` instructions, we can safely collapse the inc_rcs into a single one. The SSA was `brillig_rc_regression_6123` now looks like such: ``` brillig fn main f0 { b0(): inc_rc [Field 0, Field 0] v4 = allocate store [Field 0, Field 0] at v4 v5 = allocate store u32 0 at v5 inc_rc [Field 0, Field 0] v7 = allocate store [Field 0, Field 0] at v7 inc_rc [Field 0, Field 0] jmp b1(u32 0) ``` This PR does a slight refactor as the `track_inc_rcs_to_remove` was starting to take a lot of parameters. I made a new `RcTracker` struct. Its state is simply updated per instruction as previously and then the instructions it marks for removal are including at the end of performing DIE on a block. ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
1 changed file
with
119 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters