Skip to content

Commit

Permalink
[FIRRTL][LowerType] Handle unrealized_conversion_cast of other dialec…
Browse files Browse the repository at this point in the history
…ts (#6422)

LowerTypes was crashing when lowering `unrealized_conversion_cast` from other dialects.
This PR fixes the crash and ignores the cast op from other dialects instead of lowering them.
  • Loading branch information
prithayan authored Nov 17, 2023
1 parent bca67e6 commit 8da7ce4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,10 @@ bool TypeLoweringVisitor::visitExpr(mlir::UnrealizedConversionCastOp op) {
return builder->create<mlir::UnrealizedConversionCastOp>(field.type, input)
.getResult(0);
};
// If the input to the cast is not a FIRRTL type, getSubWhatever cannot handle
// it, donot lower the op.
if (!type_isa<FIRRTLType>(op->getOperand(0).getType()))
return false;
return lowerProducer(op, clone);
}

Expand Down
12 changes: 10 additions & 2 deletions test/Dialect/FIRRTL/lower-types.mlir
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: circt-opt -pass-pipeline='builtin.module(firrtl.circuit(firrtl-lower-types))' %s | FileCheck --check-prefixes=CHECK,COMMON %s
// RUN: circt-opt -pass-pipeline='builtin.module(firrtl.circuit(firrtl-lower-types{preserve-aggregate=all}))' %s | FileCheck --check-prefixes=AGGREGATE,COMMON %s
// RUN: circt-opt -pass-pipeline='builtin.module(firrtl.circuit(firrtl-lower-types))' --allow-unregistered-dialect %s | FileCheck --check-prefixes=CHECK,COMMON %s
// RUN: circt-opt -pass-pipeline='builtin.module(firrtl.circuit(firrtl-lower-types{preserve-aggregate=all}))' --allow-unregistered-dialect %s | FileCheck --check-prefixes=AGGREGATE,COMMON %s


firrtl.circuit "TopLevel" {
Expand Down Expand Up @@ -1363,4 +1363,12 @@ firrtl.circuit "WireProbe" {
firrtl.ref.define %y, %sp_y : !firrtl.probe<uint<5>>
firrtl.ref.define %z, %sp_z : !firrtl.probe<uint<5>>
}
firrtl.module @UnrealizedConversion( ){
// CHECK: %[[a:.+]] = "d.w"() : () -> !hw.struct<data: i64, tag: i1>
// CHECK: = builtin.unrealized_conversion_cast %[[a]] : !hw.struct<data: i64, tag: i1> to !firrtl.bundle<data: uint<64>, tag: uint<1>>
%a = "d.w"() : () -> (!hw.struct<data: i64, tag: i1>)
%b = builtin.unrealized_conversion_cast %a : !hw.struct<data: i64, tag: i1> to !firrtl.bundle<data: uint<64>, tag: uint<1>>
%w = firrtl.wire : !firrtl.bundle<data: uint<64>, tag: uint<1>>
firrtl.strictconnect %w, %b : !firrtl.bundle<data: uint<64>, tag: uint<1>>
}
}

0 comments on commit 8da7ce4

Please sign in to comment.