120 Commits

Author SHA1 Message Date
Peter Klausler
fde5e471df
[flang] C_LOC is PURE (#89437)
The standard defines C_LOC as being PURE (actually SIMPLE now in
F'2023); characterize it appropriately.

Fixes https://github.com/llvm/llvm-project/issues/88747.
2024-04-22 15:33:17 -07: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
Peter Klausler
e1ad2735c3
[flang] Clean up ISO_FORTRAN_ENV, fix NUMERIC_STORAGE_SIZE (#87566)
Address TODOs in the intrinsic module ISO_FORTRAN_ENV, and extend the
implementation of NUMERIC_STORAGE_SIZE so that the calculation of its
value is deferred until it is needed so that the effects of
-fdefault-integer-8 or -fdefault-real-8 are reflected. Emit a warning
when NUMERIC_STORAGE_SIZE is used from the module file and the default
integer and real sizes do not match.

Fixes https://github.com/llvm/llvm-project/issues/87476.
2024-04-08 11:57:01 -07:00
Michael Klemm
fb5fd2d82f
[flang][OpenMP] Compile proper omp_lib.mod from the openmp/src/include sources (#80874)
This PR changes the build system to use use the sources for the module
`omp_lib` and the `omp_lib.h` include file from the `openmp` runtime
project and not from a separate copy of these files. This will greatly
reduce potential for inconsistencies when adding features to the OpenMP
runtime implementation.

When the OpenMP subproject is not configured, this PR also disables the
corresponding LIT tests with a "REQUIRES" directive at the beginning of
the OpenMP test files.

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
2024-03-20 13:47:26 +01:00
Valentin Clement
c75009ef7c
[flang] Lower c_ptr_eq/ne for iso_c_binding (#85293)
Comparing c_ptr type for equality or inequality is raising an error.

```
not yet implemented: intrinsic module procedure: c_ptr_eq
```
or this one for inequality
```
not yet implemented: intrinsic module procedure: c_ptr_ne
```

This patch adds a lowering for them and fix the `__fortran_builtins.f90` module for inequality.

Reland after fix has landed for circular modules #85309
2024-03-14 15:50:22 -07:00
Valentin Clement (バレンタイン クレメン)
8e3c0a299f
Revert "[flang] Lower c_ptr_eq/ne for iso_c_binding" (#85293)
Reverts llvm/llvm-project#85135

There is an issue with module file generation in flang build.
2024-03-14 11:27:33 -07:00
Valentin Clement (バレンタイン クレメン)
15788e8dd3
[flang] Lower c_ptr_eq/ne for iso_c_binding (#85135)
Comparing c_ptr type for equality or inequality is raising an error. 

```
not yet implemented: intrinsic module procedure: c_ptr_eq
```
or this one for inequality
```
not yet implemented: intrinsic module procedure: c_ptr_ne
```

This patch adds a lowering for them and fix the `__fortran_builtins.f90`
module for inequality.
2024-03-14 10:30:23 -07:00
Michael Klemm
0ca74c3458
[flang][NFC] Refactor MODULE definitions to not accidentally leak symbols (#80833)
This PR continues the work started with PR #79006, by setting visibility
in MODULES to PRIVATE by default and explicitly exporting only the
desired symbols. `omp_lib` needs more work, as it should maybe be
compiled from `omp_lib.f90` in
`openmp/runtime/src/incluce/omp_lib.f90.var` instead of simply using an
INCLUDE for `omp_lib.h`
2024-02-19 12:35:38 -06: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
Michael Klemm
ab32a3c166
[flang] Do not leak intrinsics used by ISO_C_BINDING and ISO_FORTRAN_ENV (#79006)
This resolves bug #78953. Intrinsics used by the MODULE definition are
being declared PRIVATE, so that they do not leak into the namespace of
the code that USEs the modules.
2024-01-23 08:43:29 +01:00
Katherine Rasmussen
a2d7af757b
[flang] Add notify-type and notify-wait-stmt (#76594)
Add `notify-type` to `iso_fortran_env` module. Add `notify-wait-stmt` to
the parser and add checks for constraints on the statement, `C1177` and
`C1178`, from the Fortran 2023 standard. Add three semantics tests for
`notify-wait-stmt`.
2024-01-02 10:40:47 -08:00
Peter Klausler
8f3357b75b
[flang][runtime] Don't use -1 in I/O API for "default unit" (#76642)
The I/O runtime's API allows -1 to be passed for a unit number in a
READ, WRITE, or PRINT statement, where it gets replaced by 5 or 6 as
appropriate. This turns out to have been a bad idea, as it prevents the
I/O runtime from detecting and reporting a program's invalid attempt to
use -1 as an I/O unit number. So just pass 5 or 6 as appropriate.
2024-01-02 09:44:16 -08:00
Peter Klausler
5a402c5622
[flang] USE-associated explicit INTRINSIC names (#76199)
The compiler doesn't USE-associate names of intrinsic procedures from
modules (in the absence of ONLY:), so that the associating scope doesn't
get populated with names of intrinsics that were used only in
declarations (e.g., SELECTED_REAL_KIND). A recent bug report (below)
shows that we should modify that policy in the case of names that appear
in explicit INTRINSIC attribute statements. The behaviors of other
Fortran compilers are not consistent and the requirements of the
standard are not clear; this fix follows the precedent set by gfortran
and nvfortran.

Fixes https://github.com/llvm/llvm-project/issues/72084.
2023-12-26 16:03:03 -08:00
vdonaldson
3aba9264b3
[flang] IEEE_ARITHMETIC and IEEE_EXCEPTIONS intrinsic module procedures (#74138)
Implement a selection of intrinsic module procedures that involve
exceptions.

 - IEEE_GET_FLAG
 - IEEE_GET_HALTING_MODE
 - IEEE_GET_MODES
 - IEEE_GET_STATUS
 - IEEE_LOGB
 - [f23] IEEE_MAX, IEEE_MAX_MAG, IEEE_MAX_NUM, IEEE_MAX_NUM_MAG
 - [f23] IEEE_MIN, IEEE_MIN_MAG, IEEE_MIN_NUM, IEEE_MIN_NUM_MAG
 - IEEE_QUIET_EQ, IEEE_QUIET_GE, IEEE_QUIET_GT,
 - IEEE_QUIET_LE, IEEE_QUIET_LT, IEEE_QUIET_NE
 - IEEE_SET_FLAG
 - IEEE_SET_HALTING_MODE
 - IEEE_SET_MODES
 - IEEE_SET_STATUS
 - IEEE_SIGNALING_EQ, IEEE_SIGNALING_GE, IEEE_SIGNALING_GT,
 - IEEE_SIGNALING_LE, IEEE_SIGNALING_LT, IEEE_SIGNALING_NE
 - IEEE_SUPPORT_FLAG
 - IEEE_SUPPORT_HALTING
2023-12-04 09:55:54 -08:00
Peter Klausler
e4589ea2a5
[flang] Correct dummy argument names for C_ASSOCIATED() for C_FUNPTR (#70961)
The dummy argument names used for the interface to C_ASSOCIATED() were
wrong.
2023-11-13 13:53:46 -08:00
Razvan Lupusoru
3e32b80900
[flang] Consider bind(c) when lowering calls to intrinsic module procedures (#70386)
When attempting to lower an intrinsic module procedure call, take into
account bind(c). Such procedures cannot be lowered as intrinsics since
their implementation is external to the module.

With this solution, the hardcoded "omp_lib" string can be removed when
checking if intrinsic module procedure since all procedure interfaces in
that module use bind(c).
2023-10-27 07:49:31 -07:00
Peter Klausler
2565f9f49b
[flang] Remove IEEE_DENORM from IEEE_ALL (#67573)
The array of all exceptions IEEE_ALL defined in the intrinsic module
IEEE_EXCEPTIONS should contain only what the standard mandates. Existing
code depends on it having only five elements. The legacy extension
exception flag IEEE_DENORM shouldn't be an element.
2023-10-16 16:36:46 -07:00
Daniel Chen
ae1c0645aa [flang] Adding two more PowerPC MMA intrinsics
Adding mma_lxvp and mma_stxvp, which are alias to already landed vec_lxvp and vec_stxvp respectively.

Differential Revision: https://reviews.llvm.org/D158274
2023-08-21 11:00:19 -04:00
Kelvin Li
2de024ef31 [flang] Add PowerPC vec_lxv, vec_lvsl, vec_lvsr, vec_xl, vec_xl_be and vec_xlds intrinsic
Differential Revision: https://reviews.llvm.org/D157920
2023-08-18 15:02:15 -04:00
Kelvin Li
a4b2237cfc [flang] fix typo in macros in __ppc_intrinsics.f90 (NFC) 2023-08-17 10:46:25 -04:00
Daniel Chen
c09d3c1ead [flang] Add PowerPC MMA intrinsics - part 2 2023-08-15 13:56:28 -04:00
Kelvin Li
88968f9a73 [flang] Add PowerPC vec_ld, vec_lde, vec_ldl, vec_lxvp, vsx_lxvp, vec_xld2 and vec_xlw4 intrinsic
Differential Revision: https://reviews.llvm.org/D157745
2023-08-14 16:58:35 -04:00
Kelvin Li
f50eaea8ce [flang] Add PowerPC vec_splat, vec_splats and vec_splat_s32 intrinsic
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>

Differential Revision: https://reviews.llvm.org/D157728
2023-08-14 16:15:28 -04:00
Kelvin Li
d9c2c6fcb1 [flang] Add PowerPC vec_stxvp and vsx_stxvp intrinsic
Differential Revision: https://reviews.llvm.org/D157768
2023-08-14 15:38:29 -04:00
Kelvin Li
45c0053db2 [flang] Add a subset of PowerPC vector store intrinsics
This patch adds vec_st, vec_ste, vec_stxv, vec_xst, vec_xst_be, vec_xstd2
and vec_xstw4.

Differential Revision: https://reviews.llvm.org/D156333
2023-08-10 18:03:14 -04:00
Kelvin Li
d652884eb2 [flang] Add PowerPC vec_extract, vec_insert, vec_mergeh, vec_mergel, vec_perm and ver_permi intrinsic
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>
Co-authored-by: Mark Danial <Mark.Danial@ibm.com>

Differential Revision: https://reviews.llvm.org/D156197
2023-08-10 16:20:05 -04:00
Kelvin Li
facfbc9c4a [flang] Add PowerPC vec_cvbf16spn and vec_cvspbf16 intrinsic
Submit on behalf of Daniel Chen <cdchen@ca.ibm.com>

Differential Revision: https://reviews.llvm.org/D156243
2023-08-09 16:10:21 -04:00
Peter Klausler
f4a9f4b613
[flang] Foil attempts to use C_PTR/C_FUNPTR as structure constructors
The internal details of the C_PTR and C_FUNPTR types must be made private
so that user code can't try to access their components or attempt to use
their structure constructors.

Fixes llvm-test-suite/Fortran/fortran/c_ptr_tests_13.f90.

Differential Revision: https://reviews.llvm.org/D157343
2023-08-08 11:51:49 -07:00
Peter Klausler
b21c24c308
[flang][runtime] Recognize and handle FINAL subroutines with contiguous dummy arrays when data are not so
When a FINAL subroutine is being invoked for a discontiguous array, which can
happen for INTENT(OUT) dummy arguments and for some left-hand side variables
in intrinsic assignment statements, it may be the case that the subroutine
being called was defined with a dummy argument that requires contiguous data.

Extend the derived type descriptions used by the runtime to signify when
a special procedure binding requires contiguity; set the flags accordingly;
check them in the runtime support library, and, when necessary, use a
temporary shallow copy of the finalized array data in the call to the
final subroutine.

Differential Revision: https://reviews.llvm.org/D156760
2023-08-01 13:46:45 -07:00
Kelvin Li
2c2d427ca3 [flang] Add a subset of PowerPC MMA (Matrix Multiply Accelerate) intrinsics
This patch includes the a subset of MMA intrinsics that are included in
the mma intrinsic module:

mma_assemble_acc
mma_assemble_pair
mma_build_acc
mma_disassemble_acc
mma_disassemble_pair

Submit on behalf of Daniel Chen <cdchen@ca.ibm.com>

Differential Revision: https://reviews.llvm.org/D155725
2023-07-27 14:30:06 -04:00
Kelvin Li
447c3a358d [flang] Add PowerPC vec_abs, vec_nmadd, vec_msub and vec_sel intrinsics
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>

Differential Revision: https://reviews.llvm.org/D154985
2023-07-24 14:03:50 -04:00
Kelvin Li
99dc3935b9 [flang] Add PowerPC vec_convert, vec_ctf and vec_cvf intrinsic
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>

Differential Revision: https://reviews.llvm.org/D155235
2023-07-19 22:27:55 -04:00
Kelvin Li
42b41137d3 [flang] Simplify macros for the vec_sld and vec_sldw intrinsics
The ignore_tkr directive is applied to the third argument so that the number of
interfaces can be reduced.

Differential Revision: https://reviews.llvm.org/D155624
2023-07-19 08:46:43 -04:00
Peter Klausler
486be17dda
[flang] Catch impure specifics called in DO CONCURRENT
Rework the code used to check for calls to impure procedures in DO CONCURRENT
constructs.  The current code wasn't checking the representation of the
procedure references in the strongly typed expressions, so it was missing
calls to impure subprograms made via generic interfaces.  While here,
improve error messages, and fix some minor issues exposed by testing the
improved checks.

Differential Revision: https://reviews.llvm.org/D155489
2023-07-17 11:41:10 -07:00
Kelvin Li
10124b3e1e [flang] Add PowerPC vec_sl, vec_sld, vec_sldw, vec_sll, vec_slo, vec_srl and vec_sro intrinsic
Co-authored-by: pscoro

Differential Revision: https://reviews.llvm.org/D154563
2023-07-12 17:39:13 -04:00
Leandro Lupori
cb0f98e10b [flang] Force the use of intrinsic builtins in type_info
This ensures that the __Fortran_builtins module is always used
as an intrinsic module by __Fortran_type_info, which avoids issues
when, for instance, the intrinsic modules dir is present in the
include paths.

Fixes https://github.com/llvm/llvm-project/issues/63592

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D154452
2023-07-06 11:39:30 -03:00
Kelvin Li
e435129ba9 [flang] Add PowerPC vec_cmpge, vec_cmpgt, vec_cmple, vec_cmplt and vec_any_ge intrinsic
Differential Revision: https://reviews.llvm.org/D154167
2023-07-03 00:14:51 -04:00
V Donaldson
09ea692d16 [flang] IEEE_ARITHMETIC intrinsic module procedures
Implement

 - IEEE_CLASS
 - IEEE_COPY_SIGN
 - IEEE_GET_ROUNDING_MODE
 - IEEE_IS_FINITE
 - IEEE_IS_NAN
 - IEEE_IS_NEGATIVE
 - IEEE_IS_NORMAL
 - IEEE_SET_ROUNDING_MODE
 - IEEE_SIGNBIT
 - IEEE_SUPPORT_ROUNDING
 - IEEE_UNORDERED
 - IEEE_VALUE

for all REAL kinds (2, 3, 4, 8, 10, 16) where applicable.
2023-06-29 16:46:22 -07:00
Kelvin Li
f295c88937 [flang] Add PPC vec_max, vec_min, vec_madd and vec_nmsub intrinsic
Differential Revision: https://reviews.llvm.org/D152938
2023-06-26 10:52:47 -04:00
Kelvin Li
7e82379d11 [flang] rename PPC specific intrinsic modules (NFC) 2023-06-14 11:21:03 -04:00
Kelvin Li
a9e1d2e760 [flang] Add PowerPC vec_add, vec_and, vec_mul, vec_sub and vec_xor intrinsics
Differential Revision: https://reviews.llvm.org/D151857
2023-06-13 16:05:21 -04:00
Shao-Ce SUN
68f55d78e3 [Flang] Map ieee_fma intrinsic to llvm.fma
Map `ieee_fma` intrinsic to LLVM IR as `llvm.fma`.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D151872
2023-06-06 02:01:36 +08:00
Peter Klausler
f674ddc19f
[flang] CUDA Fortran - part 5/5: statement semantics
Canonicalize !$CUF KERNEL DO loop nests, similar to OpenACC/OpenMP
canonicalization.  Check statements and expressions in device contexts
for usage that isn't supported.  Add more tests, and include some
tweaks to standard modules needed to build CUDA Fortran modules.

Depends on https://reviews.llvm.org/D150159,
https://reviews.llvm.org/D150161, https://reviews.llvm.org/D150162, &
https://reviews.llvm.org/D150163.

Differential Revision: https://reviews.llvm.org/D150164
2023-06-01 13:31:35 -07:00
Hussain Kadhem
541f5c4a6d Flang implementation for COMPILER_VERSION and COMPILER_OPTIONS intrinsics
This revision implements the Fortran intrinsic procedures COMPILER_VERSION and COMPILER_OPTIONS from the iso_fortran_env module.
To be able to set the COMPILER_OPTIONS string according to the original compiler driver invocation, a string is passed to the frontend driver using the environment variable FLANG_COMPILER_OPTIONS_STRING, for lack of a better mechanism.

Fixes #59233

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D140524
2023-06-01 12:35:16 -04:00
Peter Klausler
3332dc3258
[flang] CUDA Fortran - part 3/5: declarations checking
Implements checks for CUDA Fortran attributes on objects, types, and
subprograms.  Includes a couple downgrades of existing errors into
warnings that were exposed during testing.

Depends on https://reviews.llvm.org/D150159 &
https://reviews.llvm.org/D150161.

Differential Revision: https://reviews.llvm.org/D150162
2023-05-31 10:42:26 -07:00
Peter Klausler
27f71807da
[flang] CUDA Fortran - part 2/5: symbols & scopes
Add representations of CUDA Fortran data and subprogram attributes
to the symbol table and scopes of semantics.  Set them in name
resolution, and emit them to module files.

Depends on https://reviews.llvm.org/D150159.

Differential Revision: https://reviews.llvm.org/D150161
2023-05-31 10:19:32 -07:00
Kelvin Li
ef93417470 [flang] Support for PowerPC vector type
The following PowerPC vector type syntax is added:

  VECTOR ( element-type-spec )

where element-type-sec is integer-type-spec, real-type-sec or unsigned-type-spec.

Two opaque types (__VECTOR_PAIR and __VECTOR_QUAD) are also added.

A finite set of functionalities are implemented in order to support the new types:
1. declare objects
2. declare function result
3. declare type dummy arguments
4. intrinsic assignment between the new type objects (e.g. v1=v2)
5. reference functions that return the new types

Submit on behalf of @tislam @danielcchen

Authors: @tislam @danielcchen

Differential Revision: https://reviews.llvm.org/D150876
2023-05-24 13:10:56 -04:00
Peter Klausler
a88cee1fd0
[flang] Semantics for ISO_C_BINDING's C_LOC()
Make __builtin_c_loc() into an intrinsic function and verify the
special semantic requirements on its actual arguments.

Differential Revision: https://reviews.llvm.org/D149988
2023-05-08 15:58:09 -07:00
Peter Klausler
7cf1608b4d
[flang] Rework handling of non-type-bound user-defined I/O
A fairly recent introduction of runtime I/O APIs called OutputDerivedType()
and InputDerivedType() didn't cover NAMELIST I/O's need to access
non-type-bound generic interfaces for user-defined derived type I/O
when those generic interfaces are defined in some scope other than the
one that defines the derived type.

The patch adds a new data structure shared between lowering
and the runtime that can represent all of the cases that can
arise with non-type-bound defined I/O.  It can represent
scopes in which non-type-bound defined I/O generic interfaces
are inaccessible, too, due to IMPORT statements.

The data structure is now an operand to OutputDerivedType() and
InputDerivedType() as well as a data member in the NamelistGroup
structure.

Differential Revision: https://reviews.llvm.org/D148257
2023-04-13 15:35:01 -07:00
Paul Scoropan
adc56f37cd [Flang][PowerPC] Implement PPC mtfsf/mtfsfi intrinsics
Implements the PowerPC mtfsf and mtfsfi intrinsics as well as introduces semantic error checking code for PowerPC intrinsics

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D144876
2023-04-04 13:42:00 +00:00