From 894ae308e4efd915ec731b8d54a1d68be4442bc5 Mon Sep 17 00:00:00 2001 From: Fabian Schuiki Date: Sat, 12 Feb 2022 07:58:39 +0100 Subject: [PATCH] codegen: Emit concat expr as moore.mir.concat op --- src/svlog/codegen.rs | 30 +++++++----------------------- test/mlir/expressions.sv | 8 ++++++++ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/svlog/codegen.rs b/src/svlog/codegen.rs index 8a1d8ddce..0d2f4bf97 100644 --- a/src/svlog/codegen.rs +++ b/src/svlog/codegen.rs @@ -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) => { diff --git a/test/mlir/expressions.sv b/test/mlir/expressions.sv index 56921258b..d492f2a10 100644 --- a/test/mlir/expressions.sv +++ b/test/mlir/expressions.sv @@ -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