//===- CallGraph.cpp - CallGraph analysis for MLIR ------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains interfaces and analyses for defining a nested callgraph. // //===----------------------------------------------------------------------===// #include "mlir/Analysis/CallGraph.h" #include "mlir/IR/Operation.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Support/LLVM.h" #include "llvm/ADT/SCCIterator.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/raw_ostream.h" #include <cassert> #include <memory> usingnamespacemlir; //===----------------------------------------------------------------------===// // CallGraphNode //===----------------------------------------------------------------------===// /// Returns true if this node refers to the indirect/external node. bool CallGraphNode::isExternal() const { … } /// Return the callable region this node represents. This can only be called /// on non-external nodes. Region *CallGraphNode::getCallableRegion() const { … } /// Adds an reference edge to the given node. This is only valid on the /// external node. void CallGraphNode::addAbstractEdge(CallGraphNode *node) { … } /// Add an outgoing call edge from this node. void CallGraphNode::addCallEdge(CallGraphNode *node) { … } /// Adds a reference edge to the given child node. void CallGraphNode::addChildEdge(CallGraphNode *child) { … } /// Returns true if this node has any child edges. bool CallGraphNode::hasChildren() const { … } /// Add an edge to 'node' with the given kind. void CallGraphNode::addEdge(CallGraphNode *node, Edge::Kind kind) { … } //===----------------------------------------------------------------------===// // CallGraph //===----------------------------------------------------------------------===// /// Recursively compute the callgraph edges for the given operation. Computed /// edges are placed into the given callgraph object. static void computeCallGraph(Operation *op, CallGraph &cg, SymbolTableCollection &symbolTable, CallGraphNode *parentNode, bool resolveCalls) { … } CallGraph::CallGraph(Operation *op) : … { … } /// Get or add a call graph node for the given region. CallGraphNode *CallGraph::getOrAddNode(Region *region, CallGraphNode *parentNode) { … } /// Lookup a call graph node for the given region, or nullptr if none is /// registered. CallGraphNode *CallGraph::lookupNode(Region *region) const { … } /// Resolve the callable for given callee to a node in the callgraph, or the /// unknown callee node if a valid node was not resolved. CallGraphNode * CallGraph::resolveCallable(CallOpInterface call, SymbolTableCollection &symbolTable) const { … } /// Erase the given node from the callgraph. void CallGraph::eraseNode(CallGraphNode *node) { … } //===----------------------------------------------------------------------===// // Printing /// Dump the graph in a human readable format. void CallGraph::dump() const { … } void CallGraph::print(raw_ostream &os) const { … }