[OpenMP] Honour memory-order clauses on the flush directive (#241295)

At present the acquire, release and acq_rel clauses on 'flush' are
accepted but have no effect. Flushes are emitted as `__kmpc_flush`
runtime calls, which implement a seq_cst fence.

AMD have had a downstream patch for a while (by Carlo Bertolli) which
adds per-ordering `__kmpc_flush_*` entry points to the device runtime.
This patch takes a slightly different approach: for the host, a seq_cst
flush still calls `__kmpc_flush`, and a flush with any other ordering
calls the `__kmpc_flush_explicit` entry point from #133325, so it needs
a runtime that has that. For the GPU, it emits a fence directly.

This has mild benefits: OpenMPOpt already handles fences when it
converts kernels to SPMD mode, but has no knowledge of the new
`__kmpc_flush` calls (either _explicit or Carlo's per-ordering flush
calls). Scope names differ per-GPU: they are determined using the
mechanism introduced by #213810 ("[LLVM] Unify atomic scope handling
between LLVM and Clang").

The lowering is done in OpenMPIRBuilder. The createFlush function now
takes an ordering and a scope, and is now used for every GPU flush. The
OpenMPIRBuilder-disabled path is unaffected. Flang/MLIR call createFlush
with the defaults, so their host output is unchanged, but their GPU
flushes now become fences instead of `__kmpc_flush` calls.

Since e8e05de08bea ("[OPENMP50]Add codegen for acq_rel clause in
atomic|flush directives"), a flush with neither a list nor a
memory-order clause has been passed to emitFlush as acq_rel. That is
only right for OpenMP 5.0: from 5.1 it behaves as seq_cst, and before
5.0 there were no memory-order clauses and it was a full flush. It is
now emitted as seq_cst except for OpenMP 5.0.

The flush that Clang keeps after a seq_cst atomic construct for OpenMP
4.5 and earlier goes through the same lowering, so on a GPU it is a
seq_cst fence too.

Co-authored-by: Carlo Bertolli <Carlo.Bertolli@amd.com>
Assisted-By: Claude
GitOrigin-RevId: a2d52a5163b14e3cf75b6a390efcb964d28b6aaf
1 file changed