227 Commits

Author SHA1 Message Date
David Truby
b59c88835f
[flang] Add aarch64 processor defines (#142606)
This patch adds aarch64 specific processor defines when targeting
aarch64, similar to the ones for ppc64 and x86_64
2025-06-04 14:42:23 +01:00
Tarun Prabhu
597340b5b6
Revert "Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler" (#142159)
Reverts llvm/llvm-project#136098
2025-05-30 08:27:08 -06:00
FYK
d27a210a77
Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (#136098)
This patch implements IR-based Profile-Guided Optimization support in
Flang through the following flags:

- `-fprofile-generate` for instrumentation-based profile generation

- `-fprofile-use=<dir>/file` for profile-guided optimization

Resolves #74216 (implements IR PGO support phase)

**Key changes:**

- Frontend flag handling aligned with Clang/GCC semantics

- Instrumentation hooks into LLVM PGO infrastructure

- LIT tests verifying:

    - Instrumentation metadata generation

    - Profile loading from specified path

    - Branch weight attribution (IR checks)

**Tests:**

- Added gcc-flag-compatibility.f90 test module verifying:

    -  Flag parsing boundary conditions

    -  IR-level profile annotation consistency

    -  Profile input path normalization rules

- SPEC2006 benchmark results will be shared in comments

For details on LLVM's PGO framework, refer to [Clang PGO
Documentation](https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization).

This implementation was developed by [XSCC Compiler
Team](https://github.com/orgs/OpenXiangShan/teams/xscc).

---------

Co-authored-by: ict-ql <168183727+ict-ql@users.noreply.github.com>
Co-authored-by: Tom Eccles <t@freedommail.info>
2025-05-30 08:13:53 -06:00
Cameron McInally
ce9cef79ea
[flang] Add support for -mprefer-vector-width=<value> (#142073)
This patch adds support for the -mprefer-vector-width= command line
option. The parsing of this options is equivalent to Clang's and it is
implemented by setting the "prefer-vector-width" function attribute.

Co-authored-by: Cameron McInally <cmcinally@nvidia.com>
2025-05-30 07:50:18 -06:00
Sebastian Pop
d36028120a
[flang] add -floop-interchange and enable it with opt levels (#140182)
Enable the use of -floop-interchange from the flang driver.
Enable in flang LLVM's loop interchange at levels -O2, -O3, -Ofast, and -Os.
2025-05-21 08:27:39 -05:00
shivaramaarao
32a1b6a70b
[flang][veclib] Adding AMDLIBM target to fveclib (#140533)
This commit adds AMDLIBM support to fveclib targets. The support is
already present in clang and this patch extends it to flang.
2025-05-20 01:38:35 -07:00
Kelvin Li
9a2d602187
[flang][AIX] Predefine __64BIT__ and _AIX macros (#138591) 2025-05-07 15:33:23 -04:00
Paul Walker
cb9683fad1
[Clang][Flang][Driver] Fix target parsing for -fveclib=libmvec option. (#138288)
There are various places where the -fveclib option is parsed to
determine whether its value is correct for the target. Unfortunately
these places assume case-insensitivity and subsequently use "LIBMVEC"
where the driver mandates "libmvec", thus rendering the diagnosistic
useless.

This PR corrects the naming along with similar incorrect uses within the
test files.
2025-05-06 11:57:04 +01:00
Anchu Rajendran S
580da48a93
[flang][flang-driver] Support flag -finstrument-functions (#137996) 2025-05-02 07:38:44 -07:00
Slava Zakharin
3f6ae3f0a8
[flang] Added driver options for arrays repacking. (#134002)
Added options:
  * -f[no-]repack-arrays
  * -f[no-]stack-repack-arrays
  * -frepack-arrays-contiguity=whole/innermost
2025-04-03 10:43:28 -07:00
Tom Eccles
9b2fd1a6ec
[flang][OpenMP] Bump default OpenMP version to 3.1 (#133745)
Precise OpenMP standards support information is being documented in
#132707

Flang now has good support for OpenMP Version 3.1 and earlier.
2025-04-02 10:43:48 +01:00
Kareem Ergawy
5d364481e3
[flang][OpenMP] Upstream first part of do concurrent mapping (#126026)
This PR starts the effort to upstream AMD's internal implementation of
`do concurrent` to OpenMP mapping. This replaces #77285 since we
extended this WIP quite a bit on our fork over the past year.

An important part of this PR is a document that describes the current
status downstream, the upstreaming status, and next steps to make this
pass much more useful.

In addition to this document, this PR also contains the skeleton of the
pass (no useful transformations are done yet) and some testing for the
added command line options.

This looks like a huge PR but a lot of the added stuff is documentation.

It is also worth noting that the downstream pass has been validated on
https://github.com/BerkeleyLab/fiats. For the CPU mapping, this achived
performance speed-ups that match pure OpenMP, for GPU mapping we are
still working on extending our support for implicit memory mapping and
locality specifiers.

PR stack:
- https://github.com/llvm/llvm-project/pull/126026 (this PR)
- https://github.com/llvm/llvm-project/pull/127595
- https://github.com/llvm/llvm-project/pull/127633
- https://github.com/llvm/llvm-project/pull/127634
- https://github.com/llvm/llvm-project/pull/127635
2025-04-02 09:24:38 +02:00
Nick Sarnie
48b7530273
[clang][flang][Triple][llvm] Add isOffload function to LangOpts and isGPU function to Triple (#126956)
I'm adding support for SPIR-V, so let's consolidate these checks.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-03-28 14:19:20 +00:00
Kajetan Puchalski
529c5b71c6
[flang] Add -f[no-]slp-vectorize flags (#132801)
Add -f[no-]slp-vectorize to the flang driver.
Add corresponding -fvectorize-slp to the flang frontend.

Enable -fslp-vectorize at -O2 and higher in flang to match the current
behaviour in clang.

---------

Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-03-26 16:10:35 +00:00
Shilei Tian
dccc0a836c
[NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (#131379)
This is an extension of #131357. Hopefully this would be the last one.
2025-03-14 17:02:15 -04:00
Tom Eccles
01aca42363
[flang] Add support for -f[no-]verbose-asm (#130788)
This flag provides extra commentary in the assembly output.
2025-03-13 15:22:13 +00:00
Iñaki Amatria Barral
bdbe8fa1f3
[flang] Align -x language modes with gfortran (#130268)
This PR addresses some of the issues described in
https://github.com/llvm/llvm-project/issues/127617. Key changes:

- Stop assuming fixed-form for `-x f95` unless the input is a `.i` file.
This change ensures compatibility with `-save-temps` workflows while
preventing unintended fixed-form assumptions.
- Ensure `-x f95-cpp-input` enables `-cpp` by default, aligning Flang's
behavior with `gfortran`.
2025-03-12 16:45:33 +01:00
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
David Truby
41cece8c86
[flang] Add -f[no-]vectorize flags (#119718)
This patch adds the -fvectorize and -fno-vectorize flags to flang. 

Note that this also changes the behaviour of `flang -fc1` to match that
of `clang -cc1`, which is that vectorization is only enabled in the
presence of the `-vectorize-loops` flag.

Additionally, this patch changes the behaviour of the default
optimisation levels to match clang, such that vectorization only happens
at the same levels as it does there.

This patch is in draft while I write an RFC to discuss the above two
changes.
2025-02-20 13:59:29 +00:00
Craig Topper
8da8ff8768
[flang][RISCV] Add target-abi ModuleFlag. (#126188)
This is needed to generate proper ABI flags in the ELF header for LTO
builds. If these flags aren't set correctly, we can't link with objects
that were built with the correct flags.

For non-LTO builds the mcpu/mattr in the TargetMachine will cause the
backend to infer an ABI. For LTO builds the mcpu/mattr aren't set.

I've only added lp64, lp64f, and lp64d ABIs. ilp32* requires riscv32
which is not yet supported in flang. lp64e requires a different
DataLayout string and would need additional plumbing.

Fixes #115679
2025-02-13 08:08:09 -08:00
Joseph Huber
c4ed95c85b [Flang] Fix leftover use of 'OPT_nogpulib'
Summary:
This didn't show up as a failure in precommit and I don't build flang so
this slipped by.
2025-02-13 08:14:12 -06:00
Michael Kruse
b815a3942a
[Flang] Move non-common headers to FortranSupport (#124416)
Move non-common files from FortranCommon to FortranSupport (analogous to
LLVMSupport) such that

* declarations and definitions that are only used by the Flang compiler,
but not by the runtime, are moved to FortranSupport

* declarations and definitions that are used by both ("common"), the
compiler and the runtime, remain in FortranCommon

* generic STL-like/ADT/utility classes and algorithms remain in
FortranCommon

This allows a for cleaner separation between compiler and runtime
components, which are compiled differently. For instance, runtime
sources must not use STL's `<optional>` which causes problems with CUDA
support. Instead, the surrogate header `flang/Common/optional.h` must be
used. This PR fixes this for `fast-int-sel.h`.

Declarations in include/Runtime are also used by both, but are
header-only. `ISO_Fortran_binding_wrapper.h`, a header used by compiler
and runtime, is also moved into FortranCommon.
2025-02-06 15:29:10 +01:00
Eugene Epshteyn
642288247d
[flang] Add support for -fimplicit-none-ext option (#125248)
When -fimplicit-none-ext is passed, flang behaves as if "implicit
none(external)" was specified for all relevant constructs in Fortran
source file.

Note: implicit17.f90 was based on implicit07.f90 with `implicit
none(external)` removed and `-fimplicit-none-ext` added.
2025-02-04 20:50:01 -05:00
jeanPerier
7211bf48a6
[flang][driver] add negative from of -fsave-main-program (#124110)
Add the `-fno` form for consistency and to make it easy to switch the
default for downstream users.
2025-01-27 10:51:23 +01:00
Kiran Chandramohan
ce32625966
Reland "[Flang][Driver] Add a flag to control zero initialization" (#123606)
Reverts llvm/llvm-project#123330
2025-01-21 07:57:44 +00:00
Kiran Chandramohan
8a229f595a
Revert "Revert "Revert "[Flang][Driver] Add a flag to control zero initializa…" (#123330)
Reverts llvm/llvm-project#123097

Reverting due to buildbot failure
https://lab.llvm.org/buildbot/#/builders/89/builds/14577.
2025-01-17 12:27:58 +00:00
Kiran Chandramohan
8c63648117
Revert "Revert "[Flang][Driver] Add a flag to control zero initializa… (#123097)
…tion of global v…" (#123067)"

This reverts commit 44ba43aa2b740878d83a9d6f1d52a333c0d48c22.

Adds the flag to bbc as well.
2025-01-17 12:14:20 +00:00
David Truby
0195ec452e
[flang] Add -f[no-]unroll-loops flag (#122906) 2025-01-16 06:43:32 +00:00
Kiran Chandramohan
44ba43aa2b
Revert "[Flang][Driver] Add a flag to control zero initialization of global v…" (#123067)
Reverts llvm/llvm-project#122144

Reverting due to CI failure
https://lab.llvm.org/buildbot/#/builders/89/builds/14422
2025-01-15 15:23:34 +00:00
Kiran Chandramohan
c593e3d0f7
[Flang][Driver] Add a flag to control zero initialization of global v… (#122144)
…ariables

Patch adds a flag to control zero initialization of global variables
without default initialization. The default is to zero initialize.
2025-01-15 15:06:57 +00:00
macurtis-amd
310c281b02
[flang][Driver] Preliminary support for -ftime-report (#122894)
The behavior is not entirely consistent with that of clang for the
moment since detailed timing information on the LLVM IR optimization and
code generation passes is not provided. The -ftime-report= option is
also not enabled since that is only relevant for information about the
LLVM IR passes. However, some code to handle that option has been
included, to make it easier to support the option when the issues
blocking it are resolved. A FortranSupport library has been created that
is intended to mirror the LLVM and MLIR support libraries.

Based on @tarunprabhu's PR
https://github.com/llvm/llvm-project/pull/107270 with minor changes
addressing latest review feedback. He's busy and we'd like to get this
support in ASAP.

Co-authored-by: Tarun Prabhu <tarun.prabhu@gmail.com>
2025-01-14 08:02:02 -06:00
jeanPerier
645c1ee896
[flang][driver] add option to make all main program variable static (#121968)
Co-authored-by: Kiran Chandramohan <kiranchandramohan@gmail.com>
2025-01-08 14:17:04 +01:00
Peter Klausler
fc97d2e68b
[flang] Add UNSIGNED (#113504)
Implement the UNSIGNED extension type and operations under control of a
language feature flag (-funsigned).

This is nearly identical to the UNSIGNED feature that has been available
in Sun Fortran for years, and now implemented in GNU Fortran for
gfortran 15, and proposed for ISO standardization in J3/24-116.txt.

See the new documentation for details; but in short, this is C's
unsigned type, with guaranteed modular arithmetic for +, -, and *, and
the related transformational intrinsic functions SUM & al.
2024-12-18 07:02:37 -08:00
Slava Zakharin
9d33874936
[flang] Support -f[no-]realloc-lhs. (#120165)
-frealloc-lhs is the default.
If -fno-realloc-lhs is specified, then an allocatable on the left
side of an intrinsic assignment is not implicitly (re)allocated
to conform with the right hand side. Fortran runtime will issue
an error if there is a mismatch in shape/type/allocation-status.
2024-12-17 09:06:05 -08:00
Yusuke MINATO
a88677edc0
Reland "[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv" (#118933)
This relands #110063.
The performance issue on 503.bwaves_r is found not to be related to the
patch, and is resolved by fbd89bcc when LTO is enabled.
2024-12-10 16:26:53 +09:00
Tarun Prabhu
23d7a6cedb
[flang][Driver] Support -print-supported-cpus and associated aliases (#117199)
The aliases are -mcpu=help and -mtune=help. There is still an issue with
the output which prints an example line that references clang. That is
not fixed here because it is printed in llvm/MC/SubtargetInfo.cpp. Some
more thought is needed to determine how best to handle this.

Fixes #117010
2024-11-22 11:57:03 -07:00
Kelvin Li
8e14c6c172
[flang] Support -mabi=vec-extabi and -mabi=vec-default on AIX (#113215)
This option is to enable the AIX extended and default vector ABIs.
2024-10-29 14:20:11 -04:00
Yusuke MINATO
bd6ab32e6e
Revert "[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv" (#113901)
Reverts llvm/llvm-project#110063 due to the performance regression on
503.bwaves_r in SPEC2017.
2024-10-28 14:19:20 +00:00
Yusuke MINATO
96bb375f5c
[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv (#110063)
nsw is now added to do-variable increment when -fno-wrapv is enabled as
GFortran seems to do.
That means the option introduced by #91579 isn't necessary any more.

Note that the feature of -flang-experimental-integer-overflow is enabled
by default.
2024-10-25 15:20:23 +09:00
Yusuke MINATO
9698e57548
[flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (#110061)
This patch introduces the options for integer overflow flags into Flang.
The behavior is similar to that of Clang.
2024-10-18 16:30:23 +09:00
Tarun Prabhu
839344f025
[clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)"
The underlying issue was caused by a file included in two different
places which resulted in duplicate definition errors when linking
individual shared libraries. This was fixed in c3201ddaeac02a2c86a38b
[#109874].
2024-10-14 08:44:24 -06:00
Brad Richardson
06eb10dadf
[flang][driver] rename flang-new to flang (#110023)
This does a global rename from `flang-new` to `flang`. I also
removed/changed any TODOs that I found related to making this change.

---------

Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2024-10-10 09:26:04 +01:00
Peter Klausler
4dfed691a9
[flang][preprocessor] Don't expand INCLUDE under -E by default (#110333)
Fortran INCLUDE lines have (until now) been treated like #include
directives. This isn't how things work with other Fortran compilers when
running under the -E option for preprocessing only, so stop doing it by
default, and add -fpreprocess-include-lines to turn it back on when
desired.
2024-09-30 12:38:47 -07:00
Paul Osmialowski
84a0a3d3b3
[flang][driver] Make the -J option less restrictive so we would not have to struggle with autoconf (#110010)
There are autoconf-configured projects for which the generated Makefile
is invoking flang with more than one -J option, each one specifying the
same directory. Although only one module directory should be specified
(by either -J or -module-dir), it should not really matter how many
times this same directory has been specified.

Apparently, other compilers understand it that way, hence autoconf's
configure script may generate a Makefile with the repetitive -J's.

For example, when trying to build the ABINIT [1] project (which can be
configured by either CMake or the configure script) when configured by
autoconf, it fails to build as such:

```
make[3]: Entering directory 'src/98_main'
mpifort -DHAVE_CONFIG_H -I. -I../../../src/98_main -I../..  -I../../src/incs -I../../../src/incs -Ifallbacks/exports/include  -Jbuild/mods  -Jbuild/mods -c -o abinit-abinit.o `test -f 'abinit.F90' || echo '../../../src/98_main/'`abinit.F90
error: Only one '-module-dir/-J' option allowed
make[3]: *** [Makefile:3961: abinit-abinit.o] Error 1
```

This patch solves the problem.

[1] https://github.com/abinit/abinit.git
2024-09-27 16:01:25 +01:00
Krzysztof Parzyszek
3b20a833cb
[flang][Semantics] Add LangOptions to SemanticsContext (#110013)
The motivation for this is to make OpenMP settings visible in the
semantic checks (OpenMP version in particular).
2024-09-26 08:56:22 -05:00
Krzysztof Parzyszek
58e8683a31
[flang][Frontend] Move LangOptions from Frontend to Common (#110012)
The information in LangOptions is not tied to any frontend code, and
could be used by any other component.
2024-09-26 08:56:04 -05:00
David Spickett
737c414e1d Revert "[clang][flang][mlir] Support -frecord-command-line option (#102975)"
This reverts commit b3533a156da92262eb19429d8c12f53e87f5ccec.

It caused test failures in shared library builds:
https://lab.llvm.org/buildbot/#/builders/80/builds/3854
2024-09-20 11:30:50 +00:00
Tarun Prabhu
b3533a156d
[clang][flang][mlir] Support -frecord-command-line option (#102975)
Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object
file. This behavior is also supported in clang. Some refactoring of the
code in flang to handle these command line options was carried out. The
corresponding -grecord-command-line option which saves the command line
in the debug information has not yet been enabled for flang.
2024-09-19 18:28:50 -06:00
Renaud Kauffmann
697bc748f9
Allow disabling of types from the command line (#107126)
Adding hidden options to disable types through the
`TargetCharacteristics`. I am seeing issues when I do this
programmatically and would like, for anyone, to have the ability to
reproduce them for development and testing purposes.

I am planning to file a couple of issues following this patch.
2024-09-04 08:59:55 -07:00
Tom Eccles
4f130fa943
[flang][Driver] support -fno-openmp (#107087)
Closes #83148
2024-09-04 11:28:47 +01:00