Skip to content

Commit

Permalink
Rename methods that use conditionalize to be more descriptive (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored Feb 3, 2023
1 parent 90b6036 commit b0a9695
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
28 changes: 21 additions & 7 deletions crates/noirc_evaluator/src/ssa/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl DecisionTree {

ctx[current].assumption = block_assumption;
self.compute_assumption(ctx, current);
self.conditionalize_block(ctx, current, &mut data.stack)?;
self.apply_condition_to_block(ctx, current, &mut data.stack)?;
Ok(result)
}

Expand Down Expand Up @@ -397,22 +397,26 @@ impl DecisionTree {
Ok(())
}

pub fn conditionalize_block(
/// Apply the condition of the block to each instruction
/// in the block.
pub fn apply_condition_to_block(
&self,
ctx: &mut SsaContext,
block: BlockId,
stack: &mut StackFrame,
) -> Result<(), RuntimeError> {
let assumption_id = ctx[block].assumption;
let instructions = ctx[block].instructions.clone();
self.conditionalise_inline(ctx, &instructions, stack, assumption_id)?;
self.apply_condition_to_instructions(ctx, &instructions, stack, assumption_id)?;
ctx[block].instructions.clear();
ctx[block].instructions.append(&mut stack.stack);
assert!(stack.stack.is_empty());
Ok(())
}

pub fn conditionalise_inline(
/// Applies a condition to each instruction
/// and places into the stack frame.
pub fn apply_condition_to_instructions(
&self,
ctx: &mut SsaContext,
instructions: &[NodeId],
Expand All @@ -422,7 +426,13 @@ impl DecisionTree {
if predicate == AssumptionId::dummy() || self[predicate].value != Some(ctx.zero()) {
let mut short_circuit = false;
for i in instructions {
if !self.conditionalise_into(ctx, result, *i, predicate, short_circuit)? {
if !self.apply_condition_to_instruction(
ctx,
result,
*i,
predicate,
short_circuit,
)? {
short_circuit = true;
}
}
Expand Down Expand Up @@ -477,7 +487,11 @@ impl DecisionTree {
}
}

pub fn conditionalise_into(
/// Applies a condition to the instruction
/// For most instructions, this does nothing
/// but for instructions with side-effects
/// this will alter the behavior.
pub fn apply_condition_to_instruction(
&self,
ctx: &mut SsaContext,
stack: &mut StackFrame,
Expand Down Expand Up @@ -667,7 +681,7 @@ impl DecisionTree {
ObjectType::Pointer(array_dup),
&mut memcpy_stack,
);
self.conditionalise_inline(
self.apply_condition_to_instructions(
ctx,
&memcpy_stack.stack,
stack,
Expand Down
7 changes: 6 additions & 1 deletion crates/noirc_evaluator/src/ssa/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,12 @@ pub fn inline_in_block(
if short_circuit {
super::block::short_circuit_inline(ctx, stack_frame.block);
} else {
decision.conditionalise_inline(ctx, &stack_frame.stack, &mut stack2, predicate)?;
decision.apply_condition_to_instructions(
ctx,
&stack_frame.stack,
&mut stack2,
predicate,
)?;
// we add the conditionalised instructions to the target_block, at proper location (really need a linked list!)
stack2.apply(ctx, stack_frame.block, call_id, false);
}
Expand Down

0 comments on commit b0a9695

Please sign in to comment.