CIRCT  20.0.0git
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 
12 using namespace circt;
13 using namespace firrtl;
14 
15 static 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 
23 InstanceGraph::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.
InstanceGraphNode * topLevelNode
InstanceGraph(Operation *operation)
Create a new module graph of a circuit.
InstanceGraphNode * lookup(ModuleOpInterface op)
Look up an InstanceGraphNode for a module.
Operation * getParent()
Return the parent under which all nodes are nested.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21