Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Verify RWProbeOp target has layer requirements. #7372

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lib/Dialect/FIRRTL/FIRRTLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6193,10 +6193,30 @@ LogicalResult RWProbeOp::verifyInnerRefs(hw::InnerRefNamespace &ns) {
}
return success();
};

auto checkLayers = [&](Location loc) -> LogicalResult {
auto dstLayers = getAmbientLayersAt(target.getOp());
auto srcLayers = getLayersFor(getResult());
SmallVector<SymbolRefAttr> missingLayers;
if (!isLayerSetCompatibleWith(srcLayers, dstLayers, missingLayers)) {
auto diag = emitOpError("target has insufficient layer requirements");
auto &note = diag.attachNote(loc);
note << "target is missing layer requirements: ";
llvm::interleaveComma(missingLayers, note);
return failure();
}
return success();
};
auto checks = [&](auto type, Location loc) {
if (failed(checkLayers(loc)))
return failure();
return checkFinalType(type, loc);
};

if (target.isPort()) {
auto mod = cast<FModuleLike>(target.getOp());
return checkFinalType(mod.getPortType(target.getPort()),
mod.getPortLocation(target.getPort()));
return checks(mod.getPortType(target.getPort()),
mod.getPortLocation(target.getPort()));
}
hw::InnerSymbolOpInterface symOp =
cast<hw::InnerSymbolOpInterface>(target.getOp());
Expand All @@ -6210,7 +6230,7 @@ LogicalResult RWProbeOp::verifyInnerRefs(hw::InnerRefNamespace &ns) {
return emitOpError("is not dominated by target")
.attachNote(symOp.getLoc())
.append("target here");
return checkFinalType(symOp.getTargetResult().getType(), symOp.getLoc());
return checks(symOp.getTargetResult().getType(), symOp.getLoc());
}

//===----------------------------------------------------------------------===//
Expand Down
14 changes: 14 additions & 0 deletions test/Dialect/FIRRTL/errors.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,20 @@ firrtl.circuit "RWProbeUseDef" {

// -----

firrtl.circuit "RWProbeLayerRequirements" {
firrtl.layer @A bind { }
firrtl.module @RWProbeLayerRequirements(in %cond : !firrtl.uint<1>) {
// expected-note @below {{target is missing layer requirements: @A}}
%w = firrtl.wire sym @x : !firrtl.uint<1>
firrtl.layerblock @A {
// expected-error @below {{target has insufficient layer requirements}}
%rw = firrtl.ref.rwprobe <@RWProbeLayerRequirements::@x> : !firrtl.rwprobe<uint<1>>
}
}
}
dtzSiFive marked this conversation as resolved.
Show resolved Hide resolved

// -----

firrtl.circuit "MissingClassForObjectPortInModule" {
// expected-error @below {{'firrtl.module' op references unknown class @Missing}}
firrtl.module @MissingClassForObjectPortInModule(out %o: !firrtl.class<@Missing()>) {}
Expand Down
12 changes: 12 additions & 0 deletions test/Dialect/FIRRTL/layers.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,16 @@ firrtl.circuit "Test" {
firrtl.propassign %foo_in, %str : !firrtl.string
}
}

//===--------------------------------------------------------------------===//
// RWProbe under Layer
//===--------------------------------------------------------------------===//

firrtl.module @RWProbeInLayer() {
firrtl.layerblock @A {
%w = firrtl.wire sym @sym : !firrtl.uint<1>
%rwp = firrtl.ref.rwprobe <@RWProbeInLayer::@sym> : !firrtl.rwprobe<uint<1>>
}
}

}
Loading