The Call Graph API

The following APIs interact with the structures of the Call Graph and Call Graph Node. Here’s a brief description of what each of these APIs does:

Call Graph

  void print(raw_ostream &OS) const; // Prints the call graph to the provided output stream.
  void dump() const; // Prints the call graph to the standard error (stderr).

  iterator begin(); // Returns an iterator pointing to the beginning of the call graph.
  iterator end(); // Returns an iterator pointing to the end of the call graph.

  // Returns the call graph node associated with the provided function. 
  CBCallGraphNode *operator[](const Function *F); 

The call relations for each function, like callees and callers, are maintained in its call graph node.

Call Graph Node

  Function *getFunction() const; // Returns the function that this call graph node represents.

  // Iterators over call graph nodes that represent functions called by this node.
  iterator begin();
  iterator end();

  // Iterators over call graph nodes that represent functions that call this node.
  iterator caller_begin();
  iterator caller_end();

  bool empty() const; // Checks if the node makes no function calls.
  unsigned size() const; // Returns the number of calls made by the function.

  CBCallGraphNode *operator[](unsigned i); // Returns the i'th called function.

  // Print out this call graph node.
  void dump() const;
  void print(raw_ostream &OS) const;
  void print(raw_ostream &OS, DebugInfoAnalysis &DIA) const;

  // Adds a function to the list of functions called by this.
  void addCalledFunction(CallSite CS, CBCallGraphNode *M);
  void addCallerFunction(CallSite CS, CBCallGraphNode *M);

  void removeCallEdge(iterator I); // Removes a call to a function.

  // Replaces the edge in the node for the specified call site with a new one.
  void replaceCallEdge(CallSite CS, CallSite NewCS, CBCallGraphNode *NewNode);

  // Obtain the set of callees at a given call site.
  std::set<CBCallGraphNode *> *find_callees(CallSite cs);

  bool hasCallee(const CBCallGraphNode *); // Check if a node is in the callee list.

These functions provide a set of tools for developers to interact with and manipulate call graphs while analyzing code structures.


Was this page helpful?

Last modified February 9, 2024: Update (173521e)