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

Address #295 #296

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion brilirs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ plot: plot.svg
# This is primarily used for running examples and debuging a bril program
.PHONY: example
example:
bril2json < ../benchmarks/sqrt.bril | cargo run
bril2json < ../benchmarks/float/sqrt.bril | cargo run
44 changes: 22 additions & 22 deletions brilirs/src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,28 @@ impl BBFunction {
}
let last_idx = self.blocks.len() - 1;
for (i, block) in self.blocks.iter_mut().enumerate() {
// If we're before the last block
if i < last_idx {
// Get the last instruction
let last_instr = block.instrs.last().cloned();
if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Jump | bril_rs::EffectOps::Branch,
labels,
..
}) = last_instr
{
for l in labels {
block
.exit
.push(*label_map.get(&l).ok_or(InterpError::MissingLabel(l))?);
}
} else if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Return,
..
}) = last_instr
{
// We are done, there is no exit from this block
} else {
// Get the last instruction
let last_instr = block.instrs.last().cloned();
if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Jump | bril_rs::EffectOps::Branch,
labels,
..
}) = last_instr
{
for l in labels {
block
.exit
.push(*label_map.get(&l).ok_or(InterpError::MissingLabel(l))?);
}
} else if let Some(bril_rs::Instruction::Effect {
op: bril_rs::EffectOps::Return,
..
}) = last_instr
{
// We are done, there is no exit from this block
} else {
// If we're before the last block
if i < last_idx {
block.exit.push(i + 1);
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/interp/core/non_linear_control_flow.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ARGS: false false
@main(b0: bool, b1: bool) {
jmp .start;
.end:
print x_0_2;
print x_1_2;
ret;
.l_1_3:
jmp .end;
.l_1_2:
x_1_2 : int = const 0;
jmp .l_1_3;
.l_1_1:
x_1_1 : int = const 1;
jmp .l_1_3;
.l_0_3:
br b1 .l_1_1 .l_1_2;
.l_0_2:
x_0_2 : int = const 2;
jmp .l_0_3;
.l_0_1:
x_0_1 : int = const 3;
jmp .l_0_3;
.start:
br b0 .l_0_1 .l_0_2;
}
2 changes: 2 additions & 0 deletions test/interp/core/non_linear_control_flow.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2
0