CIRCT  20.0.0git
FIRRTLInstanceGraph.h
Go to the documentation of this file.
1 //===- FIRRTLInstanceGraph.h - 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 //
9 // This file defines the FIRRTL InstanceGraph, which is similar to a CallGraph.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_FIRRTL_FIRRTLINSTANCEGRAPH_H
14 #define CIRCT_DIALECT_FIRRTL_FIRRTLINSTANCEGRAPH_H
15 
18 #include "circt/Support/LLVM.h"
19 #include "llvm/ADT/GraphTraits.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/iterator.h"
22 
23 namespace circt {
24 namespace firrtl {
28 
29 /// This graph tracks modules and where they are instantiated. This is intended
30 /// to be used as a cached analysis on FIRRTL circuits. This class can be used
31 /// to walk the modules efficiently in a bottom-up or top-down order.
32 ///
33 /// To use this class, retrieve a cached copy from the analysis manager:
34 /// auto &instanceGraph = getAnalysis<InstanceGraph>(getOperation());
36 public:
37  /// Create a new module graph of a circuit. This must be called on a FIRRTL
38  /// CircuitOp or MLIR ModuleOp.
39  explicit InstanceGraph(Operation *operation);
40 
41  /// Get the node corresponding to the top-level module of a circuit.
43 
44  /// Get the module corresponding to the top-level module of a circuit.
45  FModuleLike getTopLevelModule() {
46  return cast<FModuleLike>(*getTopLevelNode()->getModule());
47  }
48 
49 private:
51 };
52 
53 } // namespace firrtl
54 } // namespace circt
55 
56 template <>
57 struct llvm::GraphTraits<circt::firrtl::InstanceGraph *>
58  : public llvm::GraphTraits<circt::igraph::InstanceGraph *> {};
59 
60 template <>
61 struct llvm::DOTGraphTraits<circt::firrtl::InstanceGraph *>
62  : public llvm::DOTGraphTraits<circt::igraph::InstanceGraph *> {
63  using llvm::DOTGraphTraits<circt::igraph::InstanceGraph *>::DOTGraphTraits;
64 };
65 
66 #endif // CIRCT_DIALECT_FIRRTL_FIRRTLINSTANCEGRAPH_H
This graph tracks modules and where they are instantiated.
InstanceGraphNode * topLevelNode
igraph::InstanceGraphNode * getTopLevelNode() override
Get the node corresponding to the top-level module of a circuit.
FModuleLike getTopLevelModule()
Get the module corresponding to the top-level module of a circuit.
InstanceGraph(Operation *operation)
Create a new module graph of a circuit.
This is a Node in the InstanceGraph.
This graph tracks modules and where they are instantiated.
This is an edge in the InstanceGraph.
Definition: InstanceGraph.h:55
igraph::InstancePathCache InstancePathCache
igraph::InstanceRecord InstanceRecord
igraph::InstanceGraphNode InstanceGraphNode
std::map< std::string, std::set< std::string > > InstanceGraph
Iterates over the handshake::FuncOp's in the program to build an instance graph.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
A data structure that caches and provides absolute paths to module instances in the IR.