1209 Commits

Author SHA1 Message Date
Matheus Izvekov
91cdd35008
[clang] Improve nested name specifier AST representation (#147835)
This is a major change on how we represent nested name qualifications in
the AST.

* The nested name specifier itself and how it's stored is changed. The
prefixes for types are handled within the type hierarchy, which makes
canonicalization for them super cheap, no memory allocation required.
Also translating a type into nested name specifier form becomes a no-op.
An identifier is stored as a DependentNameType. The nested name
specifier gains a lightweight handle class, to be used instead of
passing around pointers, which is similar to what is implemented for
TemplateName. There is still one free bit available, and this handle can
be used within a PointerUnion and PointerIntPair, which should keep
bit-packing aficionados happy.
* The ElaboratedType node is removed, all type nodes in which it could
previously apply to can now store the elaborated keyword and name
qualifier, tail allocating when present.
* TagTypes can now point to the exact declaration found when producing
these, as opposed to the previous situation of there only existing one
TagType per entity. This increases the amount of type sugar retained,
and can have several applications, for example in tracking module
ownership, and other tools which care about source file origins, such as
IWYU. These TagTypes are lazily allocated, in order to limit the
increase in AST size.

This patch offers a great performance benefit.

It greatly improves compilation time for
[stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for
`test_on2.cpp` in that project, which is the slowest compiling test,
this patch improves `-c` compilation time by about 7.2%, with the
`-fsyntax-only` improvement being at ~12%.

This has great results on compile-time-tracker as well:

![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831)

This patch also further enables other optimziations in the future, and
will reduce the performance impact of template specialization resugaring
when that lands.

It has some other miscelaneous drive-by fixes.

About the review: Yes the patch is huge, sorry about that. Part of the
reason is that I started by the nested name specifier part, before the
ElaboratedType part, but that had a huge performance downside, as
ElaboratedType is a big performance hog. I didn't have the steam to go
back and change the patch after the fact.

There is also a lot of internal API changes, and it made sense to remove
ElaboratedType in one go, versus removing it from one type at a time, as
that would present much more churn to the users. Also, the nested name
specifier having a different API avoids missing changes related to how
prefixes work now, which could make existing code compile but not work.

How to review: The important changes are all in
`clang/include/clang/AST` and `clang/lib/AST`, with also important
changes in `clang/lib/Sema/TreeTransform.h`.

The rest and bulk of the changes are mostly consequences of the changes
in API.

PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just
for easier to rebasing. I plan to rename it back after this lands.

Fixes #136624
Fixes https://github.com/llvm/llvm-project/issues/43179
Fixes https://github.com/llvm/llvm-project/issues/68670
Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-09 05:06:53 -03:00
David Pagan
f443f56133
[clang][Sema][NFC] Fixed incorrect assert messages in SemaOpenMP (#150305) 2025-07-23 14:04:49 -07:00
David Pagan
45d99c26c3
[clang][OpenMP] In 6.0, can omit length in array section (#148048)
In OpenMP 6.0 specification, section 5.2.5 Array Sections, page 166,
lines 28-28:

When the length is absent and the size of the dimension is not known,
the array section is an assumed-size array.

Testing
- Updated LIT test
- check-all
- OpenMP_VV (formerly sollve) test case
tests/6.0/target/test_target_assumed_array_size.c
2025-07-23 10:53:38 -07:00
Fazlay Rabbi
5daaaf8d7d
[OpenMP 6.0] Allow only byref arguments with need_device_addr modifier on adjust_args clause (#149586)
If the need_device_addr adjust-op modifier is present, each list item
that appears in the clause must refer to an argument in the declaration
of the function variant that has a reference type.

Reference:
OpenMP 6.0 [Sec 9.6.2, page 332, line 31-33, adjust_args clause,
Restrictions]
2025-07-23 09:38:13 -07:00
Robert Imschweiler
77861b3a8f
[OpenMP][clang] 6.0: parsing/sema for message/severity for parallel (#146093)
Implement parsing and semantic analysis support for the message and
severity clauses that have been added to the parallel directive in
OpenMP 6.0, 12.1.
2025-07-11 11:22:06 +02:00
Robert Imschweiler
f624ba2d9d
[OpenMP][clang] 6.0: parsing/sema for num_threads 'strict' modifier (#145490)
Implement parsing and semantic analysis support for the optional
'strict' modifier of the num_threads clause. This modifier has been
introduced in OpenMP 6.0, section 12.1.2.

Note: this is basically 1:1 https://reviews.llvm.org/D138328.
2025-06-24 21:12:40 +02:00
Walter J.T.V
8c3fbaf0ee
[Clang][OpenMP][LoopTransformations] Fix incorrect number of generated loops for Tile and Reverse directives (#140532)
This patch is closely related to #139293 and addresses an existing issue
in the loop transformation codebase. Specifically, it corrects the
handling of the `NumGeneratedLoops` variable in
`OMPLoopTransformationDirective` AST nodes and its inheritors (such as
OMPUnrollDirective, OMPTileDirective, etc.).

Previously, this variable was inaccurately set for certain
transformations like reverse or tile. While this did not lead to
functional bugs, since the value was only checked to determine whether
it was greater than zero or equal to zero, the inconsistency could
introduce problems when supporting more complex directives in the
future.
2025-06-18 20:52:41 +02:00
Fazlay Rabbi
02550da932
[OpenMP 60] Initial parsing/sema for need_device_addr modifier on adjust_args clause (#143442)
Adds initial parsing and semantic analysis for `need_device_addr`
modifier on `adjust_args` clause.
2025-06-11 22:06:11 -07:00
Abhinav Gaba
02b6849cf1
[Clang][OpenMP] Fix mapping of arrays of structs with members with mappers (#142511)
This builds upon #101101 from @jyu2-git, which used compiler-generated
mappers when mapping an array-section of structs with members that have
user-defined default mappers.

Now we do the same when mapping arrays of structs.
2025-06-11 19:03:55 +00:00
CHANDRA GHALE
afbcf9529a
[OpenMP 6.0 ]Codegen for Reduction over private variables with reduction clause (#134709)
Codegen support for reduction over private variable with reduction
clause. Section 7.6.10 in in OpenMP 6.0 spec.
- An internal shared copy is initialized with an initializer value.
- The shared copy is updated by combining its value with the values from
the private copies created by the clause.
- Once an encountering thread verifies that all updates are complete,
its original list item is updated by merging its value with that of the
shared copy and then broadcast to all threads.

Sample Test Case from OpenMP 6.0 Example 
```
#include <assert.h>
#include <omp.h>
#define N 10

void do_red(int n, int *v, int &sum_v)
{
    sum_v = 0; // sum_v is private
    #pragma omp for reduction(original(private),+: sum_v)
    for (int i = 0; i < n; i++) 
    {
        sum_v += v[i];
    }
}

int main(void)
{
    int v[N];
    for (int i = 0; i < N; i++)
        v[i] = i;
    #pragma omp parallel num_threads(4)
    {
        int s_v; // s_v is private
        do_red(N, v, s_v);
        assert(s_v == 45);
    }
    return 0;
}
```
Expected Codegen:
```
 // A shared global/static variable is introduced for the reduction result.
 // This variable is initialized (e.g., using memset or a UDR initializer)
 // e.g., .omp.reduction.internal_private_var

 // Barrier before any thread performs combination
  call void @__kmpc_barrier(...)

 // Initialization block (executed by thread 0)
 // e.g., call void @llvm.memset.p0.i64(...) or call @udr_initializer(...)

  call void @__kmpc_critical(...)
    // Inside critical section:
    // Load the current value from the shared variable
    // Load the thread-local private variable's value
    // Perform the reduction operation 
    // Store the result back to the shared variable

  call void @__kmpc_end_critical(...)
  // Barrier after all threads complete their combinations

  call void @__kmpc_barrier(...)
 // Broadcast phase:
 // Load the final result from the shared variable)
 // Store the final result to the original private variable in each thread
 // Final barrier after broadcast

  call void @__kmpc_barrier(...)
```

---------

Co-authored-by: Chandra Ghale <ghale@pe31.hpc.amslabs.hpecorp.net>
2025-06-11 14:01:31 +05:30
Kazu Hirata
d953ca5659
[Sema] Drop const from a return type (NFC) (#143224) 2025-06-06 22:55:11 -07:00
Joseph Huber
539a2ac5f2
[OpenMP] Fix atomic compare handling with overloaded operators (#141142)
Summary:
When there are overloaded C++ operators in the global namespace the AST
node for these is not a `BinaryExpr` but a `CXXOperatorCallExpr`. Modify
the uses to handle this case, basically just treating it as a binary
expression with two arguments.

Fixes https://github.com/llvm/llvm-project/issues/141085
2025-05-28 21:44:55 -05:00
Aaron Ballman
131c8f84bb
[OpenMP] Fix crash with invalid size expression (#139745)
We weren't correctly handling size expressions with errors before trying
to get the type of the size expression.

No release note needed because support for 'stripe' was added to the
current release.

Fixes #139433
2025-05-13 12:55:53 -04:00
Max Graey
8aaac80ddd
[NFC] Use more isa and isa_and_nonnull instead dyn_cast for predicates (#137393)
Also fix some typos in comments

---------

Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2025-05-13 22:34:42 +08:00
Amr Hesham
a4186bd04b
[clang][OpenMP] Add error for large expr in collapse clause (#138592)
Report error when OpenMP collapse clause has an expression that can't be
represented in 64-bit

Issue #138445
2025-05-12 21:34:35 +02:00
Aaron Ballman
d5974524de
[OpenMP] Fix crash with invalid argument to simd collapse (#139313)
Same as with other recent crash fixes, this is checking whether the
argument expression contains errors or not.

Fixes #138493
2025-05-12 08:04:22 -04:00
Aaron Ballman
ab6c4f5085
[OpenMP] Fix a crash on invalid with unroll partial (#139280)
You cannot get the integer constant expression's value if the expression
contains errors.

Fixes https://github.com/llvm/llvm-project/issues/139267
2025-05-09 12:32:44 -04:00
Aaron Ballman
b249b49c13
[OpenMP] Fix crash when diagnosing dist_schedule (#139277)
We were failing to pass a required argument when emitting the
diagnostic, so the source range was being used in place of an index.
This caused a failed assertion due to the incorrect index.

Fixes #139266
2025-05-09 11:12:19 -04:00
Krzysztof Parzyszek
6094080d27
[clang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139115)
The OpenMP version is stored in language options in ASTContext. If the
context is not available, use the fallback version.

RFC:
https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
2025-05-09 07:41:54 -05:00
Aaron Ballman
187a83f86c
[OpenMP] No long crash on an invalid sizes argument (#139118)
We were trying to get type information out of an expression node which
contained errors. That causes the type of the expression to be
dependent, which the code was not expecting. Now we handle error
conditions with an early return.

Fixes #139073
2025-05-09 06:52:06 -04:00
Kazu Hirata
f002f300c5
[clang] Remove unused local variables (NFC) (#138453) 2025-05-04 10:51:40 -07:00
Krzysztof Parzyszek
52c62364e7
[OpenMP] Remove "alternativeName" from Clause and Directive classes (#138179)
The "alternativeName" was introduced ~5 years ago in D82405, and at the
moment it has only one use, the one that the original change introduced.

OpenMP 6.0 spec has introduced different spellings of some directives,
but the "alternativeName" is not an adequate mechanism to implement it.

For those reasons remove the "alternativeName" member from both Clause
and Directive in DirectiveBase.td.

Since the alternativeName text appeared in a number of clang OpenMP
tests, implement `getOpenMPClauseNameForDiag` in SemaOpenMP.cpp to
preserve the text of the diagnostics.
2025-05-02 13:02:24 -05:00
Vlad Serebrennikov
4ba27780d3 [clang][NFC] Convert Sema::CorrectTypoKind to scoped enum 2025-05-02 13:20:41 +03:00
Vlad Serebrennikov
140c2b6d08 [clang][NFC] Convert Sema::AllowFoldKind to scoped enum 2025-05-02 10:48:08 +03:00
Vlad Serebrennikov
0294c3615c [clang][NFC] Reland "Convert Sema::TryCaptureKind to scoped enum" 2025-05-02 09:39:16 +03:00
Vlad Serebrennikov
048befe9ef Revert "[clang][NFC] Convert Sema::TryCaptureKind to scoped enum"
This reverts commit be6497ff7583248d76a6710dd48cfeb63dd68f27.
2025-05-02 09:29:35 +03:00
Vlad Serebrennikov
be6497ff75 [clang][NFC] Convert Sema::TryCaptureKind to scoped enum 2025-05-02 09:25:58 +03:00
Ernesto Su
89f930a7de
[clang][OpenMP] Fix/enforce order-concurrent-nestable rules (#135463)
OpenMP has restrictions on directives allowed to be strictly nested
inside a
construct with the order(concurrent) clause specified.
 - OpenMP 5.0, 5.1, and 5.2 allows: 'loop', 'parallel', 'simd', and
     combined directives starting with 'parallel'.
 - OpenMP 6.0 allows: the above directives plus 'atomic' and
     all loop-transformation directives.

Furthermore, a region that corresponds to a construct with
order(concurrent)
specified may not contain calls to the OpenMP runtime API.

This PR fixes the following issues in the current implementation:

With -fopenmp-version=50: none of the nesting restrictions above were
enforced
 With -fopenmp-version=60:
1. Clang did not reject OpenMP runtime APIs encountered in the region.
2. Clang erroneously rejected combined directives starting with
parallel.

---------

Co-authored-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
2025-04-18 13:57:50 -04:00
Matheus Izvekov
10a1502421
[clang] AST: remove source locations from [Variable/Dependent]SizedArrayType (#135511) 2025-04-14 10:44:25 -03:00
Matheus Izvekov
14f7bd63b9
Reland: [clang] preserve class type sugar when taking pointer to member (#132401)
Original PR: #130537
Originally reverted due to revert of dependent commit. Relanding with no
changes.

This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the base class.

Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.

The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntatically, and
they represent the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.

This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.

As usual, includes a few drive-by fixes in order to make use of the
improvements.
2025-03-21 13:20:52 -03:00
CHANDRA GHALE
6da8f56619
[OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (#129938)
Initial Parse/Sema support for reduction over private variable with
reduction clause.
Section 7.6.10 in  in OpenMP 6.0 spec. 
- list item in a reduction clause can now be private in the enclosing
context.
-  Added support for _original-sharing-modifier_  with reduction clause.

---------

Co-authored-by: Chandra Ghale <ghale@pe31.hpc.amslabs.hpecorp.net>
2025-03-21 14:19:08 +05:30
Matheus Izvekov
5151e6d7fe
Revert "Reland: [clang] preserve class type sugar when taking pointer to member" (#132280)
Reverts llvm/llvm-project#132234

Needs to be reverted due to dependency.

This blocks reverting another PR, see here:
https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-20 17:52:48 -03:00
Matheus Izvekov
578f38cd08
Reland: [clang] preserve class type sugar when taking pointer to member (#132234)
Original PR: #130537
Reland after updating lldb too.

This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the base class.

Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.

The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntatically, and
they represent the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.

This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.

As usual, includes a few drive-by fixes in order to make use of the
improvements.
2025-03-20 15:33:54 -03:00
Matheus Izvekov
6cd62ad08c
Revert "[clang] improve class type sugar preservation in pointers to members" (#132215)
Reverts llvm/llvm-project#130537

This missed updating lldb, which we didn't notice due to lack of
pre-commit CI.
2025-03-20 11:09:25 -03:00
Matheus Izvekov
9b1f905b48
[clang] improve class type sugar preservation in pointers to members (#130537)
This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the class.

Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.

The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntactically, and it
also represents the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.

This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.

As usual, includes a few drive-by fixes in order to make use of the
improvements, and removing some duplications, for example
CheckBaseClassAccess is deduplicated from across SemaAccess and
SemaCast.
2025-03-20 10:30:24 -03:00
Kazu Hirata
8f011e2c7f
[Sema] Avoid repeated hash lookups (NFC) (#131263) 2025-03-14 07:20:22 -07:00
Ritanya-B-Bharadwaj
63635c1746
[clang] [OpenMP] New OpenMP 6.0 self_maps clause (#129888)
Initial parsing/sema support for self maps in map and requirement clause
[Sections 7.9.6 and 10.5.1.6 in OpenMP 6.0 spec]
2025-03-11 16:31:42 +05:30
Zahira Ammarguellat
cf69b4c668
[Clang] [OpenMP] Add support for '#pragma omp stripe'. (#126927)
This patch was reviewed and approved here:
https://github.com/llvm/llvm-project/pull/119891
However it has been reverted here:
083df25dc2
due to a build issue here:
https://lab.llvm.org/buildbot/#/builders/51/builds/10694

This patch is reintroducing the support.
2025-02-13 07:14:36 -05:00
Kazu Hirata
67e1e98811 Revert "[Clang] [OpenMP] Add support for '#pragma omp stripe'. (#119891)"
This reverts commit 070f84ebc89b11df616a83a56df9ac56efbab783.

Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/51/builds/10694
2025-02-11 12:39:01 -08:00
Zahira Ammarguellat
070f84ebc8
[Clang] [OpenMP] Add support for '#pragma omp stripe'. (#119891)
Implement basic parsing and semantic support for `#pragma omp stripe`
constuct introduced in
https://www.openmp.org/wp-content/uploads/[OpenMP-API-Specification-6-0.pdf](https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-6-0.pdf),
section 11.7.
2025-02-11 13:58:21 -05:00
Kazu Hirata
c50f924aea
[Sema] Avoid repeated hash lookups (NFC) (#126674) 2025-02-11 09:07:15 -08:00
Joseph Huber
605a9e37b6
[OpenMP] Fix infinite loop on recursive initializers (#126269)
Summary:
If the user tried to initialize a gobal declare target variable with
itself the compiler will hang forever. Add a visited set to make sure
this stops.

Fixes: https://github.com/llvm/llvm-project/issues/69194
2025-02-07 13:44:20 -06:00
David Pagan
a5fc7c3ac1
[clang][OpenMP] New OpenMP 6.0 assumption clause, 'no_openmp_constructs' (#125933)
Add initial parsing/sema support for new assumption clause so clause can
be specified. For now, it's ignored, just like the others.

Added support for 'no_openmp_construct' to release notes.

Testing
- Updated appropriate LIT tests.
- Testing: check-all
2025-02-06 12:41:10 -08:00
David Pagan
659d1feeaf
[clang][OpenMP] OpenMP 6.0 updates to restrictions with order/concurrent (#125621)
From OpenMP 6.0 features list
- OpenMP directives in concurrent loop regions
- atomics constructs on concurrent loop regions
- Lift nesting restriction on concurrent loop

Testing
- Updated test/OpenMP/for_order_messages.cpp
- check-all
2025-02-05 10:10:06 -08:00
Ritanya-B-Bharadwaj
8c36665267
[OpenMP]Initial parsing/sema support for target_device selector set (#118471)
This patch adds initial support for target_device selector set - Section
9.2 (Spec 6.0)
2025-02-05 19:24:24 +05:30
David Pagan
ad38e24eb7
[clang][OpenMP] Add 'align' modifier for 'allocate' clause (#121814)
The 'align' modifier is now accepted in the 'allocate' clause. Added LIT
tests covering codegen, PCH, template handling, and serialization for
'align' modifier.

Added support for align-modifier to release notes.

Testing
- New allocate modifier LIT tests.
- OpenMP LIT tests.
- check-all
2025-01-13 05:44:48 -08:00
Kazu Hirata
1e3e199ed9
[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-27 09:13:28 -08:00
ShashwathiNavada
612f8ec7ac
seq_cst is allowed in Flush since OpenMP 5.1. (#114072)
This PR adds support seq_cst (sequential consistency) clause for the
flush directive in OpenMP. The seq_cst clause enforces a stricter memory
ordering, ensuring that all threads observe the memory effects of the
flush in the same order, improving consistency in memory operations
across threads.

---------

Co-authored-by: Shashwathi N <nshashwa@pe28vega.hpc.amslabs.hpecorp.net>
Co-authored-by: CHANDRA GHALE <chandra.nitdgp@gmail.com>
2024-11-25 16:08:39 +05:30
Kazu Hirata
46d750be2e
[Sema] Remove unused includes (NFC) (#116461)
Identified with misc-include-cleaner.
2024-11-16 07:37:33 -08:00
Joseph Huber
b9d678d22f
[Clang] Use TargetInfo when deciding if an address space is compatible (#115777)
Summary:
Address spaces are used in several embedded and GPU targets to describe
accesses to different types of memory. Currently we use the address
space enumerations to control which address spaces are considered
supersets of eachother, however this is also a target level property as
described by the C standard's passing mentions. This patch allows the
address space checks to use the target information to decide if a
pointer conversion is legal. For AMDGPU and NVPTX, all supported address
spaces can be converted to the default address space.

More semantic checks can be added on top of this, for now I'm mainly
looking to get more standard semantics working for C/C++. Right now the
address space conversions must all be done explicitly in C/C++ unlike
the offloading languages which define their own custom address spaces
that just map to the same target specific ones anyway. The main question
is if this behavior is a function of the target or the language.
2024-11-15 06:58:36 -06:00