Skip to content

Commit e72badd

Browse files
author
Sergey Kanaev
committed
Merge branch 'sycl' into private/s-kanaev/function-whitelist
2 parents cdfee11 + 4b5d25b commit e72badd

Some content is hidden

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

44 files changed

+848
-128
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10626,7 +10626,7 @@ def err_sycl_kernel_name_class_not_top_level : Error<
1062610626
"nest in a namespace: %0">;
1062710627
def err_sycl_restrict : Error<
1062810628
"SYCL kernel cannot "
10629-
"%select{use a global variable"
10629+
"%select{use a non-const global variable"
1063010630
"|use rtti"
1063110631
"|use a non-const static data variable"
1063210632
"|call a virtual function"

clang/include/clang/Sema/Sema.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include "clang/AST/DeclTemplate.h"
2323
#include "clang/AST/DeclarationName.h"
2424
#include "clang/AST/Expr.h"
25-
#include "clang/AST/ExprConcepts.h"
2625
#include "clang/AST/ExprCXX.h"
26+
#include "clang/AST/ExprConcepts.h"
2727
#include "clang/AST/ExprObjC.h"
2828
#include "clang/AST/ExternalASTSource.h"
2929
#include "clang/AST/LocInfoType.h"
@@ -34,6 +34,7 @@
3434
#include "clang/AST/TypeLoc.h"
3535
#include "clang/AST/TypeOrdering.h"
3636
#include "clang/Basic/BitmaskEnum.h"
37+
#include "clang/Basic/DiagnosticSema.h"
3738
#include "clang/Basic/ExpressionTraits.h"
3839
#include "clang/Basic/Module.h"
3940
#include "clang/Basic/OpenMPKinds.h"
@@ -12343,6 +12344,71 @@ class Sema final {
1234312344
void finalizeSYCLDelayedAnalysis();
1234412345
};
1234512346

12347+
template <typename AttrType>
12348+
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
12349+
Expr *E) {
12350+
AttrType TmpAttr(Context, CI, E);
12351+
12352+
if (!E->isValueDependent()) {
12353+
ExprResult ICE;
12354+
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
12355+
return;
12356+
E = ICE.get();
12357+
}
12358+
12359+
if (IntelFPGAPrivateCopiesAttr::classof(&TmpAttr)) {
12360+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
12361+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
12362+
Context, IntelFPGAMemoryAttr::Default));
12363+
}
12364+
12365+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12366+
}
12367+
12368+
template <typename AttrType>
12369+
void Sema::AddOneConstantPowerTwoValueAttr(Decl *D,
12370+
const AttributeCommonInfo &CI,
12371+
Expr *E) {
12372+
AttrType TmpAttr(Context, CI, E);
12373+
12374+
if (!E->isValueDependent()) {
12375+
ExprResult ICE;
12376+
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
12377+
return;
12378+
Expr::EvalResult Result;
12379+
E->EvaluateAsInt(Result, Context);
12380+
llvm::APSInt Value = Result.Val.getInt();
12381+
if (!Value.isPowerOf2()) {
12382+
Diag(CI.getLoc(), diag::err_attribute_argument_not_power_of_two)
12383+
<< &TmpAttr;
12384+
return;
12385+
}
12386+
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
12387+
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) {
12388+
unsigned NumBankBits = BBA->args_size();
12389+
if (NumBankBits != Value.ceilLogBase2()) {
12390+
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting);
12391+
return;
12392+
}
12393+
}
12394+
}
12395+
E = ICE.get();
12396+
}
12397+
12398+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
12399+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
12400+
Context, IntelFPGAMemoryAttr::Default));
12401+
12402+
// We are adding a user NumBanks, drop any implicit default.
12403+
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
12404+
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>())
12405+
if (NBA->isImplicit())
12406+
D->dropAttr<IntelFPGANumBanksAttr>();
12407+
}
12408+
12409+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12410+
}
12411+
1234612412
/// RAII object that enters a new expression evaluation context.
1234712413
class EnterExpressionEvaluationContext {
1234812414
Sema &Actions;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,71 +3869,6 @@ bool Sema::checkRangedIntegralArgument(Expr *E, const AttrType *TmpAttr,
38693869
return false;
38703870
}
38713871

3872-
template <typename AttrType>
3873-
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
3874-
Expr *E) {
3875-
AttrType TmpAttr(Context, CI, E);
3876-
3877-
if (!E->isValueDependent()) {
3878-
ExprResult ICE;
3879-
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
3880-
return;
3881-
E = ICE.get();
3882-
}
3883-
3884-
if (IntelFPGAPrivateCopiesAttr::classof(&TmpAttr)) {
3885-
if (!D->hasAttr<IntelFPGAMemoryAttr>())
3886-
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
3887-
Context, IntelFPGAMemoryAttr::Default));
3888-
}
3889-
3890-
D->addAttr(::new (Context) AttrType(Context, CI, E));
3891-
}
3892-
3893-
template <typename AttrType>
3894-
void Sema::AddOneConstantPowerTwoValueAttr(Decl *D,
3895-
const AttributeCommonInfo &CI,
3896-
Expr *E) {
3897-
AttrType TmpAttr(Context, CI, E);
3898-
3899-
if (!E->isValueDependent()) {
3900-
ExprResult ICE;
3901-
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
3902-
return;
3903-
Expr::EvalResult Result;
3904-
E->EvaluateAsInt(Result, Context);
3905-
llvm::APSInt Value = Result.Val.getInt();
3906-
if (!Value.isPowerOf2()) {
3907-
Diag(CI.getLoc(), diag::err_attribute_argument_not_power_of_two)
3908-
<< &TmpAttr;
3909-
return;
3910-
}
3911-
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
3912-
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) {
3913-
unsigned NumBankBits = BBA->args_size();
3914-
if (NumBankBits != Value.ceilLogBase2()) {
3915-
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting);
3916-
return;
3917-
}
3918-
}
3919-
}
3920-
E = ICE.get();
3921-
}
3922-
3923-
if (!D->hasAttr<IntelFPGAMemoryAttr>())
3924-
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
3925-
Context, IntelFPGAMemoryAttr::Default));
3926-
3927-
// We are adding a user NumBanks, drop any implicit default.
3928-
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
3929-
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>())
3930-
if (NBA->isImplicit())
3931-
D->dropAttr<IntelFPGANumBanksAttr>();
3932-
}
3933-
3934-
D->addAttr(::new (Context) AttrType(Context, CI, E));
3935-
}
3936-
39373872
void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
39383873
bool IsPackExpansion) {
39393874
AlignedAttr TmpAttr(Context, CI, true, E);

clang/lib/Sema/SemaExpr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
210210
bool ObjCPropertyAccess,
211211
bool AvoidPartialAvailabilityChecks,
212212
ObjCInterfaceDecl *ClassReceiver) {
213+
if (getLangOpts().SYCLIsDevice) {
214+
if (auto VD = dyn_cast<VarDecl>(D)) {
215+
if (VD->getStorageClass() == SC_Static &&
216+
!VD->getType().isConstant(Context))
217+
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
218+
<< Sema::KernelNonConstStaticDataVariable;
219+
}
220+
}
221+
213222
SourceLocation Loc = Locs.front();
214223
if (getLangOpts().CPlusPlus && isa<FunctionDecl>(D)) {
215224
// If there were any diagnostics suppressed by template argument deduction,

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,16 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
321321
return true;
322322
}
323323

324-
bool VisitMemberExpr(MemberExpr *E) {
325-
if (VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) {
326-
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
327-
if (!IsConst && VD->isStaticDataMember())
328-
SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict)
329-
<< Sema::KernelNonConstStaticDataVariable;
330-
}
331-
return true;
332-
}
333-
334324
bool VisitDeclRefExpr(DeclRefExpr *E) {
335-
Decl* D = E->getDecl();
325+
Decl *D = E->getDecl();
336326
if (SemaRef.isKnownGoodSYCLDecl(D))
337327
return true;
338328

339329
CheckSYCLType(E->getType(), E->getSourceRange());
340330
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
341331
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
342-
if (!IsConst && VD->isStaticDataMember())
343-
SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict)
344-
<< Sema::KernelNonConstStaticDataVariable;
345-
else if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
346-
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD)) {
332+
if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
333+
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD)) {
347334
if (VD->getTLSKind() != VarDecl::TLS_None)
348335
SemaRef.Diag(E->getLocation(), diag::err_thread_unsupported);
349336
SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only -fsycl-is-device %s
2+
const int glob1 = 1;
3+
int glob2 = 2;
4+
template <typename name, typename Func>
5+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
6+
// expected-note-re@+1{{called by 'kernel_single_task<fake_kernel, (lambda at {{.*}})>}}
7+
kernelFunc();
8+
}
9+
10+
int main() {
11+
static int n = 0;
12+
const static int l = 0;
13+
kernel_single_task<class fake_kernel>([]() {
14+
int m = l;
15+
m = glob1;
16+
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
17+
m = n;
18+
// expected-error@+1{{SYCL kernel cannot use a non-const global variable}}
19+
m = glob2;
20+
});
21+
return 0;
22+
}

clang/test/SemaSYCL/sycl-restrict.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void usage(myFuncDef functionPtr) {
139139
// expected-error@+2 {{SYCL kernel cannot call through a function pointer}}
140140
#endif
141141
if ((*functionPtr)(1, 2))
142-
// expected-error@+2 {{SYCL kernel cannot use a global variable}}
142+
// expected-error@+2 {{SYCL kernel cannot use a non-const global variable}}
143143
// expected-error@+1 {{SYCL kernel cannot call a virtual function}}
144144
b.f();
145145
Check_RTTI_Restriction::kernel1<class kernel_name>([]() {
@@ -176,13 +176,14 @@ int use2(a_type ab, a_type *abp) {
176176
// expected-error@+1 {{SYCL kernel cannot use a non-const static data variable}}
177177
if (abp->stat_member)
178178
return 0;
179+
// expected-note@+1 {{called by 'use2'}}
179180
if (ab.fm())
180181
return 0;
181-
// expected-error@+1 {{SYCL kernel cannot use a global variable}}
182+
// expected-error@+1 {{SYCL kernel cannot use a non-const global variable}}
182183
return another_global;
183-
// expected-error@+1 {{SYCL kernel cannot use a global variable}}
184+
// expected-error@+1 {{SYCL kernel cannot use a non-const global variable}}
184185
return ns::glob +
185-
// expected-error@+1 {{SYCL kernel cannot use a global variable}}
186+
// expected-error@+1 {{SYCL kernel cannot use a non-const global variable}}
186187
AnotherNS::moar_globals;
187188
// expected-note@+1 {{called by 'use2'}}
188189
eh_not_ok();
@@ -202,7 +203,7 @@ __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
202203
kernelFunc();
203204
a_type ab;
204205
a_type *p;
205-
// expected-note@+1 5{{called by 'kernel_single_task}}
206+
// expected-note@+1 7{{called by 'kernel_single_task}}
206207
use2(ab, p);
207208
}
208209

clang/test/SemaSYCL/tls_error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ extern __thread void (*__once_call)(); // expected-no-error
55

66
void usage() {
77
// expected-error@+2{{thread-local storage is not supported for the current target}}
8-
// expected-error@+1{{SYCL kernel cannot use a global variable}}
8+
// expected-error@+1{{SYCL kernel cannot use a non-const global variable}}
99
__once_callable = 0;
1010
// expected-error@+3{{thread-local storage is not supported for the current target}}
11-
// expected-error@+2{{SYCL kernel cannot use a global variable}}
11+
// expected-error@+2{{SYCL kernel cannot use a non-const global variable}}
1212
// expected-error@+1{{SYCL kernel cannot call through a function pointer}}
1313
__once_call();
1414
}

libclc/generic/include/spirv/atomic/atomic_decl.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ __CLC_DECLARE_ATOMIC_ADDRSPACE(ulong, m, __SPIRV_FUNCTION_U, __SPIRV_FUNCTION_U_
2828
#ifdef cl_khr_int64_base_atomics
2929
__CLC_DECLARE_ATOMIC_ADDRSPACE(long, l, __SPIRV_FUNCTION_S, __SPIRV_FUNCTION_S_LEN)
3030
__CLC_DECLARE_ATOMIC_ADDRSPACE(ulong, m, __SPIRV_FUNCTION_U, __SPIRV_FUNCTION_U_LEN)
31+
__CLC_DECLARE_ATOMIC_ADDRSPACE(long, x, __SPIRV_FUNCTION_S, __SPIRV_FUNCTION_S_LEN)
32+
__CLC_DECLARE_ATOMIC_ADDRSPACE(ulong, y, __SPIRV_FUNCTION_U, __SPIRV_FUNCTION_U_LEN)
3133
#endif
3234
#endif
3335

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling.
10+
#define DECL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
11+
_CLC_DECL TYPE _Z18__spirv_AtomicLoadPU3##AS_MANGLED##K##TYPE_MANGLED##N5__spv5ScopeENS1_19MemorySemanticsMaskE( \
12+
volatile AS const TYPE *, enum Scope, enum MemorySemanticsMask);
13+
14+
#define DECL_AS(TYPE, TYPE_MANGLED) \
15+
DECL(TYPE, TYPE_MANGLED, global, AS1) \
16+
DECL(TYPE, TYPE_MANGLED, local, AS3)
17+
18+
DECL_AS(int, i)
19+
DECL_AS(unsigned int, j)
20+
21+
#ifdef cl_khr_int64_base_atomics
22+
DECL_AS(long, l)
23+
DECL_AS(unsigned long, m)
24+
DECL_AS(long, x)
25+
DECL_AS(unsigned long, y)
26+
#endif
27+
28+
#undef DECL_AS
29+
#undef DECL
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling.
10+
#define DECL(TYPE, TYPE_MANGLED, AS, AS_MANGLED) \
11+
_CLC_DECL void _Z19__spirv_AtomicStorePU3##AS_MANGLED##TYPE_MANGLED##N5__spv5ScopeENS1_19MemorySemanticsMaskE##TYPE_MANGLED( \
12+
volatile AS TYPE *, enum Scope, enum MemorySemanticsMask, TYPE);
13+
14+
#define DECL_AS(TYPE, TYPE_MANGLED) \
15+
DECL(TYPE, TYPE_MANGLED, global, AS1) \
16+
DECL(TYPE, TYPE_MANGLED, local, AS3)
17+
18+
DECL_AS(int, i)
19+
DECL_AS(unsigned int, j)
20+
21+
#ifdef cl_khr_int64_base_atomics
22+
DECL_AS(long, l)
23+
DECL_AS(unsigned long, m)
24+
DECL_AS(long, x)
25+
DECL_AS(unsigned long, y)
26+
#endif
27+
28+
#undef DECL_AS
29+
#undef DECL

libclc/generic/include/spirv/spirv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@
235235
#include <spirv/atomic/atomic_sub.h>
236236
#include <spirv/atomic/atomic_xchg.h>
237237
#include <spirv/atomic/atomic_xor.h>
238+
#include <spirv/atomic/atomic_load.h>
239+
#include <spirv/atomic/atomic_store.h>
238240

239241
/* cl_khr extension atomics are omitted from __spirv */
240242

libclc/generic/libspirv/SOURCES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ atomic/atomic_or.cl
1212
atomic/atomic_sub.cl
1313
atomic/atomic_xchg.cl
1414
atomic/atomic_xor.cl
15+
atomic/atomic_load.cl
16+
atomic/atomic_store.cl
1517
common/degrees.cl
1618
common/mix.cl
1719
common/radians.cl

libclc/generic/libspirv/atomic/atomic_add.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ IMPL(long, l, global, AS1, __sync_fetch_and_add_8)
2626
IMPL(unsigned long, m, global, AS1, __sync_fetch_and_add_8)
2727
IMPL(long, l, local, AS3, __sync_fetch_and_add_8)
2828
IMPL(unsigned long, m, local, AS3, __sync_fetch_and_add_8)
29+
IMPL(long, x, global, AS1, __sync_fetch_and_add_8)
30+
IMPL(unsigned long, y, global, AS1, __sync_fetch_and_add_8)
31+
IMPL(long, x, local, AS3, __sync_fetch_and_add_8)
32+
IMPL(unsigned long, y, local, AS3, __sync_fetch_and_add_8)
2933
#endif
3034
#undef IMPL

libclc/generic/libspirv/atomic/atomic_and.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ IMPL(long, l, global, AS1, __sync_fetch_and_and_8)
2626
IMPL(unsigned long, m, global, AS1, __sync_fetch_and_and_8)
2727
IMPL(long, l, local, AS3, __sync_fetch_and_and_8)
2828
IMPL(unsigned long, m, local, AS3, __sync_fetch_and_and_8)
29+
IMPL(long, x, global, AS1, __sync_fetch_and_and_8)
30+
IMPL(unsigned long, y, global, AS1, __sync_fetch_and_and_8)
31+
IMPL(long, x, local, AS3, __sync_fetch_and_and_8)
32+
IMPL(unsigned long, y, local, AS3, __sync_fetch_and_and_8)
2933
#endif
3034
#undef IMPL

0 commit comments

Comments
 (0)