Thanks Eli, that worked!<div><br></div><div>For the record, I had to make one change though. I had to bitcast to i32* (instead of i8*) otherwise I was seeing errors like:</div><div><div>Instruction referencing instruction not embedded in a basic block!</div>
<div>  %retval = alloca i32</div><div>  <badref> = bitcast i32* %retval to i8*</div><div><br></div><div>and sometimes:</div><div>Instruction does not dominate all uses!</div><div><br></div><div>That makes me curious to ask, what does the choice of i32 or i8 depend on? Is it the architecture?</div>
<div><br></div><div>Ashay</div><div><br></div><br><div class="gmail_quote">On Wed, Mar 16, 2011 at 11:40 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 9:33 PM, Ashay Rane <<a href="mailto:ashay.rane@asu.edu">ashay.rane@asu.edu</a>> wrote:<br>

> Hi Eli,<br>
> Thanks for the reply. The problem is that getOperand() returns an<br>
> llvm::Instruction (that refers to the definition of the operand). What I am<br>
> trying to find out is how to get the value of the operand. When you refer to<br>
> bitcasting to i8*, do you mean casting the return value from getOperand()<br>
> itself?<br>
> Ashay<br>
<br>
</div>I mean calling IRBuilder::CreateBitCast with the return value from getOperand().<br>
<font color="#888888"><br>
-Eli<br>
</font><div><div></div><div class="h5"><br>
> On Wed, Mar 16, 2011 at 11:03 PM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>><br>
> wrote:<br>
>><br>
>> 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<br>
>> > wondering<br>
>> > if I could get some help please.<br>
>> > The transform needs to operate on the operands of certain instructions.<br>
>> > For<br>
>> > example, given an instruction, say "%10 = load i32* %9, align 4", I have<br>
>> > to<br>
>> > record the value of %9 and process it. Of course, this is only possible<br>
>> > at<br>
>> > runtime and so I am instrumenting the code such that a particular<br>
>> > 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<br>
>> > I<br>
>> > understand, the operands could either be program variables (e.g. in "%6<br>
>> > =<br>
>> > load i32* %old, align 4") or one of the virtual registers (as in the<br>
>> > first<br>
>> > load instruction). For both cases, is it possible to extract the<br>
>> > value/address of the operand (%9 or %old)?<br>
>><br>
>> Those are both the same case; names for instructions only exist for<br>
>> the sake of readability.<br>
>><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<br>
>> > and<br>
>> > so (I suppose) I have to deal with pointers only.<br>
>><br>
>> If you only need pointers, just use i8* as the type of the argument,<br>
>> and bitcast the value to i8*.<br>
>><br>
>> > An easy way that I can think of is to directly insert the LLVM IR<br>
>> > (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<br>
>> > (without<br>
>> > going through the type hierarchy)?<br>
>><br>
>> 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>
>><br>
>> -Eli<br>
</div></div></blockquote></div><br></div>