[flang][OpenMP] Fix wrong results for FORALL in a workshare construct (#211371) A FORALL in a workshare construct could produce wrong results non-deterministically. This is caused by two issues in the workshare lowering: 1. A FORALL whose left-hand side may overlap its right-hand side is lowered into two loop nests around a runtime value stack: the first nest evaluates each right-hand side and pushes it, the second one fetches the saved values back with a running counter. That counter lives in a fir.alloca which, since omp.parallel is an alloca scope, is thread private. The counter is read, incremented and written back from inside the omp.single generated for the fetch, because the incremented value is only available there. Only the thread which executed the omp.single therefore bumped its own copy of the counter, and all the other threads kept a stale one and refetched an already consumed element on the following iterations. Collect the thread local memory which is only updated by the thread executing an omp.single and broadcast it with copyprivate, so that the copies of the other threads stay in sync. As nowait and copyprivate are mutually exclusive on a single construct, nowait is no longer set when there is something to broadcast. 2. nowait was only suppressed when the immediately enclosing operation was loop-like. A masked FORALL introduces a fir.if inside the fir.do_loop, so the last omp.single or omp.wsloop of the fir.if body was given nowait even though the loop may run it again, and even though there was more work after the loop. Thread the information down the recursion instead, so that only the work which is really last in the whole omp.workshare region may rely on the barrier emitted at the end of that region. Fixes #209942 Fixes #209943 GitOrigin-RevId: ec62b5ae07df222f06526d5260cf6baea28c7a30
Flang is a ground-up implementation of a Fortran front end written in modern C++. It started off as the f18 project (https://github.com/flang-compiler/f18) with an aim to replace the previous flang project (https://github.com/flang-compiler/flang) and address its various deficiencies. F18 was subsequently accepted into the LLVM project and rechristened as Flang.
Please note that flang is not ready yet for production usage.
Read more about flang in the docs directory. Start with the compiler overview.
To better understand Fortran as a language and the specific grammar accepted by flang, read Fortran For C Programmers and flang's specifications of the Fortran grammar and the OpenMP grammar.
Treatment of language extensions is covered in this document.
To understand the compilers handling of intrinsics, see the discussion of intrinsics.
To understand how a flang program communicates with libraries at runtime, see the discussion of runtime descriptors.
If you're interested in contributing to the compiler, read the style guide and also review how flang uses modern C++ features.
If you are interested in writing new documentation, follow LLVM's Markdown style guide.
Consult the Getting Started with Flang for information on building and running flang.