[LLVMdev] Finding the uses of a global variable

Deu Arm deuarm at gmail.com
Fri Dec 9 04:49:44 PST 2011


Hi everyone,
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)
it is not actually able to find its uses, as it gives <null> instructions!
I have even tried to iterate over instructions in the module, then find the
use-def of each instruction
for(User::op_iterator I = theInstruction->op_begin(),
E=theInstruction->op_end(); I!=E; ++I)
After it I have tried to check whether this "theInstruction" is one of
global vars (one of the "gi"-s).
But that doesn't work either, as LLVM does not think that the global vars,
which are used in an instruction, are operands of that instruction!
So anyway, how can I find the def-uses of global variables??
---Schuhmacher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111209/f025e120/attachment.html>


More information about the llvm-dev mailing list