[LLVMdev] How to get more details from storeInst ?
Cheng Liu
liucheng at eee.hku.hk
Mon Jan 21 20:15:51 PST 2013
Dear Duancan Ciao,
Your suggestion is really helpful.
Thank you very much.
Best regards,
On 1/18/2013 5:04 PM, Duncan Sands [via LLVM] wrote:
> Hi Cheng,
>
> On 18/01/13 03:00, Cheng Liu wrote:
> > I have a loop fully unrolled and got the following store instruction.
> >
> > store i32 %add.3, i32* getelementptr inbounds ([20 x [20 x i32]]*
> @c, i32 0,
> > i32 0, i32 0), align 4
> >
> > I want to know exactly which element of the array that is going to be
> > stored, which help me to transform the high level language to
> hardware. Take
> > the instruction above as an example, I know the data is stored into
> c[0][0].
> > It is just that I don't how to get c, 0, 0 from the instruction.
>
> this bit
> i32* getelementptr inbounds ([20 x [20 x i32]]* @c, i32 0, i32 0,
> i32 0)
> is a constant expression (ConstantExpr class), not an instruction (you
> can
> tell because it is printed inline).
>
> If SI is your store instruction (with type StoreInst*) then using
> SI->getPointerOperand()
> you get the stored to pointer. Call the result Ptr.
>
> You can cast that to a ConstantExpr* using
> cast<ConstantExpr>(Ptr)
> This will assert if Ptr isn't a constant expression. You can use
> dyn_cast
> instead which will return null if it isn't a constant expression. At
> this
> point you can rummage around inside the constant expression. It is
> probably
> simpler though to #include the Operator.h header, and cast Ptr to the
> GEPOperator class instead.
>
> Ciao, Duncan.
>
> >
> > At the moment, I use the method getNumOperands() and getOperand( int
> i) to
> > check all the operands of the instruction. However, I can only get two
> > operands. One of them is the data %add.s, and the other is the
> pointer. The
> > pointer has no name and it is not a constant.
>
> Yes, it is a constant (Constant class).
>
> I couldn't move further into
>
> > the pointer to get the index of the element.
> >
> > Anyone could give me some suggestions on this?
> >
> >
> >
> > --
> > View this message in context:
> http://llvm.1065342.n5.nabble.com/How-to-get-more-details-from-storeInst-tp53841.html
> > Sent from the LLVM - Dev mailing list archive at Nabble.com.
> > _______________________________________________
> > LLVM Developers mailing list
> > [hidden email] </user/SendEmail.jtp?type=node&node=53853&i=0>
> http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email] </user/SendEmail.jtp?type=node&node=53853&i=1>
> http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the
> discussion below:
> http://llvm.1065342.n5.nabble.com/How-to-get-more-details-from-storeInst-tp53841p53853.html
>
> To unsubscribe from How to get more details from storeInst ?, click
> here
> <http://llvm.1065342.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=53841&code=bGl1Y2hlbmdAZWVlLmhrdS5oa3w1Mzg0MXwtMjIyNzc5MTc5>.
> NAML
> <http://llvm.1065342.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
Cheng Liu
PhD Candidate
Electrical and Electronic Engineering
The University of Hong Kong
--
View this message in context: http://llvm.1065342.n5.nabble.com/How-to-get-more-details-from-storeInst-tp53841p54002.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130121/96859a6e/attachment.html>
More information about the llvm-dev
mailing list