[LLVMdev] Getting started with LLVM Passes

Chris Lattner sabre at nondot.org
Fri Jul 15 15:12:47 PDT 2005


On Tue, 12 Jul 2005, Sean Peisert wrote:
> Chris,

Hi Sean, sorry for the delay, this got buried in my mail.

> I've now figured out how to track and single out specific instructions, which 
> was ridiculously easy.  Thanks!

:)

> I'm now on to trying to find more detail about those instructions, such as 
> the values and addresses of the operands in memory (or, in the case of 
> operands which are pointers, trying to get the pointer values, addresses, and 
> values stored at location specified by the pointer values, etc..).
>
> Would you suggest having LLVM add code after each instruction to get this, or 
> is there another way to do this?  I've tried writing some code, as follows 
> (where i is an inst_iterator, but the results are not what I would have 
> expected:
>
> for (User::op_iterator j = i->op_begin(), f = i->op_end(); j != f; ++j) {
>    std::cerr << "Operand: " << (j->getUser())->getOperand(0) << "\n";
> }
> or
> for (User::op_iterator j = i->op_begin(), f = i->op_end(); j != f; ++j) {
>    std::cerr << "Operand: " << j << "\n";
> }

This sort of thing isn't really what you want to do.  Consider an 
instruction like this:

   %X = load int* %P

This will iterate over the operands of the instructions (in this case, 
only %P), and print out the address of the IR node for that operand.  From 
what I understand, you want a dynamic trace of the values as the program 
executes.  In this case, I would suggest adding some instrumentation like 
this:

   %X = load int* %P   ; original instruction
   call %mytracefn(int* %P)    ; Do something to trace the value being loaded

... then run the program.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/




More information about the llvm-dev mailing list