Skip to content

Commit bc51fe0

Browse files
[ESIMD] Allow non-const private statics in ESIMD kernels (#4264)
ESIMD already allows using private non-const globals in kernels. This patch allows using private non-const statics for ESIMD. This patch allows users to use static keyword to distinguish global variables accross multiple translation units, e.g.: // a.cpp ESIMD_PRIVATE ESIMD_REGISTER(X) simd<T, N> GRF; // b.cpp ESIMD_PRIVATE ESIMD_REGISTER(Y) simd<T, N> GRF; Linker will raise a validation of the ODR rule in this case. To fix it we can declare those two variables as `static` without changing their names.
1 parent 2023e10 commit bc51fe0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,14 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
225225
ExprEvalContexts.empty() ||
226226
(!isUnevaluatedContext() && !isConstantEvaluated());
227227
bool IsEsimdPrivateGlobal = isSYCLEsimdPrivateGlobal(VD);
228-
if (IsRuntimeEvaluated && !IsConst &&
228+
// Non-const statics are not allowed in SYCL except for ESIMD or with the
229+
// SYCLGlobalVar attribute.
230+
if (IsRuntimeEvaluated && !IsEsimdPrivateGlobal && !IsConst &&
229231
VD->getStorageClass() == SC_Static &&
230232
!VD->hasAttr<SYCLGlobalVarAttr>())
231233
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
232234
<< Sema::KernelNonConstStaticDataVariable;
233-
// Non-const globals are allowed for SYCL explicit SIMD or with the
235+
// Non-const globals are not allowed in SYCL except for ESIMD or with the
234236
// SYCLGlobalVar attribute.
235237
else if (IsRuntimeEvaluated && !IsEsimdPrivateGlobal && !IsConst &&
236238
VD->hasGlobalStorage() && !VD->hasAttr<SYCLGlobalVarAttr>())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -pedantic %s
2+
// expected-no-diagnostics
3+
4+
// This test checks that non-const statics are allowed for ESIMD
5+
6+
static __attribute__((opencl_private)) __attribute__((sycl_explicit_simd)) int esimdPrivStatic;
7+
8+
struct S {
9+
static __attribute__((opencl_private)) __attribute__((sycl_explicit_simd)) int esimdPrivStaticMember;
10+
};
11+
12+
__attribute__((sycl_device)) __attribute__((sycl_explicit_simd)) void usage() {
13+
esimdPrivStatic = 42;
14+
S::esimdPrivStaticMember = 42;
15+
}

0 commit comments

Comments
 (0)