Skip to content

Commit

Permalink
add ops to brillvm
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpal committed May 27, 2024
1 parent 40ec0e5 commit 8fd9790
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bril-rs/brillvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ inkwell = { git = "https://github.com/TheDan64/inkwell.git", features = [
"llvm18-0",
], rev = "6c0fb56b3554e939f9ca61b465043d6a84fb7b95" }

bril-rs = { git = "https://github.com/uwplse/bril", features = ["float", "ssa", "memory"] }
# TODO: Remove rev when https://github.com/uwplse/bril/pull/6 merges
bril-rs = { git = "https://github.com/uwplse/bril", rev="40ec0e5803c69bc2cde794785ba6b13a4fc401fe", features = ["float", "ssa", "memory"] }


# Need to set a default `main` to build `rt` bin
Expand Down
190 changes: 190 additions & 0 deletions bril-rs/brillvm/src/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,131 @@ fn build_instruction<'a, 'b>(
);
}

Instruction::Value {
args,
dest,
funcs: _,
labels: _,
op: ValueOps::Smax,
op_type: _,
} => {
let cmp_name = fresh.fresh_var();
let name = fresh.fresh_var();
build_op(
context,
builder,
heap,
fresh,
|v| {
builder.build_select(
builder.build_int_compare::<IntValue>(
IntPredicate::SGT,
v[0].try_into().unwrap(),
v[1].try_into().unwrap(),
&cmp_name
).unwrap(),
v[0],
v[1],
&name
).unwrap()
},
args,
dest
);
}

Instruction::Value {
args,
dest,
funcs: _,
labels: _,
op: ValueOps::Smin,
op_type: _,
} => {
let cmp_name = fresh.fresh_var();
let name = fresh.fresh_var();
build_op(
context,
builder,
heap,
fresh,
|v| {
builder.build_select(
builder.build_int_compare::<IntValue>(
IntPredicate::SLT,
v[0].try_into().unwrap(),
v[1].try_into().unwrap(),
&cmp_name
).unwrap(),
v[0],
v[1],
&name
).unwrap()
},
args,
dest
);
}

Instruction::Value {
args,
dest,
funcs: _,
labels: _,
op: ValueOps::Shl,
op_type: _,
} => {
let ret_name = fresh.fresh_var();
build_op(
context,
builder,
heap,
fresh,
|v| {
builder
.build_left_shift::<IntValue>(
v[0].try_into().unwrap(),
v[1].try_into().unwrap(),
&ret_name
)
.unwrap()
.into()
},
args,
dest,
);
}

Instruction::Value {
args,
dest,
funcs: _,
labels: _,
op: ValueOps::Shr,
op_type: _,
} => {
let ret_name = fresh.fresh_var();
build_op(
context,
builder,
heap,
fresh,
|v| {
builder
.build_right_shift::<IntValue>(
v[0].try_into().unwrap(),
v[1].try_into().unwrap(),
false, // sign extend
&ret_name
)
.unwrap()
.into()
},
args,
dest,
);
}

Instruction::Value {
args,
dest,
Expand Down Expand Up @@ -916,6 +1041,71 @@ fn build_instruction<'a, 'b>(
dest,
);
}
Instruction::Value {
args,
dest,
funcs: _,
labels: _,
op: ValueOps::Fmax,
op_type: _,
} => {
let cmp_name = fresh.fresh_var();
let name = fresh.fresh_var();
build_op(
context,
builder,
heap,
fresh,
|v| {
builder.build_select(
builder.build_float_compare::<FloatValue>(
FloatPredicate::OGT,
v[0].try_into().unwrap(),
v[1].try_into().unwrap(),
&cmp_name
).unwrap(),
v[0],
v[1],
&name
).unwrap()
},
args,
dest
);
}
Instruction::Value {
args,
dest,
funcs: _,
labels: _,
op: ValueOps::Fmin,
op_type: _,
} => {
let cmp_name = fresh.fresh_var();
let name = fresh.fresh_var();
build_op(
context,
builder,
heap,
fresh,
|v| {
builder.build_select(
builder.build_float_compare::<FloatValue>(
FloatPredicate::OLT,
v[0].try_into().unwrap(),
v[1].try_into().unwrap(),
&cmp_name
).unwrap(),
v[0],
v[1],
&name
).unwrap()
},
args,
dest
);
}

Instruction::Effect {
args,
funcs: _,
Expand Down

0 comments on commit 8fd9790

Please sign in to comment.