111 Commits

Author SHA1 Message Date
erichkeane
99a9133a68 [OpenACC] Implement Sema/AST for 'atomic' construct
The atomic construct is a particularly complicated one.  The directive
itself is pretty simple, it has 5 options for the 'atomic-clause'.
However, the associated statement is fairly complicated.

'read' accepts:
  v = x;
'write' accepts:
  x = expr;
'update' (or no clause) accepts:
  x++;
  x--;
  ++x;
  --x;
  x binop= expr;
  x = x binop expr;
  x = expr binop x;

'capture' accepts either a compound statement, or:
  v = x++;
  v = x--;
  v = ++x;
  v = --x;
  v = x binop= expr;
  v = x = x binop expr;
  v = x = expr binop x;

IF 'capture' has a compound statement, it accepts:
  {v = x; x binop= expr; }
  {x binop= expr; v = x; }
  {v = x; x = x binop expr; }
  {v = x; x = expr binop x; }
  {x = x binop expr ;v = x; }
  {x = expr binop x; v = x; }
  {v = x; x = expr; }
  {v = x; x++; }
  {v = x; ++x; }
  {x++; v = x; }
  {++x; v = x; }
  {v = x; x--; }
  {v = x; --x; }
  {x--; v = x; }
  {--x; v = x; }

While these are all quite complicated, there is a significant amount
of similarity between the 'capture' and 'update' lists, so this patch
reuses a lot of the same functions.

This patch implements the entirety of 'atomic', creating a new Sema file
for the sema for it, as it is fairly sizable.
2025-02-03 07:22:22 -08:00
erichkeane
2c75bda426 [OpenACC] Split up SemaOpenACC.cpp
This file is getting quite large, so this patch splits the 'clause'
specific parts off into its own file to keep them better organized.
2025-01-15 13:51:05 -08:00
erichkeane
553fa204ed [OpenACC] Implement 'at least one of' restriction for 'update'
This completes the implementation of 'update' by implementing its last
restriction. This restriction requires at least 1 of the 'self', 'host',
  or 'device' clauses.
2025-01-09 09:28:58 -08:00
erichkeane
be32621ce8 [OpenACC] Implement 'device' and 'host' clauses for 'update'
These two clauses just take a 'var-list' and specify where the variables
should be copied from/to.  This patch implements the AST nodes for them
and ensures they properly take a var-list.
2025-01-09 09:28:58 -08:00
erichkeane
2c2accbcc6 [OpenACC] Enable 'self' sema for 'update' construct
The 'self' clause is an unfortunately difficult one, as it has a
significantly different meaning between 'update' and the other
constructs.  This patch introduces a way for the 'self' clause to work
as both.  I considered making this two separate AST nodes (one for
'self' on 'update' and one for the others), however this makes the
automated macros/etc for supporting a clause break.

Instead, 'self' has the ability to act as either a condition or as a
var-list clause.  As this is the only one of its kind, it is implemented
all within it.  If in the future we have more that work like this, we
should consider rewriting a lot of the macros that we use to make
clauses work, and make them separate ast nodes.
2025-01-08 13:19:33 -08:00
erichkeane
666eee0ef8 [OpenACC] enable 'device_type' for the 'update' construct
This has a similar restriction to 'set' in that only 'async' and 'wait'
are disallowed, so this implements that restriction and enables
'device_type'.
2025-01-07 11:25:58 -08:00
erichkeane
e2c1b1fed4 [OpenACC] enable 'async' and 'wait' for 'update' construct
These work the same here as they do for every other construct, so this
is as simple as enabling them and writing tests, which this patch does.
2025-01-07 10:23:50 -08:00
erichkeane
dd1e8aa09c [OpenACC] Enable 'if' and 'if_present' for 'update' construct
The only restriction on 'if' is that only 1 can appear on an update
construct, so this enforces that.  'if_present' has no restrictions.
2025-01-07 08:20:20 -08:00
erichkeane
db81e8c42e [OpenACC] Initial sema implementation of 'update' construct
This executable construct has a larger list of clauses than some of the
others, plus has some additional restrictions.  This patch implements
the AST node, plus the 'cannot be the body of a if, while, do, switch,
    or label' statement restriction.  Future patches will handle the
    rest of the restrictions, which are based on clauses.
2025-01-07 08:20:20 -08:00
erichkeane
ff24e9a19e [OpenACC] Implement 'default_async' sema
A fairly simple one, only valid on the 'set' construct, this clause
takes an int expression.  Most of the work was already done as a part of
parsing, so this patch ends up being a lot of infrastructure.
2025-01-06 11:03:18 -08:00
erichkeane
21c785d7bd [OpenACC] Implement 'set' construct sema
The 'set' construct is another fairly simple one, it doesn't have an
associated statement and only a handful of allowed clauses. This patch
implements it and all the rules for it, allowing 3 of its for clauses.
The only exception is default_async, which will be implemented in a
future patch, because it isn't just being enabled, it needs a complete
new implementation.
2025-01-06 11:03:18 -08:00
erichkeane
bdf2555308 [OpenACC] Implement 'device_num' clause sema for 'init'/'shutdown'
This is a very simple sema implementation, and just required AST node
plus the existing diagnostics.  This patch adds tests and adds the AST
node required, plus enables it for 'init' and 'shutdown' (only!)
2024-12-19 12:21:51 -08:00
erichkeane
4bbdb018a6 [OpenACC] Implement 'init' and 'shutdown' constructs
These two constructs are very simple and similar, and only support 3
different clauses, two of which are already implemented.  This patch
adds AST nodes for both constructs, and leaves the device_num clause
unimplemented, but enables the other two.
2024-12-19 12:21:50 -08:00
erichkeane
e34cc7c993 [OpenACC] Implement 'wait' construct
The arguments to this are the same as for the 'wait' clause, so this
reuses all of that infrastructure. So all this has to do is support a
pair of clauses that are already implemented (if and async), plus create
an AST node.  This patch does so, and adds proper testing.
2024-12-18 15:06:01 -08:00
erichkeane
bfc2dbe02e [OpenACC] Implement data construct 'at least 1 of ... clauses' rule
All 4 of the 'data' constructs have a requirement that at least 1 of a
small list of clauses must appear on the construct.  This patch
implements that restriction, and updates all of the tests it takes to
do so.
2024-12-16 11:52:57 -08:00
erichkeane
fbb14dd977 [OpenACC] Implement 'use_device' clause AST/Sema
This is a clause that is only valid on 'host_data' constructs, and
identifies variables which it should use the current device address.
From a Sema perspective, the only thing novel here is mild changes to
how ActOnVar works for this clause, else this is very much like the rest
of the 'var-list' clauses.
2024-12-16 09:35:57 -08:00
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
2244d2e75c [OpenACC] Implement 'if_present' clause sema
The 'if_present' clause controls the replacement of addresses in the
var-list in current device memory.  This clause can only go on
'host_device'.  From a Sema perspective, there isn't anything to do
beyond add this to AST and pass it on.
2024-12-13 13:04:57 -08:00
erichkeane
003eb5e80d [OpenACC] Implement 'finalize' clause sema
This is a very simple clause as far as sema is concerned.  It is only
valid on 'exit data', and doesn't have any rules involving it, so it is
simply applied and passed onto the MLIR.
2024-12-13 10:41:02 -08:00
erichkeane
6d69d18437 [OpenACC] enable 'attach' clause sema for 'data' and 'enter data'
This is very similar to deviceptr, and is the same implementation as for
combined/compute constructs, so this just enables that, and adds tests.
2024-12-13 09:24:20 -08:00
erichkeane
754499c1e9 [OpenACC] Enable 'deviceptr' clause sema on data construct
Another simple implementation, as it uses the same work as the previous
implementation, just enabling it for this construct.
2024-12-13 08:38:55 -08:00
erichkeane
331f3cc94b [OpenACC] enable 'present' clause for 'data' construct
No additional sema is required once again, so this patch adds testing
and enables the clause.
2024-12-13 08:11:28 -08:00
erichkeane
1da0730ba5 [OpenACC] enable 'copyout' clause sema for data constructs
Same as the previous few, this just enables copyout for data constructs
and ensures we have sufficient test coverage.
2024-12-13 07:50:29 -08:00
erichkeane
b2b1eec2b2 [OpenACC] enable 'copyin' clause sema for 'data'/'enter data'
stop reporting 'copyin' as not implemented on a data/enter data
construct, and enforce sema rules.
2024-12-13 07:31:18 -08:00
erichkeane
9359625ba9 [OpenACC] 'create' clause sema for data/enter data constructs
Enable and add tests for 'create' on a data or enter data construct.
2024-12-13 06:55:05 -08:00
erichkeane
55154d6896 [OpenACC] Enable 'no_create' sema for data construct
Adds tests and enables the 'no_create' clause semantic analysis for the
'data' constuct, so it will no longer report 'not yet implemented'.
2024-12-13 06:33:04 -08:00
erichkeane
7a3504a133 [OpenACC] Enable 'copy' clause sema for data clause
'copy' is another that is identical in behavior on 'data' as far as
semantic analysis is concerned as the compute constructs, so this patch
adds tests and enables 'copy'.
2024-12-13 06:23:05 -08:00
erichkeane
5048808859 [OpenACC] Implement 'default' Sema for 'data' clause
No additional rules here beyond enabling it, this patch just enables
'default' and adds tests.
2024-12-12 12:54:02 -08:00
erichkeane
afcb7d4a2e [OpenACC] Implement 'wait' sema for data constructs
This is once again simply enabling this for 'data', 'enter data', and
'exit data' (and ensuring we error for 'host_data').  Implementation is
very simply to enable it rather than emit the not-implemented
diagnostic.
2024-12-12 12:16:20 -08:00
erichkeane
f0f8434afa [OpenACC] Implement sema for 'async' on 'data' constructs
This also is a clause that doesn't have any special rules, so this patch
enables it and adds tests.
2024-12-12 10:55:27 -08:00
erichkeane
6cfad635d5 [OpenACC] Implement 'if' clause sema for 'data' constructs
This is another one that has no additional sema work other than enabling
it, so this patch does just that.
2024-12-12 09:59:09 -08:00
erichkeane
8eec301fe3 [OpenACC] Implement 'device_type' for 'data' construct
Semantically this is identical to all other constructs with this tag,
except in this case the 'wait' and 'async' are the only ones allowed
after it. This patch implements that rule using the existing
infrastructure.
2024-12-12 08:37:20 -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
7d89ebfd5f [OpenACC] Implement 'reduction' for combined constructs.
Once again, this is a clause on a combined construct that does almost
exactly what the loop/compute construct version does, only with some sl
ightly different evaluation rules/sema rules as it doesn't have to
consider the parent, just the 'combined' construct.  The two sets of
rules for reduction on loop and compute are fine together, so this
ensures they are all enforced for this too.

The 'gangs' 'num_gangs' 'reduction' diagnostic (Dim>1) had to be applied
to num_gangs as well, as it previously wasn't permissible to get in this
situation, but we now can.
2024-12-09 14:06:44 -08:00
erichkeane
009b5e8e59 [OpenACC] 'vector' clause implementation for combined constructs
Similar to 'worker', the 'vector' clause has some rules that needed to
be applied on its argument legality that for combined constructs need to
look at the current construct, not the 'effective' parent construct.
Additionally, it has some interaction with `vector_length` that needed
to be encoded as well.  This patch implements it.
2024-12-06 09:06:57 -08:00
erichkeane
cb6a02abe2 [OpenACC] Implement 'worker' clause for combined constructs
This is very similar to 'gang', except with fewer restrictions, and only an
interaction with 'num_workers', plus disallowing 'gang' and 'worker' in
its associated statement.  This patch implements this, the same as how
'gang' implemented it.
2024-12-05 10:43:52 -08:00
erichkeane
3a4b9f3891 [OpenACC] Implement 'gang' clause for Combined Constructs
This one is a bit complicated, as it has some interesting interactions,
as 'gang' Sema is required to look at its containing compute construct.
Except in the case of a combined construct, they are the same. This
resulted in a large refactor of the checking code for CheckGangExpr,
plus some additional work on the diagnostics for its interaction with
'num_gangs' and 'vector'/'worker'.
2024-12-05 06:35:36 -08:00
erichkeane
e3446b9a07 [OpenACC] Fix bug with worker/vector/gang clause inside another
The original implementation rejected some valid constructs.  The rule is
supposed to be:

Gang-on-Kernel cannot have a gang in its region

Worker cannot have a worker or gang in its region

Vector cannot have worker, gang, or vector in its region.

The previous implementation improperly implemented that vector wasnt'
allowed in the other two.  This patch fixes it and adds testing for it.
2024-12-04 10:34:50 -08:00
erichkeane
eb257fe37b [OpenACC] Enable 3 more clauses for combined constructs.
'num_gangs', 'num_workers', and 'vector_length' are similar to
eachother, and are all the same implementation as for compute
constructs, so this patch just enables them and adds the necessary
testing to ensure they work correctly.  These will get more complicated
when they get combined with 'gang', 'worker', 'vector' and 'reduction',
but those restrictions will be implemented when those clauses are
enabled.
2024-12-03 09:31:40 -08:00
erichkeane
0aa7892772 [OpenACC] Implement 'tile' for combined constructs
Like collapse, this clause has only mild changes that need to be made.
Most of the associated work for the RAII container was already done
previously, so this is mostly just updating the diagnostics to properly
emit the right construct.
2024-12-02 13:31:36 -08:00
erichkeane
0aef005c94 [OpenACC] Implement 'collapse' for combined constructs.
Most of the restrictions on 'collapse' involve the contents of the loop,
so this extends enforcement of all of that to all combined construct
loops, and alters the diagnostics to better reflect the construct it is
associated with.
2024-12-02 12:49:49 -08:00
erichkeane
1f2aeef97b [OpenACC] Enable copy/create clauses for combined constructs
This is the last set of 'no op' changes, and are all incredibly similar,
so they are being done together.  They work the exact same for combined
constructs as they do for compute constructs, so this adds tests and
enables them.
2024-12-02 11:15:35 -08:00
erichkeane
8c1bd9792b [OpenACC] Expose 'no_create' clause in combined constructs
Once again, not much work besides ensuring they are supposed to work the
same.
2024-11-27 12:03:48 -08:00
erichkeane
bbbaeb5584 [OpenACC] Enable 'attach' clause for combined constructs
Once again, this clause has the same implementation for compute
constructs as combined, so this adds the tests and enables it.
2024-11-27 09:55:19 -08:00
erichkeane
969b7658fe [OpenACC] Enable 'wait' for combined constructs
Once again a situation where the combined and compute do the exact same
thing as far as Sema/AST/etc is concerned, so this patch adds tests and
enables it.
2024-11-27 08:32:33 -08:00
erichkeane
8d6c73cbf5 [OpenACC] enable 'deviceptr' for combined constructs.
This is another clause whose implementation is identical for combined
constructs as with compute constructs, so this adds tests and enables
it.
2024-11-27 07:04:15 -08:00
erichkeane
78c7024640 [OpenACC] Implement 'present' for combined constructs.
This is another clause where the parsing does all the required
enforcement besides the construct it appertains to, so this patch
removes the restriction and adds sufficient test coverage for combined
constructs.
2024-11-26 10:49:41 -08:00
erichkeane
1b44c3a142 [OpenACC] enable 'async' clause for combined constructs
No additional work required over what we did for other constructs, so
this is just adding the tests and enabling the clauses.
2024-11-14 11:18:06 -08:00
erichkeane
1cd981a5f3 [OpenACC] Implement private/firstprivate for combined constructs
This is another pair of clauses where the work is already done from
previous constructs, so this just has to allow them and include tests
for them. This patch adds testing, does a few little cleanup bits on the
clause checking, and enables these.
2024-11-14 09:57:39 -08:00