Commit Graph

1242 Commits

Author SHA1 Message Date
Rajan Walia
80c27abb2f
[fir] Add affine demotion pass
Add affine demotion pass.
Affine dialect's default lowering for loads and stores is different from
fir as it uses the `memref` type. The `memref` type is not compatible with
the Fortran runtime. Therefore, conversion of memory operations back to
`fir.load` and `fir.store` with `!fir.ref<?>` types is required.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Rajan Walia <walrajan@gmail.com>
Co-authored-by: Sourabh Singh Tomar <SourabhSingh.Tomar@amd.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111257
2021-10-08 14:03:27 +02:00
Jean Perier
d70938bbad
[fir] Add affine promotion pass
Convert fir operations which satisfy affine constraints to the affine
dialect.

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Rajan Walia <walrajan@gmail.com>
Co-authored-by: Sourabh Singh Tomar <SourabhSingh.Tomar@amd.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: schweitz, awarzynski

Differential Revision: https://reviews.llvm.org/D111155
2021-10-08 11:47:23 +02:00
peter klausler
094b380c21 [flang] Catch mismatched parentheses in prescanner
Source lines with mismatched parentheses are hard cases for error
recovery in parsing, and the best error message (viz.,
"here's an unmatched parenthesis") can be emitted from the
prescanner.

Differential Revision: https://reviews.llvm.org/D111254#3046173
2021-10-06 14:00:15 -07:00
Valentin Clement
fc66dbba1f
[fir] Add external name interop pass
Add the external name conversion pass needed for compiler
interoperability. This pass convert the Flang internal symbol name to
the common gfortran convention.

Clean up old passes without implementation in the Passes.ts file so
the project and fir-opt can build correctly.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111057
2021-10-05 20:33:41 +02:00
peter klausler
cc1d13f997 [flang] Fold MAXLOC and MINLOC
Generalize the code that folds FINDLOC to also handle
folding for MAXLOC and MINLOC.

Differential Revision: https://reviews.llvm.org/D110951
2021-10-05 11:22:02 -07:00
Craig Rasmussen
9dd3965e96 [flang] Added tests for intrinsic function 'team_number()'
reviewers: klausler, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D100897
2021-10-04 12:35:45 -07:00
Jean Perier
dc4d94e620
[fir] add fir.array_modify op
fir.array_update is only handling intrinsic assignments.
They are two big differences with user defined assignments:
1. The LHS and RHS types may not match, this does not play well
   with fir.array_update that relies on both the merge and the
   updated element to have the same type.
2. user defined assignment has a call semantics, with potential
   side effects. So if a fir.array_update can hide a call, it traits
   would need to be updated.

Instead of hiding more semantic in the fir.array_update, introduce
a new fir.array_modify op that allows de-correlating indicating that
an array value element is modified, and how it is modified.
This allow the ArrayValueCopy pass to still perform copy elision
while not having to implement the call itself, and could in general
be used for all kind of assignments (e.g. character assignment).

Update the alias analysis to not rely on the merge arguments (since
fir.array_modify has none).
Instead, analyze what is done with the element address.
This implies adding the ability to follow the users of fir.array_modify,
as well as being able to go through fir.store that may be generated to
store the RHS value in order to pass it to a user define routine.
This is done by adding a ReachCollector class to gather all array
accesses.

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

Reviewed By: schweitz

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-04 21:00:43 +02:00
peter klausler
0061e681a3 [flang] Better error recovery for missing THEN in ELSE IF
The THEN keyword in the "ELSE IF (test) THEN" statement is useless
syntactically, and to omit it is a common error (at least for me!)
that has poor error recovery.  This patch changes the parser to
cough up a simple "expected 'THEN'" and still recognize the rest of
the IF construct.

Differential Revision: https://reviews.llvm.org/D110952
2021-10-04 09:37:53 -07:00
Nimish Mishra
063c5bc31b [flang][OpenMP] Added OpenMP 5.0 specification based semantic checks for sections construct and test case for simd construct
According to OpenMP 5.0 spec document, the following semantic restrictions have been dealt with in this patch.

1. [sections construct] Orphaned section directives are prohibited. That is, the section directives must appear within the sections construct and must not be encountered elsewhere in the sections region.

 Semantic checks for the following are not necessary, since use of orphaned section construct (i.e. without an enclosing sections directive) throws parser errors and control flow never reaches the semantic checking phase. Added a test case for the same.

2. [sections construct] Must be a structured block

Added test case and made changes to branching logic

3. [simd construct] Must be a structured block / A program that branches in or out of a function with declare simd is non conforming

4. Fixed !$omp do's handling of unlabeled CYCLEs

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D108904
2021-10-02 08:40:53 +05:30
Eric Schweitz
2372249d86
[fir] Remove obsolete fir.negf and fir.modf ops
fir.negf op is replaced by mlir.negf and
fir.modf is just deleted.

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-01 16:11:36 +02:00
Eric Schweitz
15ea26de24
[fir] Add fir.char_convert op
Add the fir-char_convert op.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-01 14:40:11 +02:00
Peter Klausler
8256867508 [flang] Fold FINDLOC()
Fold the transformational intrinsic function FINDLOC() for
all combinations of optional arguments and data types.

Differential Revision: https://reviews.llvm.org/D110757
2021-09-30 12:08:10 -07:00
peter klausler
691814f9cc [flang] Fix test regression from SQRT folding
The algorithm used to fold SQRT has some holes that
led to test failures; debug and add more tests.

Differential Revision: https://reviews.llvm.org/D110744
2021-09-30 11:35:44 -07:00
Eric Schweitz
c8f03a7fe8
[fir] Update fir.extract_value and fir.insert_value ops
Move coor operand from variadic values to ArrayAttr.
Update assembly format.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 10:23:51 +02:00
Eric Schweitz
34d6c1822e
[fir] Update fir.array_update, fir.array_fetch and fir.array_merge_store
Add typeparams to fir.array_update, fir.array_fetch and
fir.array_merge_store operations. Add optional slice operands to
fir.array_merge_store op.
Move verifiers to cpp file.

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 09:56:50 +02:00
peter klausler
52711fb8da [flang] Make builtin types more easily accessible; use them
Rearrange the contents of __builtin_* module files a little and
make sure that semantics implicitly USEs the module __Fortran_builtins
before processing each source file.  This ensures that the special derived
types for TEAM_TYPE, EVENT_TYPE, LOCK_TYPE, &c. exist in the symbol table
where they will be available for use in coarray intrinsic function
processing.

Update IsTeamType() to exploit access to the __Fortran_builtins
module rather than applying ad hoc name tests.  Move it and some
other utilities from Semantics/tools.* to Evaluate/tools.* to make
them available to intrinsics processing.

Add/correct the intrinsic table definitions for GET_TEAM, TEAM_NUMBER,
and THIS_IMAGE to exercise the built-in TEAM_TYPE as an argument and
as a result.

Add/correct/extend tests accordingly.

Differential Revision: https://reviews.llvm.org/D110356
2021-09-29 13:06:01 -07:00
Andrzej Warzynski
5c52753d9f [Flang] Fix failing plugin tests
The updated tests were originally added in
https://reviews.llvm.org/D109890 and are currently causing some
buildbots to fail.

This patch:
* adds missing items in the `REQUIRERS` list in tests
* adds `flangOmpReport` (the plugin library added in D109890) as a CMake
  dependency for tests (only when examples are enabled)

Differential Revision: https://reviews.llvm.org/D110682
2021-09-29 09:27:11 +00:00
Stuart Ellis
38c42d42eb Flang OpenMP Report Plugin
This plugin parses Fortran files and creates a
YAML report with all the OpenMP constructs and
clauses seen in the file.

The following tests have been modified to be
compatible for testing the plugin, hence why
they are not reused from another directory:

- omp-atomic.f90
- omp-declarative-directive.f90
- omp-device-constructs.f90

The plugin outputs a single file in the same
directory as the source file in the following format:
`<source-file-name>.yaml`

Building the plugin:
`ninja flangOmpReport`

Running the plugin:
`./bin/flang-new -fc1 -load lib/flangOmpReport.so -plugin flang-omp-report -fopenmp <source_file.f90>`

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Stuart Ellis <stuart.ellis@arm.com>

Reviewed By: awarzynski, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109890
2021-09-28 22:57:17 +01:00
Diana Picus
37089bae29 Reland "[flang] GET_COMMAND_ARGUMENT runtime implementation"
Recommit https://reviews.llvm.org/D109813 and
https://reviews.llvm.org/D109814.

This implements the second and final entry point for GET_COMMAND_ARGUMENT,
handling the VALUE, STATUS and ERRMSG parameters.

It has a small fix in that we're now using memcpy instead of strncpy
(which was a bad idea to begin with, since we're not actually interested
in a string copy).
2021-09-28 12:34:07 +00:00
Diana Picus
6359a4cdbf Revert "[flang] GET_COMMAND_ARGUMENT(VALUE) runtime implementation"
This reverts commit 0446f1299f and
df6302311f.

There's a warning on flang-aarch64-latest-gcc related to strncpy using
the result of strlen as a bound. I'll recommit with a fix.
2021-09-28 12:07:27 +00:00
Eric Schweitz
5b5ef2e265
[fir] Add fir.save_result op
Add the fir.save_result operation. It is use to save an
array, box, or record function result SSA-value to a memory location

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-28 11:58:42 +02:00
V Donaldson
bd2623b9c2
[fir] Update fir.insert_on_range op
Update the fir.insert_on_range operation. Add a better description,
builder and verifier.

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

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-28 11:03:28 +02:00
Diana Picus
df6302311f [flang] GET_COMMAND_ARGUMENT(VALUE) runtime implementation
Partial implementation for the second entry point for
GET_COMMAND_ARGUMENT. It handles the VALUE and STATUS arguments, and
doesn't touch ERRMSG.

Differential Revision: https://reviews.llvm.org/D109813
2021-09-28 08:32:19 +00:00
Diana Picus
af63d1791b [flang] GET_COMMAND_ARGUMENT(LENGTH) runtime implementation
Implement the ArgumentLength entry point of GET_COMMAND_ARGUMENT. Also
introduce a fixture for the tests.

Note that this also changes the interface for ArgumentLength from
returning a 4-byte integer to returning an 8-byte integer.

Differential Revision: https://reviews.llvm.org/D109227
2021-09-28 08:32:19 +00:00
peter klausler
9eab0da183 [flang] Catch branching into FORALL/WHERE constructs
Enforce constraints C1034 & C1038, which disallow the use
of otherwise valid statements as branch targets when they
appear in FORALL &/or WHERE constructs.  (And make the
diagnostic message somewhat more user-friendly.)

Differential Revision: https://reviews.llvm.org/D109936
2021-09-27 10:51:44 -07:00
peter klausler
1c2e5fd66e [flang] Enforce constraint: defined ass't in WHERE must be elemental
A defined assignment subroutine invoked in the context of a WHERE
statement or construct must necessarily be elemental (C1032).

Differential Revision: https://reviews.llvm.org/D109932
2021-09-27 10:12:53 -07:00
peter klausler
f6ecea1a35 [flang] Represent (parentheses around derived types)
The strongly typed expression representation classes supported
a representation of parentheses only around intrinsic types
with specific kinds.  Parentheses around derived type variables
must also be preserved so that expressions may be distinguished
from variables; this distinction matters for actual arguments &
construct associations.

Differential Revision: https://reviews.llvm.org/D110355
2021-09-23 13:03:13 -07:00
Valentin Clement
2155aa79d7
[fir][NFC] Remove fir.cmpf replaced by mlir.cmpf
fir.cmpf op is not necessary anymore as it is replaced by mlir.cmpf.
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: schweitzpgi
Co-authored-by: jeanPerier
2021-09-23 19:05:57 +02:00
peter klausler
57705df2de [flang] Catch error: base of DATA statement object can't be a pointer
A pointer with subscripts, substring indices, or components cannot
be initialized by a DATA statement (although of course a whole pointer
can be so).  Catch the missing cases.

Differential Revision: https://reviews.llvm.org/D109931
2021-09-22 14:41:48 -07:00
peter klausler
bcb2591b6c [flang] More checking of NULL pointer actual arguments
Catch additional missing error cases for typed and untyped
NULL actual arguments to non-intrinsic procedures in cases
of explicit and implicit interfaces.

Differential Revision: https://reviews.llvm.org/D110003
2021-09-17 15:35:29 -07:00
peter klausler
338f21a4bd [flang] Enforce specification function rules on callee, not call
A function can't be a specification function if it has a dummy procedure
argument, even if it's optional and unused.  So don't check the reference
for actual procedure arguments, but rather the characteristics of the
function.

Differential Revision: https://reviews.llvm.org/D109935
2021-09-17 10:59:54 -07:00
peter klausler
f6ddfac401 [flang] Enforce fixed form rules about END continuation
From subclause 6.3.3.5: a program unit END statement cannot be
continued in fixed form, and other statements cannot have initial
lines that look like program unit END statements.  I think this
is to avoid violating assumptions that are important to legacy
compilers' statement classification routines.

Differential Revision: https://reviews.llvm.org/D109933
2021-09-17 10:59:17 -07:00
peter klausler
9245f35580 [flang] Validate SIZE(x,DIM=n) dimension for assumed-size array x
Catch invalid attempts to extract the unknowable extent of the last
dimension of an assumed-size array dummy argument, and clean up
problems with assumed-rank arguments in similar circumstances
exposed by testing the fix.

Differential Revision: https://reviews.llvm.org/D109918
2021-09-17 10:14:18 -07:00
peter klausler
20afd38651 [flang] Upgrade warning to error in case of PURE procedure
A procedure actual argument to a PURE procedure should be required
to have an explicit interface.  Implicit-interface actual arguments
to non-PURE procedures remain a warning.

Differential Revision: https://reviews.llvm.org/D109926
2021-09-17 10:13:35 -07:00
peter klausler
7ff920826c [flang] Catch errors with intrinsic array inquiry functions
The intrinsic inquiry functions SIZE and UBOUND -- but not LBOUND --
require a DIM= argument if their first argument is an assumed-size
array.  The intrinsic SHAPE must not be used with an assumed-size
array.

Differential Revision: https://reviews.llvm.org/D109912
2021-09-17 09:24:52 -07:00
peter klausler
1894250291 [flang] Revamp C1502 checking of END INTERFACE [generic-spec]
Validation of the optional generic-spec on an END INTERFACE statement
was missing many possible error cases; reimplement it.

Differential Revision: https://reviews.llvm.org/D109910
2021-09-17 08:13:10 -07:00
PeixinQiao
6fb01a9470 [flang][OpenMP] Add semantic checks for ordered construct
This patch implements the following semantic checks according to
OpenMP Version 5.1 Ordered construct restriction:

```
At most one threads clause can appear on an ordered construct; At most
one simd clause can appear on an ordered construct; At most one
depend(source) clause can appear on an ordered construct; Either
depend(sink:vec) clauses or depend(source) clauses may appear on an
ordered construct, but not both.
```

This patch also implements the following semantic checks according to
the syntax and descriptions in OpenMP Version 5.1 Ordered construct:

```
The dependence types of sink or source are only allowed on an ordered
construct. The depend(*) clauses are not allowed when ordered construct
is a block construct with an ordered region. The threads or simd clauses
are not allowed when the ordered construct is a standalone construct
with no ordered region.
```

Co-authored-by: Sameeran Joshi <sameeranjayant.joshi@amd.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D108512
2021-09-17 21:53:07 +08:00
Craig Rasmussen
ed921282e5 [flang] Make 'this_image()' an intrinsic function
Added 'this_image()' to the list of functions that are evaluated as intrinsic.
Added IsCoarray functions to determine if an expression is a coarray (corank > 1).

Added save attribute to coarray variables in test file, this_image.f90.

reviewers: klausler, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D108059
2021-09-16 22:17:32 -07:00
peter klausler
26aff847d8 [flang] Fold COUNT()
Complete folding of the intrinsic reduction function COUNT() for all
cases, including partial reductions with DIM= arguments.

Differential Revision: https://reviews.llvm.org/D109911
2021-09-16 17:09:23 -07:00
peter klausler
19afc495dc [flang] Enforce array conformance in actual arguments to ELEMENTALs
When the shapes of actual arguments to ELEMENTAL procedures are
sufficiently well known during semantics, require them to conform.

Differential Revision: https://reviews.llvm.org/D109909
2021-09-16 16:17:36 -07:00
peter klausler
d9195d6603 [flang] More precise checks for NULL() operands
Improve checking for NULL() and NULL(MOLD=) when used as
variables and expressions outside the few contexts where
a disassociated pointer can be valid.  There were both
inappropriate errors and missing checks.

Differential Revision: https://reviews.llvm.org/D109905
2021-09-16 15:52:45 -07:00
Mehdi Amini
0dc461441e Revert "[flang] Make 'this_image()' an intrinsic function"
This reverts commit 81f8ad1769.
This seems to break the shared libs build
(linaro-flang-aarch64-sharedlibs bot) with:

  undefined reference to `Fortran::semantics::IsCoarray(Fortran::semantics::Symbol const&)

(from tools/flang/lib/Evaluate/CMakeFiles/obj.FortranEvaluate.dir/tools.cpp.o)

When linking lib/libFortranEvaluate.so.14git
2021-09-15 03:28:34 +00:00
Craig Rasmussen
81f8ad1769 [flang] Make 'this_image()' an intrinsic function
Added 'this_image()' to the list of functions that are evaluated as intrinsic.
Added IsCoarray functions to determine if an expression is a coarray (corank > 1).

Added save attribute to coarray variables in test file, this_image.f90.

reviewers: klausler, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D108059
2021-09-14 16:40:08 -07:00
PeixinQiao
2685212184 [flang][OpenMP] Add semantic check for threadprivate directive
This patch implements the following check for THREADPRIVATE construct:
```
A variable that is part of another variable (as an array, structure
element or type parameter inquiry) cannot appear in a threadprivate
directive.
```

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109685
2021-09-15 00:22:03 +08:00
Arnamoy Bhattacharyya
b9a8f34d47 [flang][OpenMP] Add parsing support for nontemporal clause.
This patch adds parsing support for the nontemporal clause.  Also adds a couple of test cases.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D106896
2021-09-13 15:25:47 -04:00
Nico Weber
648feabc65 [clang] Make the driver not diagnose errors on nonexistent linker inputs
When nonexistent linker inputs are passed to the driver, the linker
now errors out, instead of the compiler. If the linker does not run,
clang now emits a "warning: linker input unused" instead of an error
for nonexistent files.

The motivation for this change is that I noticed that
`clang-cl /winsysroot sysroot main.cc ole32.lib` emitted a
"ole32.lib not found" error, even though the linker finds it just fine when
I run `clang-cl /winsysroot sysroot main.cc /link ole32.lib`.

The same problem occurs if running `clang-cl main.cc ole32.lib` in a
non-MSVC shell.

The problem is that DiagnoseInputExistence() only looked for libs in %LIB%,
but MSVCToolChain uses much more involved techniques.

For this particular problem, we could make DiagnoseInputExistence() ask
the toolchain to see if it can find a .lib file, but in general the
driver can't know what the linker will do to find files, so it shouldn't
try. For example, if we implement PR24616, lld-link will look in the
registry to determine a good default for %LIB% if it isn't set.

This is less or a problem for the gcc driver, since .a paths there are
either passed via -l flags (which honor -L), or via a qualified path
(that doesn't honor -L) -- but for example ld.lld's --chroot flag
can also trigger this problem. Without this patch,
`clang -fuse-ld=lld -Wl,--chroot,some/dir /file.o` will complain that
`/file.o` doesn't exist, even though
`clang -fuse-ld=lld -Wl,--chroot,some/dir -Wl,/file.o` succeeds just fine.

This implements rnk's suggestion on the old bug PR27234.

Differential Revision: https://reviews.llvm.org/D109624
2021-09-13 08:57:38 -04:00
Jean Perier
d892d7323e [flang] Fix common block size extension mistake in D109156
https://reviews.llvm.org/D109156 did not properly update the case where
the equivalence symbol appearing in the common statement is the
"base symbol of an equivalence group" (this was the only case that previously
worked ok, and the patch broke it).

Fix this and add a test that actually uses this code path.

Differential Revision: https://reviews.llvm.org/D109439
2021-09-09 09:12:12 +02:00
peter klausler
43a263f570 [flang] Implement semantic checks for ELEMENTAL subprograms
Adds missing semantic checks for ELEMENTAL functions and subroutines,
their dummy arguments, and their results from F'2018 15.8.1 C15100-15102.

Differential Revision: https://reviews.llvm.org/D109380
2021-09-07 14:37:23 -07:00
peter klausler
c9e9635ffe [flang] evaluate: Fold SQRT, HYPOT, & CABS
Implement IEEE Real::SQRT() operation, then use it to
also implement Real::HYPOT(), which can then be used directly
to implement Complex::ABS().

Differential Revision: https://reviews.llvm.org/D109250
2021-09-07 10:33:11 -07:00
Ivan Zhechev
dc453dcf76 [Flang] Port test_modfile.sh to Python
To enable Flang testing on Windows, shell scripts have
to be ported to Python. The following changes have been made:
"test_modfile.sh" has been ported to Python, and
the relevant tests relying on it.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D107956
2021-09-06 13:57:36 +00:00