193 Commits

Author SHA1 Message Date
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
Sergio Afonso
9dadb1f62b
[Flang][OpenMP] Add frontend support for -fopenmp-targets (#100155)
This patch adds support for the `-fopenmp-targets` option to the `bbc`
and `flang -fc1` tools. It adds an `OMPTargetTriples` property to the
`LangOptions` structure, which is filled with the triples represented by
the compiler option.

This is used to initialize the `omp.target_triples` module attribute for
later use by lowering stages.
2024-08-02 10:54:15 +01:00
Zahira Ammarguellat
42c79f70f1
Fix build flang issue. (#100736) 2024-07-26 09:24:58 -04:00
Alexis Perry-Holby
f1d3fe7aae
Add basic -mtune support (#98517)
Initial implementation for the -mtune flag in Flang.

This PR is a clean version of PR #96688, which is a re-land of PR #95043
2024-07-16 16:48:24 +01:00
Peter Klausler
65987954d9
[flang] Add -fhermetic-module-files (#98083)
Module files emitted by this Fortran compiler are valid Fortran source
files. Symbols that are USE-associated into modules are represented in
their module files with USE statements and special comments with hash
codes in them to ensure that those USE statements resolve to the same
modules that were used to build the module when its module file was
generated.

This scheme prevents unchecked module file growth in large applications
by not emitting USE-associated symbols redundantly. This problem can be
especially bad when derived type definitions must be repeated in the
module files of their clients, and the clients of those modules, and so
on. However, this scheme has the disadvantage that clients of modules
must be compiled with dependent modules in the module search path.

This new -fhermetic-module-files option causes module file output to be
free of dependences on any non-intrinsic module files; dependent modules
are instead emitted as part of the module file, rather than being
USE-associated. It is intended for top level library module files that
are shipped with binary libraries when it is not convenient to collect
and ship their dependent module files as well.

Fixes https://github.com/llvm/llvm-project/issues/97398.
2024-07-11 14:02:44 -07:00
David Truby
9e6b46a984
[flang] Implement -mcmodel flag (#95411)
This patch implements the -mcmodel flag from clang, allowing the Code
Model to be changed for the LLVM module. The same set of mcmodel
flags are accepted as in clang and the same Code Model attributes are
added to the LLVM module for those flags.

Also add `-mlarge-data-threshold` for x86-64, which is automatically set
by the shared command-line code (see below). This is also added as an 
attribute into the LLVM module and on the target machine.

A function is created for `addMCModel` that is copied out of clang's
argument handling so that it can be shared with flang.

---------

Co-authored-by: Mats Petersson <mats.petersson@arm.com>
2024-07-03 18:49:42 +01:00
Tarun Prabhu
8dd9494056
Revert "[flang] Add basic -mtune support" (#96678)
Reverts llvm/llvm-project#95043
2024-06-25 13:25:39 -06:00
Alexis Perry-Holby
a790279bf2
[flang] Add basic -mtune support (#95043)
This PR adds -mtune as a valid flang flag and passes the information
through to LLVM IR as an attribute on all functions. No specific
architecture optimizations are added at this time.
2024-06-25 18:39:35 +01:00
Jan Leyonberg
b75e7c61ff
[flang] Add -mlink-builtin-bitcode option to fc1 (#94763)
This patch enables the -mlink-builtin-bitcode flag in fc1 so that
bitcode libraries can be linked in. This is needed for OpenMP offloading
libraries.
2024-06-17 09:31:15 -04:00
Sergio Afonso
b9549261e2
[Flang][OpenMP] Add -fopenmp-force-usm option to flang (#94359)
This patch enables the `-fopenmp-force-usm` option to be passed to the
flang driver, which forwards it to the compiler frontend. This flag,
when set, results in the introduction of the `unified_shared_memory` bit
to the `omp.requires` attribute of the top-level module operation.

This is later combined with any other target device-related REQUIRES
clauses that may have been explicitly set in the compilation unit.
2024-06-05 14:43:58 +01:00
Yusuke MINATO
526553b251
[flang] Add nsw flag to do-variable increment with a new option (#91579)
This patch adds nsw flag to the increment of do-variables when a new
option is enabled.
NOTE 11.10 in the Fortran 2018 standard says they never overflow.

See also the discussion in #74709 and the following discourse post.
https://discourse.llvm.org/t/rfc-add-nsw-flags-to-arithmetic-integer-operations-using-the-option-fno-wrapv/77584/5
2024-05-16 13:16:07 +09:00
Peter Klausler
e00a3ccf43
[flang] New -fdebug-unparse-with-modules option (#91660)
This option is a compilation action that parses a source file and
performs semantic analysis on it, like the existing -fdebug-unparse
option does. Its output, however, is preceded by the effective contents
of all of the non-intrinsic modules on which it depends but does not
define, transitively preceded by the closure of all of those modules'
dependencies.

The output from this option is therefore the analyzed parse tree for a
source file encapsulated with all of its non-intrinsic module
dependencies. This output may be useful for extracting code from large
applications for use as an attachment to a bug report, or as input to a
test case reduction tool for problem isolation.
2024-05-15 15:44:37 -07:00
Kazu Hirata
f841ca0c35
Use StringRef::operator== instead of StringRef::equals (NFC) (#91864)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  276 under llvm-project/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-12 23:08:40 -07:00
Kiran Chandramohan
602df270a9
[Flang] RFC: Add support for -w option 1/n (#90420)
Add support for the -w option to switch OFF all Flang
warnings. This patch only supports switching OFF the
frontend warnings.

TODO : Support for MLIR, LLVM and Driver warnings.
TODO : Support interactions between -w, -pedantic, -Wall
2024-05-08 10:00:48 +01:00
abidh
087b33bbff
[flang] Default -g to full debug info. (#89418)
Currently, -g defaults to line tables only. This PR changes that to full
debug information. This will allow us to test/use the upcoming debug
info changes.
2024-04-22 11:19:05 +01:00
Daniel Chen
8136ac1c42
[Flang] Define c_int_fast16_t and c_int_fast32_t for PowerPC. (#88292)
On Linux, PowerPC defines `int_fast16_t` and `int_fast32_t` as `long`.
Need to update the corresponding type, `c_int_fast16_t` and
`c_int_fast32_t` in `iso_c_binding` module so they are interoparable.
2024-04-10 19:22:38 -04:00
Krzysztof Parzyszek
7d60232b38
[flang][Frontend] Implement printing defined macros via -dM (#87627)
This should work the same way as in clang.
2024-04-10 10:41:20 -05:00
jeanPerier
d0829fbded
[flang] Enable polymorphic lowering by default (#83285)
Polymorphic entity lowering status is good. The main remaining TODO is
to allow lowering of vector subscripted polymorphic entity, but this
does not deserve blocking all application using polymorphism.

Remove experimental option and enable lowering of polymorphic entity by
default.
2024-03-19 11:45:31 +01:00
Valentin Clement (バレンタイン クレメン)
8a8ef1cacf
[flang][cuda] Enable cuda with -x cuda option (#84944)
Flang driver was already able to enable the CUDA language feature base
on the file extension but there was no command line option. This PR adds
one.
2024-03-13 09:14:40 -07:00
Daniel Chen
987258f5c7
[Flang] Add __powerpc__ macro to set c_intmax_t to c_int64_t rather than c_int128_t as PowerPC only supports up to c_int64_t. (#81222)
PowerPC only supports up to `c_int64_t`. Add macro `__powerpc__` and
preprocess it for setting `c_intmax_t` in `iso_c_binding` intrinsic
module.
2024-02-13 11:03:54 -05:00
Pierre van Houtryve
500846d2f5
[AMDGPU] Introduce Code Object V6 (#76954)
Introduce Code Object V6 in Clang, LLD, Flang and LLVM. This is the same
as V5 except a new "generic version" flag can be present in EFLAGS. This
is related to new generic targets that'll be added in a follow-up patch.
It's also likely V6 will have new changes (possibly new metadata
entries) added later.

Docs change are part of the follow-up patch #76955
2024-02-05 08:19:53 +01:00
Andrzej Warzyński
8cac995ead
[flang][driver] Limit the usage of -mvscale-max and -mvscale-min (#77905)
Make sure that `-mvscale-max` and `-mvscale-min` are only available for
targets that are known to support vscale and scalable vectors.

Also fix capitalization of function variables.
2024-01-15 08:49:58 +00:00
Dominik Adamski
f443fbc49b
[Flang][OpenMP][MLIR] Add support for -nogpulib option (#71045)
If -nogpulib option is passed by the user, then the OpenMP device
runtime is not used and we should not emit globals to configure
debugging at compile-time for the device runtime.

Link to -nogpulib flag implementation for Clang:
https://reviews.llvm.org/D125314
2024-01-10 09:38:58 +01:00
Radu Salavat
0487377382
[flang] Pass to add frame pointer attribute (#74598)
Pass to add frame pointer attribute in Flang
2023-12-28 15:41:27 +00:00
Andrzej Warzyński
48e96e97d1
[flang][driver][nfc] Rename one variable (res -> invoc) (#75535)
The new name better reflects what the variable represents.
2023-12-15 15:04:54 +00:00
jeanPerier
e59e848805
[flang] Updating drivers to create data layout before semantics (#73301)
Preliminary patch to change lowering/code generation to use
llvm::DataLayout information instead of generating "sizeof" GEP (see
https://github.com/llvm/llvm-project/issues/71507).

Fortran Semantic analysis needs to know about the target type size and
alignment to deal with common blocks, and intrinsics like
C_SIZEOF/TRANSFER. This information should be obtained from the
llvm::DataLayout so that it is consistent during the whole compilation
flow.

This change is changing flang-new and bbc drivers to:
1. Create the llvm::TargetMachine so that the data layout of the target
can be obtained before semantics.
2. Sharing bbc/flang-new set-up of the
SemanticConstext.targetCharateristics from the llvm::TargetMachine. For
now, the actual part that set-up the Fortran type size and alignment
from the llvm::DataLayout is left TODO so that this change is mostly an
NFC impacting the drivers.
3. Let the lowering bridge set-up the mlir::Module datalayout attributes
since it is doing it for the target attribute, and that allows the llvm
data layout information to be available during lowering.

For flang-new, the changes are code shuffling: the `llvm::TargetMachine`
instance is moved to `CompilerInvocation` class so that it can be used
to set-up the semantic contexts. `setMLIRDataLayout` is moved to
`flang/Optimizer/Support/DataLayout.h` (it will need to be used from
codegen pass for fir-opt target independent testing.)), and the code
setting-up semantics targetCharacteristics is moved to
`Tools/TargetSetup.h` so that it can be shared with bbc.

As a consequence, LLVM targets must be registered when running
semantics, and it is not possible to run semantics for a target that is
not registered with the -triple option (hence the power pc specific
modules can only be built if the PowerPC target is available.
2023-12-06 14:20:06 +01:00
Tom Eccles
6b8d659062
[flang] remove -f[no-]alias-analysis (#74343)
Now that tbaa tags pass is enabled by default, I would like to remove
these flags. `-fno-alias-analysis` was originally intended to be useful
for debugging, but as it also disables tbaa tag generation in codegen,
it turned out to be too noisy.

@banach-space expressed that these flags felt too non-standard.

The tbaa tags pass can be toggled using `-mllvm
-disable-fir-alias-tags=0`
2023-12-05 10:03:57 +00:00
madanial0
8dc474c6b7
[flang] Pass Argv0 to getIntriniscDir and getOpenMPHeadersDir (#73254)
The `llvm::sys::fs::getMainExecutable(nullptr, nullptr)` is not able to
obtain the correct executable path on AIX without Argv0 due to the lack
of a current process on AIX's `proc` filesystem. This causes a build
failure on AIX as intrinsic module directory is missing.

---------

Co-authored-by: Mark Danial <mak.danial@ibm.com>
2023-12-04 16:34:08 -05:00
Tom Eccles
374e8288e0
[flang] (Re-)Enable alias tags pass by default (#74250)
Enable by default for optimization levels higher than 0 (same behavior
as clang).

For simplicity, only forward the flag to the frontend driver when it
contradicts what is implied by the optimization level.

This was first landed in
https://github.com/llvm/llvm-project/pull/73111 but was later reverted
due to a performance regression. That regression was fixed by
https://github.com/llvm/llvm-project/pull/74065.
2023-12-04 15:28:15 +00:00
Andrzej Warzyński
ae4d7ac9c8
[flang][driver][nfc] Move the definition of SemanticsContext (#73669)
Moves the defintion of `SemanticsContext` within the Flang driver.

Rather than in `CompilerInvocation`, semantic context fits better within
`CompilerInstance` that encapsulates the objects that are required to
run the
frontend. `CompilerInvocation` is better suited for objects
encapsulating compiler configuration (e.g. set-up resulting from user
input or host set-up).
2023-11-29 21:20:43 +00:00
Tom Eccles
5ce5ea3786
Revert "[flang] Enable alias tags pass by default (#73111)" (#73821)
This reverts commit caba0314cf631a3ba3e982cbcdc455224046c7a8.

Serious performance regressions were reported by @vzakhari
https://github.com/llvm/llvm-project/issues/58303#issuecomment-1830754173

Fixing this doesn't look quick so I will revert for now.
2023-11-29 17:10:18 +00:00
Dominik Adamski
95943d2fab [Flang] Add code-object-version option (#72638)
Information about code object version can be configured by the user for
AMD GPU target and it needs to be placed in LLVM IR generated by Flang.

Information about code object version in MLIR generated by the parser
can be reused by other tools. There is no need to specify extra flags if
we want to invoke MLIR tools (like fir-opt) separately.

Changes in comparison to a8ac93:
 * added information about required targets for test
   flang/test/Driver/driver-help.f90
2023-11-29 03:01:01 -06:00
Dominik Adamski
f00ffcdb58 Revert "[Flang] Add code-object-version option (#72638)"
This commit causes test errors on buildbots.

This reverts commit a8ac930b99d93b2a539ada7e566993d148899144.
2023-11-28 13:18:46 -06:00
Dominik Adamski
a8ac930b99
[Flang] Add code-object-version option (#72638)
Information about code object version can be configured by the user for
AMD GPU target and it needs to be placed in LLVM IR generated by Flang.

Information about code object version in MLIR generated by the parser
can be reused by other tools. There is no need to specify extra flags if
we want to invoke MLIR tools (like fir-opt) separately.
2023-11-28 19:57:36 +01:00
Tom Eccles
caba0314cf
[flang] Enable alias tags pass by default (#73111)
Enable by default for optimization levels higher than 0 (same behavior
as clang).

For simplicity, only forward the flag to the frontend driver when it
contradicts what is implied by the optimization level.

Since https://github.com/llvm/llvm-project/pull/72903 there are now no
known performance regressions.
2023-11-27 15:10:21 +00:00