collecting source code information

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

collecting source code information

Dominik Grewe
Hey!

I'd like to write a program that collects statistics of OpenCL kernels. Examples
are the number of arithmetic operations, number and types of variables, etc. In
the future I'd also like to do some static analysis, for example to try and
derive memory access patterns.

I'm new to Clang, so I'm not quite sure how to go about this... It seems like
the RecursiveASTVisitor class could be a good start, as it allows you to
traverse the AST. Overloading VisitStmt() for example would allow me to count
the number of arithmetic expressions, right?
Unfortunately I can't figure out how to start the tree traversal. What is it
that I need to pass my visitor class in order to traverse the whole file or a
certain function?
Are there any examples that show a usage of RecursiveASTVisitor?

Thanks
Dominik


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: collecting source code information

Douglas Gregor

On Jun 24, 2010, at 10:19 AM, Dominik Grewe wrote:

> Hey!
>
> I'd like to write a program that collects statistics of OpenCL kernels. Examples
> are the number of arithmetic operations, number and types of variables, etc. In
> the future I'd also like to do some static analysis, for example to try and
> derive memory access patterns.
>
> I'm new to Clang, so I'm not quite sure how to go about this... It seems like
> the RecursiveASTVisitor class could be a good start, as it allows you to
> traverse the AST. Overloading VisitStmt() for example would allow me to count
> the number of arithmetic expressions, right?

Sure, although you probably want to overload VisitBinaryOperator/VisitUnaryOperator.

> Unfortunately I can't figure out how to start the tree traversal. What is it
> that I need to pass my visitor class in order to traverse the whole file or a
> certain function?
> Are there any examples that show a usage of RecursiveASTVisitor?

Check out lib/Frontend/BoostConAction.cpp

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: collecting source code information

Dominik Grewe
Thanks for your reply. I now started using CFG rather than ASTVisitor. It allows
me to iterate over basic blocks nicely so that I can see the actual structure of
the code. Is this also possible in ASTVisitor?

Another problem:
When I reach a variable that is a parameter of my function, it is described as a
DeclRefExpr in the CFG. However, if the variable is local it is not a
DeclRefExpr and I can't figure out what type of expression it is...

Cheers
Dominik




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: collecting source code information

Dominik Grewe
 
> Another problem:
> ...

Problem solved... sorry


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: collecting source code information

Stefan Seefeld
In reply to this post by Douglas Gregor
On 06/29/2010 10:25 AM, Douglas Gregor wrote:
>
>> Unfortunately I can't figure out how to start the tree traversal. What is it
>> that I need to pass my visitor class in order to traverse the whole file or a
>> certain function?
>> Are there any examples that show a usage of RecursiveASTVisitor?
>>      
> Check out lib/Frontend/BoostConAction.cpp
>    


Where can I find RecursiveASTVisitor.hpp ? It's referred to as
lib/AST/RecursiveASTVisitor.hpp in the above BoostConAction.cpp, but I
can't see any such file in
http://llvm.org/svn/llvm-project/cfe/trunk/lib/AST/.

Thanks,
         Stefan

--

       ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: collecting source code information

Dominik Grewe
Stefan Seefeld <stefan.seefeld@...> writes:

> Where can I find RecursiveASTVisitor.hpp ? It's referred to as
> lib/AST/RecursiveASTVisitor.hpp in the above BoostConAction.cpp, but I
> can't see any such file in
> http://llvm.org/svn/llvm-project/cfe/trunk/lib/AST/.

It's part of clang, not LLVM. Check out the clang repository (see
clang.llvm.org) and you'll find the RecursiveASTVisitor.h in
include/clang/AST/RecursiveASTVisitor.h

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: collecting source code information

Stefan Seefeld-2
On 06/30/2010 04:47 AM, Dominik Grewe wrote:

> Stefan Seefeld<stefan.seefeld@...>  writes:
>
>    
>> Where can I find RecursiveASTVisitor.hpp ? It's referred to as
>> lib/AST/RecursiveASTVisitor.hpp in the above BoostConAction.cpp, but I
>> can't see any such file in
>> http://llvm.org/svn/llvm-project/cfe/trunk/lib/AST/.
>>      
> It's part of clang, not LLVM. Check out the clang repository (see
> clang.llvm.org)

That's exactly what I did: http://clang.llvm.org/ has two menu items for
"Browse svn" and "Browse VC" and the above is where they take me.

I now see that I was looking in libs/AST, not include/AST, which is why
I didn't find what I was looking for.

Thanks,
         Stefan


--

       ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev