Commit Graph

107 Commits

Author SHA1 Message Date
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
Peter Klausler
e9a8ab004c [flang] Use definability tests for better PURE constraint checking
Many semantic checks for constraints related to PURE subprograms
can be implemented in terms of Semantics' "definable.h" utilities,
slightly expanded.  Replace some particular PURE constraint
checks with calls to WhyNotDefinable(), except for cases that
had better specific error messages, and start checking some
missing constraints with DEALLOCATE statements and local
variable declarations.

Differential Revision: https://reviews.llvm.org/D147389
2023-04-03 07:00:07 -07:00
Paul Scoropan
5a222c0b82 [Flang] [PowerPC] Implement remaining PPC math operation intrinsics that do not require semantic error checks
This review implements the following PowerPC math operations that we care about:
- fnabs
- fre
- fres
- frsqrte
- frsqrtes

None of these intrinsics require additional error checks in semantics. The interfaces handle checking types and kinds

Reviewed By: kkwli0

Differential Revision: https://reviews.llvm.org/D146139
2023-03-20 15:04:16 +00:00
Peter Klausler
199402c378 [flang] Check dummy arguments of BIND(C) procedures
Declaration checking in semantics was only examining symbols with
explicit BIND(C) attributes; extend it to also check dummy arguments
to such procedures.

Differential Revision: https://reviews.llvm.org/D145746
2023-03-10 09:36:05 -08:00
Paul Scoropan
070dd18e31 [Flang] [PowerPC} Implement the floating-point conversion PowerPC intrinsics
All the fc* floating point conversion PowerPC intrinsics are simply lowered to their LLVM IR intrinsic counterparts and do not require any additional error checking.

Reviewed By: klausler, jeanPerier

Differential Revision: https://reviews.llvm.org/D145080
2023-03-06 09:50:48 -05:00
Kelvin Li
838a4d348d [Flang] Add PowerPC intrinsics
This patch adds a subset of PowerPC intrinsics - fmadd,
fmsub, fnmadd and fnmsub.

Differential Revision: https://reviews.llvm.org/D143951
2023-02-18 11:56:03 -05:00
Peter Klausler
7ed26ad10c [flang] Always incorporate parent types' special generic bindings
The runtime type information table generator was broken when dealing
with an extension derived type that didn't include a special generic
procedure binding for ASSIGNMENT(=) or user-defined I/O, but one of
whose ancestor types did.  Ensure that the runtime derived type info
tables have complete subtables for all of these special bindings,
and respect any overrides that may have been defined.

Motivating example:
  type parent
   contains
    procedure :: dtWrite => dtWrite1
    generic :: write(formatted) => dtWrite
  end type
  type, extends(parent) :: extended
   contains
    procedure :: dtWrite => dtWrite2
  end type

The runtime derived type information table for "extended" must include
a special generic procedure entry for "write(formatted)" that points
to "dtWrite2" even though "extend" has no generic procedure for
"write(formatted)".

Differential Revision: https://reviews.llvm.org/D144148
2023-02-16 08:30:20 -08:00
Peixin Qiao
c4f04a126a [flang] Make real type of kind 10 target dependent
The real(10) is supported on x86_64. On aarch64, the value of
selected_real_kind(16) should be 16 rather than 10 since real(10)
is not supported on x86_64. Previously, the real type support check
is not target dependent. Support it now through the target triple
information.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D134021
2022-10-03 15:24:39 +08:00
Peixin Qiao
3f0ad8558a Revert "[flang] Make real type of kind 10 target dependent"
This reverts commit d11e406e36.
2022-10-02 17:45:03 +08:00
Peixin Qiao
d11e406e36 [flang] Make real type of kind 10 target dependent
The real(10) is supported on x86_64. On aarch64, the value of
selected_real_kind(16) should be 16 rather than 10 since real(10)
is not supported on x86_64. Previously, the real type support check
is not target dependent. Support it now through the target triple
information.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D134021
2022-10-02 10:30:49 +08:00
Katherine Rasmussen
aa1a2ffdbf [flang] Add atomic_fetch_or to the list of intrinsics
Add the atomic subroutine, atomic_fetch_or, to the list of
intrinsic subroutines. Add new enumerators to deal with the rank
of the atom dummy argument, and the kind of atomic_int_kind. Use
check for a coindexed-object for the fourth dummy argument. Move
atomic_int_kind and atomic_logical_kind definitions from
iso_fortran_env module to the __fortran_builtins module to allow
for access to those values when analyzing `atomic_fetch_or`
calls in flang/lib/Evaluate/intrinsics.cpp.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D133174
2022-09-29 09:29:27 -07:00
Peter Klausler
194778117e [flang] Make C_F_POINTER a generic interface
The intrinsic procedure C_F_POINTER needs to be a generic interface
in intrinsic module ISO_C_BINDING.  (It also needs to be implemented,
but that remains a TODO for either lowering or the runtime.)

Differential Revision: https://reviews.llvm.org/D132685
2022-08-25 15:47:17 -07:00
Valentin Clement
a6e155fd9a [flang] Add bind(C) to buitlin C_PTR
D131585 Adds couple of semantics check for the components of BIND(C)
derived-type. This would raise an error when a component is of C_PTR
type. Add `bind(c)` to the `__builtin_c_ptr` type so the wrong error
is not triggered.

Reviewed By: peixin, jeanPerier

Differential Revision: https://reviews.llvm.org/D132350
2022-08-22 11:12:37 +02:00
Peixin Qiao
6d1a685172 [flang] Add semantic checks for interoperability of derived type (C1806)
As Fortran 2018 C1806, each component of a derived type with the BIND
attribute shall be a nonpointer, nonallocatable data component with
interoperable type.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D131585
2022-08-20 23:34:47 +08:00