summaryrefslogtreecommitdiff
path: root/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
AgeCommit message (Collapse)Author
2025-11-17[OpenMP][Flang] Change the OmpDefaultMapperName suffix (#168399)Akash Banerjee
This PR fixes a Fortran syntax violation in the OpenMP default mapper naming convention. The suffix .omp.default.mapper contains dots which are invalid in Fortran identifiers, causing failures when mappers are written to and read from module files. The fix changes the suffix to _omp_default_mapper which uses underscores instead of dots, complying with Fortran syntax rules. Key changes: - Changed OmpDefaultMapperName constant from .omp.default.mapper to _omp_default_mapper - Added GetUltimate() calls in mapper symbol resolution to properly handle symbols across module boundaries - Added new test case verifying default mappers work correctly when defined in a module and used in consuming programs This fixes #168336.
2025-11-14[OpenMP][Flang] Emit default declare mappers implicitly for derived types ↵Akash Banerjee
(#140562) This patch adds support to emit default declare mappers for implicit mapping of derived types when not supplied by user. This especially helps tackle mapping of allocatables of derived types.
2025-11-13[Flang][OpenMP] Update declare mapper lookup via use-module (#167903)Akash Banerjee
2025-11-13Revert "[Flang][OpenMP] Update declare mapper lookup via use-module" (#167896)Akash Banerjee
Reverts llvm/llvm-project#163860
2025-11-13[Flang][OpenMP] Update declare mapper lookup via use-module (#163860)Akash Banerjee
- Implemented semantic TODO to catch undeclared mappers. - Fix mapper lookup to include modules imported through USE. - Update and add tests. Fixes #163385.
2025-11-11[Flang][OpenMP][MLIR] Lowering of reduction,inreduction, nogroup and ↵Kaviya Rajendiran
lastprivate clause to MLIR (#166751) This patch add MLIR lowering support for nogroup, reduction, inreduction and lastprivate clauses of taskloop directive.
2025-10-21[Flang][OpenMP][Dialect] Swap to using MLIR dialect enum to encode map flags ↵agozillon
(#164043) This PR shifts from using the LLVM OpenMP enumerator bit flags to an OpenMP dialect specific enumerator. This allows us to better represent map types that wouldn't be of interest to the LLVM backend and runtime in the dialect. Primarily things like ref_ptr/ref_ptee/ref_ptr_ptee/atach_none/attach_always/attach_auto which are of interest to the compiler for certrain transformations (primarily in the FIR transformation passes dealing with mapping), but the runtime has no need to know about them. It also means if another OpenMP implementation comes along they won't need to stick to the same bit flag system LLVM chose/do leg work to address it.
2025-10-16[flang][OpenMP] Frontend support for ATTACH modifier (#163608)Krzysztof Parzyszek
Add parsing, semantic checks, but no lowering.
2025-10-03[Flang] Add standalone tile support (#160298)Michael Kruse
Add support for the standalone OpenMP tile construct: ```f90 !$omp tile sizes(...) DO i = 1, 100 ... ``` This is complementary to #143715 which added support for the tile construct as part of another loop-associated construct such as worksharing-loop, distribute, etc.
2025-09-10[flang][OpenMP] Enable tiling (#143715)Jan Leyonberg
This patch enables tiling in flang. In MLIR tiling is handled by changing the the omp.loop_nest op to be able to represent both collapse and tiling, so the flang front-end will combine the nested constructs into a single MLIR op. The MLIR->LLVM-IR lowering of the LoopNestOp is enhanced to first do the tiling if present, then collapse.
2025-09-04[flang] Attach proper storage to [hl]fir.declare in lowering. (#155742)Slava Zakharin
As described in https://discourse.llvm.org/t/rfc-flang-representation-for-objects-inside-physical-storage/88026, `[hl]fir.declare` should carry information about the layout of COMMON/EQUIVALENCE variables within the physical storage. This patch modifes Flang lowering to attach this information.
2025-08-29[Flang][OpenMP] Fix to resolve the crash with SIMD aligned clause. (#150612)Kaviya Rajendiran
**Issue:** When SIMD aligned clause has a alignment value which is not a power of 2, compiler crashes with error Assertion (alignment & (alignment - 1)) == 0 && "alignment is not power of 2" **Fix:** According to LLVM Language Reference manual [[link]](https://llvm.org/docs/LangRef.html#assume-opbundles), the alignment value may be non-power-of-two. In that case, the pointer value must be a null pointer otherwise the behavior is undefined. So instead of emitting `llvm.assume` intrinsic function with a null pointer having the specified alignment, modified the implementation which ignores the aligned clause which has an alignment value which is not a power of 2. This patch also emits a warning indicating that the aligned clause is ignored if the alignment value is not a power of two. It fixes the issue https://github.com/llvm/llvm-project/issues/149458
2025-08-27[NFC][flang][OpenMP] Create `FortranUtils` lib and move `createMapInfoOp` to ↵Kareem Ergawy
it (#154483)
2025-08-11Fix build error from #151513.Akash Banerjee
2025-08-11[MLIR][OpenMP] Add lowering support for AUTOMAP modifier (#151513)Akash Banerjee
Add Automap modifier to the MLIR op definition for the DeclareTarget directive's Enter clause. Also add lowering support in Flang. Automap Ref: OpenMP 6.0 section 7.9.7.
2025-08-04[flang][Lower] Make reduction processing failure a hard error (#150233)Tom Eccles
See #150178 This may regress some test cases which only ever passed by accident. I've tested SPEC2017 and a sample of applications to check that this doesn't break anything too obvious. Presumably this was not a widely used feature or we would have noticed the bug sooner. I'm unsure whether this should be backported to LLVM 21 or not: I think it is much better to refuse to compile than to silently produce the wrong result, but there is a chance this could regress something which previously worked by accident. Opinions welcome.
2025-07-31[Flang] Add parser support for AUTOMAP modifier (#151511)Akash Banerjee
Add parser support for the new AUTOMAP modifier for OpenMP Declare Target Enter clause introduced in OpenMP 6.0 section 7.9.7.
2025-07-23[flang][OpenMP] Restore reduction processor behavior broken by #145837 (#150178)Kareem Ergawy
Fixes #149089 and #149700. Before #145837, when processing a reduction symbol not yet supported by OpenMP lowering, the reduction processor would simply skip filling in the reduction symbols and variables. With #145837, this behvaior was slightly changed because the reduction symbols are populated before invoking the reduction processor (this is more convenient to shared the code with `do concurrent`). This PR restores the previous behavior.
2025-07-22[flang][OpenMP] Sema checks, lowering with new format of MAP modifiers (#149137)Krzysztof Parzyszek
OpenMP 6.0 has changed the modifiers on the MAP clause. Previous patch has introduced parsing support for them. This patch introduces processing of the new forms in semantic checks and in lowering. This only applies to existing modifiers, which were updated in the 6.0 spec. Any of the newly introduced modifiers (SELF and REF) are ignored.
2025-07-21[mlir][NFC] update `flang/Lower` create APIs (8/n) (#149912)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-11[NFC][flang] Move `ReductionProcessor` to `Lower/Support`. (#146025)Kareem Ergawy
With #145837, the `ReductionProcessor` component is now used by both OpenMP and `do concurrent`. Therefore, this PR moves it to a shared location: `flang/Lower/Support`. PR stack: - https://github.com/llvm/llvm-project/pull/145837 - https://github.com/llvm/llvm-project/pull/146025 (this one) - https://github.com/llvm/llvm-project/pull/146028 - https://github.com/llvm/llvm-project/pull/146033
2025-07-11[flang][do concurrent] Re-model `reduce` to match reductions are modelled in ↵Kareem Ergawy
OpenMP and OpenACC (#145837) This PR proposes re-modelling `reduce` specifiers to match OpenMP and OpenACC. In particular, this PR includes the following: * A new `fir` op: `fir.delcare_reduction` which is identical to OpenMP's `omp.declare_reduction` op. * Updating the `reduce` clause on `fir.do_concurrent.loop` to use the new op. * Re-uses the `ReductionProcessor` component to emit reductions for `do concurrent` just like we do for OpenMP. To do this, the `ReductionProcessor` had to be refactored to be more generalized. * Upates mapping `do concurrent` to `fir.loop ... unordered` nests using the new reduction model. Unfortunately, this is a big PR that would be difficult to divide up in smaller parts because the bottom of the changes are the `fir` table-gen changes to `do concurrent`. However, doing these MLIR changes cascades to the other parts that have to be modified to not break things. This PR goes in the same direction we went for `private/local` speicifiers. Now the `do concurrent` and OpenMP (and OpenACC) dialects are modelled in essentially the same way which makes mapping between them more trivial, hopefully. PR stack: - https://github.com/llvm/llvm-project/pull/145837 (this one) - https://github.com/llvm/llvm-project/pull/146025 - https://github.com/llvm/llvm-project/pull/146028 - https://github.com/llvm/llvm-project/pull/146033
2025-06-19[Flang][OpenMP] Update default MapType for Map Clauses and OpenMP 5.2 (#144715)Jack Styles
In OpenMP 5.2, the `target enter data` and `target exit data` constructs now have default map types if the user does not define them in the Map clause. For `target enter data`, this is `to` and `target exit data` this is `from`. This behaviour is now enabled when OpenMP 5.2 or greater is used when compiling. To enable this, the default value is now set in the `processMap` clause, with any previous behaviour being maintained for either older versions of OpenMP or other directives. See also #110008
2025-06-17[flang][OpenMP] Support using copyprivate with fir.boxchar arguments (#144092)Kajetan Puchalski
Implement the lowering for passing a fir.boxchar argument to the copyprivate clause. Resolves https://github.com/llvm/llvm-project/issues/142123. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-06-13[flang][OpenMP] Support substrings and complex part refs for DEPEND (#143907)Tom Eccles
Fixes #142404 The parser can't tell the difference between array indexing and a substring: that has to be done in semantics once we have types. Substrings can only be in the form string([lower]:[higher]) not string(index) or string(lower:higher:step). I added semantic checks to catch this for the DEPEND clause. This patch also adds lowering for correct substrings and for complex part references.
2025-05-30[NFC][OpenMP] Move the default declare mapper name suffix to OMPConstants.h ↵Akash Banerjee
(#141964) This patch moves the default declare mapper name suffix ".omp.default.mapper" to the OMPConstants.h file to be used everywhere for lowering.
2025-05-30[flang][OpenMP] Allow structure component in `task depend` clauses (#141923)Kareem Ergawy
Even though the spec (version 5.2) prohibits strcuture components from being specified in `depend` clauses, this restriction is not sensible. This PR rectifies the issue by lifting that restriction and allowing structure components in `depend` clauses (which is allowed by OpenMP 6.0).
2025-05-29[flang][OpenMP] Treat ClassType as BoxType in COPYPRIVATE (#141844)Krzysztof Parzyszek
This fixes the second problem reported in https://github.com/llvm/llvm-project/issues/141481
2025-05-28[OpenMP][Flang] Fix semantic check and scoping for declare mappers (#140560)Akash Banerjee
The current semantic check in place is incorrect, this patch fixes this. Up to 1 **'default'** named mapper should be allowed for each derived type. The current semantic check only allows up to 1 **'default'** named mapper across all derived types. This also makes sure that declare mappers follow proper scoping rules for both default and named mappers. Co-authored-by: Raghu Maddhipatla <Raghu.Maddhipatla@amd.com>
2025-05-19[flang][OpenMP] Support MLIR lowering of linear clause for omp.wsloop (#139385)NimishMishra
This patch adds support for MLIR lowering of linear clause on omp.wsloop (except for linear modifiers).
2025-05-15[Flang][MLIR][OpenMP] Improve use_device_* handling (#137198)Sergio Afonso
This patch updates MLIR op verifiers for operations taking arguments that must always be defined by an `omp.map.info` operation to check this requirement. It also modifies Flang lowering for `use_device_{addr, ptr}`, as well as the custom MLIR printer and parser for these clauses, to support initializing it to `OMP_MAP_RETURN_PARAM` and represent this in the MLIR representation as `return_param`. This internal mapping flag is what eventually is used for variables passed via these clauses into the target region when translating to LLVM IR, so making it explicit in Flang and MLIR removes an inconsistency in the current representation.
2025-05-12[Flang][OpenMP] Initial defaultmap implementation (#135226)agozillon
This aims to implement most of the initial arguments for defaultmap aside from firstprivate and none, and some of the more recent OpenMP 6 additions which will come in subsequent updates (with the OpenMP 6 variants needing parsing/semantic support first).
2025-05-09[Flang][OpenMP] MLIR lowering support for grainsize and num_tasks clause ↵Kaviya Rajendiran
(#128490) - Added MLIR lowering for grainsize and num_tasks clauses of taskloop construct.
2025-05-07[Flang][OpenMP]Support for lowering task_reduction and in_reduction to MLIR ↵Kaviya Rajendiran
(#111155) This patch, - Added support for lowering of task_reduction to MLIR - Added support for lowering of in_reduction to MLIR - Fixed incorrect DSA handling for variables in the presence of 'in_reduction' clause.
2025-04-28[flang][Lower][nfc] vector subscript lhs first element to helper (#137456)Tom Eccles
This encapsulates implementation details of hlfir.elemental_addr inside of ConvertExprToHLFIR instead of leaking to OpenMP code. Requested here: https://github.com/llvm/llvm-project/pull/133892#issuecomment-2821559394
2025-04-14[flang][OpenMP][HLFIR] Support vector subscripted array sections for DEPEND ↵Tom Eccles
(#133892) The OpenMP runtime needs the base address of the array section to identify the dependency. If we just put the vector subscript through the usual HLFIR expression lowering, that would generate a new contiguous array representing the values of the elements in the array which was sectioned. We cannot use addresses from this array because these addresses would not match dependencies on the original array. For example ``` integer :: array(1024) integer :: indices(2) indices(1) = 1 indices(2) = 100 !$omp task depend(out: array(1:512)) !$omp end task !$omp task depend(in: array(indices)) !$omp end task ``` This requires taking the lowering path previously only used for ordered assignments to get the address of the elements in the original array which were indexed. This is done using `hlfir.elemental_addr`. e.g. ``` array(indices) = 2 ``` `hlfir.elemental_addr` is awkward to use because it (by design) doesn't return something like `!hlfir.expr<>` (like `hlfir.elemental`) and so it can't have a generic lowering: each place it is used has to carefully inline the contents of the operation and extract the needed address. For this reason, `hlfir.elemental_addr` is not allowed outside of these ordered assignments. In this commit I ignore this restriction so that I can use `hlfir.elemental_addr` to lower the OpenMP DEPEND clause (this works because the operation is inlined and removed before the verifier runs). One alternative solution would have been to provide my own more limited re-implementation of `HlfirDesignatorBuilder` which skipped `hlfir::elemental_addr`, instead inlining its body directly at the current insertion point applying indices only for the first element. This would have been difficult to maintain because designation in Fortran is complex.
2025-04-08[flang][OpenMP] Lowering for CANCEL and CANCELLATIONPOINT (#134248)Tom Eccles
These will still hit TODOs in OpenMPToLLVMIRConversion.cpp
2025-04-07[flang][OpenMP] Fix copyprivate of procedure pointers (#134292)Leandro Lupori
Just modify the assert to consider fir::BoxProcType as valid. No other changes are needed. Fixes #131549
2025-04-01[flang][OpenMP][Lower] lower array subscripts for task depend (#132994)Tom Eccles
The OpenMP standard says that all dependencies in the same set of inter-dependent tasks must be non-overlapping. This simplification means that the OpenMP only needs to keep track of the base addresses of dependency variables. This can be seen in kmp_taskdeps.cpp, which stores task dependency information in a hash table, using the base address as a key. This patch generates a rebox operation to slice boxed arrays, but only the box data address is used for the task dependency. The extra box is optimized away by LLVM at O3. Vector subscripts are TODO (I will address in my next patch). This also fixes a bug for ordinary subscripts when the symbol was mapped to a box: Fixes #132647
2025-03-18[MLIR][OpenMP] Add Lowering support for implicitly linking to default ↵Akash Banerjee
declare mappers (#131006)
2025-03-12[Flang][OpenMP] Move declare mapper sym creation outside loop, NFC (#130794)Sergio Afonso
This patch simplifies the definition of `ClauseProcessor::processMapObjects` by hoisting the creation of the MLIR symbol associated to an existing `omp.declare_mapper` operation outside of the loop processing all mapped objects. That change removes some inter-iteration dependencies that made the implementation more difficult to follow.
2025-03-10[flang][OpenMP] Implement HAS_DEVICE_ADDR clause (#128568)Krzysztof Parzyszek
The HAS_DEVICE_ADDR indicates that the object(s) listed exists at an address that is a valid device address. Specifically, `has_device_addr(x)` means that (in C/C++ terms) `&x` is a device address. When entering a target region, `x` does not need to be allocated on the device, or have its contents copied over (in the absence of additional mapping clauses). Passing its address verbatim to the region for use is sufficient, and is the intended goal of the clause. Some Fortran objects use descriptors in their in-memory representation. If `x` had a descriptor, both the descriptor and the contents of `x` would be located in the device memory. However, the descriptors are managed by the compiler, and can be regenerated at various points as needed. The address of the effective descriptor may change, hence it's not safe to pass the address of the descriptor to the target region. Instead, the descriptor itself is always copied, but for objects like `x`, no further mapping takes place (as this keeps the storage pointer in the descriptor unchanged). --------- Co-authored-by: Sergio Afonso <safonsof@amd.com>
2025-03-07[Flang][OpenMP][MLIR] Implement close, present and ompx_hold modifiers for ↵agozillon
Flang maps (#129586) This PR adds an initial implementation for the map modifiers close, present and ompx_hold, primarily just required adding the appropriate map type flags to the map type bits. In the case of ompx_hold it required adding the map type to the OpenMP dialect. Close has a bit of a problem when utilised with the ALWAYS map type on descriptors, so it is likely we'll have to make sure close and always are not applied to the descriptor simultaneously in the future when we apply always to the descriptors to facilitate movement of descriptor information to device for consistency, however, we may find an alternative to this with further investigation. For the moment, it is a TODO/Note to keep track of it.
2025-03-07[flang][OpenMP] Handle pre-detemined `lastprivate` for `simd` (#129507)Kareem Ergawy
This PR tries to fix `lastprivate` update issues in composite constructs. In particular, pre-determined `lastprivate` symbols are attached to the wrong leaf of the composite construct (the outermost one). When using delayed privatization (should be the default mode in the future), this results in trying to update the `lastprivate` symbol in the wrong construct (outside the `omp.loop_nest` op). For example, given the following input: ```fortran !$omp target teams distribute parallel do simd collapse(2) private(y_max) do i=x_min,x_max do j=y_min,y_max enddo enddo ``` Without the fixes introduced in this PR, the `DataSharingProcessor` tries to generate the `lastprivate` update ops in the `parallel` op since this is the op for which the DSP instance is created. The fix consists of 2 main parts: 1. Instead of creating a single DSP instance, one instance is created for the leaf constructs that might need privatization (whether for explicit, implicit, or pre-determined symbols). 2. When generating the `lastprivate` comparison ops, we don't directly use the SSA values of the UBs and steps. Instead, we regenerated these SSA values from the original loop bounds' expressions. We have to do this to avoid using `host_eval` values in the `lastprivate` comparison logic which is illegal.
2025-02-18[MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause ↵Akash Banerjee
(#121001) Add Lowering support for OpenMP mapper field in mapInfoOp. NOTE: This patch only supports explicit mapper lowering. I'll add a separate PR soon which handles implicit default mapper recognition. Depends on #120994.
2025-02-05[flang][openmp] Changes for invoking scan Op (#123254)Anchu Rajendran S
2025-01-21[flang][OpenMP][OpenACC] remove libEvaluate dependency in passes (#123784)jeanPerier
Move OpenACC/OpenMP helpers from Lower/DirectivesCommon.h that are also used in OpenACC and OpenMP mlir passes into a new Optimizer/Builder/DirectivesCommon.h so that parser and evaluate headers are not included in Optimizer libraries (this both introduce compile-time and link-time pointless overheads). This should fix https://github.com/llvm/llvm-project/issues/123377
2025-01-03[MLIR][OpenMP] Lowering aligned clause to LLVM IR for SIMD directive (#119536)Kaviya Rajendiran
This patch, - Added a translation support for aligned clause in SIMD directive by passing the alignment details to "llvm.assume" intrinsic. - Updated the insertion point for llvm.assume intrinsic call in "OMPIRBuilder.cpp". - Added a check in aligned clause MLIR lowering, to ensure that the alignment value must be a power of 2.
2024-12-26[Flang] Add translation support for MutexInOutSet and InOutSet (#120715)Thirumalai Shaktivel
Implementatoin details: Both Mutexinoutset and Inoutset is recognized as flag=0x4 and 0x8 respectively, the flags is set to `kmp_depend_info` and passed as argument to `__kmpc_omp_task_with_deps` runtime call
2024-12-13[flang][OpenMP] Add frontend support for ompx_bare clause (#111106)Ivan R. Ivanov