Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Simplify defunctionalize return #7101

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,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 Expand Up @@ -435,19 +434,17 @@ mod tests {
}
brillig(inline) fn apply f4 {
b0(v0: Field, v1: u32):
v5 = eq v0, Field 2
jmpif v5 then: b3, else: b1
v4 = eq v0, Field 2
jmpif v4 then: b2, else: b1
b1():
constrain v0 == Field 3
v8 = call f3(v1) -> u32
jmp b2(v8)
b2(v2: u32):
jmp b4(v2)
b3():
v10 = call f2(v1) -> u32
jmp b4(v10)
b4(v3: u32):
return v3
v7 = call f3(v1) -> u32
jmp b3(v7)
b2():
v9 = call f2(v1) -> u32
jmp b3(v9)
b3(v2: u32):
return v2
}
";
assert_normalized_ssa_equals(ssa, expected);
Expand Down
Loading