Skip to content

Commit

Permalink
Merge pull request #7 from uwplse/ajpal-ops-brillvm
Browse files Browse the repository at this point in the history
Add ops to brillvm
  • Loading branch information
ajpal authored May 29, 2024
2 parents bc0061e + 0bf664d commit e2be3f5
Showing 1 changed file with 190 additions and 0 deletions.
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 e2be3f5

Please sign in to comment.