Matching 'OMPThreadPrivateDecl'( like #pragma omp threadprivate(var))

This might sound silly. But I have been trying to match OMPThreadPrivateDecl’ nodes using ASTMatcher. But I have been running into deadends.

What I am doing now is using ASTMatcher to match ‘Decl’ nodes and check if its a ‘OMPThreadPrivateDecl’ by using a dyn_cast. But this does not work.

Alternatively I tried with isa(*D) (which kind of does the same thing)

Can anyone point out how I can access the 'OMPThreadPrivateDecl nodes using ASTMAtcher or what I am doing wrong?

-Deepak

Hi,
are you sure that you have OMPThreadPrivateDecl nodes at all? Check that the code is compiled with -Xclang -fopenmp=libiomp5 option.

Best regards,
Alexey Bataev

Hello,

Thank you for replying.

Yes,you are right. I am not getting the OMPThreadPrivateDecl nodes at all.

I tried printing out the AST for a small microbenchmark with OpenMP calls using ’ clang -Xclang -ast-dump -fopenmp ". And if I have omp.h header file included, it throws an error. Now I dug around a little bit more, and have a couple of questions. Based on what I see here-http://llvm.org/devmtg/2014-10/Slides/Bataev-OpenMP.pdf, you seem to be the right person to ask. Hope you do not mind.

I have build llvm from trunk(version 3.6.0). Now to parse nodes, is the normal vanilla llvm enough or do I need to make any omp specific changes/build(like http://clang-omp.github.io/))??

p.s. My llvm build is fine for all other purposes. i have been using it for a source-to-source compiler with libtooling and I have been running the tool on NAS benchmarks(OpenMP NPB-C version). The only issue I am seeing is with openMP pragmas.So what I am trying to say is that the llvm build works fine for other cases and it is tested.

Regards,
Deepak

Deepack,
Yes, it's enough to have "vanilla clang/LLVM" for parsing OpenMP code.
But you have to porovide proper driver options to parse OpenMP nodes. In your case these options are (for clang built from trunk):

clang -c -Xclang -ast-dump -Xclang -fopenmp=libiomp5 <FileName>

Try this.

Best regards,
Alexey Bataev

Hello,

Yes, that seems to work while printing out the AST. So I should be able to get it working for libtooling as well. Thank you.

Regards,
Deepak