-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(brillig): Add unique labeling and remove relative jumps (#1652)
* feat: added unique labeling * refactor: remove relative jumps * feat: add section/global labeling * pr review * Update crates/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs * style: clippy --------- Co-authored-by: kevaundray <kevtheappdev@gmail.com>
- Loading branch information
1 parent
3050b44
commit 870ffe7
Showing
7 changed files
with
521 additions
and
444 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
409 changes: 409 additions & 0 deletions
409
crates/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Large diffs are not rendered by default.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
crates/noirc_evaluator/src/brillig/brillig_gen/brillig_fn.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::collections::HashMap; | ||
|
||
use acvm::acir::brillig_vm::RegisterIndex; | ||
|
||
use crate::{ | ||
brillig::brillig_ir::BrilligContext, | ||
ssa_refactor::ir::{function::FunctionId, value::ValueId}, | ||
}; | ||
|
||
pub(crate) struct FunctionContext { | ||
pub(crate) function_id: FunctionId, | ||
/// Map from SSA values to Register Indices. | ||
pub(crate) ssa_value_to_register: HashMap<ValueId, RegisterIndex>, | ||
} | ||
|
||
impl FunctionContext { | ||
/// Gets a `RegisterIndex` for a `ValueId`, if one already exists | ||
/// or creates a new `RegisterIndex` using the latest available | ||
/// free register. | ||
pub(crate) fn get_or_create_register( | ||
&mut self, | ||
brillig_context: &mut BrilligContext, | ||
value: ValueId, | ||
) -> RegisterIndex { | ||
if let Some(register_index) = self.ssa_value_to_register.get(&value) { | ||
return *register_index; | ||
} | ||
|
||
let register = brillig_context.create_register(); | ||
|
||
// Cache the `ValueId` so that if we call it again, it will | ||
// return the register that has just been created. | ||
// | ||
// WARNING: This assumes that a register has not been | ||
// modified. If a MOV instruction has overwritten the value | ||
// at a register, then this cache will be invalid. | ||
self.ssa_value_to_register.insert(value, register); | ||
|
||
register | ||
} | ||
} |
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
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
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
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