Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding all uses of a specific variable in LLVM

I am very new to LLVM.

I am trying to write an llvm Pass to perform something akin to taint analysis. In my effort I need to iterate through the Def-use chain of specific predefined variables. For example the dis assembly of a C program the following code

  @someVar = external global %struct.something 

This is found above a function and I want to find all uses of this @someVar inside my function. How do I do it? I started writing a function pass. But how do I get the Def Use chain of this particular identifier?

I found this in the LLVM manual http://llvm.org/docs/ProgrammersManual.html#iterate_chains.

But I am not sure how I could use it in this context.

P.S Sorry if my question is vague or naive. I am a newbie and I dont know what information is pertinent.

like image 333
ash Avatar asked Sep 05 '12 21:09

ash


1 Answers

I am pasting the code from the link

Function *F = ...;

for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i)
  if (Instruction *Inst = dyn_cast<Instruction>(*i)) {
    errs() << "F is used in instruction:\n";
    errs() << *Inst << "\n";
  }

Basically F is the value for which you want to find the chain

like image 68
knightrider Avatar answered Nov 15 '22 20:11

knightrider