6

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.

ash
  • 1,170
  • 1
  • 15
  • 24

1 Answers1

9

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

knightrider
  • 2,063
  • 1
  • 16
  • 29
  • I understand this. My question is I guess how do I get the value of a variable. It is not clear to me. – ash Sep 05 '12 at 21:30
  • 2
    @ash the code which you gave is an instruction. just do this Value *v = *i; where I was the instruction – knightrider Sep 05 '12 at 21:33
  • yes. If were to iterate through all the Instructions I know how do it. But to get a pointer to specific value, I am not sure how to do it... In my example how would you get the pointer to value of @someVar ? – ash Sep 05 '12 at 21:35
  • Ya it is. But I still have issues. I updated my original post! Thank you – ash Sep 06 '12 at 23:57
  • @ash What issues are you facing now – knightrider Sep 09 '12 at 13:01