Skip to content

Commit 2118678

Browse files
committed
Merge remote-tracking branch 'upstream/sycl' into return_static_to_property
2 parents 06d8a7d + de6e848 commit 2118678

File tree

78 files changed

+963
-3706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+963
-3706
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ def warn_drv_unknown_cuda_version: Warning<
7979
InGroup<CudaUnknownVersion>;
8080
def err_drv_cuda_host_arch : Error<"unsupported architecture '%0' for host compilation.">;
8181
def err_drv_no_sycl_libspirv : Error<
82-
"cannot find `libspirv-nvptx64--nvidiacl.bc`. Provide path to libspirv library via "
83-
"-fsycl-libspirv-path, or pass -fno-sycl-libspirv to build without linking with libspirv.">;
82+
"cannot find 'libspirv-nvptx64--nvidiacl.bc'; provide path to libspirv "
83+
"library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build "
84+
"without linking with libspirv">;
8485
def err_drv_mix_cuda_hip : Error<"Mixed Cuda and HIP compilation is not supported.">;
8586
def err_drv_bad_target_id : Error<"Invalid target ID: %0 (A target ID is a processor name "
8687
"followed by an optional list of predefined features post-fixed by a plus or minus sign deliminated "
@@ -285,12 +286,12 @@ def err_drv_omp_host_target_not_supported : Error<
285286
def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
286287
"The option -fopenmp-targets must be used in conjunction with a -fopenmp option compatible with offloading, please use -fopenmp=libomp or -fopenmp=libiomp5.">;
287288
def err_drv_expecting_fsycl_with_sycl_opt : Error<
288-
"The option %0 must be used in conjunction with -fsycl to enable offloading.">;
289+
"'%0' must be used in conjunction with '-fsycl' to enable offloading">;
289290
def err_drv_fsycl_with_c_type : Error<
290-
"The option '%0' must not be used in conjunction with '-fsycl', which expects C++ source.">;
291+
"'%0' must not be used in conjunction with '-fsycl', which expects C++ source">;
291292
def warn_drv_sycl_offload_target_duplicate : Warning<
292-
"The SYCL offloading target '%0' is similar to target '%1' already specified - will be ignored.">,
293-
InGroup<SyclTarget>;
293+
"SYCL offloading target '%0' is similar to target '%1' already specified; "
294+
"will be ignored">, InGroup<SyclTarget>;
294295
def err_drv_omp_offload_target_missingbcruntime : Error<
295296
"No library '%0' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-%1-bc-path to specify %1 bitcode library.">;
296297
def err_drv_omp_offload_target_bcruntime_not_found : Error<"Bitcode library '%0' does not exist.">;

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,17 +4383,32 @@ class SYCLFwdDeclEmitter
43834383
const DeclContext *DC = D->getDeclContext();
43844384

43854385
while (DC) {
4386-
const auto *NS = dyn_cast_or_null<NamespaceDecl>(DC);
4387-
4388-
if (!NS)
4389-
break;
4390-
4391-
++NamespaceCnt;
4392-
const StringRef NSInlinePrefix = NS->isInline() ? "inline " : "";
4393-
NSStr.insert(
4394-
0,
4395-
Twine(NSInlinePrefix + "namespace " + NS->getName() + " { ").str());
4396-
DC = NS->getDeclContext();
4386+
if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
4387+
++NamespaceCnt;
4388+
StringRef NSInlinePrefix = NS->isInline() ? "inline " : "";
4389+
NSStr.insert(
4390+
0,
4391+
Twine(NSInlinePrefix + "namespace " + NS->getName() + " { ").str());
4392+
DC = NS->getDeclContext();
4393+
} else {
4394+
// We should be able to handle a subset of the decl-context types to
4395+
// make our namespaces for forward declarations as specific as possible,
4396+
// so just skip them here. We can't use their names, since they would
4397+
// not be forward declarable, but we can try to make them as specific as
4398+
// possible.
4399+
// This permits things such as:
4400+
// namespace N1 { void foo() { kernel<class K>(...); }}
4401+
// and
4402+
// namespace N2 { void foo() { kernel<class K>(...); }}
4403+
// to co-exist, despite technically being against the SYCL rules.
4404+
// See SYCLKernelNameTypePrinter for the corresponding part that prints
4405+
// the kernel information for this type. These two must match.
4406+
if (isa<FunctionDecl, RecordDecl, LinkageSpecDecl>(DC)) {
4407+
DC = cast<Decl>(DC)->getDeclContext();
4408+
} else {
4409+
break;
4410+
}
4411+
}
43974412
}
43984413
OS << NSStr;
43994414
if (NamespaceCnt > 0)
@@ -4568,6 +4583,18 @@ class SYCLKernelNameTypePrinter
45684583
Quals.print(OS, Policy, /*appendSpaceIfNotEmpty*/ true);
45694584
}
45704585

4586+
// Use recursion to print the namespace-qualified name for the purposes of the
4587+
// canonical sycl example of a type being created in the kernel call.
4588+
void PrintNamespaceScopes(const DeclContext *DC) {
4589+
if (isa<NamespaceDecl, FunctionDecl, RecordDecl, LinkageSpecDecl>(DC)) {
4590+
PrintNamespaceScopes(DC->getParent());
4591+
4592+
const auto *NS = dyn_cast<NamespaceDecl>(DC);
4593+
if (NS && !NS->isAnonymousNamespace())
4594+
OS << NS->getName() << "::";
4595+
}
4596+
}
4597+
45714598
public:
45724599
SYCLKernelNameTypePrinter(raw_ostream &OS, PrintingPolicy &Policy)
45734600
: OS(OS), Policy(Policy) {}
@@ -4606,12 +4633,16 @@ class SYCLKernelNameTypePrinter
46064633

46074634
return;
46084635
}
4609-
// TODO: Next part of code results in printing of "class" keyword before
4610-
// class name in case if kernel name doesn't belong to some namespace. It
4611-
// seems if we don't print it, the integration header still represents valid
4612-
// c++ code. Probably we don't need to print it at all.
4613-
if (RD->getDeclContext()->isFunctionOrMethod()) {
4614-
OS << QualType::getAsString(T, Qualifiers(), Policy);
4636+
4637+
// Handle the canonical sycl example where the type is created for the first
4638+
// time in the kernel naming. We want to qualify this as fully as we can,
4639+
// but not in a way that won't be forward declarable. See
4640+
// SYCLFwdDeclEmitter::printForwardDecl for the corresponding list for
4641+
// printing the forward declaration, these two must match.
4642+
DeclContext *DC = RD->getDeclContext();
4643+
if (isa<FunctionDecl, RecordDecl, LinkageSpecDecl>(DC)) {
4644+
PrintNamespaceScopes(DC);
4645+
RD->printName(OS);
46154646
return;
46164647
}
46174648

clang/test/CodeGenSYCL/int_header1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// CHECK-NEXT:struct IsThisValid;
1616
// CHECK-NEXT:}}
1717

18-
// CHECK:template <> struct KernelInfo<class KernelName> {
18+
// CHECK:template <> struct KernelInfo<KernelName> {
1919
// CHECK:template <> struct KernelInfo<::nm1::nm2::KernelName0> {
2020
// CHECK:template <> struct KernelInfo<::nm1::KernelName1> {
2121
// CHECK:template <> struct KernelInfo<::nm1::KernelName3<::nm1::nm2::KernelName0>> {

clang/test/CodeGenSYCL/int_header_esimd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void testA() {
1919
h.single_task<class KernelA>([=]() __attribute__((sycl_explicit_simd)){});
2020
});
2121
}
22-
// CHECK-LABEL: template <> struct KernelInfo<class KernelA> {
22+
// CHECK-LABEL: template <> struct KernelInfo<KernelA> {
2323
// CHECK: static constexpr bool isESIMD() { return 1; }
2424

2525
// -- ESIMD Functor object kernel.
@@ -46,7 +46,7 @@ void testNA() {
4646
h.single_task<class KernelNA>([=]() {});
4747
});
4848
}
49-
// CHECK-LABEL: template <> struct KernelInfo<class KernelNA> {
49+
// CHECK-LABEL: template <> struct KernelInfo<KernelNA> {
5050
// CHECK: static constexpr bool isESIMD() { return 0; }
5151

5252
// -- Non-ESIMD Functor object kernel.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -fsycl-int-header=%t.h %s -o %t.out
2+
// RUN: FileCheck -input-file=%t.h %s
3+
4+
// This test validates the behavior of inline-kernel-names to try to put them in
5+
// the 'closest' possible namespace.
6+
7+
#include "Inputs/sycl.hpp"
8+
9+
using namespace sycl;
10+
11+
// Forward declarations of templated kernel function types:
12+
13+
namespace TopLevel {
14+
void use() {
15+
kernel_single_task<class DirectTopLevel>([]() {});
16+
// CHECK: namespace TopLevel {
17+
// CHECK-NEXT: class DirectTopLevel;
18+
// CHECK-NEXT: }
19+
}
20+
21+
struct TypeName {
22+
void member_func() {
23+
kernel_single_task<class DirectTopLevelMemFunc>([]() {});
24+
// CHECK: namespace TopLevel {
25+
// CHECK-NEXT: class DirectTopLevelMemFunc;
26+
// CHECK-NEXT: }
27+
}
28+
};
29+
30+
extern "C" {
31+
void use1() {
32+
kernel_single_task<class DirectTopLevelLinkage>([]() {});
33+
// CHECK: namespace TopLevel {
34+
// CHECK-NEXT: class DirectTopLevelLinkage;
35+
// CHECK-NEXT: }
36+
}
37+
struct LinkageTypeName {
38+
void member_func() {
39+
kernel_single_task<class DirectTopLevelLinkageMemFunc>([]() {});
40+
// CHECK: namespace TopLevel {
41+
// CHECK-NEXT: class DirectTopLevelLinkageMemFunc;
42+
// CHECK-NEXT: }
43+
}
44+
};
45+
}
46+
} // namespace TopLevel
47+
48+
namespace {
49+
void use2() {
50+
kernel_single_task<class TopLevelAnonNS>([]() {});
51+
// CHECK: namespace {
52+
// CHECK-NEXT: class TopLevelAnonNS;
53+
// CHECK-NEXT: }
54+
}
55+
56+
struct LinkageTypeName {
57+
void member_func() {
58+
kernel_single_task<class AnonNSMemFunc>([]() {});
59+
// CHECK: namespace {
60+
// CHECK-NEXT: class AnonNSMemFunc;
61+
// CHECK-NEXT: }
62+
}
63+
};
64+
} // namespace
65+
66+
inline namespace InlineTopLevel {
67+
void use3() {
68+
kernel_single_task<class InlineDirectTopLevel>([]() {});
69+
// CHECK: inline namespace InlineTopLevel {
70+
// CHECK-NEXT: class InlineDirectTopLevel;
71+
// CHECK-NEXT: }
72+
}
73+
struct LinkageTypeName {
74+
void member_func() {
75+
kernel_single_task<class InlineNSMemFunc>([]() {});
76+
// CHECK: inline namespace InlineTopLevel {
77+
// CHECK-NEXT: class InlineNSMemFunc;
78+
// CHECK-NEXT: }
79+
}
80+
};
81+
82+
inline namespace {
83+
void use4() {
84+
kernel_single_task<class AnonNS>([]() {});
85+
// CHECK: inline namespace {
86+
// CHECK-NEXT: class AnonNS;
87+
// CHECK-NEXT: }
88+
}
89+
90+
extern "C" {
91+
void use5() {
92+
kernel_single_task<class AnonNSLinkage>([]() {});
93+
// CHECK: inline namespace {
94+
// CHECK-NEXT: class AnonNSLinkage;
95+
// CHECK-NEXT: }
96+
}
97+
}
98+
struct LinkageTypeName {
99+
void member_func() {
100+
kernel_single_task<class InlineAnonNSMemFunc>([]() {});
101+
// CHECK: inline namespace {
102+
// CHECK-NEXT: class InlineAnonNSMemFunc;
103+
// CHECK-NEXT: }
104+
}
105+
};
106+
} // namespace
107+
} // namespace TopLevel
108+
109+
namespace A {
110+
namespace B {
111+
namespace {
112+
namespace C::D {
113+
struct DeepStruct {
114+
void member_func() {
115+
kernel_single_task<class WoahDeep>([]() {});
116+
// CHECK: namespace A { namespace B { namespace { namespace C { namespace D {
117+
// CHECK-NEXT: class WoahDeep;
118+
// CHECK-NEXT: }}}}}
119+
}
120+
};
121+
} // namespace C::D
122+
} // namespace
123+
} // namespace B
124+
} // namespace A

clang/test/CodeGenSYCL/integration_header.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
// CHECK-EMPTY:
5151
// CHECK-NEXT: };
5252
//
53-
// CHECK: template <> struct KernelInfo<class first_kernel> {
53+
// CHECK: template <> struct KernelInfo<first_kernel> {
5454
// CHECK: template <> struct KernelInfo<::second_namespace::second_kernel<char>> {
5555
// CHECK: template <> struct KernelInfo<::fourth_kernel<::template_arg_ns::namespaced_arg<1>>> {
5656

clang/test/CodeGenSYCL/kernel-param-acc-array-ih.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// CHECK-EMPTY:
2626
// CHECK-NEXT: };
2727

28-
// CHECK: template <> struct KernelInfo<class kernel_A> {
28+
// CHECK: template <> struct KernelInfo<kernel_A> {
2929

3030
#include "Inputs/sycl.hpp"
3131

clang/test/CodeGenSYCL/kernel-param-member-acc-array-ih.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// CHECK-EMPTY:
2626
// CHECK-NEXT: };
2727

28-
// CHECK: template <> struct KernelInfo<class kernel_C> {
28+
// CHECK: template <> struct KernelInfo<kernel_C> {
2929

3030
#include "Inputs/sycl.hpp"
3131

clang/test/CodeGenSYCL/kernel-param-pod-array-ih.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
// CHECK-EMPTY:
3232
// CHECK-NEXT: };
3333

34-
// CHECK: template <> struct KernelInfo<class kernel_B> {
35-
// CHECK: template <> struct KernelInfo<class kernel_C> {
36-
// CHECK: template <> struct KernelInfo<class kernel_D> {
34+
// CHECK: template <> struct KernelInfo<kernel_B> {
35+
// CHECK: template <> struct KernelInfo<kernel_C> {
36+
// CHECK: template <> struct KernelInfo<kernel_D> {
3737

3838
#include "Inputs/sycl.hpp"
3939

clang/test/CodeGenSYCL/parallel_for_this_item.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// CHECK-NEXT: "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3BEE"
1919
// CHECK-NEXT: };
2020

21-
// CHECK:template <> struct KernelInfo<class GNU> {
21+
// CHECK:template <> struct KernelInfo<GNU> {
2222
// CHECK-NEXT: __SYCL_DLL_LOCAL
2323
// CHECK-NEXT: static constexpr const char* getName() { return "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3GNU"; }
2424
// CHECK-NEXT: __SYCL_DLL_LOCAL
@@ -34,7 +34,7 @@
3434
// CHECK-NEXT: __SYCL_DLL_LOCAL
3535
// CHECK-NEXT: static constexpr bool callsAnyThisFreeFunction() { return 0; }
3636
// CHECK-NEXT:};
37-
// CHECK-NEXT:template <> struct KernelInfo<class EMU> {
37+
// CHECK-NEXT:template <> struct KernelInfo<EMU> {
3838
// CHECK-NEXT: __SYCL_DLL_LOCAL
3939
// CHECK-NEXT: static constexpr const char* getName() { return "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3EMU"; }
4040
// CHECK-NEXT: __SYCL_DLL_LOCAL
@@ -50,7 +50,7 @@
5050
// CHECK-NEXT: __SYCL_DLL_LOCAL
5151
// CHECK-NEXT: static constexpr bool callsAnyThisFreeFunction() { return 1; }
5252
// CHECK-NEXT:};
53-
// CHECK-NEXT:template <> struct KernelInfo<class OWL> {
53+
// CHECK-NEXT:template <> struct KernelInfo<OWL> {
5454
// CHECK-NEXT: __SYCL_DLL_LOCAL
5555
// CHECK-NEXT: static constexpr const char* getName() { return "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3OWL"; }
5656
// CHECK-NEXT: __SYCL_DLL_LOCAL
@@ -66,7 +66,7 @@
6666
// CHECK-NEXT: __SYCL_DLL_LOCAL
6767
// CHECK-NEXT: static constexpr bool callsAnyThisFreeFunction() { return 0; }
6868
// CHECK-NEXT:};
69-
// CHECK-NEXT:template <> struct KernelInfo<class RAT> {
69+
// CHECK-NEXT:template <> struct KernelInfo<RAT> {
7070
// CHECK-NEXT: __SYCL_DLL_LOCAL
7171
// CHECK-NEXT: static constexpr const char* getName() { return "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3RAT"; }
7272
// CHECK-NEXT: __SYCL_DLL_LOCAL
@@ -82,7 +82,7 @@
8282
// CHECK-NEXT: __SYCL_DLL_LOCAL
8383
// CHECK-NEXT: static constexpr bool callsAnyThisFreeFunction() { return 1; }
8484
// CHECK-NEXT:};
85-
// CHECK-NEXT:template <> struct KernelInfo<class FOX> {
85+
// CHECK-NEXT:template <> struct KernelInfo<FOX> {
8686
// CHECK-NEXT: __SYCL_DLL_LOCAL
8787
// CHECK-NEXT: static constexpr const char* getName() { return "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3FOX"; }
8888
// CHECK-NEXT: __SYCL_DLL_LOCAL
@@ -98,7 +98,7 @@
9898
// CHECK-NEXT: __SYCL_DLL_LOCAL
9999
// CHECK-NEXT: static constexpr bool callsAnyThisFreeFunction() { return 1; }
100100
// CHECK-NEXT:};
101-
// CHECK-NEXT:template <> struct KernelInfo<class BEE> {
101+
// CHECK-NEXT:template <> struct KernelInfo<BEE> {
102102
// CHECK-NEXT: __SYCL_DLL_LOCAL
103103
// CHECK-NEXT: static constexpr const char* getName() { return "_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E3BEE"; }
104104
// CHECK-NEXT: __SYCL_DLL_LOCAL

clang/test/CodeGenSYCL/union-kernel-param-ih.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// CHECK-EMPTY:
2525
// CHECK-NEXT:};
2626

27-
// CHECK: template <> struct KernelInfo<class kernel_A> {
27+
// CHECK: template <> struct KernelInfo<kernel_A> {
2828

2929
union MyUnion {
3030
int FldInt;

clang/test/CodeGenSYCL/wrapped-accessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// CHECK-EMPTY:
2222
// CHECK-NEXT: };
2323

24-
// CHECK: template <> struct KernelInfo<class wrapped_access> {
24+
// CHECK: template <> struct KernelInfo<wrapped_access> {
2525

2626
#include "Inputs/sycl.hpp"
2727

clang/test/Driver/clang-offload-bundler-tgtsym.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// CHECK-NOT: static_used
2222
// CHECK-NOT: sycl-spir64.llvm.used
2323
// CHECK-NOT: sycl-spir64.llvm.compiler.used
24+
// CHECK-NOT: sycl-spir64.const_as
25+
26+
const __attribute__((opencl_constant)) char const_as[] = "abc";
2427

2528
extern void undefined_func(void);
2629

0 commit comments

Comments
 (0)