Commit graph

512 commits

Author SHA1 Message Date
Jinxin (Brian) Yang
5330ebbc4a [flang] [OpenMP] Canonicalization framework (flang-compiler/f18#599)
* [OpenMP] Canonicalization framework

This is mainly designed for loop association work but can be used for others,
and `CanonicalizeOmp` must be after `CanonicalizeDo`.

At the `Block` level, recognize legal sequence of `OpenMPLoopConstruct`,
`DoConstruct`, and `OmpEndLoopDirective`. Move available `DoConstruct`
and optional `OmpEndLoopDirective` into `OpenMPLoopConstruct`. Throw error
messages if:
 1. `DoConstruct` is not following `OpenMPLoopConstruct`
 2. `OmpEndLoopDirective` is not following associated do-loop

Once this pass this done, Semantics will not proceed if error exists.

* Update on reviews

1. extract matching and move part into its own function (once `DoConstruct`
   is moved, see whether `OpenMPEndLoopDirective` is available)

2. Use a template function to access construct from ExecutionPartConstruct.

3. Move this code into namespace semantics

Original-commit: flang-compiler/f18@52979f1e93
Reviewed-on: https://github.com/flang-compiler/f18/pull/599
2019-08-22 10:34:15 -07:00
Jinxin (Brian) Yang
ca5fee5375 [flang] [OpenMP] miscellaneous parse tree fix (flang-compiler/f18#669)
Fix `aligned(argument-list[ : alignment])` for `declare simd`

(original implementation will throw parser error if `: alignment` is present.


Original-commit: flang-compiler/f18@f3f50f9ad3
Reviewed-on: https://github.com/flang-compiler/f18/pull/669
2019-08-20 10:30:29 -07:00
Jinxin (Brian) Yang
39be4ad473 [flang] [OpenMP] parse tree fix for Declare Target (flang-compiler/f18#670)
The original implementation will throw parsing error for multiple
clauses on `declare target` directive, for example:
```
!$omp declare target to(Q) link(R)
```

Based on the OpenMP Spec, we only need two types for the specifier:

```
!$omp declare target (extended-list)
```
or
```
!$omp declare target [clause[ [,] clause] ... ]
```

This fix makes `declare target` accepts either the `list` or `clauses`,
which is more general and better for error messages.

Adjusted existing test for checking the parse tree changes. More tests
will be added during Semantics.

Original-commit: flang-compiler/f18@60f47fc1a1
Reviewed-on: https://github.com/flang-compiler/f18/pull/670
2019-08-20 10:23:56 -07:00
peter klausler
10688e0903 [flang] Enable more warnings, deal with fallout
Original-commit: flang-compiler/f18@65c5b485af
Reviewed-on: https://github.com/flang-compiler/f18/pull/666
Tree-same-pre-rewrite: false
2019-08-16 09:41:07 -07:00
peter klausler
73632f5c36 [flang] Enable some new warnings, clean up some of their consequences
Original-commit: flang-compiler/f18@b82d1e9ac9
Reviewed-on: https://github.com/flang-compiler/f18/pull/666
Tree-same-pre-rewrite: false
2019-08-16 09:41:06 -07:00
Jinxin (Brian) Yang
bcaba6e571 [flang] [OpenMP] parse tree changes for OpenMPLoopConstruct (flang-compiler/f18#656)
1. Following Block and Sections constructs, re-structure loop related
   constructs into `{Begin, Loop, End}`. Being part of the work in
   PR flang-compiler/f18#599, the `Loop` and `End` nodes are optional during parser. They
   should be filled in during the phase of `CanonicalizationOfOmp`. This
   commit is solely for the parse tree change. So, after this commit,
   PR flang-compiler/f18#599 needs to be changed accordingly.

2. Removed parse tree nodes for `END DO` and `END DO SIMD`. Similar to
   Block and Sections constructs, `End` node now accepts clauses too,
   the validity checks are deferred into Semantics. This is more genernal
   and error message could be better.

3. With this commit alone, assertion error would occur when `End` directive
   is present, for example `!$OMP END DO` because the `End` node is not
   moved into `OpenMPLoopConstruct` yet. Again, PR flang-compiler/f18#599 will handle that.

More tests will be added in PR flang-compiler/f18#599 and during the future Semantics work.

Original-commit: flang-compiler/f18@8cd1932fd6
Reviewed-on: https://github.com/flang-compiler/f18/pull/656
2019-08-14 15:16:27 -07:00
Jinxin (Brian) Yang
e59305d7ae [flang] [OpenMP] parse tree changes for Sections/Parallel Sections constructs (flang-compiler/f18#652)
```
!$omp sections [clause[ [,] clause] ... ]
[!$omp section]
structured-block
[!$omp section
structured-block]
...
!$omp end sections [nowait]
```

1. Following parse tree node changes for Block constructs, changing the
   Sections/Parallel Sections to `{Begin, Section-Blocks, End}`

2. Handles `!$omp section` in the parser, do not create parse tree node
   for this directive because basically it is a delimiter to split the
   code into different `Block`s within the Sections/Parallel Sections
   constructs. So, the `Section-Blocks` here is a `std::list` of `Block`s.
   (thanks to Tim's suggestion)

3. Modify check-omp-structure.* to avoid breaking existing tests

More tests will be added during Semantics. Also, similar to Block constructs,
the `Begin` and `End` directive matching will be done in future PR.

This commit also contains Peter's important fix for allowing "!$OMP END SECTION"
as a legal statement following `Block` (daf5630: Modify execution part error
recovery to not consume !$OMP SECTION).


Original-commit: flang-compiler/f18@75d016f6d2
Reviewed-on: https://github.com/flang-compiler/f18/pull/652
2019-08-14 08:42:28 -07:00
Jinxin (Brian) Yang
65de6787e2 [flang] [OpenMP] parse tree changes for Critical Construct (flang-compiler/f18#641)
Simple changes: add source provenance for directive itself and renaming

Original-commit: flang-compiler/f18@9246d266b0
Reviewed-on: https://github.com/flang-compiler/f18/pull/641
2019-08-12 16:08:10 -07:00
Jinxin (Brian) Yang
b41d10beae [flang] [OpenMP] parse tree changes for OpenMPBlockConstruct (flang-compiler/f18#632)
* [OpenMP] parse tree changes for `OpenMPBlockConstruct`

1. merge `Workshare` and `Single` into `OpenMPBlockConstruct` because
   they both accept structured-block and syntax is similar to other block
   directives.

2. `OpenMPBlockConstruct` changes to structure like `{Begin, Block, End}`,
   where `Begin` and `End` are tuple of `{Directive, ClauseList}`.

3. Updated the check-omp-structure.* for necessary parts. Added all the END
   directive enumeration types that may have clauses.

More tests will be added during Semantics.

* [OpenMP] Update on Tim's suggestion

1. Fix unspecified enumeration for `OmpDirective` in the `OmpContext`.
   This is through getting rid of `PushContext(source)` function to
   make sure whenever it is about to push a NEW context, directive
   source location and enumeration are available. To do that, I moved
   around all the switches for directive into high level `Construct`'s
   `Enter` node. Besides fixing the issue, the side benefit is that
   whenever we call `GetContext().directive`, we are sure that the
   `directive` here was set already.

2. When `Enter` the `OmpEndBlockDirective` node, partial context
   information, such as directive source location or legal clause lists,
   needs to be reset. The new directive source location should be
   `OmpEndBlockDirective`'s `source`. The enumeration `directive`
   should not be reset for the END directives that do not accept
   clauses because nothing needs to be checked (for example any clause
   that is on `END PARALLEL` is illegal).

Original-commit: flang-compiler/f18@e5bd6b7ba0
Reviewed-on: https://github.com/flang-compiler/f18/pull/632
2019-08-09 15:11:20 -07:00
peter klausler
c9d286d6c4 [flang] Restore symbol to ProcBindingDetails
Original-commit: flang-compiler/f18@5dc1c91156
Reviewed-on: https://github.com/flang-compiler/f18/pull/638
Tree-same-pre-rewrite: false
2019-08-09 09:41:50 -07:00
Jinxin (Brian) Yang
c7fc08a8ea [flang] [OpenMP] parse tree changes for ATOMIC constructs (flang-compiler/f18#636)
1. make the parse tree nodes more conform with OpenMP spec

2. isolate the memory related clauses to make the parse tree nodes
   extendable for OpenMP 5.0

3. source provenance is saved for each atomic-clause (read, write, update,
   and capture); for atomic-clause that is not present, source location
   is saved for "ATOMIC" directive name itself

More tests will be added during Semantics.

Original-commit: flang-compiler/f18@8e2db2f868
Reviewed-on: https://github.com/flang-compiler/f18/pull/636
2019-08-09 09:39:55 -07:00
Caroline Concatto
f4a6fe026d [flang] Removing TODO comments as they are implemented by this patch
Original-commit: flang-compiler/f18@885eb92b4f
Reviewed-on: https://github.com/flang-compiler/f18/pull/584
2019-08-07 08:48:31 +01:00
Tim Keith
4887ae80cd [flang] Perform more checks on array-specs
There are many constraints on what kind of array-specs can appear
in what contexts. Add `CheckArraySpec()` to perform most of them.
When the check fails, don't set the shape of the symbol being
declared and instead set the Error flag so we can avoid cascading
errors.

Fixes flang-compiler/f18#609.

Original-commit: flang-compiler/f18@f159d97f1f
Reviewed-on: https://github.com/flang-compiler/f18/pull/630
Tree-same-pre-rewrite: false
2019-08-07 10:51:19 -07:00
Tim Keith
73738d8bba [flang] Change parsing of ambiguous array-spec
An array-spec like `(:,:)` (with one or more colons) is either a
deferred-shape-spec-list or an assumed-shape-spec-list and they
can only be distinguished by context that the parser doesn't have.

We were parsing these as assumed-shape-spec-list but they are easier
to deal with if we parse them as deferred-shape-spec-list because
anything that is the latter is also one of the former.

Original-commit: flang-compiler/f18@78c3f3b96f
Reviewed-on: https://github.com/flang-compiler/f18/pull/630
Tree-same-pre-rewrite: false
2019-08-07 10:49:54 -07:00
Tim Keith
80678685a3 [flang] Add operator<< for parser::CharBlock
Original-commit: flang-compiler/f18@439326dc96
Reviewed-on: https://github.com/flang-compiler/f18/pull/630
Tree-same-pre-rewrite: false
2019-08-07 10:49:54 -07:00
Jinxin (Brian) Yang
c4e13f6be8 [flang] [OpenMP] parse tree changes for standalone directives (flang-compiler/f18#627)
* [OpenMP] parse tree changes for standalone directives

1. Put all standalone directives except FLUSH, CANCEL, and CANCELLATION POINT
   into one `OpenMPSimpleStandaloneConstruct` (for no-clause directive,
   validity checks will be deferred to Semantics). A top-level class will
   include all the standalone directive nodes. This simplies the logic a lot.

2. All the standalone directives now have their own source provenance for
   directive name itself.

3. Change check-omp-structure.* to avoid assertions

4. Add basic tests for standalone directives, more will be added during
   the clause validity checks in Semantics

* Resolve !$OMP ORDERED ambiguity by attempting block construct first - Peter

Original-commit: flang-compiler/f18@a77aa7ed84
Reviewed-on: https://github.com/flang-compiler/f18/pull/627
2019-08-06 11:59:40 -07:00
Jinxin (Brian) Yang
deae08c21e [flang] [OpenMP] parse tree changes for declarative directives (flang-compiler/f18#620)
1. Changes are to save provenance for directive names
2. check-omp-structure.* is updated to avoid assertion errors
3. Tests added now are only for the basic usages for the declarative directives,
   more complete examples will be added once we start implementing the semantics
   checks for declarative directives

Original-commit: flang-compiler/f18@433e274f68
Reviewed-on: https://github.com/flang-compiler/f18/pull/620
2019-08-05 14:51:02 -07:00
Jinxin (Brian) Yang
cdd1ca064c [flang] [OpenMP] Add Sections and Single Construct check (flang-compiler/f18#585)
* [OpenMP] Add Sections and Single Construct check

Parse tree for OmpEndSingle needs to be modified to save the provenance
of END SINGLE directive and check its own clauses

* Update on reviews

1. PushContext is created to push new context with source provenance

2. Tweak the logic for SECTION nesting, treak Orphaned or wrong nesting
   as the same error type

3. Make sure the check for NOWAIT clause only applies to the ones that
   are not handled by parser.
   Note that the case for DO or DO_SIMD will take effect after the
   loop association work (parse tree change) is done. But I still list
   them there for completeness.

4. Happen to find that NOWAIT is not accepted by PARALLEL SECTIONS,
   fixed it in the parser.


Original-commit: flang-compiler/f18@236cf1efea
Reviewed-on: https://github.com/flang-compiler/f18/pull/585
2019-08-01 14:32:33 -07:00
peter klausler
85db492ea0 [flang] Support SELECTED_CHAR_KIND("DEFAULT")
Original-commit: flang-compiler/f18@c05c96c474
Reviewed-on: https://github.com/flang-compiler/f18/pull/590
Tree-same-pre-rewrite: false
2019-07-17 15:58:28 -07:00
Jean Perier
16cf494888 [flang] Add non standard feature for labeled do not ending with END DO or CONTINUE
* The warning was already here, this commit only refactors things so that
 it can be controled with -Mstandard.
* Also makes the warning point to the do-stmt and adds a note to the warning
  pointing to the statements where it ends.

Original-commit: flang-compiler/f18@11e1eb6edd
Reviewed-on: https://github.com/flang-compiler/f18/pull/552
Tree-same-pre-rewrite: false
2019-07-09 11:54:40 -07:00
peter klausler
3d8b3ddef0 [flang] Separate keyword from clauses in provenance of construct directives
Original-commit: flang-compiler/f18@9994d2351e
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
2019-07-15 13:05:30 -07:00
peter klausler
ef59f7ad12 [flang] Ensure that provenance is preserved in move ctor/assignment of Verbatim
Original-commit: flang-compiler/f18@fcb5513486
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:30 -07:00
peter klausler
5557fff6e8 [flang] Complete source provenance on OMP constructs (except ATOMIC)
Original-commit: flang-compiler/f18@8f6e93d579
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:29 -07:00
peter klausler
521a9770af [flang] Combine BARRIER/TASKWAIT/TASKYIELD
Original-commit: flang-compiler/f18@c56c893a05
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:28 -07:00
peter klausler
6599bdf9b5 [flang] Convert more empty classes to enums
Original-commit: flang-compiler/f18@9cf8b9eea7
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:28 -07:00
peter klausler
2075e06dff [flang] Change more empty classes into enums
Original-commit: flang-compiler/f18@e73b0368b2
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:27 -07:00
peter klausler
2d0f9636a8 [flang] Change some empty classes into enums
Original-commit: flang-compiler/f18@652e474556
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:27 -07:00
peter klausler
a3242b8107 [flang] more progress
Original-commit: flang-compiler/f18@1a219e5073
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:26 -07:00
peter klausler
1a26c576de [flang] Eliminate a lot of needless indirection in OMP data structures
Original-commit: flang-compiler/f18@47c6cb0ba9
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:25 -07:00
peter klausler
b85df73935 [flang] Restore alphabetical order to OpenMP nodes in parse tree dumper
Original-commit: flang-compiler/f18@88b1a26035
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:24 -07:00
peter klausler
51b43e9e48 [flang] Define and use OpenMPConstructDirective
Original-commit: flang-compiler/f18@cd716fa907
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:24 -07:00
peter klausler
bdec2cd8c9 [flang] Refinements; builds and passes tests again
Original-commit: flang-compiler/f18@a83410a440
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:23 -07:00
peter klausler
40c797d773 [flang] Add "..."_id token syntax for complete tokens with lookahead
Original-commit: flang-compiler/f18@19695ccfa4
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
2019-07-15 13:05:22 -07:00
peter klausler
ed2213bb51 [flang] Ensure that no OMP clause is a prefix of a later one in the grammar; then alphabetize the order.
Original-commit: flang-compiler/f18@7f4b4f8e74
Reviewed-on: https://github.com/flang-compiler/f18/pull/566
2019-07-11 15:30:32 -07:00
Jinxin Yang
ca3dc401a9 [flang] add ORDERED construct w/ THREADS and SIMD clauses (parse error)
Original-commit: flang-compiler/f18@23a71aed74
Reviewed-on: https://github.com/flang-compiler/f18/pull/566
Tree-same-pre-rewrite: false
2019-07-11 15:30:32 -07:00
peter klausler
28f4c5ca2d [flang] Update grammar and a test in light of C1516
Original-commit: flang-compiler/f18@df4ddccde7
Reviewed-on: https://github.com/flang-compiler/f18/pull/557
2019-07-10 16:42:10 -07:00
peter klausler
2ccba3837d [flang] Do not emit PROCEDURE(TYPE(REAL)), pgf90 cannot deal. Use PROCEDURE(REAL).
Original-commit: flang-compiler/f18@ee5f392381
Reviewed-on: https://github.com/flang-compiler/f18/pull/557
Tree-same-pre-rewrite: false
2019-07-10 16:42:08 -07:00
peter klausler
24eb863fda [flang] Quick additional fix for crashes on statement functions without arguments
Original-commit: flang-compiler/f18@79779967a9
Reviewed-on: https://github.com/flang-compiler/f18/pull/548
2019-07-03 13:04:56 -07:00
peter klausler
c180c0229f [flang] Trim duplicate error messages on intrinsics, and fix FINDLOC for Character data.
Original-commit: flang-compiler/f18@48ab22e213
Reviewed-on: https://github.com/flang-compiler/f18/pull/548
Tree-same-pre-rewrite: false
2019-07-03 12:30:28 -07:00
peter klausler
dbb202c5be [flang] Extirpate NCHARACTER type, NC"" literals, and EUC-JP Hollerith
Original-commit: flang-compiler/f18@10a592a591
Reviewed-on: https://github.com/flang-compiler/f18/pull/535
Tree-same-pre-rewrite: false
2019-06-28 11:22:43 -07:00
peter klausler
4470eddabd [flang] Work around GCC 7.2.0 build issue
Original-commit: flang-compiler/f18@c68349f78f
Reviewed-on: https://github.com/flang-compiler/f18/pull/531
Tree-same-pre-rewrite: false
2019-06-28 09:21:00 -07:00
peter klausler
98e3113206 [flang] Better initialization support
Original-commit: flang-compiler/f18@ff2f26fe7b
Reviewed-on: https://github.com/flang-compiler/f18/pull/531
Tree-same-pre-rewrite: false
2019-06-28 09:16:46 -07:00
peter klausler
56a1941f7f [flang] More extension names
Original-commit: flang-compiler/f18@f30d4cf73d
Reviewed-on: https://github.com/flang-compiler/f18/pull/531
Tree-same-pre-rewrite: false
2019-06-28 09:16:43 -07:00
Peter Waller
c9944df916 [flang] Revert "Remove needless braces"
This reverts commit edd18355be574122aaa9abf58c15d8c50fb085a1.

Original-commit: flang-compiler/f18@e5d164fd11
Reviewed-on: https://github.com/flang-compiler/f18/pull/532
2019-06-26 09:44:08 +00:00
Jinxin (Brian) Yang
125f295353 [flang] OpenMP structural check framework (PARALLEL as example) (flang-compiler/f18#493)
This patch is to show the framework to do OpenMP structure related check and you may find missing/incomplete implementation, which will be added in the future.

1. Each encountering construct has its own context and the context info will be filled while walking the directive/clause nodes. In the `Leave`, the current OpenMP context will be popped out.

2. When entering the construct, necessary nesting check will be performed. Use std::vector to implement the context stack because certain nesting restrictions may need to trace back more than one level.

3. PARALLEL construct is used as an example for clause validity check.

4. `EnumSet` is used to represent the directive/clause sets and to show the error msg. All the error msgs are quoted from the specification.

5. Necessary `CharBlock` is added for error msgs.

Original-commit: flang-compiler/f18@620441c03e
Reviewed-on: https://github.com/flang-compiler/f18/pull/493
2019-06-25 16:18:51 -07:00
peter klausler
9a9b450011 [flang] EQUIVALENCE numeric/character as extension with warning
Original-commit: flang-compiler/f18@0182efb759
Reviewed-on: https://github.com/flang-compiler/f18/pull/508
Tree-same-pre-rewrite: false
2019-06-19 16:34:50 -07:00
peter klausler
4f2c8fae65 [flang] Fix source provenance of .NOT., add ALLOCATED intrinsic
Original-commit: flang-compiler/f18@e7e0de9e0d
Reviewed-on: https://github.com/flang-compiler/f18/pull/505
Tree-same-pre-rewrite: false
2019-06-19 11:50:07 -07:00
peter klausler
7d24cebc17 [flang] Rearrange some move(get<>()) calls into get<>(move()) to dodge GCC possibly-uninit warnings (bogus)
Original-commit: flang-compiler/f18@f369c6025c
Reviewed-on: https://github.com/flang-compiler/f18/pull/503
Tree-same-pre-rewrite: false
2019-06-18 15:15:22 -07:00
peter klausler
f753cf3eb0 [flang] Review comments and last (?) bugs
Original-commit: flang-compiler/f18@db8302e3ab
Reviewed-on: https://github.com/flang-compiler/f18/pull/496
2019-06-18 13:46:54 -07:00
peter klausler
fdcdd504b3 [flang] more fixes from tests
Original-commit: flang-compiler/f18@bb8df72635
Reviewed-on: https://github.com/flang-compiler/f18/pull/496
Tree-same-pre-rewrite: false
2019-06-18 12:34:23 -07:00