LLVMdev digest, Vol 1 #44 - 2 msgs

llvm,

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)....

Dave

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)
    visit(*I);

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

-Chris

Oh, yeah, sorry, I forgot to answer your specific question:

> 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?

To get a DSNode for a value:
   DSGraph *G = ...;
   DSNode *N = G->getNodeForValue(V).getNode();

> Currently the links vector is not public and there is no apparent way to
> bound the getLink call (ie a getNumLinks call)....

Good point, there is now:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20021104/001500.html

Note that it is only valid to pass an offset into getLink() that is
aligned to a pointer size boundary [ie a value returned by:
DSNode::getPointerSize()]. Although there is currently an easier way to
get the pointer size (rip it directly out of DS::PointerSize), that will
change in the future when I have time to clean it up, so don't count on
that interface. :slight_smile:

-Chris