[LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?

Rob Jansen jansen at cs.umn.edu
Sat Aug 9 07:33:36 PDT 2014


To make this clearer, I've reposted the loops below, replacing dyn_cast
with cast. I've also added the assertion, which triggers in the bottom
loop, but not the top.

-Rob

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

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

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

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)
{
    User *u = cast < User > (*ui);
    u->replaceUsesOfWith(GV, GEP);
  }
}
assert(GV->use_empty());
===========================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140809/f7ff8c3a/attachment.html>


More information about the llvm-dev mailing list