From 7f366b0d85b23cf76ff1cd3e5ad3bc334c2d3b7e Mon Sep 17 00:00:00 2001 From: Mike Urbach Date: Mon, 12 Aug 2024 11:08:05 -0600 Subject: [PATCH] [FIRRTL] Add list concatenation operation. (#7486) This operation produces a list by concatenating lists of the same type. The operation definition and a simple round trip test have been added. This is used to compose lists, which is a key feature to enable hierarchical composition of Properties. --- .../circt/Dialect/FIRRTL/FIRRTLExpressions.td | 17 +++++++++++++++++ include/circt/Dialect/FIRRTL/FIRRTLVisitors.h | 5 +++-- test/Dialect/FIRRTL/round-trip.mlir | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td index f435e86ef7ce..359e64d86571 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td +++ b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td @@ -1154,6 +1154,23 @@ def ListCreateOp : FIRRTLOp<"list.create", [Pure, SameTypeOperands]> { let hasVerifier = 1; } +def ListConcatOp : FIRRTLOp<"list.concat", [Pure, SameOperandsAndResultType]> { + let summary = "Concatenate multiple lists to produce a new list"; + let description = [{ + Produces a value of list type by concatenating the provided lists. + + Example: + ```mlir + %3 = firrtl.list.concat %0, %1, %2 : !firrtl.list + ``` + }]; + + let arguments = (ins Variadic:$subLists); + let results = (outs ListType:$result); + + let assemblyFormat = "$subLists attr-dict `:` type($result)"; +} + def BoolConstantOp : FIRRTLOp<"bool", [Pure, ConstantLike]> { let summary = "Produce a constant boolean value"; let description = [{ diff --git a/include/circt/Dialect/FIRRTL/FIRRTLVisitors.h b/include/circt/Dialect/FIRRTL/FIRRTLVisitors.h index 03a2466d2b52..5f9aa0ddac9e 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLVisitors.h +++ b/include/circt/Dialect/FIRRTL/FIRRTLVisitors.h @@ -65,8 +65,8 @@ class ExprVisitor { UninferredResetCastOp, ConstCastOp, RefCastOp, // Property expressions. StringConstantOp, FIntegerConstantOp, BoolConstantOp, - DoubleConstantOp, ListCreateOp, UnresolvedPathOp, PathOp, - IntegerAddOp, IntegerMulOp, IntegerShrOp>( + DoubleConstantOp, ListCreateOp, ListConcatOp, UnresolvedPathOp, + PathOp, IntegerAddOp, IntegerMulOp, IntegerShrOp>( [&](auto expr) -> ResultType { return thisCast->visitExpr(expr, args...); }) @@ -219,6 +219,7 @@ class ExprVisitor { HANDLE(BoolConstantOp, Unhandled); HANDLE(DoubleConstantOp, Unhandled); HANDLE(ListCreateOp, Unhandled); + HANDLE(ListConcatOp, Unhandled); HANDLE(PathOp, Unhandled); HANDLE(UnresolvedPathOp, Unhandled); HANDLE(IntegerAddOp, Unhandled); diff --git a/test/Dialect/FIRRTL/round-trip.mlir b/test/Dialect/FIRRTL/round-trip.mlir index 96384fde936b..1c6ae9434ed2 100644 --- a/test/Dialect/FIRRTL/round-trip.mlir +++ b/test/Dialect/FIRRTL/round-trip.mlir @@ -104,4 +104,20 @@ firrtl.module @PropertyArithmetic() { %4 = firrtl.integer.shr %0, %1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer } +// CHECK-LABEL: firrtl.module @PropertyListOps +firrtl.module @PropertyListOps() { + %0 = firrtl.integer 0 + %1 = firrtl.integer 1 + %2 = firrtl.integer 2 + + // CHECK: [[L0:%.+]] = firrtl.list.create %0, %1 + %l0 = firrtl.list.create %0, %1 : !firrtl.list + + // CHECK: [[L1:%.+]] = firrtl.list.create %2 + %l1 = firrtl.list.create %2 : !firrtl.list + + // CHECK: firrtl.list.concat [[L0]], [[L1]] : !firrtl.list + %concat = firrtl.list.concat %l0, %l1 : !firrtl.list +} + }