diff --git a/lib/Conversion/FIRRTLToHW/LowerToHW.cpp b/lib/Conversion/FIRRTLToHW/LowerToHW.cpp index 2855be4511ef..3b7b3ed731ec 100644 --- a/lib/Conversion/FIRRTLToHW/LowerToHW.cpp +++ b/lib/Conversion/FIRRTLToHW/LowerToHW.cpp @@ -1846,26 +1846,30 @@ LogicalResult FIRRTLLowering::run() { // Iterate through each operation in the module body, attempting to lower // each of them. We maintain 'builder' for each invocation. - for (auto &op : body.front().getOperations()) { - builder.setInsertionPoint(&op); - builder.setLoc(op.getLoc()); - auto done = succeeded(dispatchVisitor(&op)); - circuitState.processRemainingAnnotations(&op, AnnotationSet(&op)); + auto result = theModule.walk([&](Operation *op){ + builder.setInsertionPoint(op); + builder.setLoc(op->getLoc()); + auto done = succeeded(dispatchVisitor(op)); + circuitState.processRemainingAnnotations(op, AnnotationSet(op)); if (done) - opsToRemove.push_back(&op); + opsToRemove.push_back(op); else { - switch (handleUnloweredOp(&op)) { + switch (handleUnloweredOp(op)) { case AlreadyLowered: break; // Something like hw.output, which is already lowered. case NowLowered: // Something handleUnloweredOp removed. - opsToRemove.push_back(&op); + opsToRemove.push_back(op); break; case LoweringFailure: backedgeBuilder.abandon(); - return failure(); + return WalkResult::interrupt(); } } - } + return WalkResult::advance(); + }); + + if (result.wasInterrupted()) + return failure(); // Replace all backedges with uses of their regular values. We process them // after the module body since the lowering table is too hard to keep up to diff --git a/test/Conversion/FIRRTLToHW/lower-to-hw.mlir b/test/Conversion/FIRRTLToHW/lower-to-hw.mlir index 06bce0aa0156..442902dc54f5 100644 --- a/test/Conversion/FIRRTLToHW/lower-to-hw.mlir +++ b/test/Conversion/FIRRTLToHW/lower-to-hw.mlir @@ -1480,6 +1480,17 @@ firrtl.circuit "Simple" attributes {annotations = [{class = // CHECK-NEXT: %6 = sv.read_inout %5 : !hw.inout // CHECK-NEXT: hw.output %2, %6 : i32, i32 } + + sv.macro.decl @IfDef_MacroDecl + // CHECK-LABEL: @IfDef + firrtl.module @IfDef() { + // CHECK: sv.ifdef + sv.ifdef @IfDef_MacroDecl { + // CHECK-NEXT: %a = hw.wire + %a = firrtl.wire : !firrtl.uint<1> + } + } + } // -----