
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:  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
231 lines
9.0 KiB
C++
231 lines
9.0 KiB
C++
// RUN: %clang_cc1 %s -fopenacc -ast-dump | FileCheck %s
|
|
|
|
// Test this with PCH.
|
|
// RUN: %clang_cc1 %s -fopenacc -emit-pch -o %t %s
|
|
// RUN: %clang_cc1 %s -fopenacc -include-pch %t -ast-dump-all | FileCheck %s
|
|
|
|
#ifndef PCH_HELPER
|
|
#define PCH_HELPER
|
|
int some_int();
|
|
short some_short();
|
|
long some_long();
|
|
enum E{};
|
|
E some_enum();
|
|
struct CorrectConvert {
|
|
operator int();
|
|
} Convert;
|
|
|
|
|
|
void NormalUses() {
|
|
// CHECK: FunctionDecl{{.*}}NormalUses
|
|
// CHECK-NEXT: CompoundStmt
|
|
#pragma acc parallel loop num_workers(some_int())
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CallExpr{{.*}}'int'
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay>
|
|
// CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc kernels loop num_workers(some_short())
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CallExpr{{.*}}'short'
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}}'short (*)()' <FunctionToPointerDecay>
|
|
// CHECK-NEXT: DeclRefExpr{{.*}}'short ()' lvalue Function{{.*}} 'some_short' 'short ()'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc parallel loop num_workers(some_long())
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CallExpr{{.*}}'long'
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}}'long (*)()' <FunctionToPointerDecay>
|
|
// CHECK-NEXT: DeclRefExpr{{.*}}'long ()' lvalue Function{{.*}} 'some_long' 'long ()'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc parallel loop num_workers(some_enum())
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CallExpr{{.*}}'E'
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}}'E (*)()' <FunctionToPointerDecay>
|
|
// CHECK-NEXT: DeclRefExpr{{.*}}'E ()' lvalue Function{{.*}} 'some_enum' 'E ()'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc kernels loop num_workers(Convert)
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <UserDefinedConversion>
|
|
// CHECK-NEXT: CXXMemberCallExpr{{.*}}'int'
|
|
// CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator int
|
|
// CHECK-NEXT: DeclRefExpr{{.*}} 'struct CorrectConvert' lvalue Var
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
}
|
|
|
|
template<typename T, typename U>
|
|
void TemplUses(T t, U u) {
|
|
// CHECK-NEXT: FunctionTemplateDecl
|
|
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 0 T
|
|
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 1 U
|
|
// CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T, U)'
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T'
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} referenced u 'U'
|
|
// CHECK-NEXT: CompoundStmt
|
|
|
|
#pragma acc parallel loop num_workers(t)
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: DeclRefExpr{{.*}} 'T' lvalue ParmVar{{.*}} 't' 'T'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc kernels loop num_workers(u)
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc parallel loop num_workers(U::value)
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>' lvalue
|
|
// CHECK-NEXT: NestedNameSpecifier TypeSpec 'U'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc kernels loop num_workers(T{})
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CXXUnresolvedConstructExpr{{.*}} 'T' 'T' list
|
|
// CHECK-NEXT: InitListExpr{{.*}} 'void'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc parallel loop num_workers(U{})
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CXXUnresolvedConstructExpr{{.*}} 'U' 'U' list
|
|
// CHECK-NEXT: InitListExpr{{.*}} 'void'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc kernels loop num_workers(typename U::IntTy{})
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CXXUnresolvedConstructExpr{{.*}} 'typename U::IntTy' 'typename U::IntTy' list
|
|
// CHECK-NEXT: InitListExpr{{.*}} 'void'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
#pragma acc parallel loop num_workers(typename U::ShortTy{})
|
|
for (unsigned i = 0; i < 5; ++i);
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CXXUnresolvedConstructExpr{{.*}} 'typename U::ShortTy' 'typename U::ShortTy' list
|
|
// CHECK-NEXT: InitListExpr{{.*}} 'void'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// Check the instantiated versions of the above.
|
|
// CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (CorrectConvert, HasInt)' implicit_instantiation
|
|
// CHECK-NEXT: TemplateArgument type 'CorrectConvert'
|
|
// CHECK-NEXT: RecordType{{.*}} 'CorrectConvert'
|
|
// CHECK-NEXT: CXXRecord{{.*}} 'CorrectConvert'
|
|
// CHECK-NEXT: TemplateArgument type 'HasInt'
|
|
// CHECK-NEXT: RecordType{{.*}} 'HasInt'
|
|
// CHECK-NEXT: CXXRecord{{.*}} 'HasInt'
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} used t 'CorrectConvert'
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} used u 'HasInt'
|
|
// CHECK-NEXT: CompoundStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <UserDefinedConversion>
|
|
// CHECK-NEXT: CXXMemberCallExpr{{.*}}'int'
|
|
// CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator int
|
|
// CHECK-NEXT: DeclRefExpr{{.*}} 'CorrectConvert' lvalue ParmVar
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion>
|
|
// CHECK-NEXT: CXXMemberCallExpr{{.*}}'char'
|
|
// CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char
|
|
// CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
|
|
// CHECK-NEXT: DeclRefExpr{{.*}} 'const int' lvalue Var{{.*}} 'value' 'const int'
|
|
// CHECK-NEXT: NestedNameSpecifier TypeSpec 'HasInt'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <UserDefinedConversion>
|
|
// CHECK-NEXT: CXXMemberCallExpr{{.*}}'int'
|
|
// CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator int
|
|
// CHECK-NEXT: MaterializeTemporaryExpr{{.*}} 'CorrectConvert' lvalue
|
|
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'CorrectConvert' functional cast to struct CorrectConvert <NoOp>
|
|
// CHECK-NEXT: InitListExpr{{.*}}'CorrectConvert'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion>
|
|
// CHECK-NEXT: CXXMemberCallExpr{{.*}}'char'
|
|
// CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char
|
|
// CHECK-NEXT: MaterializeTemporaryExpr{{.*}} 'HasInt' lvalue
|
|
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'HasInt' functional cast to struct HasInt <NoOp>
|
|
// CHECK-NEXT: InitListExpr{{.*}}'HasInt'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} kernels loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'typename HasInt::IntTy':'int' functional cast to typename HasInt::IntTy <NoOp>
|
|
// CHECK-NEXT: InitListExpr{{.*}}'typename HasInt::IntTy':'int'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
|
|
// CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
|
|
// CHECK-NEXT: num_workers clause
|
|
// CHECK-NEXT: CXXFunctionalCastExpr{{.*}} 'typename HasInt::ShortTy':'short' functional cast to typename HasInt::ShortTy <NoOp>
|
|
// CHECK-NEXT: InitListExpr{{.*}}'typename HasInt::ShortTy':'short'
|
|
// CHECK-NEXT: ForStmt
|
|
// CHECK: NullStmt
|
|
}
|
|
struct HasInt {
|
|
using IntTy = int;
|
|
using ShortTy = short;
|
|
static constexpr int value = 1;
|
|
|
|
operator char();
|
|
};
|
|
|
|
void Inst() {
|
|
TemplUses<CorrectConvert, HasInt>({}, {});
|
|
}
|
|
#endif // PCH_HELPER
|