Hello, I was facing some difficulty in implementing a transform and I was wondering if I could get some help please. The transform needs to operate on the operands of certain instructions. For example, given an instruction, say "%10 = load i32* %9, align 4", I have to record the value of %9 and process it. Of course, this is only possible at runtime and so I am instrumenting the code such that a particular function is invoked just before the instruction of interest is executed. The problem that I am facing is in getting the value of the operands. As I understand, the operands could either be program variables (e.g. in "%6 load i32* %old, align 4") or one of the virtual registers (as in the first load instruction). For both cases, is it possible to extract the value/address of the operand (%9 or %old)? If yes, what should be the best function type to use so that I can pass this value as an argument to my function? For now, I am only concerned with load and store instructions and so (I suppose) I have to deal with pointers only. An easy way that I can think of is to directly insert the LLVM IR (e.g. call void @my_function(%old)) but because I am using Module::getOrInsertFunction(), I have to have a function type. So alternatively, is there a way to insert direct LLVM instructions (without going through the type hierarchy)? Thanks, Ashay --- Ashay Rane Research Associate The University of Texas at Austin http://www.public.asu.edu/~asrane/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110316/2265bf14/attachment.html>
On Wed, Mar 16, 2011 at 6:00 PM, Ashay Rane <ashay.rane at asu.edu> wrote:> Hello, > I was facing some difficulty in implementing a transform and I was wondering > if I could get some help please. > The transform needs to operate on the operands of certain instructions. For > example, given an instruction, say "%10 = load i32* %9, align 4", I have to > record the value of %9 and process it. Of course, this is only possible at > runtime and so I am instrumenting the code such that a particular function > is invoked just before the instruction of interest is executed. > The problem that I am facing is in getting the value of the operands. As I > understand, the operands could either be program variables (e.g. in "%6 > load i32* %old, align 4") or one of the virtual registers (as in the first > load instruction). For both cases, is it possible to extract the > value/address of the operand (%9 or %old)?Those are both the same case; names for instructions only exist for the sake of readability.> If yes, what should be the best > function type to use so that I can pass this value as an argument to my > function? For now, I am only concerned with load and store instructions and > so (I suppose) I have to deal with pointers only.If you only need pointers, just use i8* as the type of the argument, and bitcast the value to i8*.> An easy way that I can think of is to directly insert the LLVM IR (e.g. call > void @my_function(%old)) but because I am using > Module::getOrInsertFunction(), I have to have a function type. So > alternatively, is there a way to insert direct LLVM instructions (without > going through the type hierarchy)?Your approach of inserting a call is fine; making your own instruction or intrinsic wouldn't make things any simpler. There aren't any shortcuts here. -Eli
Hi Eli, 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? Ashay On Wed, Mar 16, 2011 at 11:03 PM, Eli Friedman <eli.friedman at gmail.com>wrote:> On Wed, Mar 16, 2011 at 6:00 PM, Ashay Rane <ashay.rane at asu.edu> wrote: > > Hello, > > I was facing some difficulty in implementing a transform and I was > wondering > > if I could get some help please. > > The transform needs to operate on the operands of certain instructions. > For > > example, given an instruction, say "%10 = load i32* %9, align 4", I have > to > > record the value of %9 and process it. Of course, this is only possible > at > > runtime and so I am instrumenting the code such that a particular > function > > is invoked just before the instruction of interest is executed. > > The problem that I am facing is in getting the value of the operands. As > I > > understand, the operands could either be program variables (e.g. in "%6 > > load i32* %old, align 4") or one of the virtual registers (as in the > first > > load instruction). For both cases, is it possible to extract the > > value/address of the operand (%9 or %old)? > > Those are both the same case; names for instructions only exist for > the sake of readability. > > > If yes, what should be the best > > function type to use so that I can pass this value as an argument to my > > function? For now, I am only concerned with load and store instructions > and > > so (I suppose) I have to deal with pointers only. > > If you only need pointers, just use i8* as the type of the argument, > and bitcast the value to i8*. > > > An easy way that I can think of is to directly insert the LLVM IR > (e.g. call > > void @my_function(%old)) but because I am using > > Module::getOrInsertFunction(), I have to have a function type. So > > alternatively, is there a way to insert direct LLVM instructions (without > > going through the type hierarchy)? > > Your approach of inserting a call is fine; making your own instruction > or intrinsic wouldn't make things any simpler. There aren't any > shortcuts here. > > -Eli-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110316/c0e591aa/attachment.html>
Reasonably Related Threads
- [LLVMdev] Operating on contents of virtual registers
- [LLVMdev] Operating on contents of virtual registers
- [LLVMdev] Operating on contents of virtual registers
- [LLVMdev] Operating on contents of virtual registers
- [LLVMdev] Operating on contents of virtual registers