|
LLVM
4.0.0
|
A RefSCC of the call graph. More...
#include <LazyCallGraph.h>
Public Types | |
| typedef pointee_iterator < SmallVectorImpl< SCC * > ::const_iterator > | iterator |
| typedef iterator_range< iterator > | range |
| typedef pointee_iterator < SmallPtrSetImpl< RefSCC * > ::const_iterator > | parent_iterator |
Public Member Functions | |
| iterator | begin () const |
| iterator | end () const |
| ssize_t | size () const |
| SCC & | operator[] (int Idx) |
| iterator | find (SCC &C) const |
| parent_iterator | parent_begin () const |
| parent_iterator | parent_end () const |
| iterator_range< parent_iterator > | parents () const |
| bool | isParentOf (const RefSCC &C) const |
| Test if this RefSCC is a parent of C. More... | |
| bool | isAncestorOf (const RefSCC &C) const |
| Test if this RefSCC is an ancestor of C. More... | |
| bool | isChildOf (const RefSCC &C) const |
| Test if this RefSCC is a child of C. More... | |
| bool | isDescendantOf (const RefSCC &C) const |
| Test if this RefSCC is a descendant of C. More... | |
| std::string | getName () const |
| Provide a short name by printing this RefSCC to a std::string. More... | |
Mutation API | |
These methods provide the core API for updating the call graph in the presence of (potentially still in-flight) DFS-found RefSCCs and SCCs. Note that these methods sometimes have complex runtimes, so be careful how you call them. | |
| SmallVector< SCC *, 1 > | switchInternalEdgeToCall (Node &SourceN, Node &TargetN) |
| Make an existing internal ref edge into a call edge. More... | |
| void | switchTrivialInternalEdgeToRef (Node &SourceN, Node &TargetN) |
| Make an existing internal call edge between separate SCCs into a ref edge. More... | |
| iterator_range< iterator > | switchInternalEdgeToRef (Node &SourceN, Node &TargetN) |
| Make an existing internal call edge within a single SCC into a ref edge. More... | |
| void | switchOutgoingEdgeToCall (Node &SourceN, Node &TargetN) |
| Make an existing outgoing ref edge into a call edge. More... | |
| void | switchOutgoingEdgeToRef (Node &SourceN, Node &TargetN) |
| Make an existing outgoing call edge into a ref edge. More... | |
| void | insertInternalRefEdge (Node &SourceN, Node &TargetN) |
| Insert a ref edge from one node in this RefSCC to another in this RefSCC. More... | |
| void | insertOutgoingEdge (Node &SourceN, Node &TargetN, Edge::Kind EK) |
| Insert an edge whose parent is in this RefSCC and child is in some child RefSCC. More... | |
| SmallVector< RefSCC *, 1 > | insertIncomingRefEdge (Node &SourceN, Node &TargetN) |
| Insert an edge whose source is in a descendant RefSCC and target is in this RefSCC. More... | |
| void | removeOutgoingEdge (Node &SourceN, Node &TargetN) |
| Remove an edge whose source is in this RefSCC and target is not. More... | |
| SmallVector< RefSCC *, 1 > | removeInternalRefEdge (Node &SourceN, Node &TargetN) |
| Remove a ref edge which is entirely within this RefSCC. More... | |
| void | insertTrivialCallEdge (Node &SourceN, Node &TargetN) |
| A convenience wrapper around the above to handle trivial cases of inserting a new call edge. More... | |
| void | insertTrivialRefEdge (Node &SourceN, Node &TargetN) |
| A convenience wrapper around the above to handle trivial cases of inserting a new ref edge. More... | |
Friends | |
| class | LazyCallGraph |
| class | LazyCallGraph::Node |
| raw_ostream & | operator<< (raw_ostream &OS, const RefSCC &RC) |
| Print a short description useful for debugging or logging. More... | |
A RefSCC of the call graph.
This models a Strongly Connected Component of function reference edges in the call graph. As opposed to actual SCCs, these can be used to scope subgraphs of the module which are independent from other subgraphs of the module because they do not reference it in any way. This is also the unit where we do mutation of the graph in order to restrict mutations to those which don't violate this independence.
A RefSCC contains a DAG of actual SCCs. All the nodes within the RefSCC are necessarily within some actual SCC that nests within it. Since a direct call is a reference, there will always be at least one RefSCC around any SCC.
Definition at line 481 of file LazyCallGraph.h.
| typedef pointee_iterator<SmallVectorImpl<SCC *>::const_iterator> llvm::LazyCallGraph::RefSCC::iterator |
Definition at line 550 of file LazyCallGraph.h.
| typedef pointee_iterator<SmallPtrSetImpl<RefSCC *>::const_iterator> llvm::LazyCallGraph::RefSCC::parent_iterator |
Definition at line 553 of file LazyCallGraph.h.
Definition at line 551 of file LazyCallGraph.h.
|
inline |
Definition at line 555 of file LazyCallGraph.h.
Referenced by printRefSCC().
|
inline |
Definition at line 556 of file LazyCallGraph.h.
Referenced by printRefSCC().
Definition at line 562 of file LazyCallGraph.h.
|
inline |
Provide a short name by printing this RefSCC to a std::string.
This copes with the fact that we don't have a name per-se for an RefSCC while still making the use of this in debugging and logging useful.
Definition at line 591 of file LazyCallGraph.h.
References llvm::raw_ostream::flush().
| SmallVector< LazyCallGraph::RefSCC *, 1 > LazyCallGraph::RefSCC::insertIncomingRefEdge | ( | Node & | SourceN, |
| Node & | TargetN | ||
| ) |
Insert an edge whose source is in a descendant RefSCC and target is in this RefSCC.
There must be an existing path from the target to the source in this case.
NB! This is has the potential to be a very expensive function. It inherently forms a cycle in the prior RefSCC DAG and we have to merge RefSCCs to resolve that cycle. But finding all of the RefSCCs which participate in the cycle can in the worst case require traversing every RefSCC in the graph. Every attempt is made to avoid that, but passes must still exercise caution calling this routine repeatedly.
Also note that this can only insert ref edges. In order to insert a call edge, first insert a ref edge and then switch it to a call edge. These are intentionally kept as separate interfaces because each step of the operation invalidates a different set of data structures.
This returns all the RefSCCs which were merged into the this RefSCC (the target's). This allows callers to invalidate any cached information.
FIXME: We could possibly optimize this quite a bit for cases where the caller and callee are very nearby in the graph. See comments in the implementation for details, but that use case might impact users.
Definition at line 894 of file LazyCallGraph.cpp.
References llvm::SmallVectorImpl< T >::append(), assert(), llvm::iterator_range< IteratorT >::begin(), E, llvm::SmallVectorBase::empty(), llvm::iterator_range< IteratorT >::end(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::LazyCallGraph::lookupRefSCC(), llvm::make_range(), llvm::make_scope_exit(), N, parents(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::LazyCallGraph::Edge::Ref, updatePostorderSequenceForEdgeInsertion(), and llvm::verify().
Insert a ref edge from one node in this RefSCC to another in this RefSCC.
This is always a trivial operation as it doesn't change any part of the graph structure besides connecting the two nodes.
Note that we don't support directly inserting internal call edges because that could change the graph structure and requires returning information about what became invalid. As a consequence, the pattern should be to first insert the necessary ref edge, and then to switch it to a call edge if needed and handle any invalidation that results. See the switchInternalEdgeToCall routine for details.
Definition at line 858 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::lookupRefSCC(), llvm::LazyCallGraph::Edge::Ref, and llvm::verify().
| void LazyCallGraph::RefSCC::insertOutgoingEdge | ( | Node & | SourceN, |
| Node & | TargetN, | ||
| Edge::Kind | EK | ||
| ) |
Insert an edge whose parent is in this RefSCC and child is in some child RefSCC.
There must be an existing path from the SourceN to the TargetN. This operation is inexpensive and does not change the set of SCCs and RefSCCs in the graph.
Definition at line 871 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::lookupRefSCC(), and llvm::verify().
A convenience wrapper around the above to handle trivial cases of inserting a new call edge.
This is trivial whenever the target is in the same SCC as the source or the edge is an outgoing edge to some descendant SCC. In these cases there is no change to the cyclic structure of SCCs or RefSCCs.
To further make calling this convenient, it also handles inserting already existing edges.
Definition at line 1458 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::Edge::Call, E, llvm::SmallVectorImpl< T >::emplace_back(), llvm::LazyCallGraph::Node::getFunction(), llvm::LazyCallGraph::Edge::isCall(), llvm::LazyCallGraph::lookupSCC(), llvm::make_scope_exit(), llvm::SmallVectorTemplateCommon< T, typename >::size(), and llvm::verify().
A convenience wrapper around the above to handle trivial cases of inserting a new ref edge.
This is trivial whenever the target is in the same RefSCC as the source or the edge is an outgoing edge to some descendant RefSCC. In these cases there is no change to the cyclic structure of the RefSCCs.
To further make calling this convenient, it also handles inserting already existing edges.
Definition at line 1489 of file LazyCallGraph.cpp.
References assert(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::LazyCallGraph::Node::getFunction(), llvm::LazyCallGraph::lookupRefSCC(), llvm::make_scope_exit(), llvm::LazyCallGraph::Edge::Ref, llvm::SmallVectorTemplateCommon< T, typename >::size(), and llvm::verify().
Test if this RefSCC is an ancestor of C.
Definition at line 577 of file LazyCallGraph.h.
References isDescendantOf().
Test if this RefSCC is a child of C.
Definition at line 580 of file LazyCallGraph.h.
Referenced by isDescendantOf(), and isParentOf().
Test if this RefSCC is a descendant of C.
Definition at line 312 of file LazyCallGraph.cpp.
References llvm::SmallVectorBase::empty(), isChildOf(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
Referenced by isAncestorOf(), switchOutgoingEdgeToCall(), and switchOutgoingEdgeToRef().
Test if this RefSCC is a parent of C.
Definition at line 574 of file LazyCallGraph.h.
References isChildOf().
|
inline |
Definition at line 560 of file LazyCallGraph.h.
|
inline |
Definition at line 566 of file LazyCallGraph.h.
Referenced by parents().
|
inline |
Definition at line 567 of file LazyCallGraph.h.
Referenced by parents().
|
inline |
Definition at line 569 of file LazyCallGraph.h.
References llvm::make_range(), parent_begin(), and parent_end().
Referenced by insertIncomingRefEdge().
| SmallVector< LazyCallGraph::RefSCC *, 1 > LazyCallGraph::RefSCC::removeInternalRefEdge | ( | Node & | SourceN, |
| Node & | TargetN | ||
| ) |
Remove a ref edge which is entirely within this RefSCC.
Both the SourceN and the TargetN must be within this RefSCC. Removing such an edge may break cycles that form this RefSCC and thus this operation may change the RefSCC graph significantly. In particular, this operation will re-form new RefSCCs based on the remaining connectivity of the graph. The following invariants are guaranteed to hold after calling this method:
1) This RefSCC is still a RefSCC in the graph. 2) This RefSCC will be the parent of any new RefSCCs. Thus, this RefSCC is preserved as the root of any new RefSCC DAG formed. 3) No RefSCC other than this RefSCC has its member set changed (this is inherent in the definition of removing such an edge). 4) All of the parent links of the RefSCC graph will be updated to reflect the new RefSCC structure. 5) All RefSCCs formed out of this RefSCC, excluding this RefSCC, will be returned in post-order. 6) The order of the RefSCCs in the vector will be a valid postorder traversal of the new RefSCCs.
These invariants are very important to ensure that we can build optimization pipelines on top of the CGSCC pass manager which intelligently update the RefSCC graph without invalidating other parts of the RefSCC graph.
Note that we provide no routine to remove a call edge. Instead, you must first switch it to a ref edge using switchInternalEdgeToRef. This split API is intentional as each of these two steps can invalidate a different aspect of the graph structure and needs to have the invalidation handled independently.
The runtime complexity of this method is, in the worst case, O(V+E) where V is the number of nodes in this RefSCC and E is the number of edges leaving the nodes in this RefSCC. Note that E includes both edges within this RefSCC and edges from this RefSCC to child RefSCCs. Some effort has been made to minimize the overhead of common cases such as self-edges and edge removals which result in a spanning tree with no more cycles. There are also detailed comments within the implementation on techniques which could substantially improve this routine's efficiency.
Definition at line 1118 of file LazyCallGraph.cpp.
References llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LazyCallGraph::Node::begin(), llvm::LazyCallGraph::SCC::begin(), C, E, llvm::SmallVectorBase::empty(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::LazyCallGraph::Node::end(), llvm::SmallVectorImpl< T >::erase(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::find_if(), llvm::LazyCallGraph::Node::getFunction(), I, i, llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::LazyCallGraph::lookupRefSCC(), llvm::LazyCallGraph::lookupSCC(), llvm::make_range(), llvm::make_scope_exit(), N, llvm::none_of(), llvm::Number, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorTemplateCommon< T >::rbegin(), llvm::remove_if(), llvm::reverse(), and llvm::verify().
Remove an edge whose source is in this RefSCC and target is not.
This removes an inter-RefSCC edge. All inter-RefSCC edges originating from this SCC have been fully explored by any in-flight DFS graph formation, so this is always safe to call once you have the source RefSCC.
This operation does not change the cyclic structure of the graph and so is very inexpensive. It may change the connectivity graph of the SCCs though, so be careful calling this while iterating over them.
Definition at line 1054 of file LazyCallGraph.cpp.
References assert(), llvm::dbgs(), DEBUG, E, llvm::LazyCallGraph::Node::getFunction(), llvm::Value::getName(), llvm::is_contained(), llvm::LazyCallGraph::lookupRefSCC(), llvm::make_scope_exit(), and llvm::verify().
Referenced by llvm::updateCGAndAnalysisManagerForFunctionPass().
|
inline |
Definition at line 558 of file LazyCallGraph.h.
Referenced by llvm::LazyCallGraph::removeDeadFunction().
| SmallVector< LazyCallGraph::SCC *, 1 > LazyCallGraph::RefSCC::switchInternalEdgeToCall | ( | Node & | SourceN, |
| Node & | TargetN | ||
| ) |
Make an existing internal ref edge into a call edge.
This may form a larger cycle and thus collapse SCCs into TargetN's SCC. If that happens, the deleted SCC pointers are returned. These SCCs are not in a valid state any longer but the pointers will remain valid until destruction of the parent graph instance for the purpose of clearing cached information.
After this operation, both SourceN's SCC and TargetN's SCC may move position within this RefSCC's postorder list. Any SCCs merged are merged into the TargetN's SCC in order to preserve reachability analyses which took place on that SCC.
Definition at line 463 of file LazyCallGraph.cpp.
References assert(), C, llvm::LazyCallGraph::Edge::Call, E, llvm::SmallVectorBase::empty(), llvm::LazyCallGraph::Node::getFunction(), llvm::LazyCallGraph::SCC::getOuterRefSCC(), llvm::LazyCallGraph::lookupSCC(), llvm::make_range(), llvm::make_scope_exit(), N, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), updatePostorderSequenceForEdgeInsertion(), and llvm::verify().
| iterator_range< LazyCallGraph::RefSCC::iterator > LazyCallGraph::RefSCC::switchInternalEdgeToRef | ( | Node & | SourceN, |
| Node & | TargetN | ||
| ) |
Make an existing internal call edge within a single SCC into a ref edge.
Since SourceN and TargetN are part of a single SCC, this SCC may be split up due to breaking a cycle in the call edges that formed it. If that happens, then this routine will insert new SCCs into the postorder list before the SCC of TargetN (previously the SCC of both). This preserves postorder as the TargetN can reach all of the other nodes by definition of previously being in a single SCC formed by the cycle from SourceN to TargetN.
The newly added SCCs are added immediately and contiguously prior to the TargetN SCC and return the range covering the new SCCs in the RefSCC's postorder sequence. You can directly iterate the returned range to observe all of the new SCCs in postorder.
Note that if SourceN and TargetN are in separate SCCs, the simpler routine switchTrivialInternalEdgeToRef should be used instead.
Definition at line 632 of file LazyCallGraph.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LazyCallGraph::SCC::begin(), llvm::LazyCallGraph::Node::call_begin(), llvm::LazyCallGraph::Node::call_end(), llvm::SmallVectorImpl< T >::clear(), E, llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::LazyCallGraph::SCC::end(), llvm::SmallVectorImpl< T >::erase(), llvm::find_if(), llvm::LazyCallGraph::Node::getFunction(), I, llvm::LazyCallGraph::lookupRefSCC(), llvm::LazyCallGraph::lookupSCC(), llvm::make_range(), llvm::make_scope_exit(), N, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorTemplateCommon< T >::rbegin(), llvm::LazyCallGraph::Edge::Ref, llvm::reverse(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::LazyCallGraph::SCC::size(), llvm::SmallVectorImpl< T >::swap(), and llvm::verify().
Make an existing outgoing ref edge into a call edge.
Note that this is trivial as there are no cyclic impacts and there remains a reference edge.
Definition at line 818 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::Edge::Call, llvm::LazyCallGraph::Node::getFunction(), isDescendantOf(), llvm::LazyCallGraph::lookupRefSCC(), and llvm::verify().
Make an existing outgoing call edge into a ref edge.
This is trivial as there are no cyclic impacts and there remains a reference edge.
Definition at line 838 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::Node::getFunction(), isDescendantOf(), llvm::LazyCallGraph::lookupRefSCC(), llvm::LazyCallGraph::Edge::Ref, and llvm::verify().
Make an existing internal call edge between separate SCCs into a ref edge.
If SourceN and TargetN in separate SCCs within this RefSCC, changing the call edge between them to a ref edge is a trivial operation that does not require any structural changes to the call graph.
Definition at line 609 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::Node::getFunction(), llvm::LazyCallGraph::lookupRefSCC(), llvm::LazyCallGraph::lookupSCC(), llvm::make_scope_exit(), llvm::LazyCallGraph::Edge::Ref, and llvm::verify().
|
friend |
Definition at line 482 of file LazyCallGraph.h.
|
friend |
Definition at line 483 of file LazyCallGraph.h.
|
friend |
Print a short description useful for debugging or logging.
We print the SCCs wrapped in '[]'s and skipping the middle SCCs if there are a large number.
Definition at line 511 of file LazyCallGraph.h.
1.8.6