[FIRRTL] Cast to AnyRefType for metadata output port. (#7149)

We generally type-erase objects at the boundary, to avoid needing to
declare the objects' classes as part of the interface. This adds a
cast for the metadataObj reference, so we don't have to declare its
class as part of the interface. The evaluator and any tooling built on
it already know how to "see through" this cast.
This commit is contained in:
Mike Urbach 2024-06-10 14:13:38 -06:00 committed by GitHub
parent 42e1adfe72
commit 72313e072e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -856,11 +856,12 @@ void CreateSiFiveMetadataPass::runOnOperation() {
SmallVector<std::pair<unsigned, PortInfo>> ports = {
{portIndex,
PortInfo(StringAttr::get(objectOp->getContext(), "metadataObj"),
objectOp.getType(), Direction::Out)}};
AnyRefType::get(objectOp->getContext()), Direction::Out)}};
topMod.insertPorts(ports);
auto builderOM = mlir::ImplicitLocOpBuilder::atBlockEnd(
topMod->getLoc(), topMod.getBodyBlock());
builderOM.create<PropAssignOp>(topMod.getArgument(portIndex), objectOp);
auto objectCast = builderOM.create<ObjectAnyRefCastOp>(objectOp);
builderOM.create<PropAssignOp>(topMod.getArgument(portIndex), objectCast);
}
// This pass modifies the hierarchy, InstanceGraph is not preserved.

View File

@ -39,8 +39,10 @@ firrtl.circuit "retime0" attributes { annotations = [{
}]} { }
}
// CHECK-LABEL: firrtl.circuit "retime0" {
// CHECK: firrtl.module @retime0(out %metadataObj: !firrtl.class<@SiFive_Metadata
// CHECK: %sifive_metadata = firrtl.object @SiFive_Metadata
// CHECK: firrtl.module @retime0(out %metadataObj: !firrtl.any
// CHECK: [[SIFIVE_METADATA:%.+]] = firrtl.object @SiFive_Metadata
// CHECK: [[METADATA_OBJ:%.+]] = firrtl.object.anyref_cast [[SIFIVE_METADATA]]
// CHECK: propassign %metadataObj, [[METADATA_OBJ]]
// CHECK: firrtl.module @retime1() {
// CHECK: firrtl.module @retime2()