[NFC][InstanceGraph] Remove the slow target getter helper

This commit is contained in:
Nandor Licker 2023-11-18 04:10:11 -08:00
parent 1aa8ff5071
commit 2711dd5a95
6 changed files with 15 additions and 35 deletions

View File

@ -44,8 +44,7 @@ def InstanceOp : HardwareDeclOp<"instance", [
DeclareOpInterfaceMethods<FInstanceLike>,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
DeclareOpInterfaceMethods<InstanceGraphInstanceOpInterface, [
"getModuleName",
"getReferencedModuleSlow"
"getModuleName"
]>,
]> {
let summary = "Instantiate an instance of a module";

View File

@ -39,17 +39,6 @@ def InstanceGraphInstanceOpInterface : OpInterface<"InstanceOpInterface"> {
"::mlir::StringAttr", "getReferencedModuleNameAttr", (ins),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{ return $_op.getModuleNameAttr().getAttr(); }]>,
InterfaceMethod<[{
Get the referenced module (slow, unsafe). This function directly accesses
the parent operation to lookup a symbol, which is unsafe in many contexts.
}],
"::mlir::Operation *", "getReferencedModuleSlow", (ins),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
return SymbolTable::lookupNearestSymbolFrom(
$_op, getReferencedModuleNameAttr());
}]>
];
}

View File

@ -322,7 +322,9 @@ static LogicalResult convertExtMemoryOps(HWModuleOp mod) {
// Get the attached extmemory external module.
auto extmemInstance = cast<hw::InstanceOp>(*arg.getUsers().begin());
auto extmemMod =
cast<hw::HWModuleExternOp>(extmemInstance.getReferencedModuleSlow());
cast<hw::HWModuleExternOp>(SymbolTable::lookupNearestSymbolFrom(
extmemInstance, extmemInstance.getReferencedModuleNameAttr()));
ModulePortInfo portInfo(extmemMod.getPortList());
// The extmemory external module's interface is a direct wrapping of the

View File

@ -1913,18 +1913,11 @@ bool ExtClassOp::canDiscardOnUseEmpty() {
// Declarations
//===----------------------------------------------------------------------===//
/// Lookup the module or extmodule for the symbol. This returns null on
/// invalid IR.
Operation *InstanceOp::getReferencedModuleSlow() {
SmallVector<::circt::hw::PortInfo> InstanceOp::getPortList() {
auto circuit = (*this)->getParentOfType<CircuitOp>();
if (!circuit)
return nullptr;
return circuit.lookupSymbol<FModuleLike>(getModuleNameAttr());
}
SmallVector<::circt::hw::PortInfo> InstanceOp::getPortList() {
return cast<hw::PortList>(getReferencedModuleSlow()).getPortList();
llvm::report_fatal_error("instance op not in circuit");
return circuit.lookupSymbol<hw::PortList>(getModuleNameAttr()).getPortList();
}
void InstanceOp::build(OpBuilder &builder, OperationState &result,
@ -2930,14 +2923,6 @@ Operation *ObjectOp::getReferencedModule(const SymbolTable &symtbl) {
return getReferencedClass(symtbl);
}
Operation *ObjectOp::getReferencedModuleSlow() {
auto circuit = (*this)->getParentOfType<CircuitOp>();
if (!circuit)
return nullptr;
return circuit.lookupSymbol<ClassLike>(getClassNameAttr());
}
StringRef ObjectOp::getInstanceName() { return getName(); }
StringAttr ObjectOp::getInstanceNameAttr() { return getNameAttr(); }

View File

@ -94,8 +94,10 @@ struct InstanceOpConversion : public OpConversionPattern<hw::InstanceOp> {
}
// Create the new instance...
Operation *targetModule = SymbolTable::lookupNearestSymbolFrom(
op, op.getReferencedModuleNameAttr());
auto newInstance = rewriter.create<hw::InstanceOp>(
loc, op.getReferencedModuleSlow(), op.getInstanceName(), convOperands);
loc, targetModule, op.getInstanceName(), convOperands);
// re-create any structs in the result.
llvm::SmallVector<Value> convResults;
@ -381,7 +383,9 @@ static LogicalResult flattenOpsOfType(ModuleOp module, bool recursive) {
// And likewise with the converted instance ops.
for (auto instanceOp : convertedInstances) {
Operation *targetModule = instanceOp.getReferencedModuleSlow();
Operation *targetModule = SymbolTable::lookupNearestSymbolFrom(
instanceOp, instanceOp.getReferencedModuleNameAttr());
auto ioInfo = ioInfoMap[targetModule];
instanceOp.setInputNames(ArrayAttr::get(
instanceOp.getContext(),

View File

@ -531,7 +531,8 @@ InstanceDeclOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
}
SmallVector<hw::PortInfo> InstanceDeclOp::getPortList() {
return cast<hw::PortList>(getReferencedModuleSlow()).getPortList();
return cast<hw::PortList>(getReferencedModuleCached(/*cache=*/nullptr))
.getPortList();
}
//===----------------------------------------------------------------------===//