Skip to content

Commit

Permalink
[FIRRTL] Group instance-like ops using FInstanceLike
Browse files Browse the repository at this point in the history
  • Loading branch information
nandor committed Nov 21, 2023
1 parent 16e0c57 commit 1aa8ff5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 4 additions & 1 deletion include/circt/Dialect/FIRRTL/FIRRTLDeclarations.td
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class HardwareDeclOp<string mnemonic, list <Trait> traits = []> :
"firrtl::WhenOp", "firrtl::MatchOp"]>]> {}

def InstanceOp : HardwareDeclOp<"instance", [
DeclareOpInterfaceMethods<FInstanceLike>,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
DeclareOpInterfaceMethods<InstanceGraphInstanceOpInterface, [
"getModuleName",
Expand Down Expand Up @@ -597,10 +598,12 @@ def ClockGateIntrinsicOp : FIRRTLOp<"int.clock_gate", [Pure]> {
def ObjectOp : FIRRTLOp<"object", [
ParentOneOf<["firrtl::FModuleOp, firrtl::ClassOp"]>,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
DeclareOpInterfaceMethods<FInstanceLike, [
"getReferencedModule"
]>,
DeclareOpInterfaceMethods<InstanceGraphInstanceOpInterface, [
"getReferencedModuleName",
"getReferencedModuleNameAttr",
"getReferencedModule",
"getReferencedModuleSlow"
]>,
DeclareOpInterfaceMethods<OpAsmOpInterface, [
Expand Down
17 changes: 17 additions & 0 deletions include/circt/Dialect/FIRRTL/FIRRTLOpInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,23 @@ def FModuleLike : OpInterface<"FModuleLike", [Symbol, PortList, InstanceGraphMod
}];
}

def FInstanceLike : OpInterface<"FInstanceLike", [
InstanceGraphInstanceOpInterface
]> {
let cppNamespace = "circt::firrtl";
let description = "Provide common instance information.";

let methods = [
InterfaceMethod<"Get the referenced module via a symbol table.",
"::mlir::Operation *", "getReferencedModule",
(ins "const SymbolTable&":$symtbl),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
return symtbl.lookup($_op.getReferencedModuleName());
}]>,
];
}

def ClassLike : OpInterface<"ClassLike", [FModuleLike]> {
let cppNamespace = "circt::firrtl";
let description = "Provide common class information.";
Expand Down
10 changes: 1 addition & 9 deletions include/circt/Support/InstanceGraphInterface.td
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ def InstanceGraphInstanceOpInterface : OpInterface<"InstanceOpInterface"> {
/*defaultImplementation=*/[{
return SymbolTable::lookupNearestSymbolFrom(
$_op, getReferencedModuleNameAttr());
}]>,

InterfaceMethod<"Get the referenced module via a symbol table.",
"::mlir::Operation *", "getReferencedModule",
(ins "const SymbolTable&":$symtbl),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
return symtbl.lookup(getReferencedModuleName());
}]>,
}]>
];
}

Expand Down

0 comments on commit 1aa8ff5

Please sign in to comment.