59 Commits

Author SHA1 Message Date
Erich Keane
fa67986d5b
[OpenACC] Private Clause on Compute Constructs (#90521)
The private clause is the first that takes a 'var-list', thus this has a
lot of additional work to enable the var-list type. A 'var' is a
traditional variable reference, subscript, member-expression, or
array-section, so checking of these is pretty minor.

Note: This ran into some issues with array-sections (aka sub-arrays)
that will be fixed in a follow-up patch.
2024-04-30 11:28:37 -07:00
Fangrui Song
76739d1256 [clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC
Remove unneeded LLVM_FALLTHROUGH added after https://reviews.llvm.org/D131346
2024-04-25 13:25:08 -07:00
Erich Keane
dc20a0ea1f
[OpenACC] Implement 'num_gangs' sema for compute constructs (#89460)
num_gangs takes an 'int-expr-list', for 'parallel', and an 'int-expr'
for 'kernels'. This patch changes the parsing to always parse it as an
'int-expr-list', then correct the expression count during Sema. It also
implements the rest of the semantic analysis changes for this clause.
2024-04-22 08:57:25 -07:00
Erich Keane
b8adf169bb [OpenACC] Implement 'vector_length' clause On compute constructs
The 'vector_length' clause is semantically identical to the
'num_workers' clause, in that it takes a mandatory single int-expr. This
is implemented identically to it.
2024-04-18 13:27:42 -07:00
Erich Keane
76600aee9d
[OpenACC] Implement 'num_workers' clause for compute constructs (#89151)
This clause just takes an 'int expr', which is not optional. This patch
implements the clause on compute constructs.
2024-04-18 12:42:22 -07:00
Erich Keane
6133878227
[OpenACC] Implement self clause for compute constructs (#88760)
`self` clauses on compute constructs take an optional condition
expression. We again limit the implementation to ONLY compute constructs
to ensure we get all the rules correct for others. However, this one
will be particularly complicated, as it takes a `var-list` for `update`,
so when we get to that construct/clause combination, we need to do that
as well.

This patch also furthers uses of the `OpenACCClauses.def` as it became
useful while implementing this (as well as some other minor refactors as
I went through).

Finally, `self` and `if` clauses have an interaction with each other, if
an `if` clause evaluates to `true`, the `self` clause has no effect.
While this is intended and can be used 'meaningfully', we are warning on
this with a very granular warning, so that this edge case will be
noticed by newer users, but can be disabled trivially.
2024-04-16 06:57:36 -07:00
Erich Keane
daa88364df
[OpenACC] Implement 'if' clause for Compute Constructs (#88411)
Like with the 'default' clause, this is being applied to only Compute
Constructs for now. The 'if' clause takes a condition expression which
is used as a runtime value.

This is not a particularly complex semantic implementation, as there
isn't much to this clause, other than its interactions with 'self',
  which will be managed in the patch to implement that.
2024-04-12 14:13:31 -07:00
erichkeane
a6d1366b73 [NFC] Remove a pair of incorrect comments from ParseOpenACC
We attempt to continue parsing, but the comment says the opposite.  Just
remove the inaccurate comments in this patch.
2024-04-10 12:42:05 -07:00
Erich Keane
0c7b92a42a
[OpenACC] Implement Default clause for Compute Constructs (#88135)
As a followup to my previous commits, this is an implementation of a
single clause, in this case the 'default' clause. This implements all
semantic analysis for it on compute clauses, and continues to leave it
rejected for all others (some as 'doesnt appertain', others as 'not
implemented' as appropriate).

This also implements and tests the TreeTransform as requested in the
previous patch.
2024-04-10 07:10:24 -07:00
erichkeane
4d6e67f677 Fix build issue committed in 26fee0ff12
I brain-farted on how assert works :)
2024-04-08 09:08:21 -07:00
Erich Keane
26fee0ff12
[OpenACC] Implement Sema work for OpenACC Clauses (#87821)
Now that we have AST nodes for OpenACC Clauses, this patch adds their
creation to Sema and makes the Parser call all the required functions.
This also redoes TreeTransform to work with the clauses/make sure they
are transformed.

Much of this is NFC, since there is no clause we can test this behavior
with. However, there IS one noticable change; we are now no longer
diagnosing that a clause is 'not implemented' unless it there was no
errors parsing its parameters. This is because it cleans up how we
create and diagnose clauses.
2024-04-08 09:05:09 -07:00
Vlad Serebrennikov
e45f6e569d
[clang] Factor out OpenACC part of Sema (#84184)
This patch moves OpenACC parts of `Sema` into a separate class
`SemaOpenACC` that is placed in a separate header `Sema/SemaOpenACC.h`.
This patch is intended to be a model of factoring things out of `Sema`,
so I picked a small OpenACC part.

Goals are the following:
1) Split `Sema` into manageable parts.
2) Make dependencies between parts visible.
3) Improve Clang development cycle by avoiding recompiling unrelated
parts of the compiler.
4) Avoid compile-time regressions.
5) Avoid notational regressions in the code that uses Sema.
2024-04-01 22:37:37 +04:00
erichkeane
bb97c99283 [OpenACC] Enable serial/kernels Compute Constructs
So far, all the work we've done for compute constructs has only used
'parallel'.  This patch does the work to enable the same logic for
'serial' and 'kernels' constructs as well, since they are the same
semantic behavior.
2024-03-04 12:47:18 -08:00
Erich Keane
26cc6f126a
[OpenACC] Implement 'break' and 'continue' errors for Compute Cnstrcts (#82543)
OpenACC3.3 2.5.4 says: "A program may not branch into or out of a
compute construct". While some of this restriction isn't particularly
checkable, 'break' and 'continue' are possible and pretty trivial, so
this patch implements those limitations.

It IS unclear in the case of a 'break' in a 'switch' what should happen
(an antagonistic reading of the standard would prevent it from
 appearing), however we're choosing to special-case the break-in-switch
to ensure that this works (albeit, a 'parallel' directive on a 'switch'
isn't particularly useful, though permitted).

Future implementations of this rule will be in a follow-up patch.
2024-02-22 09:09:08 -08:00
Erich Keane
cb89112797
[OpenACC] Implement beginning parts of the 'parallel' Sema impl (#81659)
This patch Implements AST node creation and appertainment enforcement
for 'parallel', as well as changes the 'not implemented' messages to be
more specific. It does not deal with clauses/clause legality, nor a few
of the other rules from the standard, but this gets us most of the way
for a framework for future construct implementation.
2024-02-16 08:53:09 -08:00
erichkeane
db4ea21dfd [OpenACC] Change 'not implemented' diagnostic to be more specific
Currently we just emit a generic 'not implemented' diagnostic for all
OpenACC pragmas. This patch moves the diagnostic to 'Sema' and diagnoses
for a specific clause or construct, in preperation of implementing Sema
for constructs.
2024-02-15 12:22:11 -08:00
Erich Keane
24144d726f
[OpenACC][NFC] Implement basic OpenACC Sema infrastructure (#81874)
This patch is split off from #81659, and contains just the Sema
infrastructure that we can later use to implement semantic analysis of
OpenACC constructs.
2024-02-15 10:10:05 -08:00
erichkeane
b14731fe93 [OpenACC][NFC] Fix parse result from 'set'
Apparently 'set' was being parsed as 'shutdown'.  There isn't really any
way of detecting this without getting into a Sema implementation,
however fixing this now as I noticed it.
2024-02-08 07:57:57 -08:00
erichkeane
66ef6900f9 [OpenACC] Better recover during clause parsing
Previously we gave up immediately and just escaped.  Instead, skip to
the next close paren and see if we can continue parsing the next clause
instead.
2024-01-30 12:48:16 -08:00
erichkeane
0dd0cbd324 [OpenACC] Implement 'wait' clause parsing.
The 'wait' clause is parsed the same way as the 'wait' construct, so
this jsut differs to that function.
2024-01-30 12:48:16 -08:00
erichkeane
b52fe2df91 [OpenACC] Implement 'gang' clause parsing.
The 'gang' clause takes a 'gang-arg-list', which is one of three 'tag'
values, followed by either an 'int-expr' or a 'size-expr', both of which
we already have parsing functions for.

The optional tag values are only slightly complicated, as one is a
keyword (static), so mild modifications needed to be made for that.
2024-01-30 06:36:37 -08:00
erichkeane
463529f31b [OpenACC] Implement 'tile' clause parsing
The 'tile' clause takes a 'size-expr-list', where a 'size-expr' is
either an asterisk or an integral constant expression.  This patch
parsess it as an assignment expression, which we'll check for constness
and type in Sema.
2024-01-26 08:53:51 -08:00
erichkeane
62a384ca66 [OpenACC} Implement 'async' parsing.
async just takes an integral value, but it has a little bit of special
rules in sema, so it is implemented slightly differently than int-expr.

This patch implements async parsing.
2024-01-24 13:43:32 -08:00
erichkeane
2531a15dfd [OpenACC] Implement 'device_type' clause parsing
'device_type' takes either an asterisk or a list of impementation
specific identifiers. This patch implements the parsing for it.
Additionally, 'dtype' is an alias for 'device_type', though we're
implementing it as its own clause kind to improve future diagnostics, as
this will allow us to differentiate the spellings.
2024-01-23 09:23:42 -08:00
erichkeane
0dd72eb269 [OpenACC] Implement 'vector' and 'worker' cluase argument parsing
Both of the clauses 'vector' and 'worker' have an optional 'special'
word followed by an int-expr.  The arguments list is optional, as is the
special word, but if the parens are included, an int-expr is required.

This patch implements parsing for both.
2024-01-22 11:35:30 -08:00
erichkeane
04952c5bec [OpenACC] Implement remaining 'simple' int-expr clauses.
'num_gangs', 'num_workers', 'device_num', and 'default_async' are all
exactly the same (for the purposes of parsing) as 'vector_length', so
implement these the same way.
2024-01-22 10:43:13 -08:00
erichkeane
0d8e333a7e [OpenACC] Implement 'vector_length' clause parsing.
The 'vector_length' clause is the first of the 'int-expr' clauses that I've
implemented.  Currently this is just being parsed as an assignment-expr,
  since it needs to be usable in a list. Sema implementation will
  enforce the integral-nature of it.
2024-01-22 07:09:22 -08:00
erichkeane
58b77b8581 [OpenACC] Implement 'bind' clause parsing.
'bind' takes either a string literal, or an 'identifier' representing
the device-side function that this routine is intended to 'bind' to
(that is, to call).  However, it seems that the intent is to permit the
'identifier' to reference any function, thus we're implementing this as
an ID expression.

Additionally, while working on this I discovered that the 'routine' ID
expression parsing for C++ wouldn't allow non-static member functions to
be referenced since it expected us to call it, this was fixed as a part
of this patch as the 'bind' support needed it too.  A test was added for
routine.
2024-01-17 14:07:34 -08:00
erichkeane
3a82a1c3f6 [OpenACC] Implement 'collapse' clause parsing.
The 'collapse' clause takes an optional 'force:' followed by an integer
constant expression.  For now, parse this as an assignment expression,
and we'll check it for value/ICE later.
2024-01-17 06:46:58 -08:00
erichkeane
3973955282 [OpenACC] Implement 'reduction' clause parsing.
The 'reduction' clause takes a mandatory operator followed by a colon,
followed by a 'var-list'.  This patch implements the parsing for the
'reduction' clause.
2024-01-16 11:37:56 -08:00
erichkeane
9c4e7a159b [OpenACC] Implement 'self' clause parsing on 'update'.
The update directive has its own version of 'self' that has a 'var-list'
instead of a 'condition' (like the serial/parallel/kernel/combined
constructs).  This patch special cases it on 'update' to make sure we
parse this correctly.
2024-01-16 09:25:34 -08:00
erichkeane
7b8f7f75a0 [OpenACC] Implement copyin/create clause parsing.
Implement two more clauses, copyin and create.  These are both pretty
simple in that they are just a tag followed by a var-list.
2024-01-16 07:47:07 -08:00
erichkeane
eca25bbdbb [OpenACC] Implement 'copyout' clause parsing.
This is a fairly simple clause that just requires parsing a potential
'zero:' in front of a Clause var-list.  This patch implements/tests
that.
2024-01-16 07:04:28 -08:00
erichkeane
d5000e9cd9 rename to 'try' isntead of 'Try'x 2024-01-16 07:04:28 -08:00
erichkeane
d835d6f4ff [OpenACC} Improve diagnostics for 'tag's on clauses/directives
The 'cache' directive and various clauses have a 'tag' name that is
optional.  This patch cleans up the use of the 'cache' version so that
we get a nicer diagnostic, and enables us to do the same with clauses in
the same situation.
2024-01-16 07:04:28 -08:00
Erich Keane
9e068cd784
[OpenACC} Improve diagnostics for 'tag's on clauses/directives (#77957)
The 'cache' directive and various clauses have a 'tag' name that is
optional. This patch cleans up the use of the 'cache' version so that we
get a nicer diagnostic, and enables us to do the same with clauses in
the same situation.
2024-01-16 06:32:10 -08:00
erichkeane
060505aa0d [OpenACC] Remove mistakenly left TODO and fix format issue 2024-01-12 13:55:15 -08:00
erichkeane
7700ea1031 [OpenACC] Implement the 'rest' of the simple 'var-list' clauses
A large number of clauses are simple, required parens with a var-list.
This patch adds them all, as adding them is quite trivial.
2024-01-12 06:14:48 -08:00
erichkeane
dd5ce4572f [OpenACC] Implement 'use_device' clause parsing
'use_device' is effectively identical to the 'copy' parsing in that it
has required parens and no 'special' name, so this is a pretty trivial
impementation.  There are a number of other similar situation clauses
I'll do in a followup patch.
2024-01-11 09:34:08 -08:00
erichkeane
923f0392bf [OpenACC] Implement 'copy' Clause
The copy clause takes a var-list, similar to cache.  This patch
implements the parsing in terms of how we did cache, and does some
infrastructure for future clause parsing.

As a part of this, many functions needed to become members of Parser,
which I anticipated needing to happen in the future anyway.
2024-01-11 08:58:07 -08:00
Erich Keane
cac6b1a542
[OpenACC] Implement 'var' parsing correctly, support array sections (#77617)
While investigating implementing 'var-list' generically for the variety
of clauses that support this syntax (an extensive list!) I discovered
that it includes 'compound types' and members of compound types, as well
as array sections.

This patch genericizes that function, and implements it in terms of an
assignment expression, and enables a simplified version of OMP Array
Sections for it. OpenACC only supports a startidx + length, so this
patch implements that parsing.

However, it is currently still being represented as an OpenMP Array
Section, which is semantically very similar. It is my intent to come
back and genericize the OMP Array Sections types (or create a similar
expression node) in the future when dealing with Sema.

At the moment, the only obvious problem with it is that the diagnostic
for using it in the 'wrong' place says OpenMP instead of OpenACC, which
I intend to fix when I deal with the AST node changes.
2024-01-10 10:26:49 -08:00
erichkeane
87f67c2599 [OpenACC] Implement 'self' clause parsing
The 'self' clause takes an optional 'condition' expression, same as the
non-optional expression taken by the 'if' clause.  This patch extracts
the 'condition' expression to a separate function, and implements the
'optional parens' infrastructure for clauses, then implements 'self'
parsing.
2024-01-08 12:10:13 -08:00
erichkeane
e6b7c8c495 [OpenACC] Implement 'if' clause
The 'if' clause takes a required 'condition' expression.  This patch
implements that as an expression we will later ensure is convertible to
a binary expression.
2024-01-08 07:33:28 -08:00
Erich Keane
0e8b09c43d
[OpenACC] Implement 'default' clause parsing. (#77002)
A simple clause that is permitted on a few different constructs,
  'default' takes a required parameter of either 'none' or 'present'.
  This patch implements parsing for it.
2024-01-05 09:43:39 -08:00
Erich Keane
fdee0a35d9
[OpenACC] Add 'clause' parsing infrastructure plus a few clauses (#75052)
As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing. While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
    they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
2023-12-18 18:53:37 -08:00
erichkeane
731361cd15 [OpenACC] Fix bug with directive name being a 'special token'
If the 'directive name' is a special token instead of an identifier, we
end up asserting.  This fixes that.
2023-12-08 09:32:49 -08:00
erichkeane
9b154dad5b [OpenACC][NFC] Change Readonly token check to use isSpecialTokenKind
As brought up in a previous review, instead of checking a token's
spelling in text everywhere, we added a 'special token kind'.
This adds the only other use of a special kind to use the checking
function instead.
2023-12-08 06:14:21 -08:00
Erich Keane
df3db035d6
[OpenACC] Implement 'wait' construct parsing (#74752)
The 'wait' construct comes in two forms: one with no parens, the second
with a 'wait-argument'. This implements both forms for constructs.

Additionally, the 'wait-argument' parsing is split into its own function
because the 'wait clause' can also take the same 'wait-argument'.
2023-12-07 17:29:18 -08:00
erichkeane
26f8e1461e [OpenACC] NFC: Stop using 'getSpelling' while parsing OpenACC
It was brought up during the cache review that we shouldn't be using
'getSpelling', and instead should use the IdentifierInfo itself.  This
patch replaces all uses of it.
2023-12-06 07:12:01 -08:00
Erich Keane
721558ae40
[OpenACC] Implement 'cache' construct parsing (#74324)
The 'cache' construct takes a list of 'vars', which are array-section
style definitions. This patch implements the parsing, leaving the lower
bound and length of the bound as expressions, so that we can validate
they are the correct 'thing' in sema.
2023-12-06 06:32:45 -08:00