16 #ifndef MLIR_ANALYSIS_CALLGRAPH_H
17 #define MLIR_ANALYSIS_CALLGRAPH_H
20 #include "llvm/ADT/GraphTraits.h"
21 #include "llvm/ADT/MapVector.h"
22 #include "llvm/ADT/PointerIntPair.h"
23 #include "llvm/ADT/SetVector.h"
26 class CallOpInterface;
27 struct CallInterfaceCallable;
30 class SymbolTableCollection;
64 bool isAbstract()
const {
return targetAndKind.getInt() == Kind::Abstract; }
67 bool isCall()
const {
return targetAndKind.getInt() == Kind::Call; }
70 bool isChild()
const {
return targetAndKind.getInt() == Kind::Child; }
76 return targetAndKind == edge.targetAndKind;
81 explicit Edge(llvm::PointerIntPair<CallGraphNode *, 2, Kind> targetAndKind)
82 : targetAndKind(targetAndKind) {}
85 llvm::PointerIntPair<CallGraphNode *, 2, Kind> targetAndKind;
123 static Edge getEmptyKey() {
return Edge(BaseInfo::getEmptyKey()); }
124 static Edge getTombstoneKey() {
return Edge(BaseInfo::getTombstoneKey()); }
125 static unsigned getHashValue(
const Edge &edge) {
126 return BaseInfo::getHashValue(edge.targetAndKind);
128 static bool isEqual(
const Edge &lhs,
const Edge &rhs) {
return lhs == rhs; }
131 CallGraphNode(Region *callableRegion) : callableRegion(callableRegion) {}
134 void addEdge(CallGraphNode *node, Edge::Kind kind);
139 Region *callableRegion;
142 SetVector<Edge, SmallVector<Edge, 4>,
143 llvm::SmallDenseSet<Edge, 4, EdgeKeyInfo>>
155 using NodeMapT = llvm::MapVector<Region *, std::unique_ptr<CallGraphNode>>;
159 class NodeIterator final
160 :
public llvm::mapped_iterator<
161 NodeMapT::const_iterator,
162 CallGraphNode *(*)(const NodeMapT::value_type &)> {
164 return value.second.get();
169 NodeIterator(NodeMapT::const_iterator it)
170 : llvm::mapped_iterator<
171 NodeMapT::const_iterator,
214 void print(raw_ostream &os)
const;
233 struct GraphTraits<const
mlir::CallGraphNode *> {
253 struct GraphTraits<const
mlir::CallGraph *>
254 :
public GraphTraits<const mlir::CallGraphNode *> {
This class represents a directed edge between two nodes in the callgraph.
bool isChild() const
Returns true if this edge represents a Child edge.
CallGraphNode * getTarget() const
Returns the target node for this edge.
bool isCall() const
Returns true if this edge represents a Call edge.
bool operator==(const Edge &edge) const
bool isAbstract() const
Returns true if this edge represents an Abstract edge.
This class represents a single callable in the callgraph.
bool isExternal() const
Returns true if this node is an external node.
void addAbstractEdge(CallGraphNode *node)
Adds an abstract reference edge to the given node.
void addChildEdge(CallGraphNode *child)
Adds a reference edge to the given child node.
bool hasChildren() const
Returns true if this node has any child edges.
void addCallEdge(CallGraphNode *node)
Add an outgoing call edge from this node.
Region * getCallableRegion() const
Returns the callable region this node represents.
SmallVectorImpl< Edge >::const_iterator iterator
Iterator over the outgoing edges of this node.
void eraseNode(CallGraphNode *node)
Erase the given node from the callgraph.
CallGraphNode * resolveCallable(CallOpInterface call, SymbolTableCollection &symbolTable) const
Resolve the callable for given callee to a node in the callgraph, or the external node if a valid nod...
CallGraphNode * getUnknownCalleeNode() const
Return the callgraph node representing an indirect callee.
NodeIterator iterator
An iterator over the nodes of the graph.
CallGraphNode * lookupNode(Region *region) const
Lookup a call graph node for the given region, or nullptr if none is registered.
void dump() const
Dump the graph in a human readable format.
CallGraphNode * getOrAddNode(Region *region, CallGraphNode *parentNode)
Get or add a call graph node for the given region.
void print(raw_ostream &os) const
CallGraphNode * getExternalCallerNode() const
Return the callgraph node representing an external caller.
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class represents a collection of SymbolTables.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
static ChildIteratorType child_begin(NodeRef node)
mapped_iterator< mlir::CallGraphNode::iterator, decltype(&unwrap)> ChildIteratorType
static NodeRef unwrap(const mlir::CallGraphNode::Edge &edge)
static NodeRef getEntryNode(NodeRef node)
static ChildIteratorType child_end(NodeRef node)
static nodes_iterator nodes_begin(mlir::CallGraph *cg)
static NodeRef getEntryNode(const mlir::CallGraph *cg)
The entry node into the graph is the external node.
static nodes_iterator nodes_end(mlir::CallGraph *cg)
mlir::CallGraph::iterator nodes_iterator