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; }
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,
209 void print(raw_ostream &os)
const;
234 mapped_iterator<mlir::CallGraphNode::iterator, decltype(&unwrap)>;
245 :
public GraphTraits<const mlir::CallGraphNode *> {
258 #endif // MLIR_ANALYSIS_CALLGRAPH_H Include the generated interface declarations.
void addChildEdge(CallGraphNode *child)
Adds a reference edge to the given child node.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
bool isChild() const
Returns true if this edge represents a Child edge.
Explicitly register a set of "builtin" types.
Operation is a basic unit of execution within MLIR.
CallGraphNode * getExternalNode() const
Return the callgraph node representing the indirect-external callee.
NodeIterator iterator
An iterator over the nodes of the graph.
static ChildIteratorType child_begin(NodeRef node)
static constexpr const bool value
bool isAbstract() const
Returns true if this edge represents an Abstract edge.
static ChildIteratorType child_end(NodeRef node)
This class represents a collection of SymbolTables.
mapped_iterator< mlir::CallGraphNode::iterator, decltype(&unwrap)> ChildIteratorType
static nodes_iterator nodes_begin(mlir::CallGraph *cg)
CallGraphNode * getTarget() const
Returns the target node for this edge.
static NodeRef getEntryNode(const mlir::CallGraph *cg)
The entry node into the graph is the external node.
bool operator==(const Edge &edge) const
static NodeRef unwrap(const mlir::CallGraphNode::Edge &edge)
static NodeRef getEntryNode(NodeRef node)
void addCallEdge(CallGraphNode *node)
Add an outgoing call edge from this node.
bool isCall() const
Returns true if this edge represents a Call edge.
static void print(ArrayType type, DialectAsmPrinter &os)
friend class CallGraphNode
This class represents a single callable in the callgraph.
bool isExternal() const
Returns true if this node is an external node.
SmallVectorImpl< Edge >::const_iterator iterator
Iterator over the outgoing edges of this node.
void addAbstractEdge(CallGraphNode *node)
Adds an abstract reference edge to the given node.
static nodes_iterator nodes_end(mlir::CallGraph *cg)
This class represents a directed edge between two nodes in the callgraph.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Region * getCallableRegion() const
Returns the callable region this node represents.
mlir::CallGraph::iterator nodes_iterator
bool hasChildren() const
Returns true if this node has any child edges.