Jimborean Alexandra
2011-Jul-20 15:02 UTC
[LLVMdev] print the memory address computed by getelementptr
Hi, I want to print the memory locations computed by getelementptr. As I understood, getelementptr does not access the memory, but it contains the address it computes. I want to print these addresses at runtime (or process them). So, I try to build a function that takes as argument a pointer and prints its value. And to call this function, by sending the gep instruction as a parameter. Surely, I obtain an error for a type mismatch. Can I declare the function as taking an int64 as parameter and then (somehow) sending the value computed by getelementptr? declare void @myFunction ( i64 ) %tmp22 = getelementptr inbounds %struct.linked* %tmp21, i32 0, i32 1 %tmp = convert_tmp22_to_i64_to_get_the_value_of_the_pointer call void @myFunction(i64 %tmp) Or could you suggest a better method to get the value computed by getelementptr ? Thanks, Alexandra -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110720/e2f43389/attachment.html>
John Criswell
2011-Jul-20 15:08 UTC
[LLVMdev] print the memory address computed by getelementptr
On 7/20/11 10:02 AM, Jimborean Alexandra wrote:> Hi, > > I want to print the memory locations computed by getelementptr. As I > understood, getelementptr does not access the memory, but it contains > the address it computes. I want to print these addresses at runtime > (or process them). So, I try to build a function that takes as > argument a pointer and prints its value. And to call this function, by > sending the gep instruction as a parameter.All you really need to do here is to cast the result of the getelementptr value to the type of the parameter of your function. In this case, you need to insert a ptrtoint instruction that takes the GEP and casts it to an i64. That said, instead of casting the GEP to an i64, it would be better if your run-time function took a void *. In LLVM IR, a pointer to an i8 is a void *, and so you could insert a bitcast of the GEP to an i8 * instead of casting it to an i64. That way, you don't have to worry about the pointer size if you start using your code on both 32-bit and 64-bit targets. -- John T.> > Surely, I obtain an error for a type mismatch. Can I declare the > function as taking an int64 as parameter and then (somehow) sending > the value computed by getelementptr? > > declare void @myFunction ( i64 ) > > > %tmp22 = getelementptr inbounds %struct.linked* %tmp21, i32 0, i32 1 > > %tmp = convert_tmp22_to_i64_to_get_the_value_of_the_pointer > > call void @myFunction(i64 %tmp) > > > Or could you suggest a better method to get the value computed by > getelementptr ? > > Thanks, > Alexandra > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110720/b6cd745e/attachment.html>
Eli Friedman
2011-Jul-20 15:08 UTC
[LLVMdev] print the memory address computed by getelementptr
On Wed, Jul 20, 2011 at 8:02 AM, Jimborean Alexandra <xinfinity_a at yahoo.com> wrote:> Hi, > > I want to print the memory locations computed by getelementptr. As I > understood, getelementptr does not access the memory, but it contains the > address it computes. I want to print these addresses at runtime (or process > them). So, I try to build a function that takes as argument a pointer and > prints its value. And to call this function, by sending the gep instruction > as a parameter. > > Surely, I obtain an error for a type mismatch. Can I declare the function as > taking an int64 as parameter and then (somehow) sending the value computed > by getelementptr? > > declare void @myFunction ( i64 ) > > > %tmp22 = getelementptr inbounds %struct.linked* %tmp21, i32 0, i32 1 > > %tmp = convert_tmp22_to_i64_to_get_the_value_of_the_pointerThis instruction is called ptrtoint. :) -Eli
Jimborean Alexandra
2011-Jul-25 21:32 UTC
[LLVMdev] print the memory address computed by getelementptr
Hi again, Thank you, your suggestion worked well. I was looking for a pointer to void actually. But it seems that I do not get the memory address when passing the value of the GEP instruction. For instance, when I print the address accessed by the second operandof the store instruction store %struct.linked* %tmp23.reload8, %struct.linked** %curr.037.reg2mem I obtain a memory address of the form 7fff29c28ac8 But when I try to get the address stored in the GEP %tmp18 = getelementptr inbounds %struct.linked* %curr.025.reload, i64 0, i32 0 I obtain 2084a10 which is not the memory location I expect. Is this the computed memory location, or I did not access it correctly? Thank you. Alexandra ________________________________ From: John Criswell <criswell at illinois.edu> To: Jimborean Alexandra <xinfinity_a at yahoo.com> Cc: llvmdev at cs.uiuc.edu Sent: Wednesday, July 20, 2011 5:08 PM Subject: Re: [LLVMdev] print the memory address computed by getelementptr On 7/20/11 10:02 AM, Jimborean Alexandra wrote:>Hi, > >I want to print the memory locations computed bygetelementptr. As I understood, getelementptr does not access the memory, but it contains the address it computes. I want to print these addresses at runtime (or process them). So, I try to build a function that takes as argument a pointer and prints its value. And to call this function, by sending the gep instruction as a parameter.>All you really need to do here is to cast the result of the getelementptr value to the type of the parameter of your function. In this case, you need to insert a ptrtoint instruction that takes the GEP and casts it to an i64. That said, instead of casting the GEP to an i64, it would be better if your run-time function took a void *. In LLVM IR, a pointer to an i8 is a void *, and so you could insert a bitcast of the GEP to an i8 * instead of casting it to an i64. That way, you don't have to worry about the pointer size if you start using your code on both 32-bit and 64-bit targets. -- John T.>Surely, I obtain an error for a type mismatch. Can I declarethe function as taking an int64 as parameter and then (somehow) sending the value computed by getelementptr?> >declare void @myFunction ( i64 ) > > >%tmp22 = getelementptr inbounds %struct.linked* %tmp21, i32 0,i32 1> >%tmp = convert_tmp22_to_i64_to_get_the_value_of_the_pointer > >call void @myFunction(i64 %tmp) > > >Or could you suggest a better method to get the value computedby getelementptr ?> >Thanks, >Alexandra > > > >_______________________________________________LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110725/30e73f2f/attachment.html>
Possibly Parallel Threads
- [LLVMdev] print the memory address computed by getelementptr
- [LLVMdev] print the memory address computed by getelementptr
- [LLVMdev] How to call the llvm.prefetch intrinsic ?
- [LLVMdev] speculative parallelization in LLVM
- [LLVMdev] speculative parallelization in LLVM