Skip to content

Commit

Permalink
codegen: Emit concat expr as moore.mir.concat op
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianschuiki committed Jul 12, 2022
1 parent 0405d16 commit 894ae30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/svlog/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,31 +1899,15 @@ where
}

mir::RvalueKind::Concat(ref values) => {
let mut offset = 0;
let llty = self.emit_type_both(mir.ty)?;
trace!(
"Concatenating {} values into `{}` (as {:?})",
values.len(),
mir.ty,
llty
);
let mut result = self.emit_zero_for_type_both(llty);
for value in values.iter().rev() {
let width = value.ty.simple_bit_vector(self.cx, value.span).size;
let llval = self.emit_mir_rvalue(value)?;
trace!(
" - Value has width {}, type `{}`, in LLHD `{}`",
width,
value.ty,
self.llhd_type(llval.0)
);
if width > 0 {
result = self.mk_ins_slice(result, llval, offset, width);
offset += width;
}
let mut fields = vec![];
for value in values.iter() {
fields.push(self.emit_mir_rvalue(value)?.1);
}
self.builder.set_name(result.0, "concat".to_string());
result
(
self.emit_zero_for_type(&llty.0),
circt::moore::ConcatOp::new(self.mlir_builder, fields).into(),
)
}

mir::RvalueKind::Repeat(times, value) => {
Expand Down
8 changes: 8 additions & 0 deletions test/mlir/expressions.sv
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ function void ShiftExpressions(bit signed [21:0] x, bit [5:0] y);
bit signed [21:0] d = x >>> y;
endfunction

// CHECK-LABEL: func @Concat(
// CHECK-SAME: [[X:%.+]]: i4, [[Y:%.+]]: i2, [[Z:%.+]]: i1) -> i7 {
function bit [6:0] Concat(bit [3:0] x, bit [1:0] y, bit z);
// CHECK-NEXT: [[TMP:%.+]] = moore.mir.concat [[X]], [[Y]], [[Z]]
// CHECK-NEXT: return [[TMP]]
return {x, y, z};
endfunction

module foo;
endmodule

1 comment on commit 894ae30

@maerhart
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool that we can now also emit concat ops 🙂

Please sign in to comment.