PeiLIU via llvm-dev
2016-May-11 14:04 UTC
[llvm-dev] confused GetElementPtr, how to use it properly.
BasicBlock::iterator bit = BB->begin(); LoadInst *li = = dyn_cast<LoadInst>(bit); li->dump(); // %tmp6 = load i32* getelementptr inbounds (%struct.node* @Node, i32 0, i32 0), align 4, !dbg !59 li->getOperand(0)->dump(); // i32* getelementptr inbounds (%struct.node* @Node, i32 0, i32 0), align 4, !dbg !59 GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(li->getOperand(0)); if (gep != NULL) { std::cout << "gep not NULL" << std::endl; } The previous codes' BB is a BasicBlock pointer, I want to get the string name Node. I want to use dyn_cast to cast the value of li->getOperand(0) to a GetElementPtr pointer type, but it is likely can not casted by the dyn_cast operation. The if statement never executed. How it can be implemented? I confused by the load instruction? Any advice would be appreciate, thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160511/b4cccedd/attachment.html>
Diana Picus via llvm-dev
2016-May-11 15:27 UTC
[llvm-dev] confused GetElementPtr, how to use it properly.
Try casting to GetElementPtrConstantExpr. Hope that helps, Diana http://llvm.org/docs/doxygen/html/classllvm_1_1GetElementPtrConstantExpr.html On 11 May 2016 at 17:04, PeiLIU via llvm-dev <llvm-dev at lists.llvm.org> wrote:> BasicBlock::iterator bit = BB->begin(); > > LoadInst *li = = dyn_cast<LoadInst>(bit); > > li->dump(); // %tmp6 = load i32* getelementptr inbounds (%struct.node* > @Node, i32 0, i32 0), align 4, !dbg !59 > > li->getOperand(0)->dump(); // i32* getelementptr inbounds (%struct.node* > @Node, i32 0, i32 0), align 4, !dbg !59 > > GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(li->getOperand(0)); > > if (gep != NULL) { > std::cout << "gep not NULL" << std::endl; > } > > The previous codes' BB is a BasicBlock pointer, I want to get the string > name Node. I want to use dyn_cast to cast > > the value of li->getOperand(0) to a GetElementPtr pointer type, but it is > likely can not casted by the dyn_cast operation. > > The if statement never executed. How it can be implemented? I confused by > the load instruction? Any advice would be > > appreciate, thank you. > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >