LLVM
8.0.1
|
A lazily constructed view of the call graph of a module. More...
#include "llvm/Analysis/LazyCallGraph.h"
Classes | |
class | Edge |
A class used to represent edges in the call graph. More... | |
class | EdgeSequence |
The edge sequence object. More... | |
class | Node |
A node in the call graph. More... | |
class | postorder_ref_scc_iterator |
A post-order depth-first RefSCC iterator over the call graph. More... | |
class | RefSCC |
A RefSCC of the call graph. More... | |
class | SCC |
An SCC of the call graph. More... | |
Public Member Functions | |
LazyCallGraph (Module &M, TargetLibraryInfo &TLI) | |
Construct a graph for the given module. More... | |
LazyCallGraph (LazyCallGraph &&G) | |
LazyCallGraph & | operator= (LazyCallGraph &&RHS) |
EdgeSequence::iterator | begin () |
EdgeSequence::iterator | end () |
void | buildRefSCCs () |
postorder_ref_scc_iterator | postorder_ref_scc_begin () |
postorder_ref_scc_iterator | postorder_ref_scc_end () |
iterator_range< postorder_ref_scc_iterator > | postorder_ref_sccs () |
Node * | lookup (const Function &F) const |
Lookup a function in the graph which has already been scanned and added. More... | |
SCC * | lookupSCC (Node &N) const |
Lookup a function's SCC in the graph. More... | |
RefSCC * | lookupRefSCC (Node &N) const |
Lookup a function's RefSCC in the graph. More... | |
Node & | get (Function &F) |
Get a graph node for a given function, scanning it to populate the graph data as necessary. More... | |
ArrayRef< Function * > | getLibFunctions () const |
Get the sequence of known and defined library functions. More... | |
bool | isLibFunction (Function &F) const |
Test whether a function is a known and defined library function tracked by the call graph. More... | |
Pre-SCC Mutation API | |
These methods are only valid to call prior to forming any SCCs for this call graph. They can be used to update the core node-graph during a node-based inorder traversal that precedes any SCC-based traversal. Once you begin manipulating a call graph's SCCs, most mutation of the graph must be performed via a RefSCC method. There are some exceptions below. | |
void | insertEdge (Node &SourceN, Node &TargetN, Edge::Kind EK) |
Update the call graph after inserting a new edge. More... | |
void | insertEdge (Function &Source, Function &Target, Edge::Kind EK) |
Update the call graph after inserting a new edge. More... | |
void | removeEdge (Node &SourceN, Node &TargetN) |
Update the call graph after deleting an edge. More... | |
void | removeEdge (Function &Source, Function &Target) |
Update the call graph after deleting an edge. More... | |
General Mutation API | |
There are a very limited set of mutations allowed on the graph as a whole once SCCs have started to be formed. These routines have strict contracts but may be called at any point. | |
void | removeDeadFunction (Function &F) |
Remove a dead function from the call graph (typically to delete it). More... | |
Static Public Member Functions | |
Static helpers for code doing updates to the call graph. | |
These helpers are used to implement parts of the call graph but are also useful to code doing updates or otherwise wanting to walk the IR in the same patterns as when we build the call graph. | |
template<typename CallbackT > | |
static void | visitReferences (SmallVectorImpl< Constant *> &Worklist, SmallPtrSetImpl< Constant *> &Visited, CallbackT Callback) |
Recursively visits the defined functions whose address is reachable from every constant in the Worklist . More... | |
A lazily constructed view of the call graph of a module.
With the edges of this graph, the motivating constraint that we are attempting to maintain is that function-local optimization, CGSCC-local optimizations, and optimizations transforming a pair of functions connected by an edge in the graph, do not invalidate a bottom-up traversal of the SCC DAG. That is, no optimizations will delete, remove, or add an edge such that functions already visited in a bottom-up order of the SCC DAG are no longer valid to have visited, or such that functions not yet visited in a bottom-up order of the SCC DAG are not required to have already been visited.
Within this constraint, the desire is to minimize the merge points of the SCC DAG. The greater the fanout of the SCC DAG and the fewer merge points in the SCC DAG, the more independence there is in optimizing within it. There is a strong desire to enable parallelization of optimizations over the call graph, and both limited fanout and merge points will (artificially in some cases) limit the scaling of such an effort.
To this end, graph represents both direct and any potential resolution to an indirect call edge. Another way to think about it is that it represents both the direct call edges and any direct call edges that might be formed through static optimizations. Specifically, it considers taking the address of a function to be an edge in the call graph because this might be forwarded to become a direct call by some subsequent function-local optimization. The result is that the graph closely follows the use-def edges for functions. Walking "up" the graph can be done by looking at all of the uses of a function.
The roots of the call graph are the external functions and functions escaped into global variables. Those functions can be called from outside of the module or via unknowable means in the IR – we may not be able to form even a potential call edge from a function body which may dynamically load the function and call it.
This analysis still requires updates to remain valid after optimizations which could potentially change the set of potential callees. The constraints it operates under only make the traversal order remain valid.
The entire analysis must be re-computed if full interprocedural optimizations run at any point. For example, globalopt completely invalidates the information in this analysis.
FIXME: This class is named LazyCallGraph in a lame attempt to distinguish it from the existing CallGraph. At some point, it is expected that this will be the only call graph and it will be renamed accordingly.
Definition at line 112 of file LazyCallGraph.h.
LazyCallGraph::LazyCallGraph | ( | Module & | M, |
TargetLibraryInfo & | TLI | ||
) |
Construct a graph for the given module.
This sets up the graph and computes all of the entry points of the graph. No function definitions are scanned until their nodes in the graph are requested during traversal.
Definition at line 154 of file LazyCallGraph.cpp.
References addEdge(), llvm::dbgs(), F(), llvm::Module::getModuleIdentifier(), llvm::SmallPtrSetImpl< PtrType >::insert(), isKnownLibFunction(), LLVM_DEBUG, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::LazyCallGraph::Edge::Ref, second, and visitReferences().
Referenced by llvm::LazyCallGraph::postorder_ref_scc_iterator::operator++(), and llvm::LazyCallGraphAnalysis::run().
LazyCallGraph::LazyCallGraph | ( | LazyCallGraph && | G | ) |
Definition at line 193 of file LazyCallGraph.cpp.
|
inline |
Definition at line 939 of file LazyCallGraph.h.
void LazyCallGraph::buildRefSCCs | ( | ) |
Definition at line 1687 of file LazyCallGraph.cpp.
References assert(), llvm::LazyCallGraph::EdgeSequence::begin(), E, llvm::LazyCallGraph::EdgeSequence::empty(), llvm::LazyCallGraph::EdgeSequence::end(), llvm::LazyCallGraph::Edge::getNode(), I, N, llvm::LazyCallGraph::Node::populate(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::reverse(), and second.
Referenced by end(), llvm::ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT >::run(), and llvm::LazyCallGraphPrinterPass::run().
|
inline |
Definition at line 940 of file LazyCallGraph.h.
References buildRefSCCs().
Get a graph node for a given function, scanning it to populate the graph data as necessary.
Definition at line 984 of file LazyCallGraph.h.
Referenced by llvm::LazyCallGraphPrinterPass::run(), and llvm::LazyCallGraphDOTPrinterPass::run().
Get the sequence of known and defined library functions.
These functions, because they are known to LLVM, can have calls introduced out of thin air from arbitrary IR.
Definition at line 996 of file LazyCallGraph.h.
void LazyCallGraph::insertEdge | ( | Node & | SourceN, |
Node & | TargetN, | ||
Edge::Kind | EK | ||
) |
Update the call graph after inserting a new edge.
Definition at line 1463 of file LazyCallGraph.cpp.
References assert().
Referenced by insertEdge(), and isLibFunction().
|
inline |
Update the call graph after inserting a new edge.
Definition at line 1023 of file LazyCallGraph.h.
References insertEdge(), and removeEdge().
Test whether a function is a known and defined library function tracked by the call graph.
Because these functions are known to LLVM they are specially modeled in the call graph and even when all IR-level references have been removed remain active and reachable.
Definition at line 1006 of file LazyCallGraph.h.
References insertEdge().
Referenced by removeDeadFunction(), and llvm::InlinerPass::run().
Lookup a function in the graph which has already been scanned and added.
Definition at line 963 of file LazyCallGraph.h.
Referenced by llvm::InlinerPass::run().
Lookup a function's RefSCC in the graph.
Definition at line 975 of file LazyCallGraph.h.
References C, and lookupSCC().
Referenced by llvm::LazyCallGraph::RefSCC::insertIncomingRefEdge(), llvm::LazyCallGraph::RefSCC::insertInternalRefEdge(), llvm::LazyCallGraph::RefSCC::insertOutgoingEdge(), llvm::LazyCallGraph::RefSCC::insertTrivialRefEdge(), llvm::LazyCallGraph::RefSCC::isAncestorOf(), llvm::LazyCallGraph::RefSCC::isParentOf(), llvm::LazyCallGraph::RefSCC::removeInternalRefEdge(), llvm::LazyCallGraph::RefSCC::removeOutgoingEdge(), llvm::LazyCallGraph::RefSCC::replaceNodeFunction(), llvm::LazyCallGraph::RefSCC::switchInternalEdgeToRef(), llvm::LazyCallGraph::RefSCC::switchOutgoingEdgeToCall(), llvm::LazyCallGraph::RefSCC::switchOutgoingEdgeToRef(), and llvm::LazyCallGraph::RefSCC::switchTrivialInternalEdgeToRef().
Lookup a function's SCC in the graph.
Definition at line 969 of file LazyCallGraph.h.
Referenced by incorporateNewSCCRange(), llvm::LazyCallGraph::RefSCC::insertTrivialCallEdge(), llvm::LazyCallGraph::SCC::isAncestorOf(), lookupRefSCC(), llvm::LazyCallGraph::RefSCC::removeInternalRefEdge(), llvm::InlinerPass::run(), llvm::CGSCCToFunctionPassAdaptor< FunctionPassT >::run(), llvm::LazyCallGraph::RefSCC::switchInternalEdgeToCall(), llvm::LazyCallGraph::RefSCC::switchInternalEdgeToRef(), and llvm::LazyCallGraph::RefSCC::switchTrivialInternalEdgeToRef().
LazyCallGraph & LazyCallGraph::operator= | ( | LazyCallGraph && | RHS | ) |
Definition at line 201 of file LazyCallGraph.cpp.
References assert(), llvm::dbgs(), E, G, LLVM_DUMP_METHOD, and N.
Referenced by llvm::LazyCallGraph::postorder_ref_scc_iterator::operator++().
|
inline |
Definition at line 944 of file LazyCallGraph.h.
References assert().
Referenced by postorder_ref_sccs(), and llvm::ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT >::run().
|
inline |
Definition at line 950 of file LazyCallGraph.h.
References assert().
Referenced by postorder_ref_sccs(), and llvm::ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT >::run().
|
inline |
Definition at line 958 of file LazyCallGraph.h.
References llvm::make_range(), postorder_ref_scc_begin(), and postorder_ref_scc_end().
Referenced by llvm::LazyCallGraphPrinterPass::run().
void LazyCallGraph::removeDeadFunction | ( | Function & | F | ) |
Remove a dead function from the call graph (typically to delete it).
Note that the function must have an empty use list, and the call graph must be up-to-date prior to calling this. That means it is by itself in a maximal SCC which is by itself in a maximal RefSCC, etc. No structural changes result from calling this routine other than potentially removing entry points into the call graph.
If SCC formation has begun, this function must not be part of the current DFS in order to call this safely. Typically, the function will have been fully visited by the DFS prior to calling this routine.
Definition at line 1479 of file LazyCallGraph.cpp.
References assert(), C, F(), isLibFunction(), N, Size, llvm::LazyCallGraph::RefSCC::size(), and llvm::Value::use_empty().
Referenced by removeEdge(), and llvm::InlinerPass::run().
Update the call graph after deleting an edge.
Definition at line 1470 of file LazyCallGraph.cpp.
References assert().
Referenced by insertEdge(), and removeEdge().
Update the call graph after deleting an edge.
Definition at line 1031 of file LazyCallGraph.h.
References F(), removeDeadFunction(), and removeEdge().
|
inlinestatic |
Recursively visits the defined functions whose address is reachable from every constant in the Worklist
.
Doesn't recurse through any constants already in the Visited
set, and updates that set with every constant visited.
For each defined function, calls Callback
with that function.
Definition at line 1074 of file LazyCallGraph.h.
References llvm::SpecificBumpPtrAllocator< T >::Allocate(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), C, llvm::SmallVectorBase::empty(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::GlobalValue::isDeclaration(), llvm::User::operand_values(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T >::push_back(), and second.
Referenced by addEdge(), and LazyCallGraph().