[LLVMdev] global variable uses

Tehila Mayzels tehila at cs.technion.ac.il
Mon May 25 02:38:34 PDT 2015


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>


More information about the llvm-dev mailing list