Commit Graph

3803 Commits

Author SHA1 Message Date
Peter Steinfeld c0add1636d [flang] Fix the documentation on how to build flang
I recently had an email exchange on flang-dev that revealed that the
documentation on how to build flang is incorrect.  This update fixes
that.

Differential Revision: https://reviews.llvm.org/D116566
2022-01-10 11:54:00 -08:00
Jean Perier fb3faa8b32 [flang] Do not lose call in shape inquiry on function reference
Currently, something like `print *, size(foo(n,m))` was rewritten
to `print *, size(foo_result_symbol)` when foo result is a non constant
shape array. This cannot be processed by lowering or reprocessed by a
Fortran compiler since the syntax is wrong (`foo_result_symbol` is
unknown on the caller side) and the arguments are lost when they might
be required to compute the result shape.

It is not possible (and probably not desired) to make GetShape fail in
general in such case since returning nullopt seems only expected for
scalars or assumed rank (see GetRank usage in lib/Semantics/check-call.cpp),
and returning a vector with nullopt extent may trigger some checks to
believe they are facing an assumed size (like here in intrinsic argument
checks: 196204c72c/flang/lib/Evaluate/intrinsics.cpp (L1530)).

Hence, I went for a solution that limits the rewrite change to folding
(where the original expression is returned if the shape depends on a non
constant shape from a call).

I added a non default option to GetShapeHelper that prevents the rewrite
of shape inquiry on calls to descriptor inquiries. At first I wanted to
avoid touching GetShapeHelper, but it would require to re-implement all
its logic to determine if the shape comes from a function call or not
(the expression could be `size(1+foo(n,m))`). So added an alternate
entry point to GetShapeHelper seemed the cleanest solution to me.

Differential Revision: https://reviews.llvm.org/D116933
2022-01-10 19:10:48 +01:00
Eric Schweitz 7ecce1f695 [fir] Correct and reenable test that was removed by MLIR.
See https://github.com/llvm/llvm-project/issues/53064

The original test required a cast to be correct.
Correct the CHECK lines. Prune unused ones.

Differential Revision: https://reviews.llvm.org/D116842
2022-01-08 13:58:35 -08:00
John Ericson 44e3365775 [CMake] Factor out config prefix finding logic
See the docs in the new function for details.

 I think I found every instance of this copy pasted code. Polly could
 also use it, but currently does something different, so I will save the
 behavior change for a future revision.

We get the shared, non-installed CMake modules following the pattern
established in D116472.

It might be good to have LLD and Flang also use this, but that would be
a functional change and so I leave it as future work.

Reviewed By: beanz, lebedev.ri

Differential Revision: https://reviews.llvm.org/D116521
2022-01-07 20:16:18 +00:00
Alex Zinenko 301226562b [flang] update to reflect MLIR LLVM::GEPOp changes 2022-01-07 12:50:42 +01:00
Andrzej Warzynski ea66b46dde [flang] Separate temporary and user-specified object files
This patch updates the `flang` bash scripts to differentiate between
object files provided by the user and intermediate object files
generated by the script. The latter are an "implementation detail" that
should not be visible to the end user (i.e. deleted before the scripts
exits). The former should be preserved.

Fixes https://github.com/flang-compiler/f18-llvm-project/issues/1348

Differential Revision: https://reviews.llvm.org/D116590
2022-01-06 16:38:39 +00:00
Peixin-Qiao 8eb74626fa [flang][OpenMP] Add some semantic checks for threadprivate and declare target directives
This supports the following checks for THREADPRIVATE Directive:
```
[5.1] 2.21.2 THREADPRIVATE Directive
A threadprivate variable must not appear in any clause except the
copyin, copyprivate, schedule, num_threads, thread_limit, and if clauses.
```

This supports the following checks for DECLARE TARGET Directive:
```
[5.1] 2.14.7 Declare Target Directive
A threadprivate variable cannot appear in the directive.
```

Besides, procedure name and the entity with PARAMETER attribute cannot
be in the threadprivate directive. The main program name and module name
cannot be in the threadprivate directive and declare target directive.
There is no clear description or restriction about the entity with
PARAMETER attribute in OpenMP 5.1 Specification, and a warning is given.

Reviewed By: kiranchandramohan, shraiysh, NimishMishra

Differential Revision: https://reviews.llvm.org/D114941
2022-01-06 20:00:16 +08:00
V Donaldson dd7d5bc5bd [flang] Modify an IO format error message
F18 constraint C1308 is:

  For the G edit descriptor, e shall not be specified if w is zero.

For an edit descriptor such as 'G0.2E4', change the error message from:

  error: Unexpected 'e' in 'G0' edit descriptor

To:

  error: A 'G0' edit descriptor must not have an 'e' value
2022-01-04 14:27:34 -08:00
Benjamin Kramer 32c9208750 [flang][openacc] Remove unused variable. NFC. 2022-01-04 21:47:28 +01:00
Kiran Chandramohan 21d299172e [Flang] Enable support for conversion of recursive record types
Uses the recursive type conversion implemented in D113579, D113580.
Tests check for recursive and mutually recursive types.

Note: The downstream implementation for recursive types is a bit old
and is based on a static map. This was removed while upstreaming
(https://reviews.llvm.org/D112961) based on review comments. Since
the recursive type conversion is now available in MLIR we are using
that. If this patch is accepted we can use the same in the downstream
implementation.
Part of upstreaming flang from fir-dev branch of https://github.com/flang-compiler/f18-llvm-project.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D115937

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-01-04 13:53:58 +00:00
John Ericson b3af9fbcc9 Set the path to the shared cmake modules based on the llvm directory
It’s still possible to build parts of the main llvm build (lld, clang etc) by symlinking them into llvm/tools.

Reviewed By: Ericson2314

Differential Revision: https://reviews.llvm.org/D116472
2022-01-01 17:59:08 +00:00
John Ericson 5c3347aa8b [flang] Use `GNUInstallDirs` to support custom installation dirs.
Extracted from D99484. My new plan is to start from the outside and work
inward.

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D115569
2021-12-31 18:58:35 +00:00
Shilei Tian c7a589a2c4 [Clang][OpenMP] Add the support for atomic compare in parser
This patch adds the support for `atomic compare` in parser. The support
in Sema and CodeGen will come soon. For now, it simply eimits an error when it
is encountered.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D115561
2021-12-24 08:16:51 -05:00
Diana Picus e07736fe3c [flang] Add missing include. NFCI.
descriptor.h is using std::max, so it should include <algorithm>.

This should fix a build issue on Windows on Arm.
2021-12-22 09:17:50 +00:00
Damian Rouson b600215e80 [flang] Add a semantics test for co_max
Test a range of acceptable forms of co_max calls, including
combinations of keyword and non-keyword actual arguments of
numeric types.  Also test that several invalid forms of
co_max call generate the correct error messages.

Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D113083
2021-12-20 11:30:12 -08:00
Damian Rouson e96e3912c9 [flang] Add a semantics test for co_min
Test various acceptable forms of co_min calls, including
combinations of keyword and non-keyword actual arguments of
integer, real, and character types.  Also test that several
invalid forms of co_min call generate the correct error messages.

Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D113077
2021-12-20 11:11:16 -08:00
Damian Rouson 2f581b380a [flang] Add a semantics test for co_reduce
Test a range of acceptable forms of co_reduce calls, including
combinations of keyword and non-keyword actual arguments of
numeric types.  Also test that several invalid forms of
co_reduce call generate the correct error messages.

Reviewed By: kiranchandramohan, ktras, ekieri

Differential Revision: https://reviews.llvm.org/D113086
2021-12-20 10:46:39 -08:00
Andrzej Warzynski 6d655ad011 [flang][codegen] Add a conversion for `fir.coordinate_of` - part 2
This patch extends the `FIRToLLVMLowering` pass in Flang by extending
the hook to transform `fir.coordinate_of` into a sequence of LLVM MLIR
instructions (i.e. `CoordinateOpConversion::doRewrite`). The following
case is added:
  3.1 the input object is inside `!fir.ref` (e.g. `!fir.ref<!fir.array>` or
      `!fir.ref<!fir.type>`).
  3.2 the input object is inside `!fir.ptr` (e.g. `!fir.ptr<!fir.array>` or
      `!fir.ptr<!fir.type>`).
From the point of view of the conversion, 3.1 and 3.2 are currently identical.

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

Originally written by:
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>

Depends on: D114159

Differential Revision: https://reviews.llvm.org/D115333
2021-12-17 10:34:57 +00:00
Andrzej Warzynski d18a9aeae9 [flang] Make the frontend driver error out when requesting multiple actions
With this change, the following invocations will be treated as errors
(multiple actions are specified):
```
$ flang-new -fc1 -E -fsyntax-only file.95
$ flang-new -fc1 -fsyntax-only -fdebug-dump-symbols file.95
```
In the examples above it is not clear whether it is `-fsyntax-only` or
the other action that is run (i.e. `-E` or `-fdebug-dump-symbols`). It
makes sense to disallow such usage. This should also lead to cleaner and
clearer tests (the `RUN` lines using `%flang_fc1` will only allow one
action).

This change means that `flang-new -fc1` and `clang -cc1` will behave
differently when multiple action options are specified. As frontend
drivers are mostly used by compiler developers, this shouldn't affect or
confuse the compiler end-users. Also, `flang-new` and `clang` remain
consistent.

Tests are updated accordingly. More specifically, I've made sure that
every test specifies only one action. I've also taken the opportunity to
simplify "multiple-input-files.f90" a bit.

Differential Revision: https://reviews.llvm.org/D111781
2021-12-17 10:05:28 +00:00
Valentin Clement 3ab67c3d62
[fir] Move Factory.h to flang/Optimizer/Builder
Move the Factory.h header file to flang/Optimizer/Builder.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D115801
2021-12-16 16:08:34 +01:00
Kiran Chandramohan 80b1d472d6 [Flang][NFC] Add test with shape for allocmem and freemem
Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D115797
2021-12-16 13:48:35 +00:00
Eric Schweitz 3d092e31c1 Add a new memory allocation rewrite pass.
This pass can reclassify memory allocations (fir.alloca, fir.allocmem)
based on heuristics and settings. The intention is to allow better
performance and workarounds for conditions such as environments with
limited stack space.

Currently, implements two conversions from stack to heap allocation.
  1. If a stack allocation is an array larger than some threshold value
     make it a heap allocation.
  2. If a stack allocation is an array with a runtime evaluated size make
     it a heap allocation.

Add a lit test for both suboptions.

Reviewed By: PeteSteinfeld, vdonaldson

Differential Revision: https://reviews.llvm.org/D115763
2021-12-15 15:45:08 -08:00
Peter Klausler cea3638812 [flang] Avoid code duplication in mixed expressions
Rather than represent the mixed real/complex subexpression x*(a,b)
as (x*a,x*b), use (x,0)*(a,b) to avoid a potential code duplication
in current lowering code.  Same for mixed division, and for mixed
integer*complex and integer/complex cases.

Differential Review: https://reviews.llvm.org/D115732
2021-12-15 13:23:50 -08:00
Kiran Chandramohan 135d5d4a6d [Flang][NFC] Convert static to static inline for a function
Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D115619
2021-12-14 13:49:58 +00:00
Kiran Chandramohan f97731c765 [Flang][Unit Test] Move the declaration of kindMap to the class
kindMap variable is declared in the Setup function but passed as
a reference to the firBuilder class. The firBuilder is declared in
the class and hence its lifetime exceeds that of kindMap. This can
lead to undefined behaviour. Move the kindMap variable into the class
to avoid this.

This is part of the upstreaming effort from the fir-dev branch in [1].
[1] https://github.com/flang-compiler/f18-llvm-project

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D115631
2021-12-13 16:12:01 +00:00
Jacques Pienaar feeee78afc [mlir] Flip dialects to _Prefixed
Following
https://llvm.discourse.group/t/psa-ods-generated-accessors-will-change-to-have-a-get-prefix-update-you-apis/4476
these have been flipped to both for ~4 weeks, flipping to _Prefixed.

Differential Revision: https://reviews.llvm.org/D115585
2021-12-11 14:21:20 -08:00
Andrzej Warzynski e6e7da5515 [flang][nfc] Fix formatting 2021-12-10 08:56:57 +00:00
Andrzej Warzynski 75db341d5a [flang][codegen] Add a conversion for `!fir.coordinate_of` - part 1
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `!fir.coordinate_of` into a sequence of LLVM MLIR
instructions.

The following cases are currently supported:
  1.  the input object is a `!fir.complex` (wrapped in e.g. `!fir.ref` or
      `!fir.box`)
  2.  the input object is wrapped in a `!fir.box` (including e.g.
      `!fir.array`).
Note that `!fir.complex` inside a `!fir.box` falls under case 1. above
(i.e. it's a special case regardless of the wrapping type).

This is part of the upstreaming effort from the `!fir-dev` branch in [1].

Differential Revision: https://reviews.llvm.org/D114159

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-12-10 08:34:26 +00:00
Peter Klausler c4360b4547 [flang] Fix folding of ac-implied-do indices in structure c'tors
Array constructors with implied DO loops that oversee structure
constructors were being prematurely folded into invalid constants
containing symbolic references to the ac-implied-do indices,
because they are indeed "constant expressions" as that term is
used in the Fortran standard and implemented as IsConstantExpr().
What's actually needed in structure constructor folding is a
test for actual constant values, which is what results from
folding them later with repetition in the context of folding
an ac-implied-do.

Differential Revision: https://reviews.llvm.org/D115470
2021-12-09 18:03:04 -08:00
Jacques Pienaar 3012f35f87 [flang] Updated FIR dialect to _Both
Change dialect (and remove now redundant accessors) to generate both
form of accessors of being generated. Tried to keep this change
reasonably minimal (this also includes keeping note about not generating
getType accessor to avoid shadowing).

Differential Revision: https://reviews.llvm.org/D115420
2021-12-09 15:05:13 -08:00
Valentin Clement ad3bb7c7da
[flang] Simplify RaggedArrayHeader and make it plain C struct
- Join indirection and rank into a single value `flags`
- Make the struct a plain C struct.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D115464
2021-12-09 22:28:06 +01:00
Valentin Clement 70638d997c
[fir] Keep runtime function name in comment
Some of the function name in the comment didn't match
their actual name in the runtime. This patch fixes that.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D115076
2021-12-09 18:29:41 +01:00
Peter Klausler 627a8ac790 [flang] Add CALL FLUSH(n) legacy extension
Prior to the introduction of the FLUSH statement in Fortran 2003,
implementations provided a FLUSH subroutine.

We can't yet put Fortran code into the runtime, so this subroutine
is in C++ with a Fortran-mangled entry point name.

Differential Revision: https://reviews.llvm.org/D115289
2021-12-08 08:56:54 -08:00
Valentin Clement de467afe18
[fir] Add fir ragged array builder
This patch introduces a bunch of builder functions
to create function calls to runtime ragged arrays functions.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D114535

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-12-08 17:28:43 +01:00
Mehdi Amini 89ebd35daa Fix flang tests after MLIR changes on the handling of declarative assembly 2021-12-08 04:31:12 +00:00
AlexisPerry c2acd45393 Convert fir.allocmem and fir.freemem operations to calls to malloc and free, respectively
This patch is part of the upstreaming effort from the fir-dev branch.

Address review comments
- move CHECK blocks to after the mlir code in the test file
- fix style with respect to anonymous namespaces: only include class definitions in the namespace and make functions static and outside the namespace
- fix a few nits
- remove TODO in favor of notifyMatchFailure
- removed unnecessary CHECK line from convert-to-llvm.fir
- rebase on main - add TODO back in
- get successfull test of TODO in AllocMemOp converion of derived type with LEN params
- clearer comments and reduced use of auto
- move defintion of computeDerivedTypeSize to fix build error

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>

Reviewed By: awarzynski, clementval, kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D114104
2021-12-07 15:59:10 -07:00
Kiran Chandramohan fa51755542 [Flang] Upstream conversion of the XRebox Op
The XRebox Op is formed by the codegen rewrite which makes it easier to
convert the operation to LLVM. The XRebox op includes the information
from the rebox op and the associated slice, shift, and shape ops.

During the conversion process a new descriptor is created for reboxing.

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Val Donaldson <vdonaldson@nvidia.com>

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D114709
2021-12-07 22:22:39 +00:00
Valentin Clement 6116ff297f
[flang][runtime] Add ragged array runtime functions
This patch adds the runtime function to allocate and
deallocate ragged arrays.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D114534

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-12-07 21:22:34 +01:00
Peter Klausler 5034e1730f [flang] Remove runtime check from OpenFile::Close()
In error cases it is possible to CLOSE a unit that has not
been successfully connected, so don't crash when the file descriptor
is negative.

Differential Revision: https://reviews.llvm.org/D115165
2021-12-07 09:43:24 -08:00
Peter Klausler c84616c3b3 [flang] Avoid potential deadlock in CloseAll()
When closing all open units, don't hold the unit map lock
over the actual close operations; if one of those aborts,
CloseAll() may be called and then deadlock.

Differential Review: https://reviews.llvm.org/D115184
2021-12-07 09:42:48 -08:00
Peter Klausler 398dffd4ff [flang] Fix INQUIRE(FILE=,NAME=)
The file name output was not being copied back to the program
from the runtime.

Differential Revision: https://reviews.llvm.org/D115190
2021-12-07 08:17:08 -08:00
Valentin Clement 5d27abe629
[fir] Add fircg.ext_array_coor conversion
This patch adds the conversion pattern for the fircg.ext_array_coor
operation. It applies the address arithmetic on a dynamically shaped, shifted
and/or sliced array.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113968

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-12-06 15:52:45 +01:00
Peter Klausler 06ca9f24e7 [flang] OPEN(RECL=) handling for sequential formatted I/O
RECL= is required for direct access I/O, but is permitted
as well for sequential I/O, where it is defined by the
standard to specify a maximum record (line) length.
The standard does not say what should happen when an
sequential formatted input record appears whose length is
unequal to RECL= when it is specified.

Precedents from other compilers are unclear: one raises an error,
some honor RECL= as an effective truncation, and a few ignore the
situation.  On output, all other compilers tested raised an
error when an attempt is made to emit a record longer than RECL=.

This patch treats RECL= as effective truncation on input and
as a hard limit with error on output, and also ensures that
RECL= can be set *longer* than the actual input record lengths.

Differential Revision: https://reviews.llvm.org/D115102
2021-12-04 16:02:48 -08:00
Peter Klausler e337dc8bfe [flang] Fix folding of EXPONENT() intrinsic function
The definition of the EXPONENT() intrinsic function differs by one
from the real arithmetic folding templates concept of an unbiased
exponent, and also needs special handling for zero.  Fix, and add
more tests.

Differential Revision: https://reviews.llvm.org/D115084
2021-12-04 11:23:09 -08:00
Valentin Clement d59a0f58f4
[fir] Add fir character builder
This patch adds the FIR builder to generate the numeric intrinsic
runtime call.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: rovka

Differential Revision: https://reviews.llvm.org/D114900

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
2021-12-03 14:58:17 +01:00
Valentin Clement c32421c925
[fir] Add fir derived type runtime builder
This patch adds the builder to generate derived type runtime API calls.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: rovka

Differential Revision: https://reviews.llvm.org/D114472

Co-authored-by: Peter Klausler <pklausler@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-12-03 14:51:59 +01:00
Diana Picus 919738739a [flang] Add missing LABEL in test. NFC 2021-12-03 10:56:24 +00:00
Diana Picus 3fd250d258 [fir] TargetRewrite: Rewrite fir.address_of(func)
Rewrite AddrOfOp if taking the address of a function.

Differential Revision: https://reviews.llvm.org/D114925

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-12-03 10:56:24 +00:00
Valentin Clement 1f55103263
[fir] Add fircg.ext_embox conversion
Convert a fircg.ext_embox operation to LLVM IR dialect.
A fircg.ext_embox is converted to a sequence of operation that
create, allocate if needed, and populate a descriptor.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D114148

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-12-03 11:45:36 +01:00
Jean Perier 1c16b0db9d [flang] Return arrays in Transfer runtime with SIZE argument
In TRANSFER runtime the result was an array only if the MOLD was an array.
This is not in line with TRANSFER definition in 16.9.193 that rules that it
must also be an array if MOLD is scalar and SIZE if provided.

Differential Revision: https://reviews.llvm.org/D114943
2021-12-03 08:23:30 +01:00