<div dir="ltr">Thank you very much for your useful information. As you say, it is a subclass llvm::ConstantExpr.<div><br></div><div>Now I cast value "i32* getelementptr inbounds (%struct.Args* @globalArg, i64 0, i32 2)"  to its subclass llvm::Constant and then subclass llvm::ConstantExpr, and then I can access its indices through </div><div><br></div><div>for (unsigned i=0; i<constExpr->getNumOperands(); ++i) </div><div>    v = constExpr->getOperand(i);</div><div><br></div><div><b>However, I have another question.</b> The invoking of getNumOperands() on value "i32* getelementptr inbounds (%struct.Args* @globalArg, i64 0, i32 2)" returns 3, but it returns 1 on value "i32* getelementptr inbounds (%struct.Args* @globalArg, i64 0, i32 0)", and furthermore, through value "i32* getelementptr inbounds (%struct.Args* @globalArg, i64 0, i32 2)" is subclass llvm::Constant, but it is not subclass llvm::ConstantExpr, why?   </div><div><div class="gmail_extra"><br></div><div class="gmail_extra"><br clear="all"><div><div><br>--------------------------------------------<br>Qiuping Yi<br>Institute Of Software<br>Chinese Academy of Sciences</div></div>
<br><div class="gmail_quote">On Sun, Nov 23, 2014 at 4:08 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Sat, Nov 22, 2014 at 11:09 AM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Qiuping,<br>
<br>
If I'm reading the IR correctly, what you have is a<br>
GetElementPtrConstantExpr [1].  It subclasses from llvm::Constant.<br></blockquote><div><br></div></span><div>If you want the same code to handle GetElementPtrConstantExpr *and* GetElementPtrInst, you can use GEPOperator.</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Thanks,<br>
-- Sanjoy<br>
<br>
[1]: <a href="http://llvm.org/docs/doxygen/html/classllvm_1_1GetElementPtrConstantExpr.html" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1GetElementPtrConstantExpr.html</a><br>
<div><div><br>
On Sat, Nov 22, 2014 at 1:10 AM, Qiuping Yi <<a href="mailto:yiqiuping@gmail.com" target="_blank">yiqiuping@gmail.com</a>> wrote:<br>
> Hi Michael,<br>
><br>
> Thank you very much.<br>
><br>
> But idx_begin/idx_end iterators can only be used through a getelementptr<br>
> instruction, right? However, I think value "i32* getelementptr inbounds<br>
> (%struct.Args* @globalArg, i64 0, i32 2)" itself is not a getelementptr<br>
> instruction, so? Or could you tell me how can I get a getelementptr<br>
> instruction first from this value?<br>
><br>
><br>
> --------------------------------------------<br>
> Qiuping Yi<br>
> Institute Of Software<br>
> Chinese Academy of Sciences<br>
><br>
> On Sat, Nov 22, 2014 at 4:49 PM, Michael Zolotukhin <<a href="mailto:mzolotukhin@apple.com" target="_blank">mzolotukhin@apple.com</a>><br>
> wrote:<br>
>><br>
>> Hi Qiuping,<br>
>><br>
>> I guess you need to use getPointerOperand to access the pointer operand<br>
>> (@globalArg in your example) and idx_begin/idx_end iterators to access<br>
>> indexes. You can find a short description of these functions in<br>
>> documentation [1], or look at examples of their uses in the code, e.g. in<br>
>> lib/Transforms/InstCombine/*.cpp.<br>
>><br>
>> [1] <a href="http://llvm.org/doxygen/classllvm_1_1GetElementPtrInst.html" target="_blank">http://llvm.org/doxygen/classllvm_1_1GetElementPtrInst.html</a><br>
>><br>
>> Best regards,<br>
>> Michael<br>
>><br>
>> On Nov 22, 2014, at 12:32 AM, Qiuping Yi <<a href="mailto:yiqiuping@gmail.com" target="_blank">yiqiuping@gmail.com</a>> wrote:<br>
>><br>
>> Hi, all<br>
>><br>
>> I am a LLVM user. I want to get every element in the next instruction:<br>
>><br>
>> %0 = load i32* getelementptr inbounds (%struct.Args* @globalArg, i64 0,<br>
>> i32 2), align 4, !dbg !85, !clap !86<br>
>><br>
>> Now I can only get value "i32* getelementptr inbounds (%struct.Args*<br>
>> @globalArg, i64 0, i32 2)" through "getOperand(0)",<br>
>> but I can not get "%struct.Args* @globalArg", "i64 0", and "i32 2" in this<br>
>> instruction.<br>
>><br>
>> I know I can get the indices of getelementptr instructions through<br>
>> "getOperand()", but now in the previous example,<br>
>> I want to get the indices from a getlementptr value. How should I do?<br>
>> Thank you in advance.<br>
>><br>
>><br>
>> Best Regards!<br>
>><br>
>> --------------------------------------------<br>
>> Qiuping Yi<br>
>> Institute Of Software<br>
>> Chinese Academy of Sciences<br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div></div>