[HW] Implement SymbolUserOpInterface for HW's IntanceOp (#1747)

This speeds up verification by using a prebuilt symbol table to look up
the referenced module instead of a linear walk of the IR.  A similar
change was recently made to the FIRRTL InstanceOp in 438ffeb0.
This commit is contained in:
Andrew Young 2021-09-08 10:04:28 -07:00 committed by GitHub
parent 7893a67e3d
commit e38fa006ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View File

@ -278,6 +278,7 @@ def HWModuleGeneratedOp : HWOp<"module.generated",
}
def InstanceOp : HWOp<"instance", [HasParent<"HWModuleOp">, Symbol,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>]> {
let summary = "Create an instance of a module";
let description = [{
@ -326,8 +327,6 @@ def InstanceOp : HWOp<"instance", [HasParent<"HWModuleOp">, Symbol,
$instanceName (`sym` $sym_name^)? $moduleName `(` $inputs `)` attr-dict
`:` functional-type($inputs, results)
}];
let verifier = "return ::verifyInstanceOp(*this);";
}
def OutputOp : HWOp<"output", [Terminator, HasParent<"HWModuleOp">,

View File

@ -725,18 +725,18 @@ static LogicalResult verifyInstanceOpTypes(InstanceOp op,
return success();
}
static LogicalResult verifyInstanceOp(InstanceOp op) {
auto referencedModule = op.getReferencedModule();
LogicalResult InstanceOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
auto *referencedModule =
symbolTable.lookupNearestSymbolFrom(*this, moduleNameAttr());
if (referencedModule == nullptr)
return op.emitError("Cannot find module definition '")
<< op.moduleName() << "'";
return emitError("Cannot find module definition '") << moduleName() << "'";
// If the referenced module is internal, check that input and result types are
// consistent with the referenced module.
if (!isa<HWModuleOp>(referencedModule))
return success();
return verifyInstanceOpTypes(op, referencedModule);
// If the referenced module is internal, check that input and result types are
// consistent with the referenced module.
return verifyInstanceOpTypes(*this, referencedModule);
}
StringAttr InstanceOp::getResultName(size_t idx,