10061 Commits

Author SHA1 Message Date
Jean-Didier PAILLEUX
370d34fe40
[flang][Driver] Add support of -fd-lines-as-comments and -fd-lines-as-code flags (#127605)
`-fd-lines-as-code` and `-fd-lines-as-comments` enables treatment for
lines beginning with `d` or `D` in fixed form sources.
Using these options in free form has no effect.
If the `-fd-lines-as-code` option is given they are treated as if the
first column contained a blank.
If the `-fd-lines-as-comments` option is given, they are treated as
comment lines.
2025-03-03 11:55:36 +00:00
jeanPerier
9805854699
[flang][NFC] clean-up fir.field_index legacy usages in tests (#129219)
After #127231, fir.coordinate_of should directly carry the field.

I updated the lowering and codegen tests in #12731, but not the FIR to
FIR tests, which is what this patch is cleaning up.
2025-03-03 10:01:54 +01:00
Valentin Clement (バレンタイン クレメン)
d1fd3698a9
[flang][cuda] Allow unsupported data transfer to be done on the host (#129160)
Some data transfer marked as unsupported can actually be deferred to an
assignment on the host when the variables involved are unified or
managed.
2025-03-02 16:12:01 -08:00
klensy
62f15a042b
[flang][test] Fix filecheck annotation typos [2/n] (#126099)
Few more fixes, previous: #92387

Co-authored-by: klensy <nightouser@gmail.com>
2025-02-28 10:04:16 +00:00
jeanPerier
a8db1fb9b5
[flang] update fir.coordinate_of to carry the fields (#127231)
This patch updates fir.coordinate_op to carry the field index as
attributes instead of relying on getting it from the fir.field_index
operations defining its operands.

The rational is that FIR currently has a few operations that require
DAGs to be preserved in order to be able to do code generation. This is
the case of fir.coordinate_op, which requires its fir.field operand
producer to be visible.
This makes IR transformation harder/brittle, so I want to update FIR to
get rid if this.

Codegen/printer/parser of fir.coordinate_of and many tests need to be
updated after this change.
2025-02-28 09:50:05 +01:00
Kareem Ergawy
e0c690990d
[flang][OpenMP] Add reduction clause support to loop directive (#128849)
Extends `loop` directive transformation by adding support for the
`reduction` clause.
2025-02-28 05:46:03 +01:00
KAWASHIMA Takahiro
0e56f6dc3e
[flang][docs][NFC] Fix Markdown /*comments*/ (#129018)
`*` in `/*comments*/` were interpreted as emphasis marks and were not
displayed in https://flang.llvm.org/docs/Extensions.html.
2025-02-28 10:18:37 +09:00
Peter Klausler
51dc52631c
[flang] Catch more defined I/O conflicts (#129115)
The code that checks for conflicts between type-bound defined I/O
generic procedures and non-type-bound defined I/O interfaces only works
when then procedures are defined in the same module as subroutines. It
doesn't catch conflicts when either are external procedures, procedure
pointers, dummy procedures, &c. Extend the checking to cover those cases
as well.

Fixes https://github.com/llvm/llvm-project/issues/128752.
2025-02-27 16:16:34 -08:00
Kazu Hirata
44c6616a4a [flang] Fix a warning
This patch fixes:

  flang/lib/Semantics/check-declarations.cpp:2009:15: error: unused
  variable 'kind' [-Werror,-Wunused-variable]
2025-02-27 14:48:13 -08:00
Peter Klausler
cbef629838
[flang] Catch type-bound generic with inherited indistinguishable spe… (#128980)
…cific

When checking generic procedures for indistinguishable specific
procedures, don't neglect to include specific procedures from any
accessible instance of the generic procedure inherited from its parent
type..

Fixes https://github.com/llvm/llvm-project/issues/128760.
2025-02-27 14:33:11 -08:00
Peter Klausler
c6dd9f4278
[flang] Catch usage of : and * lengths in array c'tors (#128974)
The definition of an array constructor doesn't preclude the use of
[character(:)::] or [character(*)::] directly, but there is language
elsewhere in the standard that restricts their use to specific contexts,
neither of which include explicitly typed array constructors.

Fixes https://github.com/llvm/llvm-project/issues/128755.
2025-02-27 14:32:50 -08:00
Peter Klausler
78acf7bb0a
[flang] Enforce C1503 (#128962)
Enforce an obscure constraint from the standard: an abstract interface
is not allowed to have the same name as an intrinsic type keyword. I
suspect this is meant to prevent a declaration like "PROCEDURE(REAL),
POINTER :: P" from being ambiguous.

Fixes https://github.com/llvm/llvm-project/issues/128744.
2025-02-27 14:32:30 -08:00
Peter Klausler
e843d514b1
[flang] Refine handling of SELECT TYPE associations in analyses (#128935)
A few bits of semantic checking need a variant of the
ResolveAssociations utility function that stops when hitting a construct
entity for a type or class guard. This is necessary for cases like the
bug below where the analysis is concerned with the type of the name in
context, rather than its shape or storage or whatever. So add a flag to
ResolveAssociations and GetAssociationRoot to make this happen, and use
it at the appropriate call sites.

Fixes https://github.com/llvm/llvm-project/issues/128608.
2025-02-27 14:32:12 -08:00
Peter Klausler
523537f0c9
[flang] Silence spurious error (#128777)
When checking for conflicts between type-bound generic defined I/O
procedures and non-type-bound defined I/O generic interfaces, don't
worry about conflicts where the type-bound generic interface is
inaccessible in the scope around the non-type-bound interface.

Fixes https://github.com/llvm/llvm-project/issues/126797.
2025-02-27 14:31:50 -08:00
Peter Klausler
8b7a90b84b
[flang] Accept proc ptr function result as actual argument without IN… (#128771)
…TENT

A dummy procedure pointer with no INTENT attribute may associate with an
actual argument that is the result of a reference to a function that
returns a procedure pointer, we think.

Fixes https://github.com/llvm/llvm-project/issues/126950.
2025-02-27 14:31:24 -08:00
Peter Klausler
e1ba1be787
[flang] Account for accessibility in extensibility check (#128765)
A derived type with a component of the same name as the type is not
extensible... unless the extension occurs in another module where the
conflicting component is inaccessible.

Fixes https://github.com/llvm/llvm-project/issues/126114.
2025-02-27 14:30:55 -08:00
Peter Klausler
161d002a09
[flang] Silence warnings from hermetic module files (#128763)
Modules read from module files must have their symbols tagged with the
ModFile flag to suppress all warnings messages that might be emitted for
their contents. (Actionable warnings will have been emitted when the
modules were originally compiled, so we don't want to repeat them later
when the modules are USE'd.) The module symbols of the additional
modules in hermetic module files were not being tagged with that flag;
fix.
2025-02-27 14:29:35 -08:00
Peter Klausler
fce29486ac
[flang] Fix bogus error on defined I/O procedure. (#125898)
The check that "v_list" be deferred shape is just wrong; there are no
deferred shape non-pointer non-allocatable dummy arguments in Fortran.
Correct to check for an assumed shape dummy argument. And de-split the
error messages that were split across multiple source lines, making them
much harder to find with grep.

Fixes https://github.com/llvm/llvm-project/issues/125878.
2025-02-27 14:29:00 -08:00
Peter Klausler
3e3855b0e5
[flang] Don't flag CLASS(*) ASSOCIATED() pointer or target as error (#125890)
As I read the standard, an unlimited polymorphic pointer or target
should be viewed as compatible with any data target or data pointer when
used in the two-argument form of the intrinsic function ASSOCIATED().

Fixes https://github.com/llvm/llvm-project/issues/125774.
2025-02-27 14:28:34 -08:00
Peter Klausler
29025a0600
[flang] Catch more semantic errors with coarrays (#125536)
Detect and report a bunch of uncaught semantic errors with coarray
declarations. Add more tests, and clean up bad usage in existing tests.
2025-02-27 14:28:08 -08:00
Peter Klausler
a21089a24b
[flang] Support COSHAPE() intrinsic function (#125286)
Enable COSHAPE in the intrinsics table and enable its test.
2025-02-27 14:27:46 -08:00
Peter Klausler
9a49a03dc9
[flang] Refine handling of NULL() actual to non-optional allocatable … (#116126)
…dummy

We presently allow a NULL() actual argument to associate with a
non-optional dummy allocatable argument only under INTENT(IN). This is
too strict, as it precludes the case of a dummy argument with default
intent. Continue to require that the actual argument be definable under
INTENT(OUT) and INTENT(IN OUT), and (contra XLF) interpret NULL() as
being an expression, not a definable variable, even when it is given an
allocatable MOLD.

Fixes https://github.com/llvm/llvm-project/issues/115984.
2025-02-27 14:27:19 -08:00
vdonaldson
62d4cc811a
[flang] Modifications to ieee_support_standard (#128895)
Some Arm processors support exception halting control and some do not.
An Arm executable will run on either type of processor, so it is
effectively unknown at compile time whether or not this support will be
available. ieee_support_halting is therefore implemented with a runtime
check.

The result of a call to ieee_support_standard depends in part on support
for halting control. Update the ieee_support_standard implementation to
check for support for halting control at runtime.
2025-02-27 14:57:10 -05:00
Jan Leyonberg
c3b3352f73
[MLIR][ROCDL] Add conversion of math.erfc to AMD GPU library calls (#128899)
This patch adds a pattern to convert the math.erfc operation to AMD GPU
library calls.

Depends on: #128897 for the flang test
2025-02-27 14:32:25 -05:00
Jan Leyonberg
326638bac1
[Flang] Generate math.erfc op for non-precise erfc interinsic calls (#128897)
This patch changes the codegen for non-precise erfc calls to generate
math.erfc ops. This wasn't done before because the math dialect did not
have a erfc operation at the time.
2025-02-27 11:57:56 -05:00
Kareem Ergawy
f6262fa035
[flang] Extend omp loop semantic checks for reduction (#128823)
Extend semantic checks for `omp loop` directive to report errors when a
`reduction` clause is specified on a standalone `loop` directive with
`teams` binding.

This is similar to how clang behaves.
2025-02-27 12:08:04 +01:00
Tom Eccles
db48d49311
[mlir][OpenMP] Pack task private variables into a heap-allocated context struct (#125307)
See RFC:

https://discourse.llvm.org/t/rfc-openmp-supporting-delayed-task-execution-with-firstprivate-variables/83084

The aim here is to ensure that tasks which are not executed for a while
after they are created do not try to reference any data which are now
out of scope. This is done by packing the data referred to by the task
into a heap allocated structure (freed at the end of the task).

I decided to create the task context structure in
OpenMPToLLVMIRTranslation instead of adapting how it is done
CodeExtractor (via OpenMPIRBuilder] because CodeExtractor is (at least
in theory) generic code which could have other unrelated uses.
2025-02-27 09:22:44 +00:00
Valentin Clement (バレンタイン クレメン)
110b77f328
[flang][cuda] Handle floats in atomiccas (#128970) 2025-02-26 20:13:10 -08:00
Valentin Clement (バレンタイン クレメン)
eb84c1181e
[flang][cuda] Add more math intrinsic interfaces in cudadevice (#128931) 2025-02-26 13:32:54 -08:00
Iñaki Amatria Barral
722c7c0b0f
[flang][Semantics] Ensure deterministic mod file output (#128655)
This PR adds a test to ensure deterministic ordering in `.mod` files. It
also includes related changes to prevent non-deterministic symbol
ordering caused by pointers outside the cooked source. This issue is
particularly noticeable when using Flang as a library and compiling the
same files multiple times.
2025-02-26 18:19:02 +01:00
Valentin Clement (バレンタイン クレメン)
e350485595
[flang][cuda] Set alloca block in cuf kernel (#128776)
Temporary created during lowering in a cuf kernel must be set in the cuf
kernel itself otherwise they will be allocated on the host.
2025-02-25 17:25:23 -08:00
Valentin Clement (バレンタイン クレメン)
f3000d7d27
[flang][cuda] Do not trigger automatic deallocation in main (#128789)
Similar to host flow, do not trigger automatic deallocation at then end
of the main program since anything could happen like a
cudaDevcieReset().
2025-02-25 17:25:04 -08:00
Valentin Clement (バレンタイン クレメン)
65cf534139
[flang][cuda] Add interfaces for __ldcg, __ldca, __ldcs, __ldlu, __ldcv, __stwb, __stcg, __stcs, __stwt (#128766) 2025-02-25 14:31:41 -08:00
Mats Petersson
24b7759a9d
[FLANG][OpenMP]Add frontend support for ASSUME and ASSUMES (#120770)
Enough suport to parse correctly formed directives of !$OMP ASSUME and
!$OMP ASSUMES with teh related clauses that go with them: ABSENT,
CONTAINS, NO_OPENPP, NO_OPENMP_ROUTINES, NO_PARALLELISM and HOLDS.

Tests added for unparsing and dump parse-tree.

Semantics support is very minimal and no specific tests added.

The lowering will hit a TODO, and there are tests in Lower/OpenMP/Todo
to make it clear that this is currently expected behaviour.

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2025-02-25 17:36:25 +00:00
Sergio Afonso
25c19eb117
[Flang][OpenMP] Allow host evaluation of loop bounds for distribute (#127822)
This patch adds `target teams distribute [simd]` and equivalent
construct nests to the list of cases where loop bounds can be evaluated
in the host, as they represent kernels for which the trip count must
also be evaluated in advance to the kernel call.
2025-02-25 10:35:21 +00:00
Slava Zakharin
724b91b467
[flang-rt] Fixed freestanding memmove. (#128604) 2025-02-24 16:56:28 -08:00
Valentin Clement (バレンタイン クレメン)
36b339b84a
[flang][cuda] Relax assertion for atomicexch (#128582)
atomicexch interfaces accepts also floating point numbers. Relax the
assertion so float are also accepted.
2025-02-24 14:25:35 -08:00
Slava Zakharin
0caa8f42be Reland "[flang] Set LLVM specific attributes to fir.call's of Fortran runtime. (#128093)"
This change is inspired by a case in facerec benchmark, where
performance
of scalar code may improve by about 6%@aarch64 due to getting rid of
redundant
loads from Fortran descriptors. These descriptors are corresponding
to subroutine local ALLOCATABLE, SAVE variables. The scalar loop nest
in LocalMove subroutine contains call to Fortran runtime IO functions,
and LLVM globals-aa analysis cannot prove that these calls do not modify
the globalized descriptors with internal linkage.

This patch sets and propagates llvm.memory_effects attribute for
fir.call
operations calling Fortran runtime functions. In particular, it tries
to set the Other memory effect to NoModRef. The Other memory effect
includes accesses to globals and captured pointers, so we cannot set
it for functions taking Fortran descriptors with one exception
for calls where the Fortran descriptor arguments are all null.

As long as different calls to the same Fortran runtime function may have
different attributes, I decided to attach the attributes to the calls
rather than functions. Moreover, attaching the attributes to func.func
will require propagating these attributes to llvm.func, which is not
happening right now.

In addition to llvm.memory_effects, the new pass sets llvm.nosync
and llvm.nocallback attributes that may also help LLVM alias analysis
(e.g. see #127707). These attributes are ignored currently.
I will support them in LLVM IR dialect in a separate patch.

I also added another pass for developers to be able to print
declarations/calls of all Fortran runtime functions that are recognized
by the attributes setting pass. It should help with maintenance
of the LIT tests.
2025-02-24 14:18:17 -08:00
Valentin Clement (バレンタイン クレメン)
bef4e5204a
[flang][cuda] Fix type mismatch in atomiccas (#128548) 2025-02-24 13:22:18 -08:00
Slava Zakharin
69cc16fb55 Revert "[flang] Set LLVM specific attributes to fir.call's of Fortran runtime. (#128093)"
This reverts commit 36fdeb2aded08a776fcffefa73cb7667e7fc6c2d.
2025-02-24 10:52:53 -08:00
Slava Zakharin
4d53616901 Revert "[flang] Workaround build failure."
This reverts commit 823a597d2ad0a76e8d5278a789f37a07b393cd2a.
2025-02-24 10:52:48 -08:00
Slava Zakharin
823a597d2a [flang] Workaround build failure.
https://lab.llvm.org/buildbot/#/builders/140/builds/17587
Looks like it is related to some specific version of the build compiler.
2025-02-24 10:36:36 -08:00
Valentin Clement (バレンタイン クレメン)
8dbc393e44
[flang][cuda][NFC] Remove shared alloc addr space (#128535) 2025-02-24 10:05:32 -08:00
Slava Zakharin
36fdeb2ade
[flang] Set LLVM specific attributes to fir.call's of Fortran runtime. (#128093)
This change is inspired by a case in facerec benchmark, where
performance
of scalar code may improve by about 6%@aarch64 due to getting rid of
redundant
loads from Fortran descriptors. These descriptors are corresponding
to subroutine local ALLOCATABLE, SAVE variables. The scalar loop nest
in LocalMove subroutine contains call to Fortran runtime IO functions,
and LLVM globals-aa analysis cannot prove that these calls do not modify
the globalized descriptors with internal linkage.

This patch sets and propagates llvm.memory_effects attribute for
fir.call
operations calling Fortran runtime functions. In particular, it tries
to set the Other memory effect to NoModRef. The Other memory effect
includes accesses to globals and captured pointers, so we cannot set
it for functions taking Fortran descriptors with one exception
for calls where the Fortran descriptor arguments are all null.

As long as different calls to the same Fortran runtime function may have
different attributes, I decided to attach the attributes to the calls
rather than functions. Moreover, attaching the attributes to func.func
will require propagating these attributes to llvm.func, which is not
happening right now.

In addition to llvm.memory_effects, the new pass sets llvm.nosync
and llvm.nocallback attributes that may also help LLVM alias analysis
(e.g. see #127707). These attributes are ignored currently.
I will support them in LLVM IR dialect in a separate patch.

I also added another pass for developers to be able to print
declarations/calls of all Fortran runtime functions that are recognized
by the attributes setting pass. It should help with maintenance
of the LIT tests.
2025-02-24 09:27:48 -08:00
vdonaldson
0b52aa1bdb
[flang] Unsupported rounding modes (#128240)
Two new ieee_round_type values were added in f18 beyond the four values
defined in f03 and f08: ieee_away and ieee_other. Contemporary hardware
typically does not have support for these rounding modes, so flang does
not support them. ieee_support_rounding calls for these values return
false. Current generated code handles some attempts to set the rounding
mode to one of these unsupported values by setting the mode to
ieee_nearest. Update the code to explicitly do this in all cases.
2025-02-24 10:50:03 -05:00
jeanPerier
8199c2d427
[flang][NFC] update some old tests to HLFIR lowering (#127230)
Update some LIT tests that are using the legacy lowering to use HLFIR.

This makes testing more modular and is a step towards getting rid of the
legacy lowering (that is only kept because of the tests).
There are many more.

I deleted a couple file that were very specific to the legacy lowering
(e.g. array-copy).
2025-02-24 15:02:34 +01:00
Valentin Clement (バレンタイン クレメン)
93b2e47f12
[flang][cuda] Avoid assign element mismatch when doing data transfer from a constant (#128252)
Currently when we do a CUDA data transfer from a constant, we embox it
and delegate the assignment to the runtime. When the type of the
constant is not exactly the same as the destination descriptor, the
runtime will emit an assignment mismatch error.

Convert the constant when necessary so the assignment is fine.
2025-02-21 17:46:46 -08:00
Valentin Clement (バレンタイン クレメン)
6038fd44d4
[flang][cuda] Lower atomiccas, atomicxor and atomicexch (#128242)
Lower atomiccas, atomicxor and atomicexch to corresponding llvm atomic
operations.
2025-02-21 15:12:52 -08:00
Andre Kuhlenschmidt
374c470cd1
[Flang] Give a more specific error message for expressions where an IO Unit is expected (#126970)
This PR fixes #125446 by specializing the error message that is
generated when an arbitrary expression is used as an IO Unit. See the
tests for specific examples, but the general gist is that if you use a
non-variable expression as the IO unit argument to a read or write, you
now get a more specific error message indicating the the expression
could have been a scalar integer expression or character variable.
2025-02-21 13:14:15 -08:00
David Truby
449f84fea6
[flang] fix AArch64 PCS for struct following pointer (#127802)
Pointers are already handled as taking up a register in the ABI
handling, but the handling for structs was not taking this into account.
This patch changes the struct handling to acknowledge that pointer
arguments take up an integer register.

Fixes #123075
2025-02-21 10:50:52 -08:00