CIRCT 20.0.0git
Loading...
Searching...
No Matches
FIRRTLInstanceGraph.cpp
Go to the documentation of this file.
1//===- FIRRTLInstanceGraph.cpp - Instance Graph -----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "mlir/IR/BuiltinOps.h"
11
12using namespace circt;
13using namespace firrtl;
14
15static CircuitOp findCircuitOp(Operation *operation) {
16 if (auto mod = dyn_cast<mlir::ModuleOp>(operation))
17 for (auto &op : *mod.getBody())
18 if (auto circuit = dyn_cast<CircuitOp>(&op))
19 return circuit;
20 return cast<CircuitOp>(operation);
21}
22
23InstanceGraph::InstanceGraph(Operation *operation)
24 : igraph::InstanceGraph(findCircuitOp(operation)) {
25 topLevelNode = lookup(cast<CircuitOp>(getParent()).getNameAttr());
26}
static CircuitOp findCircuitOp(Operation *operation)
This graph tracks modules and where they are instantiated.
InstanceGraph(Operation *operation)
Create a new module graph of a circuit.
Operation * getParent()
Return the parent under which all nodes are nested.
InstanceGraphNode * lookup(ModuleOpInterface op)
Look up an InstanceGraphNode for a module.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.