Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Add integer addition property op. #6691

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions include/circt/Dialect/FIRRTL/FIRRTLExpressions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,27 @@ def DoubleConstantOp : FIRRTLOp<"double", [Pure, ConstantLike]> {
let assemblyFormat = "$value attr-dict";
}

class IntegerBinaryPrimOp<string mnemonic, list<Trait> traits = []> :
BinaryPrimOp<mnemonic, FIntegerType, FIntegerType, FIntegerType,
[Pure, SameOperandsAndResultType] # traits> {
// We use the standard inferReturnTypes from SameOperandsAndResultType.
let inferReturnTypesDecl = "";
}

def IntegerAddOp : IntegerBinaryPrimOp<"integer.add", [Commutative]> {
uenoku marked this conversation as resolved.
Show resolved Hide resolved
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.
//
Expand Down
6 changes: 6 additions & 0 deletions lib/Dialect/FIRRTL/FIRRTLFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions lib/Dialect/FIRRTL/FIRRTLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions test/Dialect/FIRRTL/round-trip.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Loading