@@ -570,12 +570,13 @@ struct FIRRTLModuleLowering
570570 LogicalResult
571571 lowerModulePortsAndMoveBody (FModuleOp oldModule, hw::HWModuleOp newModule,
572572 CircuitLoweringState &loweringState);
573- LogicalResult lowerModuleOperations (hw::HWModuleOp module ,
574- CircuitLoweringState &loweringState);
573+ LogicalResult lowerModuleBody (hw::HWModuleOp module ,
574+ CircuitLoweringState &loweringState);
575575 LogicalResult lowerFormalBody (verif::FormalOp formalOp,
576576 CircuitLoweringState &loweringState);
577577 LogicalResult lowerSimulationBody (verif::SimulationOp simulationOp,
578578 CircuitLoweringState &loweringState);
579+ LogicalResult lowerBody (Operation *op, CircuitLoweringState &loweringState);
579580};
580581
581582} // end anonymous namespace
@@ -617,9 +618,7 @@ void FIRRTLModuleLowering::runOnOperation() {
617618 verificationFlavor, getAnalysis<InstanceGraph>(),
618619 &getAnalysis<NLATable>());
619620
620- SmallVector<hw::HWModuleOp, 32 > modulesToProcess;
621- SmallVector<verif::FormalOp> formalOpsToProcess;
622- SmallVector<verif::SimulationOp> simulationOpsToProcess;
621+ SmallVector<Operation *, 32 > opsToProcess;
623622
624623 AnnotationSet circuitAnno (circuit);
625624 moveVerifAnno (getOperation (), circuitAnno, extractAssertAnnoClass,
@@ -643,7 +642,7 @@ void FIRRTLModuleLowering::runOnOperation() {
643642 return failure ();
644643
645644 state.recordModuleMapping (&op, loweredMod);
646- modulesToProcess .push_back (loweredMod);
645+ opsToProcess .push_back (loweredMod);
647646 // Lower all the alias types.
648647 module .walk ([&](Operation *op) {
649648 for (auto res : op->getResults ()) {
@@ -677,7 +676,7 @@ void FIRRTLModuleLowering::runOnOperation() {
677676 oldOp.getParametersAttr ());
678677 newOp.getBody ().emplaceBlock ();
679678 state.recordModuleMapping (oldOp, newOp);
680- formalOpsToProcess .push_back (newOp);
679+ opsToProcess .push_back (newOp);
681680 return success ();
682681 })
683682 .Case <SimulationOp>([&](auto oldOp) {
@@ -689,7 +688,7 @@ void FIRRTLModuleLowering::runOnOperation() {
689688 body.addArgument (seq::ClockType::get (builder.getContext ()), loc);
690689 body.addArgument (builder.getI1Type (), loc);
691690 state.recordModuleMapping (oldOp, newOp);
692- simulationOpsToProcess .push_back (newOp);
691+ opsToProcess .push_back (newOp);
693692 return success ();
694693 })
695694 .Default ([&](Operation *op) {
@@ -747,28 +746,14 @@ void FIRRTLModuleLowering::runOnOperation() {
747746 ->setAttr (moduleHierarchyFileAttrName,
748747 ArrayAttr::get (&getContext (), testHarnessHierarchyFiles));
749748
750- // Lower all module bodies.
751- auto result = mlir::failableParallelForEachN (
752- &getContext (), 0 , modulesToProcess. size (), [&](auto index ) {
753- return lowerModuleOperations (modulesToProcess[index] , state);
749+ // Lower all module and formal op bodies.
750+ auto result =
751+ mlir::failableParallelForEach ( &getContext (), opsToProcess, [&](auto op ) {
752+ return lowerBody (op , state);
754753 });
755754 if (failed (result))
756755 return signalPassFailure ();
757756
758- // Lower all formal op bodies.
759- result = mlir::failableParallelForEach (
760- &getContext (), formalOpsToProcess,
761- [&](auto op) { return lowerFormalBody (op, state); });
762- if (failed (result))
763- return signalPassFailure ();
764-
765- // Lower all simulation op bodies.
766- result = mlir::failableParallelForEach (
767- &getContext (), simulationOpsToProcess,
768- [&](auto op) { return lowerSimulationBody (op, state); });
769- if (failed (result))
770- return signalPassFailure ();
771-
772757 // Move binds from inside modules to outside modules.
773758 for (auto bind : state.binds ) {
774759 bind->moveBefore (bind->getParentOfType <hw::HWModuleOp>());
@@ -1900,11 +1885,24 @@ struct FIRRTLLowering : public FIRRTLVisitor<FIRRTLLowering, LogicalResult> {
19001885};
19011886} // end anonymous namespace
19021887
1903- LogicalResult FIRRTLModuleLowering::lowerModuleOperations (
1904- hw::HWModuleOp module , CircuitLoweringState &loweringState) {
1888+ LogicalResult
1889+ FIRRTLModuleLowering::lowerModuleBody (hw::HWModuleOp module ,
1890+ CircuitLoweringState &loweringState) {
19051891 return FIRRTLLowering (module , loweringState).run ();
19061892}
19071893
1894+ LogicalResult
1895+ FIRRTLModuleLowering::lowerBody (Operation *op,
1896+ CircuitLoweringState &loweringState) {
1897+ if (auto moduleOp = dyn_cast<hw::HWModuleOp>(op))
1898+ return lowerModuleBody (moduleOp, loweringState);
1899+ if (auto formalOp = dyn_cast<verif::FormalOp>(op))
1900+ return lowerFormalBody (formalOp, loweringState);
1901+ if (auto simulationOp = dyn_cast<verif::SimulationOp>(op))
1902+ return lowerSimulationBody (simulationOp, loweringState);
1903+ return failure ();
1904+ }
1905+
19081906// This is the main entrypoint for the lowering pass.
19091907LogicalResult FIRRTLLowering::run () {
19101908 // Mark the module's block arguments are already lowered. This will allow
0 commit comments