[mlir][flang][OpenMP] Privatize LINEAR list items with linear privatizers; support ALLOCATABLE (#228827)
Flang miscompiled `LINEAR` on an `ALLOCATABLE` list item (#182401). The
linear
operand was the descriptor reference, but `linear_var_types` held the
element
type, so translation created an undersized private copy and the program
crashed.
This patch makes linear list items use privatizer recipes, the same way
`private` and `reduction` do.
**MLIR**
- The `linear` clause on `omp.wsloop` and `omp.simd` now carries a
privatizer
symbol and an entry block argument for each list item:
```mlir
omp.private {type = linear} @x.linear : i32
omp.simd linear(@x.linear %x -> %arg0 : !llvm.ptr = %step : i32)
linear_var_types([i32]) {
```
- New `linear` `DataSharingType` for `omp.private`. Also an optional
`data_address` region that yields the address of the underlying linear
value when the privatized type wraps it (e.g. a Fortran descriptor).
- Verifier checks:
- a linear clause must use a `linear` privatizer whose type matches its
list item;
- `linear` privatizers can't be used in other clauses;
- `data_address` is only allowed on `linear` privatizers, which can't
have a copy region;
- `omp.declare_simd` doesn't accept linear privatizers.
**Translation**
- Linear variables are allocated, initialized and deallocated through
the
existing private-variable path.
- The start value is read from the original variable, the private copy
is
set to `start + iv * step`, and the value from the last iteration is
copied back. All accesses go through the `data_address` region when the
privatizer has one.
- The old `.linear_result` temporary and the in-place rewrite of the
original variable are removed.
**Flang**
- `processLinear` and the implicit linear IV of `simd` now create
`linear`
privatizers through `DataSharingProcessor`. For an allocatable, the
recipe has a `data_address` region (`fir.load` + `fir.box_addr`).
- For composite `do simd` and `distribute parallel do simd`, linear
privatizers go on `omp.wsloop`.
- Lowering linear without delayed privatization now emits a TODO.
Fixes #182401
GitOrigin-RevId: ac5d3955cd1931f71109caa8c026319ca69ca252
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.