87 Commits

Author SHA1 Message Date
erichkeane
1ab81f8e7f [OpenACC] Implement 'delete' AST/Sema for 'exit data' construct
'delete' is another clause that has very little compile-time
implication, but needs a full AST that takes a var list.  This patch
ipmlements it fully, plus adds sufficient test coverage.
2024-12-16 06:44:53 -08:00
erichkeane
3351b3bf8d [OpenACC] implement 'detach' clause sema
This is another new clause specific to 'exit data' that takes a pointer
argument. This patch implements this the same way we do a few other
clauses (like attach) that have the same restrictions.
2024-12-13 13:51:41 -08:00
erichkeane
010d0115fc [OpenACC] Create AST nodes for 'data' constructs
These constructs are all very similar and closely related, so this patch
creates the AST nodes for them, serialization, printing/etc.
Additionally the restrictions are all added as tests/todos in the tests,
as those will have to be implemented once we get those clauses implemented.
2024-12-12 07:28:30 -08:00
erichkeane
ee090cb83b [OpenACC] Treat 'delete' as a valid clause during parsing in C++ mode
This didn't end up being properly tested, but 'delete' as a keyword
causes us to not properly recognize it as a clause kind.  This patch
correctly adds the work to make sure it is recognized correctly.
2024-12-11 14:19:20 -08:00
Kazu Hirata
834dfd2315
[Parse] Remove ParseDiagnostic.h (#116496)
This patch removes clang/Parse/ParseDiagnostic.h because it just
forwards to clang/Basic/DiagnosticParse.h.
2024-11-18 07:19:33 -08:00
erichkeane
39351f8e46 [OpenACC] Implement AST/Sema for combined constructs
Combined constructs (OpenACC 3.3 section 2.11) are a short-cut for
writing a `loop` construct immediately inside of a `compute` construct.
However, this interaction requires we do additional work to ensure that
we get the semantics between the two correct, as well as diagnostics.

This patch adds the semantic analysis for the constructs (but no
    clauses), as well as the AST nodes.
2024-11-12 09:26:25 -08:00
Erich Keane
b0cfbfd74b
[OpenACC] Implement loop restrictions on for loops. (#115370)
OpenACC restricts the contents of a 'for' loop affected by a 'loop'
construct without a 'seq'. The loop variable must be integer, pointer,
or random-access-iterator, it must monotonically increase/decrease, and
the trip count must be computable at runtime before the function.

This patch tries to implement some of these limitations to the best of
our ability, though it causes us to be perhaps overly restrictive at the
moment. I expect we'll revisit some of these rules/add additional
supported forms of loop-variable and 'monotonically increasing' here,
but the currently enforced rules are heavily inspired by the OMP
implementation here.
2024-11-08 05:49:45 -08:00
Erich Keane
cf456ed2a4
[OpenACC] implement loop 'worker' clause. (#112206)
The worker clause specifies iterations of the loop/ that are executed in
parallel by distributing the iterations among the multiple works within
a single gang.

The sema rules for this type are simply that it cannot be combined with
a `kernel` construct with a `num_workers` clause, child `loop` clauses
cannot contain a `gang` or `worker` clause, and that the argument is oly
allowed when associated with a `kernel`.
2024-10-14 09:08:24 -07:00
Erich Keane
5b25c31351
[OpenACC] Implement loop 'gang' clause. (#112006)
The 'gang' clause is used to specify parallel execution of loops, thus
has some complicated rules depending on the 'loop's associated compute
construct. This patch implements all of those.
2024-10-11 09:05:19 -07:00
Erich Keane
d412cea8c4
[OpenACC] Implement 'tile' attribute AST (#110999)
The 'tile' clause shares quite a bit of the rules with 'collapse', so a
followup patch will add those tests/behaviors. This patch deals with
adding the AST node.

The 'tile' clause takes a series of integer constant expressions, or *.
The asterisk is now represented by a new OpenACCAsteriskSizeExpr node,
else this clause is very similar to others.
2024-10-03 08:34:43 -07:00
Erich Keane
da4b972ef6
[OpenACC] Enforce all 'collapse' intervening rules (#110684)
'collapse' makes the 'loop' construct apply to the next N nested loops,
and 'loop' requires all associated loops be 'for' loops (or range-for).

This patch adds this restriction, plus adds a number of infrastructure
changes to permit some of the other restrictions in the future to be
implemented.

'collapse' also requires that there is not any calls to other directives
 inside of the collapse region, so this also implements that limitation.
2024-10-02 07:10:53 -07:00
Erich Keane
97da34e015
[OpenACC] Add 'collapse' clause AST/basic Sema implementation (#109461)
The 'collapse' clause on a 'loop' construct is used to specify how many
nested loops are associated with the 'loop' construct. It takes an
optional 'force' tag, and an integer constant expression as arguments.

There are many other restrictions based on the contents of the loop/etc,
but those are implemented in followup patches, for now, this patch just
adds the AST node and does basic argument checking on the loop-count.
2024-10-01 06:40:21 -07:00
erichkeane
2b939e182d [OpenACC] Implement auto/seq/independent clause Sema for 'loop'
These three clauses are all quite trivial, as they take no parameters.
They are mutually exclusive, and 'seq' has some other exclusives that
are implemented here.

The ONE thing that isn't implemented is 2.9's restriction (line 2010):
  'A loop associated with a 'loop' construct that does not have a 'seq'
   clause must be written to meet all the following conditions'.

Future clauses will require similar work, so it'll be done as a
followup.
2024-06-05 10:17:21 -07:00
Erich Keane
42f4e505a3
[OpenACC] Loop construct basic Sema and AST work (#93742)
This patch implements the 'loop' construct AST, as well as the basic
appertainment rule. Additionally, it sets up the 'parent' compute
construct, which is necessary for codegen/other diagnostics.

A 'loop' can apply to a for or range-for loop, otherwise it has no other
restrictions (though some of its clauses do).
2024-06-05 06:21:48 -07:00
erichkeane
193e9007ef [OpenACC][NFC] Fix begin loc and split it from the directive location
I discovered while working on something else that we were using the
location of the directive name as the 'beginloc' which caused some
problems in a few places.  This patch makes it so our beginloc is the
'#' as we originally designed, and then adds a DirectiveLoc concept to a
construct for use diagnosing the name.
2024-05-28 13:39:40 -07:00
Erich Keane
a15b685c2d
[OpenACC] Implement 'reduction' sema for compute constructs (#92808)
'reduction' has a few restrictions over normal 'var-list' clauses:

1- On parallel, a num_gangs can only have 1 argument when combined with
reduction. These two aren't able to be combined on any other of the
compute constructs however.

2- The vars all must be 'numerical data types' types of some sort, or a
'composite of numerical data types'. A list of types is given in the
standard as a minimum, so we choose 'isScalar', which covers all of
these types and keeps types that are actually numeric. Other compilers
don't seem to implement the 'composite of numerical data types', though
we do.

3- Because of the above restrictions, member-of-composite is not
allowed, so any access via a memberexpr is disallowed. Array-element and
sub-arrays (aka array sections) are both permitted, so long as they meet
the requirements of #2.

This patch implements all of these for compute constructs.
2024-05-21 06:51:25 -07:00
erichkeane
8ef2011b2c Reapply "[OpenACC] device_type clause Sema for Compute constructs"
device_type, also spelled as dtype, specifies the applicability of the
clauses following it, and takes a series of identifiers representing the
architectures it applies to.  As we don't have a source for the valid
architectures yet, this patch just accepts all.

Semantically, this also limits the list of clauses that can be applied
after the device_type, so this implements that as well.

This reverts commit 06f04b2e27f2586d3db2204ed4e54f8b78fea74e.
This reapplies commit c4a9a374749deb5f2a932a7d4ef9321be1b2ae5d.
The build failures were caused by the patch depending on the order of
evaluation of arguments to a function. This reapplication separates out
the capture of one of the values.
2024-05-13 10:29:43 -07:00
erichkeane
06f04b2e27 Revert "[OpenACC] device_type clause Sema for Compute constructs"
This reverts commit c4a9a374749deb5f2a932a7d4ef9321be1b2ae5d.

This and the followup patch keep hitting an assert I wrote on the build
bots in a way that isn't clear.  Reverting so I can fix it without a
rush.
2024-05-13 08:40:43 -07:00
erichkeane
c4a9a37474 [OpenACC] device_type clause Sema for Compute constructs
device_type, also spelled as dtype, specifies the applicability of the
clauses following it, and takes a series of identifiers representing the
architectures it applies to.  As we don't have a source for the valid
architectures yet, this patch just accepts all.

Semantically, this also limits the list of clauses that can be applied
after the device_type, so this implements that as well.
2024-05-13 07:50:19 -07:00
erichkeane
5ad418b55c Remove stale TODO comment 2024-05-09 10:57:59 -07:00
erichkeane
b1b465218d [OpenACC] 'wait' clause for compute construct sema
'wait' takes a few int-exprs (well, a series of async-arguments, but
    those are effectively just an int-expr), plus a pair of tags. This
patch adds the support for this to the AST, and does the appropriate
semantic analysis for them.
2024-05-09 06:44:12 -07:00
erichkeane
8d2ab2a0ec [OpenACC][NFC] Fix EndLoc behavior of optional clause params
It was discovered while writing the 'wait' clause ast tests that the
'endloc' wasn't set correctly when there was no arguments.  This patch
ensures we set it right, and adds an assert to prevent us from messing
it up in the future.
2024-05-09 06:44:11 -07:00
erichkeane
30cfe2b2ac [OpenACC] Implement 'async' clause sema for compute constructs
This is a pretty simple clause, it takes an 'async-argument', which
effectively needs to be just parsed as an 'int' argument, since it can
be an arbitrarly integer at runtime (and negative values are legal for
implementation defined values).

This patch also cleans up the async-argument parsing, so 'wait' got some
minor quality-of-life improvements for parsing (both clause and
    construct).
2024-05-07 07:14:14 -07:00
erichkeane
48c8a5791a [OpenACC] Implement 'deviceptr' and 'attach' sema for compute constructs
These two are very similar to the other 'var-list' variants, except they
require that the type of the variable be a pointer.  This patch
implements that restriction.
2024-05-06 09:29:04 -07:00
erichkeane
01e91a2dde [OpenACC] Implement copyin, copyout, create clauses for compute construct
Like 'copy', these also have alternate names, so this implements that as
well.  Additionally, these have an optional tag of either 'readonly' or
'zero' depending on the clause.

Otherwise, this is a pretty rote implementation of the clause, as there
aren't any special rules for it.
2024-05-03 07:51:25 -07:00
erichkeane
054f7c0565 [OpenACC] Implement copy clause for compute constructs.
Like present, no_create, and first_private, copy is a clause that takes
just a var-list, and follows the same rules as the others.

The one unique part of this clause is that it ALSO supports two
deprecated/backwards-compatibility spellings, so this patch adds them
and implements them.
2024-05-03 07:20:41 -07:00
erichkeane
bd909d2e6f [OpenACC] Implement no_create and present clauses on compute constructs
These two are, from a semantic checking perspective, identical to
first-private/private/etc, other than appertainment. This patch
implements both.
2024-05-03 06:51:54 -07:00
erichkeane
a13c5140a2 [OpenACC] Implement firstprivate clause for compute constructs
This clause is pretty nearly copy/paste from private, except that it
doesn't support 'loop', and thus 'kernelsloop' for appertainment.
2024-05-03 06:33:35 -07:00
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