Hi Eli,<div><br></div><div>Thanks for the reply. The problem is that getOperand() returns an llvm::Instruction (that refers to the definition of the operand). What I am trying to find out is how to get the value of the operand. When you refer to bitcasting to i8*, do you mean casting the return value from getOperand() itself?</div>
<div><br></div><div>Ashay</div><div><br><br><div class="gmail_quote">On Wed, Mar 16, 2011 at 11:03 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Wed, Mar 16, 2011 at 6:00 PM, Ashay Rane <<a href="mailto:ashay.rane@asu.edu">ashay.rane@asu.edu</a>> wrote:<br>

> Hello,<br>
> I was facing some difficulty in implementing a transform and I was wondering<br>
> if I could get some help please.<br>
> The transform needs to operate on the operands of certain instructions. For<br>
> example, given an instruction, say "%10 = load i32* %9, align 4", I have to<br>
> record the value of %9 and process it. Of course, this is only possible at<br>
> runtime and so I am instrumenting the code such that a particular function<br>
> is invoked just before the instruction of interest is executed.<br>
> The problem that I am facing is in getting the value of the operands. As I<br>
> understand, the operands could either be program variables (e.g. in "%6 =<br>
> load i32* %old, align 4") or one of the virtual registers (as in the first<br>
> load instruction). For both cases, is it possible to extract the<br>
> value/address of the operand (%9 or %old)?<br>
<br>
</div>Those are both the same case; names for instructions only exist for<br>
the sake of readability.<br>
<div class="im"><br>
> If yes, what should be the best<br>
> function type to use so that I can pass this value as an argument to my<br>
> function? For now, I am only concerned with load and store instructions and<br>
> so (I suppose) I have to deal with pointers only.<br>
<br>
</div>If you only need pointers, just use i8* as the type of the argument,<br>
and bitcast the value to i8*.<br>
<div class="im"><br>
> An easy way that I can think of is to directly insert the LLVM IR (e.g. call<br>
> void @my_function(%old)) but because I am using<br>
> Module::getOrInsertFunction(), I have to have a function type. So<br>
> alternatively, is there a way to insert direct LLVM instructions (without<br>
> going through the type hierarchy)?<br>
<br>
</div>Your approach of inserting a call is fine; making your own instruction<br>
or intrinsic wouldn't make things any simpler.  There aren't any<br>
shortcuts here.<br>
<font color="#888888"><br>
-Eli</font></blockquote></div></div>