Skip to content

Commit fa1ff0a

Browse files
committed
[SYCL] Add SYCL device code attribute to clang.
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 2f8d080 commit fa1ff0a

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ class LangOpt<string name, bit negated = 0> {
294294
def MicrosoftExt : LangOpt<"MicrosoftExt">;
295295
def Borland : LangOpt<"Borland">;
296296
def CUDA : LangOpt<"CUDA">;
297+
def SYCL : LangOpt<"SYCL">;
297298
def COnly : LangOpt<"CPlusPlus", 1>;
298299
def CPlusPlus : LangOpt<"CPlusPlus">;
299300
def OpenCL : LangOpt<"OpenCL">;
@@ -983,6 +984,13 @@ def CUDAShared : InheritableAttr {
983984
let Documentation = [Undocumented];
984985
}
985986

987+
def SYCLDevice : InheritableAttr {
988+
let Spellings = [GNU<"sycl_device">];
989+
let Subjects = SubjectList<[Function, Var]>;
990+
let LangOpts = [SYCL];
991+
let Documentation = [Undocumented];
992+
}
993+
986994
def C11NoReturn : InheritableAttr {
987995
let Spellings = [Keyword<"_Noreturn">];
988996
let Subjects = SubjectList<[Function], ErrorDiag>;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
21482148
return emitIFuncDefinition(GD);
21492149

21502150
if (LangOpts.SYCL) {
2151-
if (!Global->hasAttr<OpenCLKernelAttr>())
2151+
if (!Global->hasAttr<SYCLDeviceAttr>())
21522152
return;
21532153
}
21542154

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ FunctionDecl *CreateSYCLKernelFunction(ASTContext &Context, StringRef Name,
4646
Result->setParams(Params);
4747
// TODO: Add SYCL specific attribute for kernel and all functions called
4848
// by kernel.
49+
Result->addAttr(SYCLDeviceAttr::CreateImplicit(Context));
4950
Result->addAttr(OpenCLKernelAttr::CreateImplicit(Context));
5051
Result->addAttr(AsmLabelAttr::CreateImplicit(Context, Name));
52+
// To see kernel in ast-dump.
53+
DC->addDecl(Result);
5154
return Result;
5255
}
5356

clang/test/Misc/pragma-attribute-supported-attributes-list.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
// CHECK-NEXT: ReturnTypestate (SubjectMatchRule_function, SubjectMatchRule_variable_is_parameter)
117117
// CHECK-NEXT: ReturnsNonNull (SubjectMatchRule_objc_method, SubjectMatchRule_function)
118118
// CHECK-NEXT: ReturnsTwice (SubjectMatchRule_function)
119+
// CHECK-NEXT: SYCLDevice (SubjectMatchRule_function, SubjectMatchRule_variable)
119120
// CHECK-NEXT: ScopedLockable (SubjectMatchRule_record)
120121
// CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
121122
// CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang -S --sycl -I /sycl_include_path -I /opencl_include_path -Xclang -ast-dump %s | FileCheck %s
2+
// XFAIL: *
3+
#include <CL/sycl.hpp>
4+
5+
6+
using namespace cl::sycl;
7+
8+
int main() {
9+
10+
queue myQueue;
11+
12+
myQueue.submit([&](handler &cgh) {
13+
14+
cgh.single_task<class kernel_function>([=]() {
15+
});
16+
});
17+
18+
myQueue.wait();
19+
}
20+
// CHECK: SYCLDeviceAttr

0 commit comments

Comments
 (0)