Skip to content

Commit

Permalink
Refactor defunctionalization to not create intermediate blocks before…
Browse files Browse the repository at this point in the history
… return
  • Loading branch information
aakoshh committed Jan 17, 2025
1 parent a4ea747 commit 7ace374
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,22 +339,21 @@ fn create_apply_function(
})
}

/// Crates a return block, if no previous return exists, it will create a final return
/// Else, it will create a bypass return block that points to the previous return block
/// If no previous return target exists, it will create a final return,
/// otherwise returns the existing return block to jump to.
fn build_return_block(
builder: &mut FunctionBuilder,
previous_block: BasicBlockId,
passed_types: &[Type],
target: Option<BasicBlockId>,
) -> BasicBlockId {
if let Some(return_block) = target {
return return_block;
}
let return_block = builder.insert_block();
builder.switch_to_block(return_block);

let params = vecmap(passed_types, |typ| builder.add_block_parameter(return_block, typ.clone()));
match target {
None => builder.terminate_with_return(params),
Some(target) => builder.terminate_with_jmp(target, params),
}
builder.terminate_with_return(params);
builder.switch_to_block(previous_block);
return_block
}
Expand Down

0 comments on commit 7ace374

Please sign in to comment.