Bernard Nongpoh via llvm-dev
2016-Aug-31 07:16 UTC
[llvm-dev] Check if getElementPtr Operand
Thanks Ryan, I'm able to retrieved the type using the following code: Type *type=getElementPtrInst->getSourceElementType(); On Fri, Aug 12, 2016 at 7:00 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:> Take a look at visitGetElementPtrInst in InstructionCombining.cpp for some > examples about how to iterate over GEP and check for type. > > http://llvm.org/docs/doxygen/html/InstructionCombining_ > 8cpp_source.html#l01334 > > Hope I understood your question correctly. > > On Fri, Aug 12, 2016 at 6:34 AM, Bernard Nongpoh via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hello, >> consider the following IR code : >> %count4 = getelementptr inbounds %struct.r32, %struct.r32* %cur.087, i64 >> 0, i32 4 >> >> How to check in the instruction, whether the operand is a structure or >> not >> >> if(isa<GetElementPtrInst>(instruction)) >> { >> GetElementPtrInst *getElementPtrInst=dyn_cast<GetElementPtrInst>(&instruction); >> >> //check if getElemetPtrInst operands structure or array. >> >> } >> >> Thank You >> >> regards, >> >> Bernard Nongpoh >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160831/bf590407/attachment.html>
Pierre Gagelin via llvm-dev
2016-Aug-31 07:29 UTC
[llvm-dev] Check if getElementPtr Operand
Hi, just a remark in your code below> How to check in the instruction, whether the operand is a > structure or not > > if(isa<GetElementPtrInst>(instruction)) > { > GetElementPtrInst *getElementPtrInst=dyn_cast<GetElementPtrInst>(&instruction); > > //check if getElemetPtrInst operands structure or array. > > }dyn_cast does the job of isa already (and the job of cast if isa is true), here you better do this directly: if(GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&instruction) ) { // processing on GEP } And beware of your isa: it should operate on a pointer to an instruction, not the instruction instance itself (just like for dyn_cast). Hope that helps, Pierre -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160831/c7d2e697/attachment.html>
Bernard Nongpoh via llvm-dev
2016-Aug-31 07:35 UTC
[llvm-dev] Check if getElementPtr Operand
Hello Pierre, Great!!! Thanks for your recommendation, Bernard On Wed, Aug 31, 2016 at 12:59 PM, Pierre Gagelin <up833083 at myport.ac.uk> wrote:> Hi, just a remark in your code below > > How to check in the instruction, whether the operand is a structure or not >>> >>> if(isa<GetElementPtrInst>(instruction)) >>> {GetElementPtrInst *getElementPtrInst=dyn_cast<GetElementPtrInst>(&instruction); >>> >>> //check if getElemetPtrInst operands structure or array. >>> >>> } >>> >>> dyn_cast does the job of isa already (and the job of cast if isa is > true), here you better do this directly: > > if( GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&instruction) ) { > // processing on GEP > } > > And beware of your isa: it should operate on a pointer to an instruction, > not the instruction instance itself (just like for dyn_cast). Hope that > helps, Pierre >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160831/dc6e8fc6/attachment.html>