Skip to content

Commit

Permalink
[FIRRTLToHW] Walk regions/blocks when converting
Browse files Browse the repository at this point in the history
Change the `LowerToHW` FIRRTL to HW conversion pass to walk
`firrtl.module` bodies as opposed to just visiting operations in their
bodies.  This has the benefit of allowing intermixing of operations from
other dialects, e.g., `sv.ifdef`, which may be generated by passes right
before this conversion runs.

Practically, this is part of turning on inline layer support for FIRRTL
compiler pipelines.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
  • Loading branch information
seldridge committed Dec 3, 2024
1 parent c0a8cdd commit 6538b1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/Conversion/FIRRTLToHW/LowerToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/Conversion/FIRRTLToHW/lower-to-hw.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,17 @@ firrtl.circuit "Simple" attributes {annotations = [{class =
// CHECK-NEXT: %6 = sv.read_inout %5 : !hw.inout<i32>
// 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>
}
}

}

// -----
Expand Down

0 comments on commit 6538b1e

Please sign in to comment.