Commit Graph

73 Commits

Author SHA1 Message Date
Mats Petersson
040e0d4fa4 [flang]Accept directive inside type definition (#87804)
Some applications have alignment directives for members inside types.

This allows those to be present, but generally getting ignored [with a warning]
later on in the processing. This is just to allow the compilation to complete.
2024-04-09 12:54:24 +01:00
Peter Klausler
6e261d9c37 [flang] Accept more unrecognized !DIR$ compiler directives (#85829)
When encountering an unparsable !DIR$ compiler directive line, accept it
as a whole source line and emit a warning that it is unrecognizable.

Fixes https://github.com/llvm/llvm-project/issues/59107,
https://github.com/llvm/llvm-project/issues/82212, and
https://github.com/llvm/llvm-project/issues/82654.
2024-03-26 08:46:21 -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
Peter Klausler
60fa2b0670 [flang] Parse !$CUF KERNEL DO <<< (*) (#85338)
Accept and represent asterisks within the parenthesized grid and block
specification lists.
2024-03-15 13:57:42 -07:00
Mats Petersson
601a9587a1 [Flang] Add support for assume_aligned directive (#81747)
This adds the parsing (and unparse) of the compiler drective assume_aligned.

The compiler will issue a warning that the directive is ignored.
2024-03-01 15:28:20 +00:00
Peter Klausler
7c55dd8de6 [flang] Accept multiple spaces after compiler directive sentinel (#76541)
The prescanner allows multiple spaces within a compiler directive, but
not between the directive's sentinel (e.g., !DIR$) and the directive's
first token.

Fixes https://github.com/llvm/llvm-project/issues/76537.
2024-01-02 09:15:04 -08:00
harishch4
482a37b860 [Flang][OpenMp]Add testcase for threadprivate with blank common block (#74969) 2023-12-18 18:27:34 +05:30
Peter Klausler
ea3a3b25b9 [flang] Handle continuation line edge case (#74751)
For a character literal that is split over more than one source line
with free form line continuation using '&'
at the end of one line but missing the standard-required '&' on the
continuation line, also handle the case of spaces at the beginning of
the continuation line.
    
For example,
    
PRINT *, 'don'&
   't poke the bear'
    
now prints "don't poke the bear", like nearly all other Fortran
compilers do.
    
This is not strictly standard conforming behavior, and the compiler
emits a portability warning with -pedantic.
    
Fixes llvm-test-suite/Fortran/gfortran/regression/continuation_1.f90,
.../continuation_12.f90, and .../continuation_13.f90.
2023-12-11 13:09:12 -08:00
Valentin Clement (バレンタイン クレメン)
f4c5c470cd [flang][openacc] Enforce no branching out of compute region for combined construct (#73581)
`A program may not branch into or out of a compute construct.` This
restriction is also true for combined constructs. This patch enforce
this rule.
2023-11-28 08:50:30 -08:00
Shraiysh
8840eb3fb5 [flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -06:00
Shraiysh
c06700bd75 Revert "[flang][OpenMP] Add semantic check for declare target" (#72592)
Reverts llvm/llvm-project#71861
2023-11-16 19:17:56 -06:00
Shraiysh
7ff8094a39 [flang][OpenMP] Add semantic check for declare target (#71861)
This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE
TARGET` construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```

Based on the tests for to clause, the tests for enter clause are added.

This patch does not add tests where both to and enter clause are used together.
2023-11-16 18:03:32 -06:00
Peter Klausler
1c91d9bdea [flang] Ensure that portability warnings are conditional (#71857)
Before emitting a warning message, code should check that the usage in
question should be diagnosed by calling ShouldWarn(). A fair number of
sites in the code do not, and can emit portability warnings
unconditionally, which can confuse a user that hasn't asked for them
(-pedantic) and isn't terribly concerned about portability *to* other
compilers.

Add calls to ShouldWarn() or IsEnabled() around messages that need them,
and add -pedantic to tests that now require it to test their portability
messages, and add more expected message lines to those tests when
-pedantic causes other diagnostics to fire.
2023-11-13 16:13:50 -08:00
Shraiysh
97c9c9429c [flang][OpenMP] Added semantic checks for target update (#71270)
This patch adds the following semantic check for target update

```
At least one motion-clause must be specified.
```

A motion clause is either a `to` or a `from` clause.

This patch also adds a test for the following semantic check which was
already supported.

```
At most one nowait clause can appear on the directive.
```
2023-11-04 15:20:43 -05:00
SiHuaN
8b91de5d6a [Flang][OpenMP] Correctly handling continuation lines with Fixed Source Form Conditional Compilation Sentinels (#70309)
Fixes #67947

---------

Co-authored-by: SiHuaN <liyongtai@iscas.ac.cn>
Co-authored-by: Leandro Lupori <leandro.lupori@gmail.com>
2023-11-01 09:05:33 +08:00
Z572
7de70e0f72 [Flang][OpenMP] Fix comments that should not be Sentinels on fixed format. (#68911)
Fixes #68653
2023-10-31 00:20:00 +08:00
Valentin Clement
2991c39de5 [flang][openacc] Fix unparsing of bind clause on acc routine
unparsing for the bind clause was adding extra
parenthesis. This patch fixes that.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158210
2023-08-17 14:02:17 -07:00
Sergio Afonso
65e80d6dfd [Flang][OpenMP] Improve support for if clause on combined constructs
This patch adds support for matching multiple OpenMP `if` clauses to their
specified directive in a combined construct. It also enables this clause to be
attached by name to `simd` and `teams` directives, in addition to the others
that were already supported.

This patch on its own cannot yet be tested because there is currently no
lowering to MLIR support for any combined construct containing two or more
OpenMP directives that can have an `if` clause attached.

Depends on D155981.

Differential Revision: https://reviews.llvm.org/D156313
2023-08-04 10:43:12 +01:00
Peter Klausler
2734f15437 [flang][openmp] Handle !$INCLUDE "foo" (bug #64128)
Detect and process INCLUDE lines that are guarded by OpenMP conditional
compilation markers (!$), when enabled.

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

Differential Revision: https://reviews.llvm.org/D156759
2023-08-01 11:35:23 -07:00
Peter Klausler
28eec1bd85 [flang] Portability warning and documentation for an obscure extension
A quotation mark can appear in a Fortran character literal by doubling
it; for example, PRINT *, "'""'" prints '"'.  When those doubled
quotation marks are split by a free form line continuation, the
continuation line should have an ampersand before the second quotation
mark.  But most compilers, including this one, allow the second
quotation mark to appear as the first character on the continuation
line, too.

So this works:

  print *, "'"&
"'"

but it really should be written as:

  print *, "'"&
&"'"

Emit a portability warning and document that we support this near-universal
extension.

Differential Revision: https://reviews.llvm.org/D155973
2023-07-21 14:30:40 -07:00
Peter Klausler
d78701e51f [flang] Fix minor nits with INCLUDE line recognition
Fix some problems with INCLUDE line recognition pointed out by some
recently-added tests to the LLVM test suite.

Differential Revision: https://reviews.llvm.org/D155497
2023-07-17 12:58:26 -07:00
Peter Klausler
e12ffe6a93 [flang] Honor #line and related preprocessing directives
Extend the SourceFile class to take account of #line directives
when computing source file positions for error messages.
Adjust the output of #line directives to -E output so that they
reflect any #line directives that were in the input.

Differential Revision: https://reviews.llvm.org/D153910
2023-06-29 08:27:37 -07:00
Valentin Clement
5923e46fce [flang][openacc] Add parsing support for dim in gang clause
Add parsing supprot for dim in gang clause

Depends on D151971

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151972
2023-06-13 20:33:36 -07:00
Valentin Clement
ae86fe8591 [flang][openacc] Add parser support for the force modifier in the collapse clause
This patch adds parser support for the force modifier on the collapse clause
introduced in OpenACC 3.3.
Lowering will currently hit a TODO as the MLIR representation of the acc.loop
might need some update.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D151974
2023-06-12 11:01:59 -07: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
Leandro Lupori
0e1fa91740 [flang] Fix character initialization after continuation
The insertion of a space on a line continuation right before
a character literal was confusing TokenSequence::ToLowerCase(),
that was unable to identify the character literal as such,
causing it to be converted to lower case.

Fix this by skipping spaces in the beginning and end of each
token, before testing for token type.

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

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D151885
2023-06-01 16:48:11 -03:00
Peter Klausler
f513bd8088 [flang] CUDA Fortran - part 4/5: definability and characteristics
Extend the definability and procedure characteristics checking
infrastructure in semantics to check for context-dependent CUDA object
definability violations and problems with CUDA attribute incompatibility
in procedure interfaces.

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

Differential Revision: https://reviews.llvm.org/D150163
2023-05-31 14:25:38 -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
Peter Klausler
4ad7279392 [flang] CUDA Fortran - part 1/5: parsing
Begin upstreaming of CUDA Fortran support in LLVM Flang.

This first patch implements parsing for CUDA Fortran syntax,
including:
 - a new LanguageFeature enum value for CUDA Fortran
 - driver change to enable that feature for *.cuf and *.CUF source files
 - parse tree representation of CUDA Fortran syntax
 - dumping and unparsing of the parse tree
 - the actual parsers for CUDA Fortran syntax
 - prescanning support for !@CUF and !$CUF
 - basic sanity testing via unparsing and parse tree dumps

... along with any minimized changes elsewhere to make these
work, mostly no-op cases in common::visitors instances in
semantics and lowering to allow them to compile in the face
of new types in variant<> instances in the parse tree.

Because CUDA Fortran allows the kernel launch chevron syntax
("call foo<<<blocks, threads>>>()") only on CALL statements and
not on function references, the parse tree nodes for CallStmt,
FunctionReference, and their shared Call were rearranged a bit;
this caused a fair amount of one-line changes in many files.

More patches will follow that implement CUDA Fortran in the symbol
table and name resolution, and then semantic checking.

Differential Revision: https://reviews.llvm.org/D150159
2023-05-31 09:48:59 -07:00
Kelvin Li
2849e11907 [flang] Handle @PROCESS directive
Treat lines that start with @process as a comment line. The directive
is accepted and ignored.

Differential Revision: https://reviews.llvm.org/D150883
2023-05-21 22:37:28 -04:00
Peter Klausler
60b673023f [flang] Better error recovery for missing THEN in IF construct
Presented with "IF (...)" with no following tokens in the statement,
diagnose a missing "THEN" instead of complaining about all of the
possible action statement initial tokens that could have been there
for a non-construct IF statement.

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

Differential Revision: https://reviews.llvm.org/D150783
2023-05-18 11:41:07 -07:00
Peter Klausler
cbc5d42fce [flang] Allow compiler directives in macros
Modify the prescanner to allow compiler directives to appear in
macro expansions, and adjust the parser to accept a semicolon
as a directive terminator.

Differential Revision: https://reviews.llvm.org/D150780
2023-05-18 11:04:30 -07:00
Peter Klausler
a6569e578e [flang] Don't mistakenly tokenize a Hollerith literal from "DO 100 H=..." (bug #58732)
After tokenizing an identifier, don't allow the next token to be a
Hollerith literal.

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

Differential Revision: https://reviews.llvm.org/D150406
2023-05-16 09:56:22 -07:00
Ethan Luis McDonough
6311ab2147 [Flang] Syntax support for OMP Allocators Construct
OpenMP 5.2 introduces a Fortran specific construct that aims to replace the executable allocate directive.  This patch seeks to add parser support for the directive as well as the allocator clause with the [[ https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-2.pdf#section.6.6 | extended align/complex ]] modifier.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D149727
2023-05-10 14:57:20 -05:00
Ethan Luis McDonough
42df495114 [flang] OpenMP allocate directive parse tree fix
Addresses the same issue as the following abandoned revision: D104391.

Rewrite leading declarative allocations so they are nested within their respective executable allocate directive

Original:
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPExecutableAllocate

After rewriting:
ExecutionPartConstruct -> OpenMPExecutableAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate

Reviewed By: kiranchandramohan

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

Co-authored-by: Isaac Perry <isaac.perry@arm.com>
2023-05-05 15:50:49 -05:00
Ethan Luis McDonough
a6e616cdb1 Revert "[flang] OpenMP allocate directive parse tree fix"
This reverts commit 597d8563cd.
2023-05-05 15:47:00 -05:00
Ethan Luis McDonough
597d8563cd [flang] OpenMP allocate directive parse tree fix
Addresses the same issue as the following abandoned revision: D104391.

Rewrite leading declarative allocations so they are nested within their respective executable allocate directive

Original:
```
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPExecutableAllocate
```

After rewriting:
```
ExecutionPartConstruct -> OpenMPExecutableAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
```

Co-authored-by: Isaac Perry <isaac.perry@arm.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148409
2023-05-05 14:55:25 -05:00
Ethan Luis McDonough
936d40cdb5 Revert "[flang] OpenMP allocate directive parse tree fix"
This reverts commit 5faf45a3d2.
Once again arcanist stripped the co-author metadata.  I'm going to add it to the revision description and try one last time.
2023-05-05 14:50:14 -05:00
Ethan Luis McDonough
5faf45a3d2 [flang] OpenMP allocate directive parse tree fix
Addresses the same issue as the following abandoned revision: D104391.

Rewrite leading declarative allocations so they are nested within their respective executable allocate directive

Original:
```
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPExecutableAllocate
```

After rewriting:
```
ExecutionPartConstruct -> OpenMPExecutableAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
```

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148409
2023-05-05 14:41:15 -05:00
Ethan Luis McDonough
c89959842f Revert "[flang] OpenMP allocate directive parse tree fix"
This reverts commit eaf7d97865.
Arcanist stripped co-author data from initial commit.
2023-05-05 14:31:01 -05:00
Ethan Luis McDonough
eaf7d97865 [flang] OpenMP allocate directive parse tree fix
Addresses the same issue as the following abandoned revision: D104391.

Rewrite leading declarative allocations so they are nested within their respective executable allocate directive

Original:
```
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPExecutableAllocate
```

After rewriting:
```
ExecutionPartConstruct -> OpenMPExecutableAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
```

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148409
2023-05-05 13:53:11 -05:00
Kiran Chandramohan
3ad806a480 [Flang][OpenMP] NFC: Move OpenMP parser tests to a sub-directory
Now that the test files are in the OpenMP subdirectory, remove the
`omp` prefix.
2023-02-25 10:56:53 +00:00
Kavitha Natarajan
a7d352c76d [flang][OpenMP] Add parser support for order clause
Added parser support for OpenMP 5.0 & 5.1 feature
ORDER([order-modifier :]concurrent) clause for all
applicable and supported OpenMP directives.

Reviewed By: kiranchandramohan, abidmalikwaterloo

Differential Revision: https://reviews.llvm.org/D142524
2023-02-21 19:31:19 +05:30
Akash Banerjee
849c440226 [Flang][OpenMP] Added parser support for device_type clause
This patch adds parser suppert for the device_type clause used by the Declare Target directive.

Differential Revision: https://reviews.llvm.org/D143671
2023-02-16 14:03:34 +00:00
Peter Klausler
7c84f6a43a [flang] Emit portability warning for extension
f18 accepts statement labels in fixed form source even if they follow
a semicolon -- i.e., they're not in the fixed form's label field.
Emit a warning for such usage.

Differential Revision: https://reviews.llvm.org/D143817
2023-02-13 10:21:39 -08:00
Peter Klausler
c7f8bc0ee8 [flang][parser] Diagnose an invalid space
In free form, don't silently skip over an invalid space between
an underscore and a kind parameter.

Differential Revision: https://reviews.llvm.org/D142760
2023-01-27 14:54:53 -08:00
Nadeem, Usman
c2d8974a89 [Flang] Fix parsing error on loop count compiler directive
Fixes: https://github.com/llvm/llvm-project/issues/58731
Fixes: https://github.com/llvm/llvm-project/issues/56678

Only handles this form which was reported: `!DIR$ LOOP COUNT (n1[, n2]...)`

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

Change-Id: I768c8cb9f289c5fc4adee1ef8262c6d827574f27
2023-01-17 19:15:47 -08:00
Abid Malik
84bf4b7cdf [flang][OpenMP] Parser support for the unroll construct (5.1)
added parser support for the unroll construct

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D138229
2023-01-17 12:38:00 +00:00
Abid Malik
8feb5d419c [flang][OpenMP] Added parser support for Tile Construct ( OpenMP 5.1)
Added parser support for Tile Construct .

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D136359
2023-01-17 11:50:22 +00:00
Peter Klausler
7d147a3263 [flang] Warn on missing colons (C768)
In a derived type definition, a type bound procedure declaration
statement with neither interface nor attributes is required by constraint
C768 to have the optional "::" between the PROCEDURE keyword and the
bindings if any binding has a renaming with "=>".  The colons are
not actually necessary for a correct and unambiguous parse, so
emit a warning when they are missing.

Differential Revision: https://reviews.llvm.org/D139065
2022-12-03 09:27:39 -08:00