Skip to content

Commit 47191b3

Browse files
author
Alexander Batashev
committed
Merge remote-tracking branch 'origin/sycl' into private/abatashe/image_api_test
* origin/sycl: [SYCL] Implement thread-local storage restriction (intel#1281) [Driver][SYCL][FPGA] Adjust the output location for the project report (intel#1278)
2 parents 1670fac + eb373c4 commit 47191b3

File tree

7 files changed

+93
-25
lines changed

7 files changed

+93
-25
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,22 @@ void SYCL::fpga::BackendCompiler::ConstructJob(Compilation &C,
272272
} else {
273273
// Output directory is based off of the first object name
274274
for (Arg * Cur : Args) {
275-
SmallString<128> AN = Cur->getSpelling();
276-
StringRef Ext(llvm::sys::path::extension(AN));
277-
if (!Ext.empty()) {
278-
types::ID Ty = getToolChain().LookupTypeForExtension(Ext.drop_front());
279-
if (Ty == types::TY_INVALID)
280-
continue;
281-
if (types::isSrcFile(Ty) || Ty == types::TY_Object) {
282-
llvm::sys::path::replace_extension(AN, "prj");
283-
ReportOptArg += Args.MakeArgString(AN);
284-
break;
285-
}
275+
if (Cur->getOption().getKind() != Option::InputClass)
276+
continue;
277+
SmallString<128> ArgName = Cur->getSpelling();
278+
StringRef Ext(llvm::sys::path::extension(ArgName));
279+
if (Ext.empty())
280+
continue;
281+
types::ID Ty = getToolChain().LookupTypeForExtension(Ext.drop_front());
282+
if (Ty == types::TY_INVALID)
283+
continue;
284+
if (types::isSrcFile(Ty) || Ty == types::TY_Object) {
285+
// Project report should be saved into CWD, so strip off any
286+
// directory information if provided with the input file.
287+
ArgName = llvm::sys::path::filename(ArgName);
288+
llvm::sys::path::replace_extension(ArgName, "prj");
289+
ReportOptArg += Args.MakeArgString(ArgName);
290+
break;
286291
}
287292
}
288293
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7060,10 +7060,13 @@ NamedDecl *Sema::ActOnVariableDeclarator(
70607060

70617061
// Static variables declared inside SYCL device code must be const or
70627062
// constexpr
7063-
if (getLangOpts().SYCLIsDevice && SCSpec == DeclSpec::SCS_static &&
7064-
!R.isConstant(Context))
7065-
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_sycl_restrict)
7066-
<< Sema::KernelNonConstStaticDataVariable;
7063+
if (getLangOpts().SYCLIsDevice) {
7064+
if (SCSpec == DeclSpec::SCS_static && !R.isConstant(Context))
7065+
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_sycl_restrict)
7066+
<< Sema::KernelNonConstStaticDataVariable;
7067+
else if (NewVD->getTSCSpec() == DeclSpec::TSCS_thread_local)
7068+
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_thread_unsupported);
7069+
}
70677070

70687071
switch (D.getDeclSpec().getConstexprSpecifier()) {
70697072
case CSK_unspecified:

clang/lib/Sema/SemaExpr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,16 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
212212
ObjCInterfaceDecl *ClassReceiver) {
213213
if (getLangOpts().SYCLIsDevice) {
214214
if (auto VD = dyn_cast<VarDecl>(D)) {
215-
if (VD->getStorageClass() == SC_Static &&
216-
!VD->getType().isConstant(Context))
215+
bool IsConst = VD->getType().isConstant(Context);
216+
if (VD->getTLSKind() != VarDecl::TLS_None)
217+
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_thread_unsupported);
218+
219+
if (!IsConst && VD->getStorageClass() == SC_Static)
217220
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
218221
<< Sema::KernelNonConstStaticDataVariable;
222+
else if (!IsConst && VD->hasGlobalStorage() && !isa<ParmVarDecl>(VD))
223+
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
224+
<< Sema::KernelGlobalVariable;
219225
}
220226
}
221227

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
322322

323323
CheckSYCLType(E->getType(), E->getSourceRange());
324324
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
325-
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
326-
if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
327-
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD)) {
328-
if (VD->getTLSKind() != VarDecl::TLS_None)
329-
SemaRef.Diag(E->getLocation(), diag::err_thread_unsupported);
330-
SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict)
331-
<< Sema::KernelGlobalVariable;
332-
}
333325
if (!VD->isLocalVarDeclOrParm() && VD->hasGlobalStorage()) {
334326
VD->addAttr(SYCLDeviceAttr::CreateImplicit(SemaRef.Context));
335327
SemaRef.addSyclDeviceDecl(VD);

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@
232232
// RUN: | FileCheck -DOUTDIR=%t_dir -check-prefix=CHK-FPGA-REPORT-OPT %s
233233
// CHK-FPGA-REPORT-OPT: aoc{{.*}} "-sycl" {{.*}} "-output-report-folder=[[OUTDIR]]{{/|\\\\}}file.prj"
234234

235+
/// -fintelfpga output report file from dir/source
236+
// RUN: mkdir -p %t_dir
237+
// RUN: touch %t_dir/dummy.cpp
238+
// RUN: %clangxx -### -fsycl -fintelfpga %t_dir/dummy.cpp 2>&1 \
239+
// RUN: | FileCheck -DOUTDIR=%t_dir -check-prefix=CHK-FPGA-REPORT-OPT2 %s
240+
// RUN: %clang_cl -### -fsycl -fintelfpga %t_dir/dummy.cpp 2>&1 \
241+
// RUN: | FileCheck -DOUTDIR=%t_dir -check-prefix=CHK-FPGA-REPORT-OPT2 %s
242+
// CHK-FPGA-REPORT-OPT2: aoc{{.*}} "-sycl" {{.*}} "-output-report-folder=dummy.prj"
243+
// CHK-FPGA-REPORT-OPT2-NOT: aoc{{.*}} "-sycl" {{.*}} "-output-report-folder=[[OUTDIR]]{{.*}}"
244+
235245
/// -fintelfpga static lib (aoco)
236246
// RUN: echo "Dummy AOCO image" > %t.aoco
237247
// RUN: echo "void foo() {}" > %t.c
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s
2+
3+
thread_local const int prohobit_ns_scope = 0;
4+
thread_local int prohobit_ns_scope2 = 0;
5+
thread_local const int allow_ns_scope = 0;
6+
7+
struct S {
8+
static const thread_local int prohibit_static_member;
9+
static thread_local int prohibit_static_member2;
10+
};
11+
12+
struct T {
13+
static const thread_local int allow_static_member;
14+
};
15+
16+
void foo() {
17+
// expected-error@+1{{thread-local storage is not supported for the current target}}
18+
thread_local const int prohibit_local = 0;
19+
// expected-error@+1{{thread-local storage is not supported for the current target}}
20+
thread_local int prohibit_local2;
21+
}
22+
23+
void bar() { thread_local int allow_local; }
24+
25+
void usage() {
26+
// expected-note@+1 {{called by}}
27+
foo();
28+
// expected-error@+1 {{thread-local storage is not supported for the current target}}
29+
(void)prohobit_ns_scope;
30+
// expected-error@+2 {{SYCL kernel cannot use a non-const global variable}}
31+
// expected-error@+1 {{thread-local storage is not supported for the current target}}
32+
(void)prohobit_ns_scope2;
33+
// expected-error@+1 {{thread-local storage is not supported for the current target}}
34+
(void)S::prohibit_static_member;
35+
// expected-error@+2 {{SYCL kernel cannot use a non-const static data variable}}
36+
// expected-error@+1 {{thread-local storage is not supported for the current target}}
37+
(void)S::prohibit_static_member2;
38+
}
39+
40+
template <typename name, typename Func>
41+
__attribute__((sycl_kernel))
42+
// expected-note@+2 2{{called by}}
43+
void
44+
kernel_single_task(Func kernelFunc) { kernelFunc(); }
45+
46+
int main() {
47+
// expected-note@+1 2{{called by}}
48+
kernel_single_task<class fake_kernel>([]() { usage(); });
49+
return 0;
50+
}

clang/test/SemaSYCL/tls_error.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ void usage() {
1515

1616
template <typename name, typename Func>
1717
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
18+
//expected-note@+1{{called by}}
1819
kernelFunc();
1920
}
2021

2122
int main() {
23+
//expected-note@+1{{called by}}
2224
kernel_single_task<class fake_kernel>([]() { usage(); });
2325
return 0;
2426
}

0 commit comments

Comments
 (0)