class LazyCallGraph

Declaration

class LazyCallGraph { /* full declaration omitted */ };

Description

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.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:112

Method Overview

  • public LazyCallGraph(llvm::LazyCallGraph && G)
  • public LazyCallGraph(llvm::Module & M, function_ref<llvm::TargetLibraryInfo &(llvm::Function &)> GetTLI)
  • public EdgeSequence::iterator begin()
  • public void buildRefSCCs()
  • public EdgeSequence::iterator end()
  • public llvm::LazyCallGraph::Node & get(llvm::Function & F)
  • public ArrayRef<llvm::Function *> getLibFunctions() const
  • public void insertEdge(llvm::Function & Source, llvm::Function & Target, Edge::Kind EK)
  • public void insertEdge(llvm::LazyCallGraph::Node & SourceN, llvm::LazyCallGraph::Node & TargetN, Edge::Kind EK)
  • public bool isLibFunction(llvm::Function & F) const
  • public llvm::LazyCallGraph::Node * lookup(const llvm::Function & F) const
  • public llvm::LazyCallGraph::RefSCC * lookupRefSCC(llvm::LazyCallGraph::Node & N) const
  • public llvm::LazyCallGraph::SCC * lookupSCC(llvm::LazyCallGraph::Node & N) const
  • public llvm::LazyCallGraph::postorder_ref_scc_iterator postorder_ref_scc_begin()
  • public llvm::LazyCallGraph::postorder_ref_scc_iterator postorder_ref_scc_end()
  • public iterator_range<llvm::LazyCallGraph::postorder_ref_scc_iterator> postorder_ref_sccs()
  • public void removeDeadFunction(llvm::Function & F)
  • public void removeEdge(llvm::LazyCallGraph::Node & SourceN, llvm::LazyCallGraph::Node & TargetN)
  • public void removeEdge(llvm::Function & Source, llvm::Function & Target)
  • public template <typename CallbackT>static void visitReferences(SmallVectorImpl<llvm::Constant *> & Worklist, SmallPtrSetImpl<llvm::Constant *> & Visited, CallbackT Callback)

Methods

LazyCallGraph(llvm::LazyCallGraph&& G)

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:937

Parameters

llvm::LazyCallGraph&& G

LazyCallGraph(
    llvm::Module& M,
    function_ref<llvm::TargetLibraryInfo&(
        llvm::Function&)> GetTLI)

Description

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.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:934

Parameters

llvm::Module& M
function_ref<llvm::TargetLibraryInfo&( llvm::Function&)> GetTLI

EdgeSequence::iterator begin()

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:940

void buildRefSCCs()

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:943

EdgeSequence::iterator end()

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:941

llvm::LazyCallGraph::Node& get(llvm::Function& F)

Description

Get a graph node for a given function, scanning it to populate the graph data as necessary.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:985

Parameters

llvm::Function& F

ArrayRef<llvm::Function*> getLibFunctions() const

Description

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.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:997

void insertEdge(llvm::Function& Source,
                llvm::Function& Target,
                Edge::Kind EK)

Description

Update the call graph after inserting a new edge.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1024

Parameters

llvm::Function& Source
llvm::Function& Target
Edge::Kind EK

void insertEdge(
    llvm::LazyCallGraph::Node& SourceN,
    llvm::LazyCallGraph::Node& TargetN,
    Edge::Kind EK)

Description

Update the call graph after inserting a new edge.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1021

Parameters

llvm::LazyCallGraph::Node& SourceN
llvm::LazyCallGraph::Node& TargetN
Edge::Kind EK

bool isLibFunction(llvm::Function& F) const

Description

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.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1007

Parameters

llvm::Function& F

llvm::LazyCallGraph::Node* lookup(
    const llvm::Function& F) const

Description

Lookup a function in the graph which has already been scanned and added.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:964

Parameters

const llvm::Function& F

llvm::LazyCallGraph::RefSCC* lookupRefSCC(
    llvm::LazyCallGraph::Node& N) const

Description

Lookup a function's RefSCC in the graph.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:976

Parameters

llvm::LazyCallGraph::Node& N

Returns

null if the function hasn't been assigned a RefSCC via the RefSCC iterator walk.

llvm::LazyCallGraph::SCC* lookupSCC(
    llvm::LazyCallGraph::Node& N) const

Description

Lookup a function's SCC in the graph.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:970

Parameters

llvm::LazyCallGraph::Node& N

Returns

null if the function hasn't been assigned an SCC via the RefSCC iterator walk.

llvm::LazyCallGraph::postorder_ref_scc_iterator
postorder_ref_scc_begin()

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:945

llvm::LazyCallGraph::postorder_ref_scc_iterator
postorder_ref_scc_end()

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:951

iterator_range<llvm::LazyCallGraph::
                   postorder_ref_scc_iterator>
postorder_ref_sccs()

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:959

void removeDeadFunction(llvm::Function& F)

Description

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.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1056

Parameters

llvm::Function& F

void removeEdge(
    llvm::LazyCallGraph::Node& SourceN,
    llvm::LazyCallGraph::Node& TargetN)

Description

Update the call graph after deleting an edge.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1029

Parameters

llvm::LazyCallGraph::Node& SourceN
llvm::LazyCallGraph::Node& TargetN

void removeEdge(llvm::Function& Source,
                llvm::Function& Target)

Description

Update the call graph after deleting an edge.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1032

Parameters

llvm::Function& Source
llvm::Function& Target

template <typename CallbackT>
static void visitReferences(
    SmallVectorImpl<llvm::Constant*>& Worklist,
    SmallPtrSetImpl<llvm::Constant*>& Visited,
    CallbackT Callback)

Description

Recursively visits the defined functions whose address is reachable from every constant in the \p Worklist. Doesn't recurse through any constants already in the \p Visited set, and updates that set with every constant visited. For each defined function, calls \p Callback with that function.

Declared at: llvm/include/llvm/Analysis/LazyCallGraph.h:1075

Templates

CallbackT

Parameters

SmallVectorImpl<llvm::Constant*>& Worklist
SmallPtrSetImpl<llvm::Constant*>& Visited
CallbackT Callback