Skip to content

Commit 43f3f1e

Browse files
committed
[SQUASH] Addressed review comments.
- Better checking and diagnostics - More tests Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent a445578 commit 43f3f1e

File tree

11 files changed

+45
-55
lines changed

11 files changed

+45
-55
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,16 +1135,6 @@ def SYCLKernel : InheritableAttr {
11351135
let Documentation = [SYCLKernelDocs];
11361136
}
11371137

1138-
// Marks functions which must not be vectorized via horizontal SIMT widening,
1139-
// e.g. because the function is already vectorized. Used to mark SYCL
1140-
// explicit SIMD kernels and functions.
1141-
def SYCLSimd : InheritableAttr {
1142-
let Spellings = [GNU<"sycl_explicit_simd">];
1143-
let Subjects = SubjectList<[Function]>;
1144-
let LangOpts = [SYCLIsDevice];
1145-
let Documentation = [SYCLSimdDocs];
1146-
}
1147-
11481138
// Available in SYCL explicit SIMD extension. Binds a file scope private
11491139
// variable to a specific register.
11501140
def SYCLRegisterNum : InheritableAttr {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,6 @@ The SYCL kernel in the previous code sample meets these expectations.
330330
}];
331331
}
332332

333-
def SYCLSimdDocs : Documentation {
334-
let Category = DocCatFunction;
335-
let Content = [{
336-
The ``__attribute__((sycl_explicit_simd))`` attribute is used by the device
337-
compiler front end to mark kernels and functions to be compiled and executed
338-
in the explicit SIMD mode. In this mode subgroup size is always 1 and
339-
explicit SIMD extensions - such as manual vectorization using wide vector
340-
data types and operations can be used. Compiler may decide to compile such
341-
functions using different different optimization and code generation
342-
pipeline.
343-
}];
344-
}
345-
346333
def SYCLRegisterNumDocs : Documentation {
347334
let Category = DocCatVariable;
348335
let Content = [{

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10888,4 +10888,6 @@ def err_ext_int_bad_size : Error<"%select{signed|unsigned}0 _ExtInt must "
1088810888
"have a bit size of at least %select{2|1}0">;
1088910889
def err_ext_int_max_size : Error<"%select{signed|unsigned}0 _ExtInt of bit "
1089010890
"sizes greater than %1 not supported">;
10891+
def err_esimd_glob_cant_init : Error<
10892+
"(SYCL explicit SIMD) private global variable cannot have an initializer">;
1089110893
} // end of sema component.

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12660,6 +12660,14 @@ class Sema final {
1266012660
void finalizeSYCLDelayedAnalysis(const FunctionDecl *Caller,
1266112661
const FunctionDecl *Callee,
1266212662
SourceLocation Loc);
12663+
12664+
/// Tells whether given variable is a SYCL explicit SIMD extension's "private
12665+
/// global" variable - global variable in the private address space.
12666+
bool isSYCLEsimdPrivateGlobal(VarDecl *VDecl) {
12667+
return getLangOpts().SYCLIsDevice && getLangOpts().SYCLExplicitSIMD &&
12668+
VDecl->hasGlobalStorage() &&
12669+
(VDecl->getType().getAddressSpace() != LangAS::opencl_constant);
12670+
}
1266312671
};
1266412672

1266512673
template <typename AttrType>

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,13 +3885,6 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) {
38853885
if (!D || D->getType().getAddressSpace() == LangAS::Default) {
38863886
return LangAS::opencl_global;
38873887
}
3888-
if (D)
3889-
AddrSpace = D->getType().getAddressSpace();
3890-
if (AddrSpace == LangAS::opencl_private ||
3891-
AddrSpace == LangAS::opencl_local)
3892-
// SYCL explicit SIMD path: recognize globals in private or local address
3893-
// space.
3894-
return AddrSpace;
38953888
}
38963889

38973890
if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {

clang/lib/Sema/SemaDecl.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11979,6 +11979,13 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
1197911979
VDecl->setInvalidDecl();
1198011980
return;
1198111981
}
11982+
// In the SYCL explicit SIMD extension non constant "private globals" can't
11983+
// be explicitly initialized in the declaration.
11984+
if (isSYCLEsimdPrivateGlobal(VDecl)) {
11985+
Diag(VDecl->getLocation(), diag::err_esimd_glob_cant_init);
11986+
VDecl->setInvalidDecl();
11987+
return;
11988+
}
1198211989

1198311990
// The LoaderUninitialized attribute acts as a definition (of undef).
1198411991
if (VDecl->hasAttr<LoaderUninitializedAttr>()) {
@@ -12578,12 +12585,9 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
1257812585
if (getLangOpts().OpenCL &&
1257912586
Var->getType().getAddressSpace() == LangAS::opencl_local)
1258012587
return;
12581-
// In SYCL ESIMD device code non-constant file scope variables can't be
12582-
// initialized.
12583-
// TODO add proper diagnostics for both SYCL and OpenCL paths
12584-
if (getLangOpts().SYCLExplicitSIMD && getLangOpts().SYCLIsDevice &&
12585-
Var->isFileVarDecl() && Var->hasGlobalStorage() &&
12586-
(Var->getType().getAddressSpace() != LangAS::opencl_constant))
12588+
// In SYCL explicit SIMD extension "private global" variables can't be
12589+
// initialized even implicitly, so don't synthesize an implicit initializer.
12590+
if (isSYCLEsimdPrivateGlobal(Var))
1258712591
return;
1258812592

1258912593
// C++03 [dcl.init]p9:

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4504,7 +4504,8 @@ static void handleSYCLRegisterNumAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
45044504
<< AL << 0;
45054505
return;
45064506
}
4507-
assert(AL.getNumArgs() == 1);
4507+
if (!checkAttributeNumArgs(S, AL, 1))
4508+
return;
45084509
uint32_t RegNo = 0;
45094510
const Expr *E = AL.getArgAsExpr(0);
45104511
if (!checkUInt32Argument(S, AL, E, RegNo, 0, /*StrictlyUnsigned=*/true))

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
221221
if (!IsConst && VD->getStorageClass() == SC_Static)
222222
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
223223
<< Sema::KernelNonConstStaticDataVariable;
224-
// Non-const globals are allowed for CM.
225-
else if (!getLangOpts().SYCLExplicitSIMD && !IsConst &&
224+
// Non-const globals are allowed for SYCL explicit SIMD.
225+
else if (!isSYCLEsimdPrivateGlobal(VD) && !IsConst &&
226226
VD->hasGlobalStorage() && !isa<ParmVarDecl>(VD))
227227
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
228228
<< Sema::KernelGlobalVariable;

clang/test/CodeGenSYCL/esimd-private-global.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
// This test checks that FE allows globals with register_num attribute in ESIMD mode.
66

77
__attribute__((opencl_private)) __attribute__((register_num(17))) int vc;
8-
9-
// CHECK-DAG: @vc = {{.+}} i32 0, align 4 #0
10-
// CHECK-DAG: attributes #0 = { "genx_byte_offset"="17" "genx_volatile" }
8+
// CHECK: @vc = {{.+}} i32 0, align 4 #0
119

1210
SYCL_EXTERNAL void init_vc(int x) {
1311
vc = x;
12+
// CHECK: store i32 %0, i32* @vc
1413
}
14+
// CHECK: attributes #0 = { "genx_byte_offset"="17" "genx_volatile" }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-explicit-simd -fsyntax-only -verify -pedantic %s
2+
3+
// no error expected
4+
__attribute__((opencl_private)) __attribute__((register_num(17))) int privGlob;
5+
6+
// expected-error@+1{{'register_num' attribute takes one argument}}
7+
__attribute__((opencl_private)) __attribute__((register_num())) int privGlob1;
8+
9+
// expected-error@+1{{'register_num' attribute takes one argument}}
10+
__attribute__((opencl_private)) __attribute__((register_num(10, 11))) int privGlob2;
11+
12+
// expected-error@+1{{(SYCL explicit SIMD) private global variable cannot have an initializer}}
13+
__attribute__((opencl_private)) int privGlob3 = 10;
14+
15+
void foo() {
16+
// expected-warning@+1{{'register_num' attribute only applies to global variables}}
17+
__attribute__((register_num(17))) int privLoc;
18+
}

clang/test/SemaSYCL/esimd-register-num-attr.cpp

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)