[LLVMdev] [Openmp-dev] Clang Plugin to analyze OpenMP AST

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

[LLVMdev] [Openmp-dev] Clang Plugin to analyze OpenMP AST

Simone Atzeni
Hi,

I am writing a plugin to get information about the OpenMP constructs from the AST.
I am basically writing a “RecursiveASTVisitor” and I am trying to find the OpenMP statement and get information like filename and line of code.

When I am visiting recursively each statement I have my own switch on the “StmtClass” and for now I am focusing on “OMPParallelForDirectiveClass”.
In my understanding, once I find the beginning of the OpenMP statement, its children are all the statement inside the OpenMP construct.
I was wondering if there is a way to know the lines of code where the OpenMP construct starts and where it finishes (in terms of lines of code), and then get the the same information for their children (lines of code of the other statement in the OpenMP construct).

In my example, once I find the OMPParallelForDirectiveClass statement I am trying to print line of code using the 3 functions getSpellingLineNumber, getExpansionLineNumber and get PresumedLineNumber using the location start and location end, however the numbers are all equal.
Also, I am looping into its children and the last statement that I got is that one before the closed bracket of the OpenMP constructs. Can I suppose that "the line of code of the last statement + 1” is the end of the OpenMP construct? What if there are new empty line?

Hope this is clear and you can give me some advice.

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

Re: [LLVMdev] [Openmp-dev] Clang Plugin to analyze OpenMP AST

Simone Atzeni
Also I noticed that if I dump the statement using “dump(SourceManager)” I got more info, in particular for example given the following program:

------------------------------------------------------------------------------------------------------------------------------
#pragma omp parallel for                                                                                                      
  for (int i = 1; i < MAX; i++) {                                                                                              
    x[i] = x[i - 1];                                                                                                          
    a = a + 1;                                                                                                                
  }
------------------------------------------------------------------------------------------------------------------------------

and as result I get:

------------------------------------------------------------------------------------------------------------------------------
OMPParallelForDirective 0x6c24258 </path/to/source.c:22:9, col:25>
|-CapturedStmt 0x6c23df0 <line:23:3, line:26:3>
----------------

The captured statement starts at line 23 (which is the line where the for-loop starts and line 26 is the closing bracket.
How do I get those information?

Thanks.
Best,
Simone

> On Dec 9, 2014, at 08:53, Simone Atzeni <[hidden email]> wrote:
>
> Hi,
>
> I am writing a plugin to get information about the OpenMP constructs from the AST.
> I am basically writing a “RecursiveASTVisitor” and I am trying to find the OpenMP statement and get information like filename and line of code.
>
> When I am visiting recursively each statement I have my own switch on the “StmtClass” and for now I am focusing on “OMPParallelForDirectiveClass”.
> In my understanding, once I find the beginning of the OpenMP statement, its children are all the statement inside the OpenMP construct.
> I was wondering if there is a way to know the lines of code where the OpenMP construct starts and where it finishes (in terms of lines of code), and then get the the same information for their children (lines of code of the other statement in the OpenMP construct).
>
> In my example, once I find the OMPParallelForDirectiveClass statement I am trying to print line of code using the 3 functions getSpellingLineNumber, getExpansionLineNumber and get PresumedLineNumber using the location start and location end, however the numbers are all equal.
> Also, I am looping into its children and the last statement that I got is that one before the closed bracket of the OpenMP constructs. Can I suppose that "the line of code of the last statement + 1” is the end of the OpenMP construct? What if there are new empty line?
>
> Hope this is clear and you can give me some advice.
>
> Thanks.
> Best,
> Simone


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

Re: [LLVMdev] [Openmp-dev] Clang Plugin to analyze OpenMP AST

Pan, Wei
02182   SourceRange getSourceRange() const LLVM_READONLY {
02183     return getCapturedStmt()->getSourceRange();
02184   }

Sounds like it is just the range of the statement being captured.

Wei

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Simone Atzeni
Sent: Tuesday, December 09, 2014 1:30 PM
To: [hidden email]; [hidden email]; [hidden email]
Subject: Re: [LLVMdev] [cfe-dev][Openmp-dev] Clang Plugin to analyze OpenMP AST

Also I noticed that if I dump the statement using “dump(SourceManager)” I got more info, in particular for example given the following program:

------------------------------------------------------------------------------------------------------------------------------
#pragma omp parallel for                                                                                                      
  for (int i = 1; i < MAX; i++) {                                                                                              
    x[i] = x[i - 1];                                                                                                          
    a = a + 1;                                                                                                                
  }
------------------------------------------------------------------------------------------------------------------------------

and as result I get:

------------------------------------------------------------------------------------------------------------------------------
OMPParallelForDirective 0x6c24258 </path/to/source.c:22:9, col:25>
|-CapturedStmt 0x6c23df0 <line:23:3, line:26:3>
----------------

The captured statement starts at line 23 (which is the line where the for-loop starts and line 26 is the closing bracket.
How do I get those information?

Thanks.
Best,
Simone

> On Dec 9, 2014, at 08:53, Simone Atzeni <[hidden email]> wrote:
>
> Hi,
>
> I am writing a plugin to get information about the OpenMP constructs from the AST.
> I am basically writing a “RecursiveASTVisitor” and I am trying to find the OpenMP statement and get information like filename and line of code.
>
> When I am visiting recursively each statement I have my own switch on the “StmtClass” and for now I am focusing on “OMPParallelForDirectiveClass”.
> In my understanding, once I find the beginning of the OpenMP statement, its children are all the statement inside the OpenMP construct.
> I was wondering if there is a way to know the lines of code where the OpenMP construct starts and where it finishes (in terms of lines of code), and then get the the same information for their children (lines of code of the other statement in the OpenMP construct).
>
> In my example, once I find the OMPParallelForDirectiveClass statement I am trying to print line of code using the 3 functions getSpellingLineNumber, getExpansionLineNumber and get PresumedLineNumber using the location start and location end, however the numbers are all equal.
> Also, I am looping into its children and the last statement that I got is that one before the closed bracket of the OpenMP constructs. Can I suppose that "the line of code of the last statement + 1” is the end of the OpenMP construct? What if there are new empty line?
>
> Hope this is clear and you can give me some advice.
>
> Thanks.
> Best,
> Simone


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

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

Re: [LLVMdev] [Openmp-dev] Clang Plugin to analyze OpenMP AST

Bataev, Alexey
In reply to this post by Simone Atzeni
Hi Simone,
You don't need to analyze all children of the openmp construct, you need
to analyze only the first one. All other children maybe just some
special helper expressions/statements, not actually a construct under
OpenMP directive.
To get the position of the whole OpenMP construct you need to get
startloc of the OpenMP directive itself and endloc of the associated
stmt under this OpenMP directive, i.e. endloc of the first child of
OpenMP directive.

Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
Intel Corp.

09.12.2014 18:53, Simone Atzeni пишет:

> Hi,
>
> I am writing a plugin to get information about the OpenMP constructs from the AST.
> I am basically writing a “RecursiveASTVisitor” and I am trying to find the OpenMP statement and get information like filename and line of code.
>
> When I am visiting recursively each statement I have my own switch on the “StmtClass” and for now I am focusing on “OMPParallelForDirectiveClass”.
> In my understanding, once I find the beginning of the OpenMP statement, its children are all the statement inside the OpenMP construct.
> I was wondering if there is a way to know the lines of code where the OpenMP construct starts and where it finishes (in terms of lines of code), and then get the the same information for their children (lines of code of the other statement in the OpenMP construct).
>
> In my example, once I find the OMPParallelForDirectiveClass statement I am trying to print line of code using the 3 functions getSpellingLineNumber, getExpansionLineNumber and get PresumedLineNumber using the location start and location end, however the numbers are all equal.
> Also, I am looping into its children and the last statement that I got is that one before the closed bracket of the OpenMP constructs. Can I suppose that "the line of code of the last statement + 1” is the end of the OpenMP construct? What if there are new empty line?
>
> Hope this is clear and you can give me some advice.
>
> Thanks.
> Best,
> Simone
>

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

Re: [LLVMdev] [Openmp-dev] Clang Plugin to analyze OpenMP AST

Alexey Bataev
In reply to this post by Simone Atzeni
Hi Simone,
You don't need to analyze all children of the openmp construct, you need
to analyze only the first one. All other children maybe just some
special helper expressions/statements, not actually a construct under
OpenMP directive.
To get the position of the whole OpenMP construct you need to get
startloc of the OpenMP directive itself and endloc of the associated
stmt under this OpenMP directive, i.e. endloc of the first child of
OpenMP directive.

Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
Intel Corp.

09.12.2014 18:53, Simone Atzeni пишет:

> Hi,
>
> I am writing a plugin to get information about the OpenMP constructs from the AST.
> I am basically writing a “RecursiveASTVisitor” and I am trying to find the OpenMP statement and get information like filename and line of code.
>
> When I am visiting recursively each statement I have my own switch on the “StmtClass” and for now I am focusing on “OMPParallelForDirectiveClass”.
> In my understanding, once I find the beginning of the OpenMP statement, its children are all the statement inside the OpenMP construct.
> I was wondering if there is a way to know the lines of code where the OpenMP construct starts and where it finishes (in terms of lines of code), and then get the the same information for their children (lines of code of the other statement in the OpenMP construct).
>
> In my example, once I find the OMPParallelForDirectiveClass statement I am trying to print line of code using the 3 functions getSpellingLineNumber, getExpansionLineNumber and get PresumedLineNumber using the location start and location end, however the numbers are all equal.
> Also, I am looping into its children and the last statement that I got is that one before the closed bracket of the OpenMP constructs. Can I suppose that "the line of code of the last statement + 1” is the end of the OpenMP construct? What if there are new empty line?
>
> Hope this is clear and you can give me some advice.
>
> Thanks.
> Best,
> Simone
>


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
--
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
Intel Corp.