Skip to content

Commit

Permalink
[SYCL] Add SYCL device code attribute to clang.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazarev <[email protected]>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent 2f8d080 commit fa1ff0a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class LangOpt<string name, bit negated = 0> {
def MicrosoftExt : LangOpt<"MicrosoftExt">;
def Borland : LangOpt<"Borland">;
def CUDA : LangOpt<"CUDA">;
def SYCL : LangOpt<"SYCL">;
def COnly : LangOpt<"CPlusPlus", 1>;
def CPlusPlus : LangOpt<"CPlusPlus">;
def OpenCL : LangOpt<"OpenCL">;
Expand Down Expand Up @@ -983,6 +984,13 @@ def CUDAShared : InheritableAttr {
let Documentation = [Undocumented];
}

def SYCLDevice : InheritableAttr {
let Spellings = [GNU<"sycl_device">];
let Subjects = SubjectList<[Function, Var]>;
let LangOpts = [SYCL];
let Documentation = [Undocumented];
}

def C11NoReturn : InheritableAttr {
let Spellings = [Keyword<"_Noreturn">];
let Subjects = SubjectList<[Function], ErrorDiag>;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
return emitIFuncDefinition(GD);

if (LangOpts.SYCL) {
if (!Global->hasAttr<OpenCLKernelAttr>())
if (!Global->hasAttr<SYCLDeviceAttr>())
return;
}

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ FunctionDecl *CreateSYCLKernelFunction(ASTContext &Context, StringRef Name,
Result->setParams(Params);
// TODO: Add SYCL specific attribute for kernel and all functions called
// by kernel.
Result->addAttr(SYCLDeviceAttr::CreateImplicit(Context));
Result->addAttr(OpenCLKernelAttr::CreateImplicit(Context));
Result->addAttr(AsmLabelAttr::CreateImplicit(Context, Name));
// To see kernel in ast-dump.
DC->addDecl(Result);
return Result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
// CHECK-NEXT: ReturnTypestate (SubjectMatchRule_function, SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: ReturnsNonNull (SubjectMatchRule_objc_method, SubjectMatchRule_function)
// CHECK-NEXT: ReturnsTwice (SubjectMatchRule_function)
// CHECK-NEXT: SYCLDevice (SubjectMatchRule_function, SubjectMatchRule_variable)
// CHECK-NEXT: ScopedLockable (SubjectMatchRule_record)
// CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
// CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
Expand Down
20 changes: 20 additions & 0 deletions clang/test/SemaSYCL/sycl-device-attr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %clang -S --sycl -I /sycl_include_path -I /opencl_include_path -Xclang -ast-dump %s | FileCheck %s
// XFAIL: *
#include <CL/sycl.hpp>


using namespace cl::sycl;

int main() {

queue myQueue;

myQueue.submit([&](handler &cgh) {

cgh.single_task<class kernel_function>([=]() {
});
});

myQueue.wait();
}
// CHECK: SYCLDeviceAttr

0 comments on commit fa1ff0a

Please sign in to comment.