Documentation of support in Clang for OpenMP pragmas/clauses

Hi,

I know that this list refers to OpenMP runtime and I have Clang font-end related question, but my question refers to support for OpenMP in Clang, so I decided to put it here.

Is there any documentation available anywhere which describes how support for OpenMP pragmas is handled in Clang frontend?

It could be anything like old docs, pdfs, slides, email threads in which OpenMP in Clang is somehow explained/discussed from higher level point of view.

I see there are classes like DSAStackTy which implements methods like DSAStackTy::getDSA/addDSA.
And there are luckily some comments which describe such class.

But it is tough to understand their exact purposes without having higher level point of view – what for they are used and how they should be used.

In my case I would like to add experimental clause to omp parallel pragma. The clause will contain name of variable (which is used in parallel region) and I want to mark somehow the variable during codegen.

I’m trying to use LocalDeclMap but it gives declaration of the variable not references.

Maybe I could write some mapping from scratch but I believe there is already sth which might be used for similar purposes.

In general, having better view of support for OpenMP in clang, I wouldn’t write such detailed questions describing one case.

So that is why I’m looking for some (even old) documents… :blush:

Thanks,
Przemek

Hi, there is no exact document, describing sema analysis of the OpenMP. There are 10 yo slides with some design description.

DSAStack handles data-sharing attributes for each particular OpenMP region. It comes in the natural way: the top-most item in DSAStack represents the attributes for the innermost OpenMP region. Stack handles data-sharing attributes for each variable, referenced/used in OpenMP structures block/clauses.

In general, sema analysis/codegen for OpenMP constructs follows the general clang design.

LocalDeclMap is the associative container between local variables in the function and their emitted Address (and LValue).

1 Like

Thank you Alexey,
I’ve found also older document:
https://discourse.llvm.org/uploads/short-url/1y90eQ29Lqyi3XONNz1GLPFbqZG.pdf
Is there described valid approach or it was later redesigned and I shouldn’t look into that?

One more question:
when I’m dumping AST using clang: -S -Xclang -ast-dump -fopenmp
it looks like I don’t get whole AST (or all ASTs).
When CodeGen for outlined function is executed it looks like it is executed based on another ASTs. Is it possible to dump all ASTs? Or am I thinking wrong…

Przemek

I’ve found also older document:
https://discourse.llvm.org/uploads/short-url/1y90eQ29Lqyi3XONNz1GLPFbqZG.pdf
Is there described valid approach or it was later redesigned and I shouldn’t look into that?

That was outdated long time ago, clang implemented very similar, but different approach.

One more question:
when I’m dumping AST using clang: -S -Xclang -ast-dump -fopenmp
it looks like I don’t get whole AST (or all ASTs).
When CodeGen for outlined function is executed it looks like it is executed based on another ASTs. Is it possible to dump all ASTs? Or am I thinking wrong…

It dumps everything it has. The codegen just does some extra work by emitting omp_parallel functions for the parallel regions, for example. But it uses the AST, you see after ast-dump

There’s also been a tutorial a few years ago* (*thus, the usual caveats on LLVM being an evolving code base and documentation falling out of date very much apply): Poster 91: FreeCompilerCamp: Online Training for Extending Compilers, FreeCompilerCamp.org: Training for OpenMP Compiler Development from Cloud, FreeCompilerCamp.org: Training for OpenMP Compiler Development from Cloud, https://github.com/freeCompilerCamp

Unfortunately, the main website is very much dead (and the .org URL leads to a what looks like spam), but the posts survive: https://github.com/freeCompilerCamp/freecompilercamp.github.io/tree/master/_posts

In particular, you may be interested in the following:

Rather than those, follow along a commit that added a feature recently. Git blame something “new” or ask here.
I added some clauses and last year or so we added pragmas.
Those commits show what to do, the above is less helpful as they initially developed it w/o input (IIRC).

Thank you all for the hints!

Przemek

You can check OpenMP Support — Clang 19.0.0git documentation .