[LLVMdev] Iterating on the DSGraph...

Chris Lattner sabre at nondot.org
Fri Nov 8 17:18:01 PST 2002

> What is the best way to implement a traversal of the DS graph, starting at
> a scalar and processing all nodes to which the scalar allows access?
> Currently the links vector is not public and there is no apparent way to
> bound the getLink call (ie a getNumLinks call)....

Warning, untested code follows, but you should get the idea:

#include "llvm/Analysis/DSGraphTraits.h"

DSNode *N = ...

  // Visit all children of a node...
  for (DSNode::iterator I = N->begin(), E = N->end(); I != E; ++I)
    if (I->getNode())
      visit(I->getNode(), I->getOffset());

  // Depth first traversal from a node:
#include "Support/DepthFirstIterator.h"

  for (df_iterator<DSNode*> I = df_begin(N), E = df_end(); I != E; ++I)

  Note that this hasn't been tested recently, but it should basically



More information about the llvm-dev mailing list