[cfe-dev] How to know whether expression is derived from induction variable?

Gabor Kozar kozargabor at gmail.com
Thu Sep 26 14:48:01 PDT 2013


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.



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).



--
Gábor Kozár -- ShdNx
kozargabor at gmail.com





On Thu, Sep 26, 2013, at 21:19, Madhur Amilkanthwar wrote:

But then which function is expected? Only getConditionVariable()
returns VarDecl.
I just want to know induction var and all vars which are derived from
induction var.



On Fri, Sep 27, 2013 at 12:46 AM, Pan, Wei <[1]wei.pan at intel.com>
wrote:

It looks like you are calling the wrong function
getConditionVariable(), which returns 0 most of time.

[2]http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html#a43f4d356ba
a047f895978ddc8d64fee0

Weo

  __________________________________________________________________

From: [3]cfe-dev-bounces at cs.uiuc.edu [[4]cfe-dev-bounces at cs.uiuc.edu]
on behalf of Madhur Amilkanthwar [[5]madhur13490 at gmail.com]
Sent: Thursday, September 26, 2013 12:58 PM
To: Gabor Kozar
Cc: [6]cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] How to know whether expression is derived from
induction variable?


I am very basic thing now
I inherited RecursiveASTVisitor Class and  overloaded function
VisitStmt as
bool VisitStmt(Stmt *s)
{
if(isa<ForStmt>(s))
{
std::cout<<"For Statement found\n";
VarDecl *D=cast<ForStmt>(s)->getConditionVariable();
if(D->isLocalVarDecl())
llvm::errs()<<"local";
}
return true;
}
but I am facing runtime error.(seg fault) any clue?




On Thu, Sep 26, 2013 at 7:35 PM, Madhur Amilkanthwar
<[7]madhur13490 at gmail.com> wrote:

Ohk..this looks cool. Let me try that. Thanks.




On Thu, Sep 26, 2013 at 6:37 PM, Gabor Kozar <[8]kozargabor at gmail.com>
wrote:

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.

--
Gábor Kozár -- ShdNx
[9]kozargabor at gmail.com



On Thu, Sep 26, 2013, at 15:00, Madhur Amilkanthwar wrote:

Hi,
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.
Assume following code:
for(int i=0;i<32;i++)
  i=i+2;

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?

Any help appreciated.

--
Thank You.
Madhur D. Amilkanthwar
RISE lab,
IIT Madras.

_______________________________________________

cfe-dev mailing list

[10]cfe-dev at cs.uiuc.edu

[11]http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



_______________________________________________

cfe-dev mailing list

[12]cfe-dev at cs.uiuc.edu

[13]http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev









--
Thank You.
Madhur D. Amilkanthwar
RISE lab,
IIT Madras.





--
Thank You.
Madhur D. Amilkanthwar
RISE lab,
IIT Madras.




--
Thank You.
Madhur D. Amilkanthwar
RISE lab,
IIT Madras.

References

1. mailto:wei.pan at intel.com
2. http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html#a43f4d356baa047f895978ddc8d64fee0
3. mailto:cfe-dev-bounces at cs.uiuc.edu
4. mailto:cfe-dev-bounces at cs.uiuc.edu
5. mailto:madhur13490 at gmail.com
6. mailto:cfe-dev at cs.uiuc.edu
7. mailto:madhur13490 at gmail.com
8. mailto:kozargabor at gmail.com
9. mailto:kozargabor at gmail.com
  10. mailto:cfe-dev at cs.uiuc.edu
  11. http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
  12. mailto:cfe-dev at cs.uiuc.edu
  13. http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130926/6d2772b2/attachment.html>


More information about the cfe-dev mailing list