Skip to content

Commit 29d7494

Browse files
committed
[FIRRTL] Use InnerRefUserOpInterface for bind op
Drop the SymbolUserOpInterface in favour of InnerRefUserOpInterface. Using this new trait makes verification for the bind op faster and simpler, because the verification method is handed an inner symbol table.
1 parent 5d8da83 commit 29d7494

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

include/circt/Dialect/FIRRTL/FIRRTLStatements.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def LayerBlockOp : FIRRTLOp<
414414
//===----------------------------------------------------------------------===//
415415

416416
def BindOp : FIRRTLOp<"bind",
417-
[DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
417+
[DeclareOpInterfaceMethods<InnerRefUserOpInterface>]> {
418418
let summary = "Indirect instantiation statement";
419419
let description = [{
420420
Indirectly instantiate a module from the context of another module. BindOp

lib/Dialect/FIRRTL/FIRRTLOps.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6398,32 +6398,23 @@ void HierarchicalModuleNameOp::getAsmResultNames(
63986398
// BindOp
63996399
//===----------------------------------------------------------------------===//
64006400

6401-
namespace {
6402-
template <class Op>
6403-
Op findInnerSym(StringAttr name, Block *body) {
6404-
for (auto &op : llvm::reverse(body->getOperations()))
6405-
if (auto target = dyn_cast<Op>(op))
6406-
if (auto innerSym = target.getInnerSym())
6407-
if (innerSym->getSymName() == name)
6408-
return target;
6409-
return {};
6410-
}
6411-
} // namespace
6401+
LogicalResult BindOp::verifyInnerRefs(hw::InnerRefNamespace &ns) {
6402+
auto ref = getInstanceAttr();
6403+
auto target = ns.lookup(ref);
6404+
if (!target)
6405+
return emitError()
6406+
<< "has target that cannot be resolved: " << ref;
6407+
6408+
if (!target.isOpOnly())
6409+
return emitError() << "target " << ref << " is not an operation";
6410+
6411+
auto instance = dyn_cast<InstanceOp>(target.getOp());
6412+
if (!instance)
6413+
return emitError() << "target " << ref << " is not an instance";
6414+
6415+
if (!instance.getDoNotPrint())
6416+
return emitError() << "target " << ref << " is not marked doNotPrint";
64126417

6413-
LogicalResult BindOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
6414-
auto circuit = getOperation()->getParentOfType<CircuitOp>();
6415-
auto module = dyn_cast_or_null<FModuleOp>(
6416-
symbolTable.lookupSymbolIn(circuit, getInstance().getModule()));
6417-
if (!module)
6418-
return emitError("Referenced module doesn't exist ")
6419-
<< getInstance().getModule() << "::" << getInstance().getName();
6420-
auto inst =
6421-
findInnerSym<InstanceOp>(getInstance().getName(), module.getBodyBlock());
6422-
if (!inst)
6423-
return emitError("Referenced instance doesn't exist ")
6424-
<< getInstance().getModule() << "::" << getInstance().getName();
6425-
if (!inst.getDoNotPrint())
6426-
return emitError("Referenced instance isn't marked as doNotPrint");
64276418
return success();
64286419
}
64296420

test/Dialect/FIRRTL/errors.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,15 +2890,15 @@ firrtl.circuit "SimulationPortType3" {
28902890

28912891
firrtl.circuit "BindTargetMissingModule" {
28922892
firrtl.module @BindTargetMissing() {}
2893-
// expected-error @below {{Referenced module doesn't exist "XXX"::"YYY}}
2893+
// expected-error @below {{has target that cannot be resolved: #hw.innerNameRef<@XXX::@YYY>}}
28942894
firrtl.bind <@XXX::@YYY>
28952895
}
28962896

28972897
// -----
28982898

28992899
firrtl.circuit "BindTargetMissingInstance" {
29002900
firrtl.module @BindTargetMissingInstance() {}
2901-
// expected-error @below {{Referenced instance doesn't exist "BindTargetMissingInstance"::"YYY"}}
2901+
// expected-error @below {{has target that cannot be resolved: #hw.innerNameRef<@BindTargetMissingInstance::@YYY>}}
29022902
firrtl.bind <@BindTargetMissingInstance::@YYY>
29032903
}
29042904

@@ -2910,6 +2910,6 @@ firrtl.circuit "BindTargetMissingDoNotPrintFlag" {
29102910
firrtl.instance target sym @target @Target()
29112911
}
29122912

2913-
// expected-error @below {{Referenced instance isn't marked as doNotPrint}}
2913+
// expected-error @below {{target #hw.innerNameRef<@BindTargetMissingDoNotPrintFlag::@target> is not marked doNotPrint}}
29142914
firrtl.bind <@BindTargetMissingDoNotPrintFlag::@target>
29152915
}

0 commit comments

Comments
 (0)