LLVM Def-Use & Use-Def Chains

LLVM provides a little documentation on the subject, you can use the following link for that.
http://llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains

Below is an example of a function pass that illustrates both def-use and use-def chains. Of course if you need to trace a pointer all the way through all of its uses you will need to do this recursively.

virtual bool runOnFunction(Function &F) {
std::vector worklist;
for(inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
worklist.push_back(&*I);
}

// def-use chain for Instruction
for(std::vector::iterator iter = worklist.begin(); iter != worklist.end(); ++iter){
Instruction* instr = *iter;
errs() << "def: " <<*instr << "\n"; for(Value::use_iterator i = instr->use_begin(), ie = instr->use_end(); i!=ie; ++i){
Value *v = *i;
Instruction *vi = dyn_cast(*i);
errs() << "\t\t" << *vi << "\n"; } } // use-def chain for Instruction for(std::vector::iterator iter = worklist.begin(); iter != worklist.end(); ++iter){
Instruction* instr = *iter;
errs() << "use: " <<*instr << "\n"; for (User::op_iterator i = instr -> op_begin(), e = instr -> op_end(); i != e; ++i) {
Value *v = *i;
Instruction *vi = dyn_cast(*i);
errs() << "\t\t" << *vi << "\n"; } } return false; }