-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c54590
commit 8f4c593
Showing
9 changed files
with
162 additions
and
50 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
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
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
55 changes: 55 additions & 0 deletions
55
noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/resolve_within_unconstrained.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,55 @@ | ||
use crate::ssa::{ | ||
ir::{ | ||
function::{Function, RuntimeType}, | ||
instruction::{Instruction, Intrinsic}, | ||
types::Type, | ||
value::Value, | ||
}, | ||
ssa_gen::Ssa, | ||
}; | ||
use acvm::FieldElement; | ||
use fxhash::FxHashSet as HashSet; | ||
|
||
impl Ssa { | ||
/// A simple SSA pass to find any calls to `Intrinsic::WithinUnconstrained` and replacing any references to the result of the intrinsic | ||
/// with the correct boolean value. | ||
/// Note that this pass must run after the pass that does runtime separation, since in SSA generation an ACIR function can end up targeting brillig. | ||
#[tracing::instrument(level = "trace", skip(self))] | ||
pub(crate) fn resolve_within_unconstrained(mut self) -> Self { | ||
for func in self.functions.values_mut() { | ||
replace_within_unconstrained(func); | ||
} | ||
self | ||
} | ||
} | ||
|
||
fn replace_within_unconstrained(func: &mut Function) { | ||
let mut within_unconstrained_calls = HashSet::default(); | ||
for block_id in func.reachable_blocks() { | ||
for &instruction_id in func.dfg[block_id].instructions() { | ||
let target_func = match &func.dfg[instruction_id] { | ||
Instruction::Call { func, .. } => *func, | ||
_ => continue, | ||
}; | ||
|
||
match &func.dfg[target_func] { | ||
Value::Intrinsic(Intrinsic::WithinUnconstrained) => { | ||
within_unconstrained_calls.insert(instruction_id); | ||
} | ||
_ => continue, | ||
}; | ||
} | ||
} | ||
|
||
for instruction_id in within_unconstrained_calls { | ||
let call_returns = func.dfg.instruction_results(instruction_id); | ||
let original_return_id = call_returns[0]; | ||
|
||
func.dfg.replace_result(instruction_id, original_return_id); | ||
let known_value = func.dfg.make_constant( | ||
FieldElement::from(matches!(func.runtime(), RuntimeType::Brillig)), | ||
Type::bool(), | ||
); | ||
func.dfg.set_value_from_id(original_return_id, known_value); | ||
} | ||
} |
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