7

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.

1 Answer 1

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

5
  • 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 5, 2012 at 21:30
  • 2
    @ash the code which you gave is an instruction. just do this Value *v = *i; where I was the instruction Sep 5, 2012 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 5, 2012 at 21:35
  • Ya it is. But I still have issues. I updated my original post! Thank you
    – ash
    Sep 6, 2012 at 23:57
  • @ash What issues are you facing now Sep 9, 2012 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.