diff --git a/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp b/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp index 25ca0304299..ad66f37aed4 100644 --- a/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp +++ b/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp @@ -441,9 +441,23 @@ bool LowerClassesPass::shouldCreateClass(FModuleLike moduleLike) { if (moduleLike.isPublic()) return true; - return llvm::any_of(moduleLike.getPorts(), [](PortInfo port) { + // Create a class for modules with property ports. + bool hasClassPorts = llvm::any_of(moduleLike.getPorts(), [](PortInfo port) { return isa(port.type); }); + + if (hasClassPorts) + return true; + + // Create a class for modules that instantiate classes or modules with + // property ports. + for (auto op : + moduleLike.getOperation()->getRegion(0).getOps()) + for (auto result : op->getResults()) + if (type_isa(result.getType())) + return true; + + return false; } // Create an OM Class op from a FIRRTL Class op or Module op with properties. diff --git a/test/Dialect/FIRRTL/lower-classes.mlir b/test/Dialect/FIRRTL/lower-classes.mlir index e30aff21a45..516106a3a22 100644 --- a/test/Dialect/FIRRTL/lower-classes.mlir +++ b/test/Dialect/FIRRTL/lower-classes.mlir @@ -327,3 +327,14 @@ firrtl.circuit "AnyCast" { firrtl.propassign %foo, %0 : !firrtl.anyref } } + +// CHECK-LABEL: firrtl.circuit "ModuleWithPropertySubmodule" +firrtl.circuit "ModuleWithPropertySubmodule" { + firrtl.module private @ModuleWithPropertySubmodule() { + %c0 = firrtl.integer 0 + %inst.prop = firrtl.instance inst @SubmoduleWithProperty(in prop: !firrtl.integer) + firrtl.propassign %inst.prop, %c0 : !firrtl.integer + } + firrtl.module private @SubmoduleWithProperty(in %prop: !firrtl.integer) { + } +}