diff --git a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td index 26006aab1428..d834014c3ef2 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td +++ b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td @@ -1181,6 +1181,27 @@ def DoubleConstantOp : FIRRTLOp<"double", [Pure, ConstantLike]> { let assemblyFormat = "$value attr-dict"; } +class IntegerBinaryPrimOp traits = []> : + BinaryPrimOp { + // We use the standard inferReturnTypes from SameOperandsAndResultType. + let inferReturnTypesDecl = ""; +} + +def IntegerAddOp : IntegerBinaryPrimOp<"integer.add", [Commutative]> { + let summary = "Add two FIntegerType values"; + let description = [{ + The add operation result is the arbitrary precision signed integer + arithmetic sum of the two operands. + + Example: + ```mlir + %2 = firrtl.integer.add %0, %1 : (!firrtl.integer, !firrtl.integer) -> + !firrtl.integer + ``` + }]; +} + //===----------------------------------------------------------------------===// // RefOperations: Operations on the RefType. // diff --git a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp index d06866876846..ff1927bbdb9a 100644 --- a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp @@ -935,6 +935,12 @@ LogicalResult NEQPrimOp::canonicalize(NEQPrimOp op, PatternRewriter &rewriter) { }); } +OpFoldResult IntegerAddOp::fold(FoldAdaptor adaptor) { + // TODO: implement constant folding, etc. + // Tracked in https://github.com/llvm/circt/issues/6696. + return {}; +} + //===----------------------------------------------------------------------===// // Unary Operators //===----------------------------------------------------------------------===// diff --git a/lib/Dialect/FIRRTL/FIRRTLOps.cpp b/lib/Dialect/FIRRTL/FIRRTLOps.cpp index 7834dd6046cb..e1e222270884 100644 --- a/lib/Dialect/FIRRTL/FIRRTLOps.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLOps.cpp @@ -5750,6 +5750,9 @@ void GTPrimOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { void HeadPrimOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { genericAsmResultNames(*this, setNameFn); } +void IntegerAddOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { + genericAsmResultNames(*this, setNameFn); +} void IsTagOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { genericAsmResultNames(*this, setNameFn); } diff --git a/test/Dialect/FIRRTL/round-trip.mlir b/test/Dialect/FIRRTL/round-trip.mlir index 8900b6f8a5d8..a2ff1f23139b 100644 --- a/test/Dialect/FIRRTL/round-trip.mlir +++ b/test/Dialect/FIRRTL/round-trip.mlir @@ -71,4 +71,13 @@ firrtl.module @Layers( firrtl.module @LayersEnabled() attributes {layers = [@LayerA]} { } +// CHECK-LABEL: firrtl.module @PropertyArithmetic +firrtl.module @PropertyArithmetic() { + %0 = firrtl.integer 1 + %1 = firrtl.integer 2 + + // CHECK: firrtl.integer.add %0, %1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer + %2 = firrtl.integer.add %0, %1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer +} + }