Rob Jansen
2014-Aug-09 01:03 UTC
[LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?
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>
Tim Northover
2014-Aug-09 10:06 UTC
[LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?
Hi Rob, On 9 August 2014 02:03, Rob Jansen <jansen at cs.umn.edu> wrote:> Why is the first for loop not equivalent to the second?In the second loop, "*ui" is an llvm::Use object. It's owned by a User, but isn't a subclass of one. To match the first loop, you either need to call Value::user_begin instead of use_begin, or do the cast on "ui->getUser()". Cheers. Tim.
Rob Jansen
2014-Aug-09 14:26 UTC
[LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?
On Sat, Aug 9, 2014 at 6:06 AM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Rob, > > On 9 August 2014 02:03, Rob Jansen <jansen at cs.umn.edu> wrote: > > Why is the first for loop not equivalent to the second? > > In the second loop, "*ui" is an llvm::Use object. It's owned by a > User, but isn't a subclass of one. To match the first loop, you either > need to call Value::user_begin instead of use_begin, or do the cast on > "ui->getUser()". >I think this is incorrect since the use_iterator is defined as: `typedef value_use_iterator<User> use_iterator;` and indeed `ui->getUser();` is not a callable function on a User. What am I missing? -Rob -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140809/ed8317a4/attachment.html>
Apparently Analagous Threads
- [LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?
- [LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?
- [LLVMdev] difference between replaceAllUsesWith and replaceUsesOfWith?
- [LLVMdev] global variable uses
- [LLVMdev] PATCH: Use size reduction -- wave2