From 5c20f56072d0aceb92c5aa073bf8a00c3d99ecd5 Mon Sep 17 00:00:00 2001 From: Mike Urbach Date: Mon, 14 Aug 2023 22:18:02 -0600 Subject: [PATCH] [FIRRTL] Add a folder for FIntegerConstantOp. This isn't used by much yet, but some parts of the MLIR infrastructure (e.g., Dialect Conversion) assume ConstantLike ops have a folder. This adds the usual folder, same as StringConstantOp and others. --- include/circt/Dialect/FIRRTL/FIRRTLExpressions.td | 1 + lib/Dialect/FIRRTL/FIRRTLFolds.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td index e8e25f49c964..449948634227 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td +++ b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td @@ -1115,6 +1115,7 @@ def FIntegerConstantOp : FIRRTLOp<"integer", [Pure, ConstantLike]> { }]; let arguments = (ins APSIntAttr:$value); let results = (outs FIntegerType:$result); + let hasFolder = 1; let hasCustomAssemblyFormat = true; } diff --git a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp index 2f4b3735df2f..1ec13dc1735f 100644 --- a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp @@ -410,6 +410,11 @@ OpFoldResult StringConstantOp::fold(FoldAdaptor adaptor) { return getValueAttr(); } +OpFoldResult FIntegerConstantOp::fold(FoldAdaptor adaptor) { + assert(adaptor.getOperands().empty() && "constant has no operands"); + return getValueAttr(); +} + //===----------------------------------------------------------------------===// // Binary Operators //===----------------------------------------------------------------------===//