[LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?

Rob Jansen jansen at cs.umn.edu
Fri Aug 8 18:03:33 PDT 2014


Why is the first for loop not equivalent to the second?

Thanks,
Rob

===========================

for (GlobalVariable **i = Globals.begin(), **e = Globals.end(); i != e;
++i) {
  GlobalVariable *GV = *i;

  Constant *GEP = ConstantExpr::getGetElementPtr(...);
  GV->replaceAllUsesWith(GEP);
}

===========================

for (GlobalVariable **i = Globals.begin(), **e = Globals.end(); i != e;
++i) {
  GlobalVariable *GV = *i;

  Constant *GEP = ConstantExpr::getGetElementPtr(...);

for (Value::use_iterator ui = GV->use_begin(); ui != GV->use_end(); ++ui) {
  if(User *u = dyn_cast < User > (*ui)) {
    u->replaceUsesOfWith(GV, GEP);
  }
}

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


More information about the llvm-dev mailing list