2802 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
bd63d9349a
[flang][OpenMP] Sort OpenMP-related names in dump-parse-tree.h, NFC (#154589) 2025-08-21 08:15:03 -05:00
Kazu Hirata
8a5b6b302e
[flang] Use SmallPtrSet directly instead of SmallSet (NFC) (#154471)
I'm trying to remove the redirection in SmallSet.h:

template <typename PointeeType, unsigned N>
class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N>
{};

to make it clear that we are using SmallPtrSet.  There are only
handful places that rely on this redirection.

This patch replaces SmallSet to SmallPtrSet where the element type is
a pointer.
2025-08-20 16:30:24 -07:00
Valentin Clement (バレンタイン クレメン)
a4e8ec9de9
[flang][cuda][NFC] Add getDataAttr helper (#154586) 2025-08-20 13:46:29 -07:00
Krzysztof Parzyszek
9f1679190e
[flang][OpenMP] Update GetOmpObjectList, move to parser utils (#154389)
`GetOmpObjectList` takes a clause, and returns the pointer to the
contained OmpObjectList, or nullptr if the clause does not contain one.
Some clauses with object list were not recognized: handle all clauses,
and move the implementation to flang/Parser/openmp-utils.cpp.
2025-08-20 12:41:26 -05:00
Jean-Didier PAILLEUX
e4334afca0
[flang] Add support of THIS_IMAGE and NUM_IMAGES with PRIF (#154081)
In relation to the approval and merge of the
https://github.com/llvm/llvm-project/pull/76088 specification about
multi-image features in Flang.
Here is a PR on adding support for `THIS_IMAGE` and `NUM_IMAGES` in
conformance with the PRIF specification.
For `THIS_IMAGE`, the lowering to the subroutine containing the coarray
argument is not present in this PR, and will be in a future one.
2025-08-20 08:11:42 +02:00
Valentin Clement (バレンタイン クレメン)
f64b5c9c6f
[flang][cuda] Fix hasDataAttr signature in header file (#154435)
Fix for #154422
2025-08-19 22:49:57 +00:00
Valentin Clement (バレンタイン クレメン)
af8a149546
[flang][cuda] Add utility function cuf::hasDataAttr (#154422) 2025-08-19 14:25:32 -07:00
Krzysztof Parzyszek
42350f428d
[flang][OpenMP] Parse GROUPPRIVATE directive (#153807)
No semantic checks or lowering yet.
2025-08-19 08:32:43 -05:00
Peter Klausler
2cf982c0f5
[flang] Don't duplicate impure function call for UBOUND() (#153648)
Because the per-dimension information in a descriptor holds an extent
and a lower bound, but not an upper bound, the calculation of the upper
bound sometimes requires that the extent and lower bound be extracted
from a descriptor and added together, minus 1. This shouldn't be
attempted when the NamedEntity of the descriptor is something that
shouldn't be duplicated and used twice; specifically, it shouldn't apply
to NamedEntities containing references to impure functions as parts of
subscript expressions.

Fixes https://github.com/llvm/llvm-project/issues/153031.
2025-08-18 14:43:13 -07:00
Krzysztof Parzyszek
8429f7faaa
[flang][OpenMP] Parsing support for DYN_GROUPPRIVATE (#153615)
This does not perform semantic checks or lowering.
2025-08-18 13:35:02 -05:00
Chaitanya
4a3bf27c69
[OpenMP] Introduce omp.target_allocmem and omp.target_freemem omp dialect ops. (#145464)
This PR introduces two new ops in omp dialect, omp.target_allocmem and
omp.target_freemem.
omp.target_allocmem: Allocates heap memory on device. Will be lowered to
omp_target_alloc call in llvm.
omp.target_freemem: Deallocates heap memory on device. Will be lowered
to omp+target_free call in llvm.


Example:
  %1 = omp.target_allocmem %device : i32, i64
  omp.target_freemem %device, %1 : i32, i64

The work in this PR is C-P/inspired from @ivanradanov commit from
coexecute implementation:
[Add fir omp target alloc and free
ops](be860ac8ba)
[Lower omp_target_{alloc,free} to
llvm](6e2d584dc9)
2025-08-18 18:15:11 +05:30
Jean-Didier PAILLEUX
acdbb00af5
[flang] Adding support of -fcoarray flang and init PRIF (#151675)
In relation to the approval and merge of the
[PRIF](https://github.com/llvm/llvm-project/pull/76088) specification
about multi-image features in Flang, here is a first PR to add support
for the `-fcoarray` compilation flag and the initialization of the PRIF
environment.
Other PRs will follow for adding support of lowering to PRIF.
2025-08-15 16:04:49 -07:00
Slava Zakharin
95d4362521
[flang] Added hlfir.eoshift operation definition. (#153105)
This is a basic definition of the operation corresponding to
the Fortran's EOSHIFT transformational intrinsic.
2025-08-15 13:15:35 -07:00
Akash Banerjee
1fd1d63463 [MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (#153048)
Add a new AutomapToTargetData pass. This gathers the declare target
enter variables which have the AUTOMAP modifier. And adds
omp.declare_target_enter/exit mapping directives for fir.alloca and
fir.free oeprations on the AUTOMAP enabled variables.

Automap Ref: OpenMP 6.0 section 7.9.7.
2025-08-15 15:41:41 +01:00
Markus Böck
8582025f1f
[mlir][Transforms] Turn 1:N -> 1:1 dispatch fatal error into match failure (#153605)
Prior to this PR, the default behaviour of a conversion pattern which
receives operands of a 1:N is to abort the compilation. This has
historically been useful when the 1:N type conversion got merged into
the dialect conversion as it allowed us to easily find patterns that
should be capable of handling 1:N type conversions but didn't.

However, this behaviour has the disadvantage of being non-composable:
While the pattern in question cannot handle the 1:N type conversion,
another pattern part of the set might, but doesn't get the chance as
compilation is aborted.

This PR fixes this behaviour by failing to match and instead of
aborting, giving other patterns the chance to legalize an op. The
implementation uses a reusable function called `dispatchTo1To1` to allow
derived conversion patterns to also implement the behaviour.
2025-08-15 11:45:25 +02:00
Kajetan Puchalski
d3d96e2057
[flang][OpenMP] Add -f[no]-openmp-simd (#150269)
Both clang and gfortran support the -fopenmp-simd flag, which enables
OpenMP support only for simd constructs, while disabling the rest of
OpenMP.

Implement the appropriate parse tree rewriting to remove non-SIMD OpenMP
constructs at the parsing stage.

Add a new SimdOnly flang OpenMP IR pass which rewrites generated OpenMP
FIR to handle untangling composite simd constructs, and clean up OpenMP
operations leftover after the parse tree rewriting stage.
With this approach, the two parts of the logic required to make the flag
work can be self-contained within the parse tree rewriter and the MLIR
pass, respectively. It does not need to be implemented within the core
lowering logic itself.

The flag is expected to have no effect if -fopenmp is passed explicitly,
and is only expected to remove OpenMP constructs, not things like OpenMP
library functions calls. This matches the behaviour of other compilers.

---------

Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-08-14 14:20:15 +01:00
Peter Klausler
442ae603c5
[flang] Warn about inexact real literal implicit widening pitfall (#152799)
When a REAL or COMPLEX literal appears without an explicit kind suffix
or a kind-determining exponent letter, and the conversion of that
literal from decimal to binary is inexact, emit a warning if that
constant is later implicitly widened to a more precise kind, since it
will have a different value than was probably intended.

Values that convert exactly from decimal to default real, e.g. 1.0 and
0.125, do not elicit this warning.

There are many contexts in which Fortran implicitly converts constants.
This patch covers name constant values, variable and component
initialization, constants in expressions, structure constructor
components, and array constructors.

For example, "real(8) :: tenth = 0.1" is a common Fortran bug that's
hard to find, and is one that often trips up even experienced Fortran
programmers. Unlike C and C++, the literal constant 0.1 is *not* double
precision by default, and it does not have the same value as 0.1d0 or
0.1_8 do when it is converted from decimal to real(4) and then to
real(8).
2025-08-13 14:36:13 -07:00
Valentin Clement (バレンタイン クレメン)
a2899c457e
[flang][cuda] Support data transfer with conversion (#153242)
When the rhs of the data transfer is from a different type, allocate a
new temp on the host and first transfer the rhs to it. Then, use the
elemental op created to do the conversion.
2025-08-13 10:55:15 -07:00
Krzysztof Parzyszek
dc1c9d3f4f
[flang][Evaluate] Pattern matching framework for evaluate::Expr (#153042)
Implement a framework to make it easier to detect if evaluate::Expr<T>
has certain structure.
2025-08-13 07:24:36 -05:00
Akash Banerjee
1c7720ef78 Revert "[MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (#153048)"
This reverts commit 4e6d510eb3ec5b5e5ea234756ea1f0b283feee4a.
2025-08-12 20:19:45 +01:00
Krzysztof Parzyszek
4b7f3806f6
[flang][OpenMP] Move rewriting of min/max from Lower to Semantics (#153038)
There semantic analysis of the ATOMIC construct will require additional
rewriting (reassociation of certain expressions for user convenience),
and that will be driven by diagnoses made in the semantic checks.

While the rewriting of min/max is not required to be done in semantic
analysis, moving it there will make all rewriting for ATOMIC construct
be located in a single location.
2025-08-12 12:13:50 -05:00
Akash Banerjee
4e6d510eb3
[MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (#153048)
Add a new AutomapToTargetData pass. This gathers the declare target
enter variables which have the AUTOMAP modifier. And adds
omp.declare_target_enter/exit mapping directives for fir.alloca and
fir.free oeprations on the AUTOMAP enabled variables.

Automap Ref: OpenMP 6.0 section 7.9.7.
2025-08-12 15:18:15 +01:00
Krzysztof Parzyszek
f0471bca0b
[flang][Evaluate] Implement rewriting framework for evaluate::Expr (#153037)
The structure of evaluate::Expr is highly customized for the specific
operation or entity that it represents. The different cases are
expressed with different types, which makes the traversal and
modifications somewhat complicated. There exists a framework for
read-only traversal (traverse.h), but there is nothing that helps with
modifying evaluate::Expr.

It's rare that evaluate::Expr needs to be modified, but for the cases
where it needs to be, this code will make it easier.

---------

Co-authored-by: Tom Eccles <tom.eccles@arm.com>
2025-08-11 13:55:25 -05:00
Akash Banerjee
0998da27e9 Revert "[MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (#151989)"
This reverts commit 5a5e8ba0c388d57aecb359ed67919cda429fc7b1.
2025-08-11 13:52:39 +01:00
Akash Banerjee
5a5e8ba0c3
[MLIR][OpenMP] Add a new AutomapToTargetData conversion pass in FIR (#151989)
Add a new `AutomapToTargetData` pass. This gathers the declare target
enter variables which have the `AUTOMAP` modifier. And adds
`omp.declare_target_enter/exit` mapping directives for `fir.allocmem`
and `fir.freemem` oeprations on the `AUTOMAP` enabled variables.

Automap Ref: OpenMP 6.0 section 7.9.7.
2025-08-11 13:18:38 +01:00
Akash Banerjee
3b10b9a2b0
[MLIR][OpenMP] Add lowering support for AUTOMAP modifier (#151513)
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-11 12:45:22 +01:00
parabola94
dea50a1797
[flang][Driver] Enable FLANG_DEFAULT_LINKER (#149786)
The default linker can be changed by a CMake variable
CLANG_DEFAULT_LINKER. However, it also changes the default linker
invoked by clang. In fact, there already exists FLANG_DEFAULT_LINKER,
but it does not work. This patch fixes it.

Note that FLANG_DEFAULT_LINKER will have the same value as
CLANG_DEFAULT_LINKER unless it is defined explicitly. That means this
patch does not affect the current behavior.

Fixes #73153

---------

Co-authored-by: Michael Kruse <github@meinersbur.de>
2025-08-10 05:21:14 +09:00
Nikita Popov
c23b4fbdbb
[IR] Remove size argument from lifetime intrinsics (#150248)
Now that #149310 has restricted lifetime intrinsics to only work on
allocas, we can also drop the explicit size argument. Instead, the size
is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead.
We never used that capability, so we should remove the need to handle
that possibility everywhere (though many key places, including stack
coloring, did not actually respect this).
2025-08-08 11:09:34 +02:00
Krzysztof Parzyszek
e368b5343d
[flang][OpenMP] Make OpenMPCriticalConstruct follow block structure (#152007)
This allows not having the END CRITICAL directive in certain situations.
Update semantic checks and symbol resolution.
2025-08-07 08:10:25 -05:00
Valentin Clement (バレンタイン クレメン)
eb0ddba26b
Reland "[flang][cuda] Set the allocator of derived type component after allocation" (#152418)
Reviewed in #152379
- Move the allocator index set up after the allocate statement otherwise
the derived type descriptor is not allocated.
- Support array of derived-type with device component
2025-08-06 21:49:55 -07:00
Valentin Clement (バレンタイン クレメン)
a196281896
[flang][cuda] Remove meaningless warning on CUDA shared arguments (#152404)
The warning in issued during the compatibility check makes little sense.
Just remove it as it is confusing.
2025-08-06 18:50:07 -07:00
Valentin Clement (バレンタイン クレメン)
7d3134f6cc
Revert "[flang][cuda] Set the allocator of derived type component after allocation" (#152402)
Reverts llvm/llvm-project#152379

Buildbot failure
https://lab.llvm.org/buildbot/#/builders/207/builds/4905
2025-08-06 15:55:53 -07:00
Valentin Clement (バレンタイン クレメン)
d897355876
[flang][cuda] Set the allocator of derived type component after allocation (#152379)
- Move the allocator index set up after the allocate statement otherwise
the derived type descriptor is not allocated.
- Support array of derived-type with device component
2025-08-06 15:14:00 -07:00
Eugene Epshteyn
cae7bebcaa
[flang-rt] Runtime implementation of extended intrinsic function SECNDS() (#152021)
Until the compiler part is fully hooked up via
https://github.com/llvm/llvm-project/pull/151878, tested this using
`external`:
```
external secnds
real s1, s2
s1 = secnds(0.0)
print *, "Seconds from midnight:", s1
call sleep(2)
s2 = secnds(s1)
print *, "Seconds from s1", s2
print *, "Seconds from midnight:", secnds(0.0)
end
```
2025-08-06 16:02:27 -04:00
Valentin Clement (バレンタイン クレメン)
3847620ba9
[flang][NFC] Move the rest of ops creation to new APIs (#152079) 2025-08-05 07:27:43 -07:00
Valentin Clement (バレンタイン クレメン)
3b23fdb35d
[flang][NFC] Update more FIR op creation to the new APIs (#152060) 2025-08-04 17:53:44 -07:00
Valentin Clement (バレンタイン クレメン)
9b195dc3ef
[flang][cuda] Generate cuf.allocate for descriptor with CUDA components (#152041)
The descriptor for derived-type with CUDA components are allocated in
managed memory. The lowering was calling the standard runtime on
allocate statement where it should be a `cuf.allocate` operation.
2025-08-04 16:51:11 -07:00
Carlos Seo
9bb31e8f88
[Flang] Fix crash when a derived type with private attribute is specified in extends (#151051)
While lowering to HLFIR, when a parent type is private, its name is
mangled, so we need to get it from the parent symbol.

Fixes #120922
2025-08-04 10:38:15 -03:00
Krzysztof Parzyszek
ca513ee1ec
[flang][OpenMP] Remove unused class OmpMemoryOrderClause, NFC (#151759) 2025-08-04 07:34:00 -05:00
Razvan Lupusoru
2f33b01651
[flang] Ensure lowering diagnostic handler does not outlive lowering (#151608)
When the LoweringBridge is created, it registers an MLIR Diagnostics
handler with the MLIRContext. However, it never deregisters it once
lowering is finished.

This fixes this particular scenario. It also makes it so that the
Diagnostics handler is optional.
2025-08-01 09:27:36 -07:00
Krzysztof Parzyszek
6533ad04ed
[flang][OpenMP] Make all block constructs share the same structure (#150956)
The structure is
- OmpBeginDirective (aka OmpDirectiveSpecification)
- Block
- optional<OmpEndDirective> (aka optional<OmpDirectiveSpecification>)

The OmpBeginDirective and OmpEndDirective are effectively different
names for OmpDirectiveSpecification. They exist to allow the semantic
analyses to distinguish between the beginning and the ending of a block
construct without maintaining additional context.

The actual changes are in the parser: parse-tree.h and openmp-parser.cpp
in particular. The rest is simply changing the way the directive/clause
information is accessed (typically for the simpler).

All standalone and block constructs now use OmpDirectiveSpecification to
store the directive/clause information.
2025-08-01 07:52:59 -05:00
Krzysztof Parzyszek
1ee1bddd74
[flang][Evaluate] OperationCode cleanup, fix for Constant<T> (#151566)
Make the OperationCode overloads take the derived operation instead of
the Operation base class instance. This makes them usable from visitors
of "Expr<T>.u".

Also, fix small bug: OperationCode(Constant<T>) shoud be "Constant".
2025-08-01 07:50:51 -05:00
Akash Banerjee
9fdd1d3d46
[Flang] Add parser support for AUTOMAP modifier (#151511)
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-31 15:56:16 +01:00
Krzysztof Parzyszek
6984922905
[flang][OpenMP] Store directive information in OpenMPSectionConstruct (#150804)
The OpenMPSectionConstruct corresponds to the `!$omp section` directive,
but there is nothing in the AST node that stores the directive
information. Even though the only possibility (at the moment) is
"section" without any clauses, for improved generality it is helpful to
have that information anyway.
2025-07-31 07:51:22 -05:00
Krzysztof Parzyszek
6ffcfc5a8a
[flang][OpenMP] Make OmpDirectiveNameModifier a distrinct type (#150768)
It was an alias for OmpDirectiveName, which could cause confusion in
parse-tree visitors: a visitor for OmpDirectiveNameModifier could be
executed for an OmpDirectiveName node, leading to unexpected results.
2025-07-31 07:23:48 -05:00
Peter Klausler
b01ab5318e
[flang][CUDA] Apply intrinsic operator overrides (#151018)
Fortran's intrinsic numeric and relational operators can be overridden
with explicit interfaces so long as one or more of the dummy arguments
have the DEVICE attribute. Semantics already allows this without
complaint, but fails to replace the operations with the defined specific
procedure calls when analyzing expressions.
2025-07-30 11:41:40 -07:00
Andre Kuhlenschmidt
062b22e462
[flang][openacc] Add semantic checks for atomic constructs (#149579)
An error report of the following code generating non-atomic code led us
to realize there are missing checks in the OpenACC atomics code. Add
some of those checks for atomic and sketch how the rest of the code
should proceed in checking the rest of the properties. The following
cases are all reported as errors.
```fortran
! Originally reported error!
!$acc atomic capture
a = b
c = b
!$acc end atomic capture
! Other ambiguous, but related errors!
!$acc atomic capture
x = i
i = x
!$acc end atomic capture
!$acc atomic capture
a = b
b = b
!$acc end atomic capture
!$acc atomic capture
a = b
a = c
!$acc end atomic capture
```
2025-07-30 08:13:07 -07:00
Razvan Lupusoru
4128cf3b26
[flang][acc] Lower do and do concurrent loops specially in acc regions (#149614)
When OpenACC is enabled and Fortran loops are annotated with `acc loop`,
they are lowered to `acc.loop` operation. And rest of the contained
loops use the normal FIR lowering path.

Hovever, the OpenACC specification has special provisions related to
contained loops and their induction variable. In order to adhere to
this, we convert all valid contained loops to `acc.loop` in order to
store this information appropriately.

The provisions in the spec that motivated this change (line numbers are
from OpenACC 3.4):
- 1353 Loop variables in Fortran do statements within a compute
construct are predetermined to be private to the thread that executes
the loop.
- 3783 When do concurrent appears without a loop construct in a kernels
construct it is treated as if it is annotated with loop auto. If it
appears in a parallel construct or an accelerator routine then it is
treated as if it is annotated with loop independent.

By valid loops - we convert do loops and do concurrent loops which have
induction variable. Loops which are unstructured are not handled.
2025-07-29 10:03:22 -07:00
Ivan Butygin
e68a20e0b7
[mlir] Reland Move InitAll*** implementation into static library (#151150)
Reland https://github.com/llvm/llvm-project/pull/150805

Shared libs build was broken.

Add `${dialect_libs}` and `${conversion_libs}` to
`MLIRRegisterAllExtensions` because it depends on
`registerConvert***ToLLVMInterface` functions.
2025-07-29 18:15:33 +03:00
Mehdi Amini
7057eee481
Revert "[mlir][core] Move InitAll*** implementation into static library." (#151118)
Reverts llvm/llvm-project#150805

Some bots are failing.
2025-07-29 12:26:47 +02:00