1151 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
815b0046b8
[clang][OpenMP] Slightly refactor EndOpenMPDSABlock for readability, NFC (#109003)
Change the loop
```
  if (isOpenMPExecutableDirective)
    for (Clause)
      if (Clause is kind1)
        multi
        line
        do
        something1;
      else if (Clause is kind2)
        ...
      ...
```
to
```
  auto do1 = ...do something1...;
  auto do2 = ...do something2...;
  ...

  if (isOpenMPExecutableDirective)
    for (Clause)
      if (Clause is kind1)
        do1();
      else if (Clause is kind2)
        do2();
      ...
    ...
```
2024-09-17 15:14:07 -05:00
Krzysztof Parzyszek
3ba0755d3e
[clang][OpenMP] Simplify handling of implicit DSA/mapping information (#106786)
Create `VariableImplicitInfo` to hold the data. Most of it is used all
at once, so aggregating it seems like a good idea.
2024-09-07 09:10:21 -05:00
Dan Liew
ff04c5b2e6
[NFC][Sema] Move Sema::AssignmentAction into its own scoped enum (#106453)
The primary motivation behind this is to allow the enum type to be
referred to earlier in the Sema.h file which is needed for #106321.

It was requested in #106321 that a scoped enum be used (rather than
moving the enum declaration earlier in the Sema class declaration).
Unfortunately doing this creates a lot of churn as all use sites of the
enum constants had to be changed. Appologies to all downstream forks in
advanced.

Note the AA_ prefix has been dropped from the enum value names as they
are now redundant.
2024-08-29 12:00:28 -07:00
Yuxuan Chen
e732d1ce86
[Clang] Fix ICE in SemaOpenMP with structured binding (#104822)
Fixes https://github.com/llvm/llvm-project/issues/104810.

Clang currently crashes on the following program:
```
struct S {
  int i;
};

auto [a] = S{1};

void foo() {
    a;
}
```
when `-fopenmp` is enabled. 

Because `a` is neither `VarDecl` nor `FieldDecl`. It's a `BindingDecl`
that's not handled in `SemaOpenMP.cpp`'s `getCanonicalDecl`. It appears
to me that this pattern matching is merely just for a refined return
type of the overrides. It can also be achieved with just using the
virtual `Decl::getCanonicalDecl()` instead. Do the final casting should
be safe for `ValueDecl`s.
2024-08-19 14:06:10 -07:00
Julian Brown
3188e9b4e0
[clang][OpenMP] Diagnose badly-formed collapsed imperfect loop nests (#60678) (#101305)
This patch fixes a couple of cases where Clang aborts with loop nests
that are being collapsed (via the relevant OpenMP clause) into a new,
combined loop.

The problematic cases happen when a variable declared within the loop
nest is used in the (init, condition, iter) statement of a more
deeply-nested loop. I don't think these cases (generally?) fall under
the non-rectangular loop nest rules as defined in OpenMP 5.0+, but I
could be wrong (and anyway, emitting an error is better than crashing).

In terms of implementation: the crash happens because (to a first
approximation) all the loop bounds calculations are pulled out to the
start of the new, combined loop, but variables declared in the loop nest
"haven't been seen yet". I believe there is special handling for
iteration variables declared in "for" init statements, but not for
variables declared elsewhere in the "imperfect" parts of a loop nest.

So, this patch tries to diagnose the troublesome cases before they can
cause a crash. This is slightly awkward because at the point where we
want to do the diagnosis (SemaOpenMP.cpp), we don't have scope
information readily available. Instead we "manually" scan through the
AST of the loop nest looking for var decls (ForVarDeclFinder), then we
ensure we're not using any of those in loop control subexprs
(ForSubExprChecker). All that is only done when we have a "collapse"
clause.

Range-for loops can also cause crashes at present without this patch, so
are handled too.
2024-08-19 09:37:32 -04:00
Krzysztof Parzyszek
de5ea2d122 [clang][OpenMP] Change /* ParamName */ to /*ParamName=*/, NFC
Change
  foo(/* Index */ 0);
to
  foo(/*Index=*/0);

There was a mix of these two formats in the source. Clang-format treats
the latter one a bit better, so use that one consistently.
2024-08-18 10:48:49 -05:00
Krzysztof Parzyszek
e05307f663 [clang][OpenMP] Avoid multiple calls to getCurrentDirective in DSAChecker, NFC 2024-08-18 10:25:52 -05:00
Shilei Tian
1c269929d0
[Clang][Sema][OpenMP] Allow thread_limit to accept multiple expressions (#102715) 2024-08-10 09:54:58 -04:00
Krystian Stasiowski
55ea36002b
[Clang][Sema] Make UnresolvedLookupExprs in class scope explicit specializations instantiation dependent (#100392)
A class member named by an expression in a member function that may instantiate to a static _or_ non-static member is represented by a `UnresolvedLookupExpr` in order to defer the implicit transformation to a class member access expression until instantiation. Since `ASTContext::getDecltypeType` only creates a `DecltypeType` that has a `DependentDecltypeType` as its canonical type when the operand is instantiation dependent, and since we do not transform types unless they are instantiation dependent, we need to mark the `UnresolvedLookupExpr` as instantiation dependent in order to correctly build a `DecltypeType` using the expression as its operand with a `DependentDecltypeType` canonical type. Fixes #99873.
2024-08-06 12:40:44 -04:00
Shilei Tian
cee594cf36
[Clang][Sema][OpenMP] Allow num_teams to accept multiple expressions (#99732)
By the OpenMP standard, `num_teams` clause can only accept one
expression (for now). In this patch, we extend it to allow to accept
multiple expressions when it is used with `target teams ompx_bare`
construct. This will allow to launch a multi-dim grid, same as CUDA/HIP.
2024-08-06 10:55:15 -04:00
Julian Brown
a42e515e3a
[OpenMP] OpenMP 5.1 "assume" directive parsing support (#92731)
This is a minimal patch to support parsing for "omp assume" directives.
These are meant to be hints to a compiler's optimisers: as such, it is
legitimate (if not very useful) to ignore them. The patch builds on top
of the existing support for "omp assumes" directives (note spelling!).

Unlike the "omp [begin/end] assumes" directives, "omp assume" is
associated with a compound statement, i.e. it can appear within a
function. The "holds" assumption could (theoretically) be mapped onto
the existing builtin "__builtin_assume", though the latter applies to a
single point in the program, and the former to a range (i.e. the whole
of the associated compound statement).

This patch fixes sollve's OpenMP 5.1 "omp assume"-based tests.
2024-08-05 07:37:07 -04:00
Kazu Hirata
1fa7f05b70
[clang] Construct SmallVector with ArrayRef (NFC) (#101898) 2024-08-04 23:46:34 -07:00
jyu2-git
d8b61dd84b
[OpenMP] Generate implicit default mapper for mapping array section. (#101101)
This is only for struct containing nested structs with user defined
mappers.

Add four functions:
1>buildImplicitMap: build map for default mapper
2>buildImplicitMapper:  build default mapper.
3>hasUserDefinedMapper for given mapper name and mapper type, lookup
user defined map, if found one return true.
4>isImplicitMapperNeeded check if Mapper is needed

During create map, in checkMappableExpressionList, call
isImplicitMapperNeeded when it return true, call buildImplicitMapper to
generate implicit mapper and added to map clause.

https://github.com/llvm/llvm-project/pull/101101
2024-08-02 17:22:40 -07:00
Krzysztof Parzyszek
243b27f7e1
[clang][OpenMP] Rename varlists to varlist, NFC (#101058)
It returns a range of variables (via Expr*), not a range of lists.
2024-07-30 08:11:09 -05:00
Jannick Kremer
c9cc6c4772
[Clang][Sema][NFC] Remove duplicate check in if-condition (#101070)
Resolves #101041
2024-07-30 10:02:15 +08:00
nicebert
8470a23c48
[OpenMP] Defaultmap: fixes scalar issue, adds all variable category (#99315)
Fixes issue with defaultmap where scalar isn't handled correctly for
present modifier. Adds all variable cateogry introduced in OpenMP 5.2
and alters existing tests for error messages to check OpenMP 5.2
defaultmap messages.
2024-07-25 14:30:14 -05:00
Krzysztof Parzyszek
51507046c0
[clang][OpenMP] Mark all SIMD regions as non-throwing (#100162)
[4.5:75:19], [5.0:114:3], [5.1:137:21], [5.2:235:30]
"No exception can be raised in the **simd** region."
2024-07-23 18:11:27 -05:00
Krzysztof Parzyszek
c74730070a
[clang][OpenMP] Move "loop" directive mapping from sema to codegen (#99905)
Given "loop" construct, clang will try to treat it as "for",
"distribute" or "simd", depending on either the implied binding, or the
bind clause if present. This patch moves the code that performs this
construct remapping from sema to codegen.

For a "loop" construct without a bind clause, this patch will create an
implicit bind clause based on implied binding to simplify further
analysis.

During codegen the function `EmitOMPGenericLoopDirective` (i.e. "loop")
will invoke the "emit" functions for "for", "distribute" or "simd",
depending on the bind clause.

---------

Co-authored-by: Alexey Bataev <a.bataev@gmx.com>
2024-07-23 07:31:42 -05:00
Krzysztof Parzyszek
e9709899db [clang][OpenMP] Avoid names that hide existing variables, NFC 2024-07-22 10:22:20 -05:00
Michael Kruse
5c93a94f5a
[Clang][OpenMP] Add interchange directive (#93022)
Add the interchange directive which will be introduced in the upcoming
OpenMP 6.0 specification. A preview has been published in [Technical
Report 12](https://www.openmp.org/wp-content/uploads/openmp-TR12.pdf).
2024-07-19 09:24:40 +02:00
Michael Kruse
80865c01e1
[Clang][OpenMP] Add reverse directive (#92916)
Add the reverse directive which will be introduced in the upcoming
OpenMP 6.0 specification. A preview has been published in [Technical
Report 12](https://www.openmp.org/wp-content/uploads/openmp-TR12.pdf).

---------

Co-authored-by: Alexey Bataev <a.bataev@outlook.com>
2024-07-18 10:35:32 +02:00
Krzysztof Parzyszek
97ebc97949 [clang[OpenMP] Revert accidentally included changes from previous commit 2024-07-15 09:10:11 -05:00
Krzysztof Parzyszek
a1dfe15632
[clang][OpenMP] Simplify check for taskloop in `ActOnOpenMPLoopInitia… (#98633)
…lization`

Replace the explicit list of compound directives ending with taskloop
with checking for the last leaf construct.
2024-07-15 08:53:14 -05:00
Krzysztof Parzyszek
861a8ed68b
[clang][OpenMP] Remove compound directives from checkNestingOfRegions (#98387)
Express the constraints via constituent directives.
2024-07-15 08:20:18 -05:00
Krzysztof Parzyszek
ba29e3a58d [clang][OpenMP] Add early exit to/unindent ActOnOpenMPLoopInitialization
NFC
2024-07-12 08:18:28 -05:00
Krzysztof Parzyszek
81cdf9472c
[clang][OpenMP] Fix region nesting check for scan directive (#98386)
The previous check was inconsistent. For example, it would allow
```
#pragma omp target
#pragma omp parallel for
  for (...) {
#pragma omp scan
  }
```
but not
```
#pragma omp target parallel for
  for (...) {
#pragma omp scan
  }
```

Make the check conform to the wording on the specification.
2024-07-11 08:07:58 -05:00
Krzysztof Parzyszek
2c42c2263d
[clang][OpenMP] Make getOpenMPCaptureRegionForClause more generic (#98180)
Rewrite `getOpenMPCaptureRegionForClause` with more generic code,
relying on directive composition instead of listing individual
directives.
2024-07-09 15:12:46 -05:00
Krzysztof Parzyszek
6461b921fd
[clang][OpenMP] Change ActOnOpenMPRegionStart to use captured regions (#97445)
Instead of checking specific directives, this function now gets the list
of captured regions, and processes them individually. This makes this
function directive-agnostic (except a few cases of leaf constructs).
2024-07-03 07:58:01 -05:00
Krzysztof Parzyszek
acaa0262a9
[clang][OpenMP] Use leaf constructs in mapLoopConstruct (#97446)
This removes mentions of specific combined directives.

Also, add a quote from the OpenMP spec to explain the code dealing with
the `bind` clause.
2024-07-03 07:57:31 -05:00
Krzysztof Parzyszek
deda50fd79
[clang][OpenMP] Implement isOpenMPCapturingDirective (#97090)
Check if the given directive can capture variables, and thus needs a
captured statement.

Simplify some code using this function.
2024-07-01 15:46:04 -05:00
Krzysztof Parzyszek
51797a7c55 [clang][OpenMP] Unindent checkNestingOfRegions, NFC
The entire body of the function is inside of an if-statement, followed
by a "return false". Invert the condition and return early, unindent
and clang-format the function.
2024-07-01 10:46:37 -05:00
Krzysztof Parzyszek
0ce801f91c
[clang][OpenMP] Implement isOpenMPExecutableDirective (#97089)
What is considered "executable" in clang differs slightly from the
OpenMP's "executable" category. In addition to the executable category,
subsidiary directives, and OMPD_error are considered executable.

Implement a function that performs that check.
2024-06-29 09:37:32 -05:00
Julian Brown
6ba764a54e
[OpenMP] [NFC] SemaOpenMP.cpp and StmtOpenMP.cpp spelling fixes (#96814)
This patch just fixes a few spelling mistakes in the above two files. (I
changed one British spelling to American -- analyse to analyze --
because the latter spelling is used elsewhere in file, and it's probably
best to be consistent.)
2024-06-28 12:36:20 -05:00
Krzysztof Parzyszek
08892cc07d
[clang][OpenMP] Simplify handling of if clause (#96936)
Get the allowed name modifiers from the list of constituent leaf
directives.
2024-06-28 07:46:18 -05:00
Krzysztof Parzyszek
4ed8796bfe [clang][OpenMP] clang-format SemaOpenMP.cpp, NFC
There are only a handful of changes, and now the entire file can be
kept clang-formatted.
2024-06-27 09:05:48 -05:00
Krzysztof Parzyszek
34fe6da6e4
[clang][OpenMP] Place some common code in functions (#96811)
There are chunks of code repeated in a number of functions. This patch
moves some of that code into individual functions.
2024-06-27 07:16:27 -05:00
Mike Rice
b097018fda
[clang][OpenMP] Fix teams nesting of region check (#94806)
The static verifier flagged dead code in the check since the loop will
only execute once and never reach the iterator increment.

The loop needs to iterate twice to correctly diagnose when a statement
is after the teams.

Since there are two iterations again, reset the iterator to the first
teams directive when the double teams case is seen so the diagnostic can
report both locations.
2024-06-24 13:31:39 -07:00
Mike Rice
65d300989b
[OpenMP][NFC] Fix argument order of SourceLocations for allocate clause (#94777)
Static verifier caught passing ColonLoc/LParenLoc in wrong order. Marked
as NFC since these don't seem to be used for anything currently that I
can think to test for.
2024-06-10 08:24:03 -07:00
Mike Rice
cb3ff9a393
[clang][OpenMP][NFC] Remove unnecessary nullptr check (#94680)
Static verifier reports unchecked use of pointer after explicitly
checking earlier in the function. It appears the pointer won't be a
nullptr, so remove the unneeded check for consistency.
2024-06-10 08:12:12 -07:00
Vlad Serebrennikov
6b755b0cf4
[clang] Split up SemaDeclAttr.cpp (#93966)
This patch moves language- and target-specific functions out of
`SemaDeclAttr.cpp`. As a consequence, `SemaAVR`, `SemaM68k`,
`SemaMSP430`, `SemaOpenCL`, `SemaSwift` were created (but they are not
the only languages and targets affected).

Notable things are that `Sema.h` actually grew a bit, because of
templated helpers that rely on `Sema` that I had to make available from
outside of `SemaDeclAttr.cpp`. I also had to left CUDA-related in
`SemaDeclAttr.cpp`, because it looks like HIP is building up on top of
CUDA attributes.

This is a follow-up to #93179 and continuation of efforts to split
`Sema` up. Additional context can be found in #84184 and #92682.
2024-06-05 09:46:37 +04:00
Vlad Serebrennikov
baabaa4ce9
[clang][NFC] Move PDiag into SemaBase (#93849)
This patch moves `PDiag` into `SemaBase`, making it readily available
everywhere across `Sema` without `SemaRef`, like the regular `Diag`.
2024-05-30 23:38:46 +04:00
Oleksandr T
7b77301c22
[clang] fix(93002): clang/lib/Sema/SemaOpenMP.cpp:7405: Possible & / && mixup ? (#93093)
Fixes #93002
2024-05-30 07:58:34 -05:00
Michael Kruse
9120562dfc
[Clang][OpenMP] Enable tile/unroll on iterator- and foreach-loops (#91459)
OpenMP loop transformation did not work on a for-loop using an iterator
or range-based for-loops. The first reason is that it combined the
iterator's type for generated loops with the type of `NumIterations` as
generated for any `OMPLoopBasedDirective` which is an integer. Fixed by
basing all generated loop variables on `NumIterations`.

Second, C++11 range-based for-loops include syntactic sugar that needs
to be executed before the loop. This additional code is now added to the
construct's Pre-Init lists.

Third, C++20 added an initializer statement to range-based for-loops
which is also added to the pre-init statement. PreInits used to be a
`DeclStmt` which made it difficult to add arbitrary statements from
`CXXRangeForStmt`'s syntactic sugar, especially the for-loops init
statement which does not need to be a declaration. Change it to be a
general `Stmt` that can be a `CompoundStmt` to hold arbitrary Stmts,
including DeclStmts. This also avoids the `PointerUnion` workaround used
by `checkTransformableLoopNest`.

End-to-end tests are added to verify the expected number and order of
loop execution and evaluations of expressions (such as iterator
dereference). The order and number of evaluations of expressions in
canonical loops is explicitly undefined by OpenMP but checked here for
clarification and for changes to be noticed.
2024-05-22 14:30:31 +02:00
SunilKuravinakop
ce67fcf15f
Avoid unevaluated implicit private (#92055)
For every variable used under `#pragma omp task` directive
(`DeclRefExpr`) an ImplicitPrivateVariable is created in the AST, if
`private` or `shared` clauses are not present. If the variable has the
property of `non_odr_use_unevaluated` e.g. for statements which use
`sizeof( i )` `i` will have `non_odr_use_unevaluated` . In such cases
CodeGen was asserting by avoiding emitting of LLVM IR for such
variables. To prevent this assertion this checkin avoids adding the
ImplicitPrivateVariable for variables with `non_odr_use_unevaluated`.

---------

Authored-by: Sunil Kuravinakop <kuravina@pe28vega.us.cray.com>
2024-05-16 12:25:53 -04:00
Michael Kruse
b0b6c16b47
[Clang][OpenMP][Tile] Allow non-constant tile sizes. (#91345)
Allow non-constants in the `sizes` clause such as
```
#pragma omp tile sizes(a)
for (int i = 0; i < n; ++i)
```
This is permitted since tile was introduced in [OpenMP
5.1](https://www.openmp.org/spec-html/5.1/openmpsu53.html#x78-860002.11.9).

It is possible to sneak-in negative numbers at runtime as in
```
int a = -1;
#pragma omp tile sizes(a)
```
Even though it is not well-formed, it should still result in every loop
iteration to be executed exactly once, an invariant of the tile
construct that we should ensure. `ParseOpenMPExprListClause` is
extracted-out to be reused by the `permutation` clause of the
`interchange` construct. Some care was put into ensuring correct behavior
in template contexts.
2024-05-13 16:10:58 +02:00
Michael Kruse
f0590581aa [Clang][OpenMP] Fix unused lambda capture warning. 2024-05-13 14:55:34 +02:00
Michael Kruse
e76b257483
[Clang][OpenMP][Tile] Ensure AST node uniqueness. (#91325)
One of the constraints of an AST is that every node object must appear
at most once, hence we define lamdas that create a new AST node at every
use.
2024-05-13 14:31:39 +02:00
Krystian Stasiowski
8009bbec59
Reapply "[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" (#90152)
Reapplies #84050, addressing a bug which cases a crash when an
expression with the type of the current instantiation is used as the
_postfix-expression_ in a class member access expression (arrow form).
2024-04-30 14:25:09 -04:00
Pranav Kant
0c6e1ca1c7 Revert "[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)"
This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.
2024-04-26 00:18:08 +00:00
Krystian Stasiowski
a8fd0d029d
[Clang][Sema] Diagnose class member access expressions naming non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)
Consider the following:
```cpp
template<typename T>
struct A
{
    auto f()
    {
        return this->x;
    }
};
```
Although `A` has no dependent base classes and the lookup context for
`x` is the current instantiation, we currently do not diagnose the
absence of a member `x` until `A<T>::f` is instantiated. This patch
moves the point of diagnosis for such expressions to occur at the point
of definition (i.e. prior to instantiation).
2024-04-25 14:50:53 -04:00