Hi,
 
I'm trying to change all uses of a global variable so they'll use a
different global variable.
For instance, I have:
@a = global [100 x [100 x i64]] zeroinitializer, align 16
@b = global [100 x [100 x i64]] zeroinitializer, align 16
 
And I want to change the use
%arrayidx = getelementptr inbounds [100 x [100 x i64]]* @a, i32 0, i64 %3
to
%arrayidx = getelementptr inbounds [100 x [100 x i64]]* @b, i32 0, i64 %3 
 
But, when I'm iterating the uses with the use_iterator of the Global
variable, I get the Global variable's definition/allocation as the use(s)
and not the "real" uses (the GEP). 
Why? Isn't the meaning of use here is where @a is used?
 
The relevant code (var is a GlobalVariable *):
var->dump();  // prints: @a = global [100 x [100 x i64]] zeroinitializer,
align 16
for (GlobalVariable::use_iterator U = var->use_begin(); U !=
var->use_end();
U++) {
                Constant * CE = dyn_cast<Constant>(*U); // this is  the
only
cast that works here
                CE->dump(); // prints: @a = global [100 x [100 x i64]]
zeroinitializer, align 16
}
 
Thanks for your help,
Tehila.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150525/50aac2a8/attachment.html>
Hi Tehila, On 25 May 2015 at 02:38, Tehila Mayzels <tehila at cs.technion.ac.il> wrote:> Why? Isn't the meaning of use here is where @a is used?Each element you're iterating through is an llvm::Use, which records both what is being used and the user. Possibly confusingly, what you get when you simply dereference it is the thing being used. You should either call U->getUser() or iterate using user_begin/user_end instead. Though there's actually a function Value::ReplaceAllUsesWith which might mean you don't need the loop at all, depending on how complex your change is. Cheers. Tim.
Thanks a lot for the explanation, Tim! Tehila. -----Original Message----- From: Tim Northover [mailto:t.p.northover at gmail.com] Sent: Monday, May 25, 2015 6:42 PM To: Tehila Mayzels Cc: LLVM Developers Mailing List Subject: Re: [LLVMdev] global variable uses Hi Tehila, On 25 May 2015 at 02:38, Tehila Mayzels <tehila at cs.technion.ac.il> wrote:> Why? Isn't the meaning of use here is where @a is used?Each element you're iterating through is an llvm::Use, which records both what is being used and the user. Possibly confusingly, what you get when you simply dereference it is the thing being used. You should either call U->getUser() or iterate using user_begin/user_end instead. Though there's actually a function Value::ReplaceAllUsesWith which might mean you don't need the loop at all, depending on how complex your change is. Cheers. Tim.