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 struct CallInterfaceCallable;
62 bool isAbstract()
const {
return targetAndKind.getInt() == Kind::Abstract; }
65 bool isCall()
const {
return targetAndKind.getInt() == Kind::Call; }
68 bool isChild()
const {
return targetAndKind.getInt() == Kind::Child; }
74 return targetAndKind == edge.targetAndKind;
79 explicit Edge(llvm::PointerIntPair<CallGraphNode *, 2, Kind> targetAndKind)
80 : targetAndKind(targetAndKind) {}
83 llvm::PointerIntPair<CallGraphNode *, 2, Kind> targetAndKind;
121 static Edge getEmptyKey() {
return Edge(BaseInfo::getEmptyKey()); }
122 static Edge getTombstoneKey() {
return Edge(BaseInfo::getTombstoneKey()); }
123 static unsigned getHashValue(
const Edge &edge) {
124 return BaseInfo::getHashValue(edge.targetAndKind);
126 static bool isEqual(
const Edge &lhs,
const Edge &rhs) {
return lhs == rhs; }
140 llvm::SetVector<Edge, SmallVector<Edge, 4>,
141 llvm::SmallDenseSet<Edge, 4, EdgeKeyInfo>>
153 using NodeMapT = llvm::MapVector<Region *, std::unique_ptr<CallGraphNode>>;
157 class NodeIterator final
158 :
public llvm::mapped_iterator<
159 NodeMapT::const_iterator,
160 CallGraphNode *(*)(const NodeMapT::value_type &)> {
161 static CallGraphNode *unwrap(
const NodeMapT::value_type &value) {
162 return value.second.get();
167 NodeIterator(NodeMapT::const_iterator it)
168 : llvm::mapped_iterator<
169 NodeMapT::const_iterator,
170 CallGraphNode *(*)(
const NodeMapT::value_type &)>(it, &unwrap) {}
204 void print(raw_ostream &os)
const;
229 mapped_iterator<mlir::CallGraphNode::iterator, decltype(&unwrap)>;
231 return {node->
begin(), &unwrap};
234 return {node->
end(), &unwrap};
240 :
public GraphTraits<const mlir::CallGraphNode *> {
253 #endif // MLIR_ANALYSIS_CALLGRAPH_H Definition: InferTypeOpInterface.cpp:20
void addChildEdge(CallGraphNode *child)
Adds a reference edge to the given child node.
Definition: CallGraph.cpp:56
iterator begin() const
Definition: CallGraph.h:199
bool isChild() const
Returns if this edge represents a Child edge.
Definition: CallGraph.h:68
Definition: PassRegistry.cpp:413
Definition: Operation.h:27
CallGraphNode * getExternalNode() const
Return the callgraph node representing the indirect-external callee.
Definition: CallGraph.h:186
iterator begin() const
Definition: CallGraph.h:109
NodeIterator iterator
An iterator over the nodes of the graph.
Definition: CallGraph.h:198
static ChildIteratorType child_begin(NodeRef node)
Definition: CallGraph.h:230
bool isAbstract() const
Returns if this edge represents an Abstract edge.
Definition: CallGraph.h:62
static ChildIteratorType child_end(NodeRef node)
Definition: CallGraph.h:233
mapped_iterator< mlir::CallGraphNode::iterator, decltype(&unwrap)> ChildIteratorType
Definition: CallGraph.h:229
static nodes_iterator nodes_begin(mlir::CallGraph *cg)
Definition: CallGraph.h:248
CallGraphNode * getTarget() const
Returns the target node for this edge.
Definition: CallGraph.h:71
static NodeRef getEntryNode(const mlir::CallGraph *cg)
The entry node into the graph is the external node.
Definition: CallGraph.h:242
bool operator==(const Edge &edge) const
Definition: CallGraph.h:73
static NodeRef unwrap(const mlir::CallGraphNode::Edge &edge)
Definition: CallGraph.h:223
Definition: CallInterfaces.h:24
static NodeRef getEntryNode(NodeRef node)
Definition: CallGraph.h:221
void addCallEdge(CallGraphNode *node)
Add an outgoing call edge from this node.
Definition: CallGraph.cpp:51
bool isCall() const
Returns if this edge represents a Call edge.
Definition: CallGraph.h:65
friend class CallGraphNode
Definition: CallGraph.h:86
Definition: CallGraph.h:38
bool isExternal() const
Returns if this node is the external node.
Definition: CallGraph.cpp:34
void print(OpAsmPrinter &p, AffineIfOp op)
Definition: AffineOps.cpp:1671
iterator end() const
Definition: CallGraph.h:200
SmallVectorImpl< Edge >::const_iterator iterator
Iterator over the outgoing edges of this node.
Definition: CallGraph.h:108
void addAbstractEdge(CallGraphNode *node)
Definition: CallGraph.cpp:45
static nodes_iterator nodes_end(mlir::CallGraph *cg)
Definition: CallGraph.h:249
This class represents a directed edge between two nodes in the callgraph.
Definition: CallGraph.h:41
friend class CallGraph
Definition: CallGraph.h:145
Region * getCallableRegion() const
Definition: CallGraph.cpp:38
mlir::CallGraph::iterator nodes_iterator
Definition: CallGraph.h:247
bool hasChildren() const
Returns true if this node has any child edges.
Definition: CallGraph.cpp:61
Definition: CallGraph.h:152
iterator end() const
Definition: CallGraph.h:110