<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>I do not believe there is a direct method to achieve this. You'll most likely have to look at the init expr for the ForStmt, and check if it is a DeclStmt (or maybe an assignment, if you're interested in that, in which case check for BinaryOperator and CXXOperatorCallExpr), and if so, what is the variable being declared.<br></div>
<div> </div>
<div>By the way, RecursiveASTVisitor is incredibly flexible, you can just use bool VisitForStmt() instead of using VisitStmt and dyn-casting around. RecursiveASTVisitor has Visit* and Traverse* methods for all AST nodes (it's hacked together with macros and codegen).</div>
<div> </div>
<div id="sig19426269"><div class="signature">-- <br></div>
<div class="signature">  Gábor Kozár -- ShdNx<br></div>
<div class="signature">  kozargabor@gmail.com<br></div>
<div class="signature"> </div>
</div>
<div> </div>
<div> </div>
<div>On Thu, Sep 26, 2013, at 21:19, Madhur Amilkanthwar wrote:<br></div>
<blockquote type="cite"><div dir="ltr">But then which function is expected? Only getConditionVariable() returns VarDecl.<div>I just want to know induction var and all vars which are derived from induction var.<br></div>
<div> </div>
</div>
<div><div> </div>
<div> </div>
<div><div>On Fri, Sep 27, 2013 at 12:46 AM, Pan, Wei <span dir="ltr"><<a href="mailto:wei.pan@intel.com" target="_blank">wei.pan@intel.com</a>></span> wrote:<br></div>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="direction:ltr;font-size:10pt;font-family:Tahoma"><div>It looks like you are calling the wrong function getConditionVariable(), which returns 0 most of time.<br></div>
<div> </div>
<div>
<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html#a43f4d356baa047f895978ddc8d64fee0" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html#a43f4d356baa047f895978ddc8d64fee0</a><br></div>
<div> </div>
<div>
Weo<br></div>
<div> </div>
<div> </div>
<div style="font-size:16px;font-family:Times New Roman">
<hr>
<div style="direction:ltr"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Tahoma"><b>From:</b> <a href="mailto:cfe-dev-bounces@cs.uiuc.edu" target="_blank">cfe-dev-bounces@cs.uiuc.edu</a> [<a href="mailto:cfe-dev-bounces@cs.uiuc.edu" target="_blank">cfe-dev-bounces@cs.uiuc.edu</a>] on behalf of Madhur Amilkanthwar [<a href="mailto:madhur13490@gmail.com" target="_blank">madhur13490@gmail.com</a>]</span></span><br></div>
<div style="direction:ltr"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Tahoma">


<b>Sent:</b> Thursday, September 26, 2013 12:58 PM</span></span><br></div>
<div style="direction:ltr"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Tahoma">
<b>To:</b> Gabor Kozar</span></span><br></div>
<div style="direction:ltr"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Tahoma">
<b>Cc:</b> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a></span></span><br></div>
<div style="direction:ltr"><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:Tahoma">
<b>Subject:</b> Re: [cfe-dev] How to know whether expression is derived from induction variable?</span></span><br></div>
<div style="direction:ltr"> </div>
<div><div><div> </div>
<div><div dir="ltr">I am very basic thing now
<div>I inherited RecursiveASTVisitor Class and  overloaded function VisitStmt as<br></div>
<div><div>bool VisitStmt(Stmt *s)<br></div>
<div><span style="white-space:pre-wrap"></span>{<br></div>
<div><span style="white-space:pre-wrap"></span>if(isa<ForStmt>(s))<br></div>
<div><span style="white-space:pre-wrap"></span>{<br></div>
<div><span style="white-space:pre-wrap"></span>std::cout<<"For Statement found\n";<br></div>
<div><span style="white-space:pre-wrap"></span>VarDecl *D=cast<ForStmt>(s)->getConditionVariable();<br></div>
<div><span style="white-space:pre-wrap"></span>if(D->isLocalVarDecl())<br></div>
<div><span style="white-space:pre-wrap"></span>llvm::errs()<<"local";<br></div>
<div><span style="white-space:pre-wrap">}</span><br></div>
</div>
<div><span style="white-space:pre-wrap">return true;</span><br></div>
<div><span style="white-space:pre-wrap">}</span><br></div>
<div><span style="white-space:pre-wrap">but I am facing runtime error.(seg fault) any clue?</span><br></div>
<div> </div>
</div>
<div><div> </div>
<div> </div>
<div> </div>
<div><div>On Thu, Sep 26, 2013 at 7:35 PM, Madhur Amilkanthwar <span dir="ltr">
<<a href="mailto:madhur13490@gmail.com" target="_blank">madhur13490@gmail.com</a>></span> wrote:<br></div>
<div> </div>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ohk..this looks cool. Let me try that. Thanks.<br></div>
<div><div><div><div> </div>
<div> </div>
<div> </div>
<div><div>On Thu, Sep 26, 2013 at 6:37 PM, Gabor Kozar <span dir="ltr">
<<a href="mailto:kozargabor@gmail.com" target="_blank">kozargabor@gmail.com</a>></span> wrote:<br></div>
<div> </div>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<u></u>
<br></div>
<div><div>The simplest probably would be finding all relevant loop nodes, i.e. ForExpr-s, identifying the loop induction variable, i.e. the VarDecl-s (if any), and finally running a RecursiveASTVisitor on its body, looking for a DeclRefExpr referring to any of the
 VarDecl-s you identified in the previous step.
<br></div>
<div> </div>
<div><div>-- 
<br></div>
<div>Gábor Kozár -- ShdNx
<br></div>
<div><a href="mailto:kozargabor@gmail.com" target="_blank">kozargabor@gmail.com</a>
<br></div>
<div> </div>
</div>
<div><div><div> </div>
<div> </div>
<div>On Thu, Sep 26, 2013, at 15:00, Madhur Amilkanthwar wrote:
<br></div>
</div>
</div>
<blockquote type="cite"><div><div><div dir="ltr"><div><div><div><div><div>Hi,
<br></div>
<div>I am interested in knowing if an expression is derived from loop induction variable or not. As of now, I am able to inspect every expression after locating "if" statement in the code.

<br></div>
<div>Assume following code:
<br></div>
</div>
<div>for(int i=0;i<32;i++)
<br></div>
</div>
<div>  i=i+2;
<br></div>
<div> </div>
</div>
<div>in above code, I am able to get access to the expression "i+2" but how should I analyze its LHS and RHS for induction variable?
<br></div>
<div> </div>
</div>
<div>Any help appreciated. 
<br></div>
<div><div><div><div><div><div> </div>
<div>-- 
<br></div>
<div>Thank You.
<br></div>
<div>Madhur D. Amilkanthwar
<br></div>
<div>RISE lab,
<br></div>
<div>IIT Madras. 
<br></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div><u>_______________________________________________</u>
<br></div>
<div>cfe-dev mailing list
<br></div>
<div><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a>
<br></div>
<div><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a>
<br></div>
</blockquote></div>
<div> </div>
<div>
_______________________________________________<br></div>
<div>
cfe-dev mailing list<br></div>
<div>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br></div>
<div>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br></div>
<div> </div>
<div> </div>
</blockquote></div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div>
-- <br></div>
<div>
Thank You.<br></div>
<div>
Madhur D. Amilkanthwar<br></div>
<div>
RISE lab,<br></div>
<div>
IIT Madras.<br></div>
<div> </div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div>
-- <br></div>
<div>
Thank You.<br></div>
<div>
Madhur D. Amilkanthwar<br></div>
<div>
RISE lab,<br></div>
<div>
IIT Madras.<br></div>
<div> </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote></div>
<div> </div>
<div> </div>
<div> </div>
<div>-- <br></div>
<div>Thank You.<br></div>
<div>Madhur D. Amilkanthwar<br></div>
<div>RISE lab,<br></div>
<div>IIT Madras.<br></div>
<div> </div>
</div>
</blockquote></body>
</html>