[LLVMdev] Confusion with GetElementPtr and Defs/Uses

Griffin Wright gwright215 at gmail.com
Wed Jul 13 08:43:26 PDT 2011


I've been hung up on some issues for several weeks now, and some of them
seem to stem from GetElementPtr instructions.

Say we have a Definition: *%29 = getelementptr inbounds [10 x i32]* @c, i32
0, i32 %28*

Now, I'd like to see the uses of that definition.  In my code, I do this
twice, in slightly different ways.  This first method works and shows
instructions that use %29:

*for(Value::use_iterator useIt = defInsn->use_begin(), useIt_e =
          useIt != useIt_e; useIt++){
        Instruction *pUseInstr = dyn_cast<Instruction>(*useIt);  //This is
the current use of the defInsn

However, this code later on does not work and shows the def of %29 to have
no uses [not the case] (pIRI here is a data structure we've created which
keeps track of defs and useBBs.  The defs part works fine.):

*for (std::map<BasicBlock*, InstrRelInfo::UseInfo*>::iterator useBB_iter =
           useBB_iter != pIRI->useBBs.end(); ++useBB_iter) {
        for (InstrRelInfo::UseInfo::iterator use_iter =
             use_iter != (*useBB_iter).second->end(); ++use_iter) {
          DEBUG(dbgs() << *((*use_iter).first));

As far as I can tell, this is only an issue for getelementptr instructions,
so I was wondering if there's some special thing I need to do here to handle
that or what.  getelementptr instructions do successfully show up in the
second technique when it is the getelementptr instruction itself that has a
use of some def.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110713/bea6e80d/attachment.html>

More information about the llvm-dev mailing list