[LLVMdev] Finding the uses of a global variable

Duncan Sands baldrick at free.fr
Fri Dec 9 05:45:23 PST 2011

Hi Deu,

> I am writing a pass that finds all uses of global variables (my goal is to find
> the uses of strings, and strings are defined as global variables). So, I can
> iterate over global vars by
> for(Module::global_iterator gi = M.global_begin(), gend = M.global_end(); gi !=
> gend; ++gi) ......
> But if I use its def-use chain
> for(Value::use_iterator i = gi->use_begin(), e = F->use_end; i!=e; ++i)

this is the correct approach, though that should presumably be gi->use_end()
rather than F->use_end.

> it is not actually able to find its uses, as it gives <null> instructions!

That just means that the uses are not instructions.  Must likely they are
ConstantExpr's, probably bitcast or getelementptr constant expressions.

Ciao, Duncan.

More information about the llvm-dev mailing list