hi, i am writing a simple LLVM pass to analyze the Store instruction. my pass derives from InstVisitor class, and the method to handle Store instruction is like this: void MyPass::visitStoreInst(StoreInst &I) { ... } It is pretty simple to handle Store. however, in on test i got an instruction like below: store i8 %tmp5, i8* inttoptr (i32 301959828 to i8*) the second operand is "i8* inttoptr (i32 301959828 to i8*)", and i have no idea how i can retrieve the address 301959828, given the StoreInst argument of visitStoreInst. i am looking in the the code of LLVM, but still fail to see how to extract this information. any suggestion is very appreciated. i am really struggling here now ... thanks so much. Jun -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130418/91dc8992/attachment.html>
On 4/18/13 9:56 AM, Jun Koi wrote:> hi, > > i am writing a simple LLVM pass to analyze the Store instruction. > my pass derives from InstVisitor class, and the method to handle Store > instruction is like this: > > void MyPass::visitStoreInst(StoreInst &I) { > ... > } > > It is pretty simple to handle Store. however, in on test i got an > instruction like below: > > store i8 %tmp5, i8* inttoptr (i32 301959828 to i8*)The inttoptr used here is a Constant Expression (llvm::ConstantExpr). You'll need to take the operand to the store, cast it to llvm::ConstantExpr, and then examine the opcode and operands of the constant expression. The ConstantExpr class is documented at http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html and is described in the LLVM Language Reference Manual. -- John T.> > the second operand is "i8* inttoptr (i32 301959828 to i8*)", and i > have no idea how i can retrieve the address 301959828, given the > StoreInst argument of visitStoreInst. > > i am looking in the the code of LLVM, but still fail to see how to > extract this information. > > any suggestion is very appreciated. i am really struggling here now ... > > thanks so much. > Jun > > > > _______________________________________________ > 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/20130418/5a864af0/attachment.html>
On Thu, Apr 18, 2013 at 11:11 PM, John Criswell <criswell at illinois.edu>wrote:> On 4/18/13 9:56 AM, Jun Koi wrote: > > hi, > > i am writing a simple LLVM pass to analyze the Store instruction. > my pass derives from InstVisitor class, and the method to handle Store > instruction is like this: > > void MyPass::visitStoreInst(StoreInst &I) { > ... > } > > It is pretty simple to handle Store. however, in on test i got an > instruction like below: > > store i8 %tmp5, i8* inttoptr (i32 301959828 to i8*) > > > The inttoptr used here is a Constant Expression (llvm::ConstantExpr). > You'll need to take the operand to the store, cast it to > llvm::ConstantExpr, and then examine the opcode and operands of the > constant expression. > > The ConstantExpr class is documented at > http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html and is described > in the LLVM Language Reference Manual. > >OK, I tried my best, and come up with code like below: void MyPass::visitStoreInst(StoreInst &I) { Value *op2 = I.getOperand(1); // the address where we store data if (const ConstantExpr *c = dyn_cast <ConstantExpr>(op2)) { // how to extract the Int Constant here? } } The problem is that given ConstantExpr, i am not sure how to extract the Int Constant operand. According to http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html, this class only provides method such as getWithOperands(), but this method doesnt seem to do what I want. I grep through the code of LLVM, but cannot find any example doing this. any more hint, please? Thanks, Jun -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130419/497b7414/attachment.html>