Skip to content

Commit 7d548f2

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#2)
2 parents 26aff04 + 78d80a1 commit 7d548f2

File tree

164 files changed

+2924
-594
lines changed

Some content is hidden

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

164 files changed

+2924
-594
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group<f_Group>;
18181818
def fintelfpga : Flag<["-"], "fintelfpga">, Group<f_Group>,
18191819
Flags<[CC1Option, CoreOption]>, HelpText<"Perform ahead of time compilation for FPGA">;
18201820
def fsycl : Flag<["-"], "fsycl">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
1821-
HelpText<"generate SYCL code.">;
1821+
HelpText<"Generate SYCL code">;
18221822
def fno_sycl : Flag<["-"], "fno-sycl">, Group<f_Group>, Flags<[NoArgumentUnused, CoreOption]>;
18231823
def fsycl_device_only : Flag<["-"], "fsycl-device-only">, Flags<[CoreOption]>,
18241824
HelpText<"Compile SYCL kernels for device">;

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,6 +2455,67 @@ static bool isTypeSubstitutable(Qualifiers Quals, const Type *Ty,
24552455
return true;
24562456
}
24572457

2458+
namespace {
2459+
struct DeclContextDesc {
2460+
Decl::Kind DeclKind;
2461+
StringRef Name;
2462+
};
2463+
} // namespace
2464+
2465+
// For Scopes argument, the only supported Decl::Kind values are:
2466+
// - Namespace
2467+
// - CXXRecord
2468+
// - ClassTemplateSpecialization
2469+
static bool matchQualifiedTypeName(const QualType &Ty,
2470+
ArrayRef<DeclContextDesc> Scopes) {
2471+
// The idea: check the declaration context chain starting from the type
2472+
// itself. At each step check the context is of expected kind
2473+
// (namespace) and name.
2474+
const CXXRecordDecl *RecTy = Ty->getAsCXXRecordDecl();
2475+
2476+
if (!RecTy)
2477+
return false; // only classes/structs supported
2478+
const auto *Ctx = dyn_cast<DeclContext>(RecTy);
2479+
2480+
for (const auto &Scope : llvm::reverse(Scopes)) {
2481+
Decl::Kind DK = Ctx->getDeclKind();
2482+
StringRef Name = "";
2483+
2484+
if (DK != Scope.DeclKind)
2485+
return false;
2486+
2487+
switch (DK) {
2488+
case Decl::Kind::ClassTemplateSpecialization:
2489+
// ClassTemplateSpecializationDecl inherits from CXXRecordDecl
2490+
case Decl::Kind::CXXRecord:
2491+
Name = cast<CXXRecordDecl>(Ctx)->getName();
2492+
break;
2493+
case Decl::Kind::Namespace:
2494+
Name = cast<NamespaceDecl>(Ctx)->getName();
2495+
break;
2496+
default:
2497+
return false;
2498+
}
2499+
if (Name != Scope.Name)
2500+
return false;
2501+
Ctx = Ctx->getParent();
2502+
}
2503+
return Ctx->isTranslationUnit();
2504+
}
2505+
2506+
static bool isSYCLHostHalfType(const Type *Ty) {
2507+
// FIXME: this is not really portable, since the bunch of namespace below
2508+
// is not specified by the SYCL standard and highly depends on particular
2509+
// implementation
2510+
static const std::array<DeclContextDesc, 5> Scopes = {
2511+
DeclContextDesc{Decl::Kind::Namespace, "cl"},
2512+
DeclContextDesc{Decl::Kind::Namespace, "sycl"},
2513+
DeclContextDesc{Decl::Kind::Namespace, "detail"},
2514+
DeclContextDesc{Decl::Kind::Namespace, "half_impl"},
2515+
DeclContextDesc{Decl::Kind::CXXRecord, "half"}};
2516+
return matchQualifiedTypeName(QualType(Ty, 0), Scopes);
2517+
}
2518+
24582519
void CXXNameMangler::mangleType(QualType T) {
24592520
// If our type is instantiation-dependent but not dependent, we mangle
24602521
// it as it was written in the source, removing any top-level sugar.
@@ -2514,6 +2575,11 @@ void CXXNameMangler::mangleType(QualType T) {
25142575

25152576
bool isSubstitutable =
25162577
isTypeSubstitutable(quals, ty, Context.getASTContext());
2578+
if (Context.isUniqueNameMangler() && isSYCLHostHalfType(ty)) {
2579+
// Set isSubstitutable to false for cl::sycl::detail::half_impl::half
2580+
// to achieve the same mangling for other components
2581+
isSubstitutable = false;
2582+
}
25172583
if (isSubstitutable && mangleSubstitution(T))
25182584
return;
25192585

@@ -2990,6 +3056,11 @@ void CXXNameMangler::mangleType(const RecordType *T) {
29903056
mangleType(static_cast<const TagType*>(T));
29913057
}
29923058
void CXXNameMangler::mangleType(const TagType *T) {
3059+
if (Context.isUniqueNameMangler() && isSYCLHostHalfType(T)) {
3060+
// Mangle cl::sycl::detail::half_imple::half as _Float16
3061+
mangleType(Context.getASTContext().Float16Ty);
3062+
return;
3063+
}
29933064
mangleName(T->getDecl());
29943065
}
29953066

clang/lib/AST/QualTypeNames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static NestedNameSpecifier *createOuterNNS(const ASTContext &Ctx, const Decl *D,
197197
// Ignore inline namespace;
198198
NS = dyn_cast<NamespaceDecl>(NS->getDeclContext());
199199
}
200-
if (NS->getDeclName()) {
200+
if (NS && NS->getDeclName()) {
201201
return createNestedNameSpecifier(Ctx, NS, WithGlobalNsPrefix);
202202
}
203203
return nullptr; // no starting '::', no anonymous

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
16381638
O << "// This is auto-generated SYCL integration header.\n";
16391639
O << "\n";
16401640

1641+
O << "#include <CL/sycl/detail/defines.hpp>\n";
16411642
O << "#include <CL/sycl/detail/kernel_desc.hpp>\n";
16421643

16431644
O << "\n";
@@ -1651,7 +1652,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
16511652
}
16521653
O << "\n";
16531654

1654-
O << "namespace cl {\n";
1655+
O << "__SYCL_INLINE namespace cl {\n";
16551656
O << "namespace sycl {\n";
16561657
O << "namespace detail {\n";
16571658

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// RUN: %clangxx -fsycl-device-only -fsycl-unnamed-lambda -emit-llvm %s -o %t1.bc
2+
// RUN: llvm-dis %t1.bc -o - | FileCheck %s
3+
// RUN: %clangxx -fsycl-device-only -fsycl-unnamed-lambda -emit-llvm %s -DUSE_WRAPPER=1 -o %t2.bc
4+
// RUN: llvm-dis %t2.bc -o - | FileCheck %s
5+
6+
// Mangling of kernel lambda must be the same for both versions of half
7+
// CHECK: __unique_stable_name{{.*}} = private unnamed_addr constant [52 x i8] c"_ZTSN2cl4sycl6bufferINS0_4pairIDF16_NS0_5dummyEEEEE\00"
8+
9+
// Helper function to get string returned by __unique_stable_name in LLVM IR
10+
template <typename T>
11+
void print() {
12+
auto temp = __unique_stable_name(T);
13+
}
14+
15+
// Helper function to get "print" emitted in device code
16+
template<typename T, typename F>
17+
__attribute__((sycl_kernel)) void helper(F f) {
18+
print<T>();
19+
f();
20+
}
21+
22+
// Half wrapper, as it defined in SYCL headers
23+
namespace cl {
24+
namespace sycl {
25+
namespace detail {
26+
namespace half_impl {
27+
class half {
28+
public:
29+
half operator=(int) {return *this;}
30+
};
31+
} // namespace half_impl
32+
} // namespace detail
33+
} // namespace sycl
34+
} // namespace cl
35+
36+
#ifndef USE_WRAPPER
37+
using half = _Float16;
38+
#else
39+
using half = cl::sycl::detail::half_impl::half;
40+
#endif
41+
42+
// A few more fake data types to complicate the mangling
43+
namespace cl {
44+
namespace sycl {
45+
struct dummy {
46+
int a;
47+
};
48+
template<typename T1, typename T2>
49+
struct pair {
50+
T1 a;
51+
T2 b;
52+
};
53+
template <typename T>
54+
class buffer {
55+
public:
56+
T &operator[](int) const { return value; }
57+
mutable T value;
58+
};
59+
} // namespace sycl
60+
} // namespace cl
61+
62+
int main() {
63+
cl::sycl::buffer<cl::sycl::pair<half, cl::sycl::dummy>> B1;
64+
65+
helper<decltype(B1)>([](){});
66+
67+
return 0;
68+
}

0 commit comments

Comments
 (0)