Commit Graph

126 Commits

Author SHA1 Message Date
Scott Manley
e6a4346b5a [flang] add getElementType() to fir::SquenceType and fir::VectorType (#112770)
getElementType() was missing from Sequence and Vector types. Did a
replace of the obvious places getEleTy() was used for these two types
and updated to use this name instead.

Co-authored-by: Scott Manley <scmanley@nvidia.com>
2024-10-18 09:29:25 +02:00
Kelvin Li
74f3cc0f96 [flang] Call __clog instead of clog on AIX (#111442) 2024-10-08 11:41:55 -04:00
jeanPerier
c4204c0b29 [flang] replace fir.complex usages with mlir complex (#110850)
Core patch of
https://discourse.llvm.org/t/rfc-flang-replace-usages-of-fir-complex-by-mlir-complex-type/82292.
After that, the last step is to remove fir.complex from FIR types.
2024-10-03 17:10:57 +02:00
David Truby
856c38d542 [flang] Implement GETUID and GETGID intrinsics (#110679)
GETUID and GETGID are non-standard intrinsics supported by a number of
other Fortran compilers. On supported platforms these intrinsics simply
call the POSIX getuid() and getgid() functions and return the result.
The only platform we support that does not have these is Windows.

Windows does not have the same concept of UIDs and GIDs, so on Windows
we issue a warning indicating this and return 1 from both functions.

Co-authored-by: Yi Wu <yi.wu2@arm.com>
2024-10-02 13:26:40 +01:00
vdonaldson
936142e0e7 [flang] IEEE_RINT, IEEE_INT (#110509)
IEEE_RINT rounds a real value to an integer-valued real.

IEEE_INT rounds a real value to an integer value.
The primary IEEE_INT result is generated with a call to IEEE_RINT.
2024-10-01 09:15:16 -04:00
David Truby
78ccffc053 [flang] Add MALLOC and FREE intrinsics for Cray pointers (#110018)
MALLOC and FREE are extensions provided by gfortran, Intel Fortran and
classic flang to allocate memory for Cray pointers. These are used in
some legacy codes such as libexodus.

All the above compilers accept using MALLOC and FREE with integers as
well, despite that this will often signify a bug in user code. We should
accept the same as the other compilers for compatibility.
2024-09-30 22:40:16 +01:00
David Truby
7a0a7947ee Revert "[flang] Implement GETUID and GETGID intrinsics" (#110531)
Reverts llvm/llvm-project#108017
2024-09-30 17:35:27 +01:00
David Truby
054eadcb11 [flang] Implement GETUID and GETGID intrinsics (#108017)
GETUID and GETGID are non-standard intrinsics supported by a number of
other Fortran compilers. On supported platforms these intrinsics simply
call the POSIX getuid() and getgid() functions and return the result.
The only platform we support that does not have these is Windows.

Windows does not have the same concept of UIDs and GIDs, so on Windows
we issue a warning indicating this and return 1 from both functions.

Co-authored-by: Yi Wu <yi.wu2@arm.com>

---------

Co-authored-by: Yi Wu <yi.wu2@arm.com>
2024-09-30 14:36:39 +01:00
Slava Zakharin
fc51c7f0cc [flang][runtime] Disable LDBL_MANT_DIG == 113 for the offload builds. (#109339)
When compiling on aarch64 some `LDBL_MANT_DIG == 113` entries
end up trying to use `complex<long double>` for which there are
no certain specializations in `libcudacxx`. This change-set
includes a clean-up for `LDBL_MANT_DIG == 113` usage, which is replaced
with `HAS_LDBL128` that is set in `float128.h`.
2024-09-19 15:45:45 -07:00
jeanPerier
2051a7bcd3 [flang][NFC] turn fir.call is_bind_c into enum for procedure flags (#105691)
First patch to fix a BIND(C) ABI issue
(https://github.com/llvm/llvm-project/issues/102113). I need to keep
track of BIND(C) in more locations (fir.dispatch and func.func
operations), and I need to fix a few passes that are dropping the
attribute on the floor. Since I expect more procedure attributes that
cannot be reflected in mlir::FunctionType will be needed for ABI,
optimizations, or debug info, this NFC patch adds a new enum attribute
to keep track of procedure attributes in the IR.

This patch is not updating lowering to lower more attributes, this will
be done in a separate patch to keep the test changes low here.

Adding the attribute on fir.dispatch and func.func will also be done in
separate patches.
2024-08-23 14:32:43 +02:00
vdonaldson
4cdc19b84c [flang] IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP, NEAREST (#100782)
IEEE_ARITHMETIC intrinsic module procedures IEEE_NEXT_AFTER,
IEEE_NEXT_DOWN, and IEEE_NEXT_UP, and intrinsic NEAREST return larger or
smaller values adjacent to their primary REAL argument. The four
procedures vary in how the direction is chosen, in how special cases are
treated, and in what exceptions are generated. Implement the three
IEEE_ARITHMETIC procedures. Update the NEAREST implementation to support
all six REAL kinds 2,3,4,8,10,16, and fix several bugs.

IEEE_NEXT_AFTER(X,Y) returns a NaN when Y is a NaN as that seems to be
the universal choice of other compilers.

Change the front end compile time implementation of these procedures to
return normal (HUGE) values for infinities when applicable, rather than
always returning the input infinity.
2024-07-29 09:22:36 -04:00
jeanPerier
a19e5aedd9 [flang] load SECOND result in genSecond (#99342)
Until genSecond, all intrinsic `genXXX` returning scalar intrinsic
(except NULL) were returning them as value.

The code calling genIntrinsicCall is using that assumption when
generation the asExprOp because hflir.expr<> of scalar are badly
supported in tools (I should likely just forbid them all together), the
type is meant for "non trivial" values: arrays, character, and derived
type. For instance, the added tests crashed with error: `'arith.subf' op
operand #0 must be floating-point-like, but got '!hlfir.expr<f32>'`

Load the result in genSecond and add an assert after genIntrinsicCall to
better enforce this.
2024-07-18 09:36:13 +02:00
Tom Eccles
850a2e6874 [flang] Fix compiler warning (#99306) 2024-07-17 17:05:55 +01:00
Tom Eccles
60ec6868ea [flang] Implement SECOND intrinsic (#98881)
The SECOND intrinsic is a gnu extension providing an alias for CPU_TIME:
https://gcc.gnu.org/onlinedocs/gfortran/SECOND.html

This cannot be implemented as a straightforward alias because there is
both a function and a subroutine form.
2024-07-16 11:29:36 +01:00
Michael Klemm
a5a29a26aa [Flang] Implement RENAME intrinsic (code-gen + runtime entry point) (#98359)
This PR implements the RENAME intrinsic, which is a GFortran extension
(see
https://gcc.gnu.org/onlinedocs/gfortran/intrinsic-procedures/rename.html).
2024-07-15 08:39:19 +02:00
Tarun Prabhu
4a8f1d670f [flang] Lower 2-argument F2008 atan intrinsic
Implement lowering and testing of the atan(y,x) form of the atan
intrinsic. Since the standard specifies that the behavior of this form
is identical to the atan2 intrinsic, everything is lowered to atan2.

In addition to tests for the atan(y,x) intrinsic, tests for the atan(x)
intrinsic were also added/updated.
2024-07-11 07:24:42 -06:00
jeanPerier
727ecaf7d1 [flang] allow intrinsic module procedures to be implemented in Fortran (#97743)
Currently, all procedures from intrinsic modules that are not BIND(C)
are expected to be intercepted by the compiler in lowering and to have a
handler in IntrinsicCall.cpp.

As more "intrinsic" modules are being added (OpenMP, OpenACC, CUF, ...),
this requirement is preventing seamless implementation of intrinsic
modules in Fortran. Procedures from intrinsic modules are different from
generic intrinsics defined in section 16 of the standard. They are
declared in Fortran file seating in the intrinsic module directory and
inside the compiler they look like regular user call except for the
INTRINSIC attribute set on their module. So an easy implementation is
just to have the implementation done in Fortran and linked to the
runtime without any need for the compiler to necessarily understand and
handle these calls in special ways.

This patch splits the lookup and generation part of IntrinsicCall.cpp so
that it can be allowed to only intercept calls to procedure from
intrinsic module if they have a handler. Otherwise, the assumption is
that they should be implemented in Fortran.

Add explicit TODOs handler for the IEEE procedure that are known to not
yet been implemented and won't be implemented via Fortran code so that
this patch is an NFC for what is currently supported.

This patch also prevents doing two lookups in the intrinsic table (There
was one to get argument lowering rules, and another one to generate the
code).
2024-07-08 16:30:27 +02:00
Slava Zakharin
8ce1aed55f [flang] Lower MATMUL to type specific runtime calls. (#97547)
Lower MATMUL to the new runtime entries added in #97406.
2024-07-03 21:18:56 -07:00
Valentin Clement (バレンタイン クレメン)
887bd73d72 [flang] Handle procedure pointer and dummy procecure in REDUCE intrinsic calls (#95843)
Add handling for procedure pointer and dummy procedure in REDUCE
intrinsic call lowering.
2024-06-18 13:09:16 -07:00
Alexander Shaposhnikov
77d8cfb3c5 [Flang] Switch to common::visit more call sites (#90018)
Switch to common::visit more call sites.

Test plan: ninja check-all
2024-06-17 12:59:04 -07:00
Valentin Clement (バレンタイン クレメン)
38fd0181a0 [flang] Lower REDUCE intrinsic for reduction op with args by value (#95353)
#95297 Updates the runtime entry points to distinguish between reduction
operation with arguments passed by value or by reference. Add lowering
to support the arguments passed by value.
2024-06-14 10:21:37 -07:00
jeanPerier
65f746e76c [flang] Update UBOUND runtime API and lowering (#95085)
LBOUND and SHAPE runtime were added with an API that avoids making a
dynamic allocation for the small result storage. Update the UBOUND API
that was already there and used in lowering outside of the assumed-rank
case.
Add tests for the assumed-rank case.
2024-06-13 10:44:21 +02:00
Valentin Clement (バレンタイン クレメン)
27f3ac5929 [flang] Fix character scalar result for REDUCE intrinsic call (#95076)
The character reduce runtime functions expect a pointer to a scalar
character of the correct length for the result of character reduce. A
descriptor was passed so far. Fix the lowering so a proper temporary is
created and passed to the runtime.
2024-06-11 10:10:42 -07:00
David Parks
a03e93e1b2 [flang] Add runtime support for Fortran intrinsic ERFC_SCALED (#95040)
Co-authored-by: David Parks <dparks@nvidia.com>
2024-06-11 09:40:00 -07:00
jeanPerier
4cff320e0d [flang] lower LBOUND for assumed-rank arrays (#94995) 2024-06-11 09:08:29 +02:00
Valentin Clement (バレンタイン クレメン)
6ffdcfa7fc [flang] Lower REDUCE intrinsic with DIM argument (#94771)
This is a follow up patch to #94652 and handles the lowering of the
reduce intrinsic with DIM argument and non scalar result.
2024-06-10 21:05:39 -07:00
Valentin Clement (バレンタイン クレメン)
0babff9675 [flang] Lower REDUCE intrinsic with no DIM argument and rank 1 (#94652)
This patch lowers the `REDUCE` intrinsic call to the runtime equivalent
for scalar results. Call with array result will follow.
2024-06-10 14:12:57 -07:00
jeanPerier
0257f9cde5 [flang] lower SHAPE with assumed-rank arguments (#94812)
Allocate result statically on the stack (using max rank) and use the
runtime to fill it in correctly.
2024-06-10 10:22:53 +02:00
jeanPerier
55bdb36e39 [flang] lower SIZE and SIZEOF for assumed-ranks (#94684) 2024-06-07 16:09:56 +02:00
jiajie zhang
68413219db [flang] Add GETCWD runtime and lowering intrinsics implementation (#92746)
This patch add support of intrinsics GNU extension GETCWD
https://github.com/llvm/llvm-project/issues/84203. Some usage info and
example has been added to `flang/docs/Intrinsics.md`. The patch contains
both the lowering and the runtime code and works on both Windows and
Linux.


|   System   |   Implmentation  |
|-----------|--------------------|
| Windows | _getcwd               |
| Linux       |getcwd                  |
2024-06-06 12:28:02 +08:00
jeanPerier
d99cf1b916 [flang] lower assumed-rank inquiries - part 1 (#94475)
Lower assumed-rank inquiries, except SIZE/SHAPE/UBOUND/LBOUND. This is
mainly about adding tests, and removing a couple TODOs in helpers.
2024-06-05 23:16:20 +02:00
vdonaldson
6179036038 [flang] Support calling ieee_support_flag with an array argument (#93772)
If present, the optional second argument of the ieee_exceptions
intrinsic module procedure ieee_support_flag may be either a scalar or
an array. Change the signature of the routine that implements this
function so that it is processed as a transformational function, not an
elemental function, which accounts for this argument variant.
2024-05-30 09:40:02 -04:00
Valentin Clement (バレンタイン クレメン)
66db7c609c [flang] Lower selected_char_kind to runtime call (#93095)
Runtime support has been added in
https://github.com/llvm/llvm-project/pull/89691. This patch adds
lowering in a similar way than `selected_int_kind`, `selected_real_kind`
and `selected_logical_kind` added in #93091.

Some gfortran tests can be enabled after this patch is landed.

- `Fortran/gfortran/regression/selected_char_kind_1.f90`
- `Fortran/gfortran/regression/selected_char_kind_4.f90`
2024-05-22 14:54:21 -07:00
Valentin Clement (バレンタイン クレメン)
bdbf927a83 [flang] Lower selected_logical_kind to its runtime call (#93091)
Runtime support has been added in #89691. This patch adds lowering in a
similar way than `selected_int_kind` and `selected_real_kind`.
2024-05-22 14:42:51 -07:00
jiajie zhang
dc8d70acf7 [reland][flang] Add ETIME runtime and lowering intrinsics implementation (#92571)
This is same as https://github.com/llvm/llvm-project/pull/90578 with an
added fix. This PR updated tests of etime intrinsic due to Lowering
changes for assigning dummy_scope to hlfir.declare. Referring to
https://github.com/llvm/llvm-project/pull/92472 and
https://github.com/llvm/llvm-project/pull/90989
2024-05-18 01:00:25 +08:00
Mehdi Amini
6706aebefa Revert "[flang] Add ETIME runtime and lowering intrinsics implementation" (#92354)
Reverts llvm/llvm-project#90578

This broke the premerge linux buildbot.
2024-05-15 23:26:07 -07:00
jiajie zhang
245b7b65cb [flang] Add ETIME runtime and lowering intrinsics implementation (#90578)
This patch add support of intrinsics GNU extension ETIME
https://github.com/llvm/llvm-project/issues/84205. Some usage info and
example has been added to `flang/docs/Intrinsics.md`. The patch contains
both the lowering and the runtime code and works on both Windows and
Linux.


|   System  |   Implmentation  |
|-----------|--------------------|
| Windows| GetProcessTimes |
| Linux      |times                     |
2024-05-16 12:42:01 +08: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
Razvan Lupusoru
c5c8ae4354 [flang] Use i16 instead of i2 for cmdstat (#91647)
The code for preparing cmdstat was generating an i2 constant with value
0, casting it, and then storing it into i16 storage. Just generate i16
constant directly.
2024-05-10 07:45:35 -07:00
Christian Sigg
fac349a169 Reapply "[mlir] Mark isa/dyn_cast/cast/... member functions depreca… (#90406)
…ted. (#89998)" (#90250)

This partially reverts commit 7aedd7dc75.

This change removes calls to the deprecated member functions. It does
not mark the functions deprecated yet and does not disable the
deprecation warning in TypeSwitch. This seems to cause problems with
MSVC.
2024-04-28 22:01:42 +02:00
dyung
7aedd7dc75 Revert "[mlir] Mark isa/dyn_cast/cast/... member functions deprecated. (#89998)" (#90250)
This reverts commit 950b7ce0b8.

This change is causing build failures on a bot
https://lab.llvm.org/buildbot/#/builders/216/builds/38157
2024-04-26 12:09:13 -07:00
Christian Sigg
950b7ce0b8 [mlir] Mark isa/dyn_cast/cast/... member functions deprecated. (#89998)
See https://mlir.llvm.org/deprecation and
https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-04-26 16:28:30 +02:00
jeanPerier
3328ccf689 [flang] lower SHAPE intrinsic (#89785)
Semantics usually fold SHAPE into an array constructor, but sometimes it
cannot (like when the source is a function result that cannot be
duplicated in expression analysis). Add lowering handling for shape.
2024-04-24 15:30:45 +02:00
jeanPerier
8ddfb66903 [flang] Fix MASKR/MASKL lowering for INTEGER(16) (#87496)
The all one masks was not properly created for i128 types because
builder.createIntegerConstant ended-up truncating -1 to something
positive.

Add a builder.createAllOnesInteger/createMinusOneInteger helpers and use
them where createIntegerConstant(..., -1) was used.
Add an assert in createIntegerConstant to catch negative numbers for
i128 type.
2024-04-08 10:18:56 +02:00
Slava Zakharin
315c88c5fb [flang] Fixed MODULO(x, inf) to produce NaN. (#86145)
Straightforward computation of `A − FLOOR (A / P) * P` should
produce NaN, when P is infinity. The -menable-no-infs lowering
can still use the relaxed operations sequence.
2024-04-03 10:19:06 -07:00
jeanPerier
a4798bb0b6 [flang][NFC] use mlir::SymbolTable in lowering (#86673)
Whenever lowering is checking if a function or global already exists in
the mlir::Module, it was doing module->lookup.

On big programs (~5000 globals and functions), this causes important
slowdowns because these lookups are linear. Use mlir::SymbolTable to
speed-up these lookups. The SymbolTable has to be created from the
ModuleOp and maintained in sync. It is therefore placed in the
converter, and FirOPBuilders can take a pointer to it to speed-up the
lookups.

This patch does not bring mlir::SymbolTable to FIR/HLFIR passes, but
some passes creating a lot of runtime calls could benefit from it too.
More analysis will be needed.

As an example of the speed-ups, this patch speeds-up compilation of
Whizard compare_amplitude_UFO.F90 from 5 mins to 2 mins on my machine
(there is still room for speed-ups).
2024-04-02 14:29:29 +02:00
AtariDreams
4d69855e9d [flang] Silence MSVC warning about shifts (NFC) (#83737)
Yes, 64-bit shifts are intended.
2024-03-24 10:48:04 +00:00
Slava Zakharin
86293a7c13 [flang] Lower REAL(16) MODULO to Float128Math library call. (#85322)
I did not test it through in #85005, and my assumption was wrong:
arith::RemFOp might be lowered to an fmodf128() call that does not
exist everywhere.
2024-03-15 08:25:49 -07: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