diff --git a/clang/include/clang/CIR/Dialect/IR/CIROpenCLAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIROpenCLAttrs.td index b80ea308608a..576d619fcf7a 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROpenCLAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROpenCLAttrs.td @@ -168,4 +168,21 @@ def OpenCLVersionAttr : CIR_Attr<"OpenCLVersion", "cl.version"> { let assemblyFormat = "`<` $major_version `,` $minor_version `>`"; } + +//===----------------------------------------------------------------------===// +// OpenCLKernelAttr +//===----------------------------------------------------------------------===// + +// TODO: It might be worthwhile to introduce a generic attribute applicable to +// all offloading languages. +def OpenCLKernelAttr : CIRUnitAttr< + "OpenCLKernel", "cl.kernel"> { + let summary = "OpenCL kernel"; + let description = [{ + Indicate the function is a OpenCL kernel. + }]; + + let storageType = [{ OpenCLKernelAttr }]; +} + #endif // MLIR_CIR_DIALECT_CIR_OPENCL_ATTRS diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index 53252ee78bd6..2a1b1a69da3d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -430,6 +430,9 @@ void CIRGenModule::constructAttributeList(StringRef Name, } if (TargetDecl->hasAttr()) { + auto cirKernelAttr = + mlir::cir::OpenCLKernelAttr::get(builder.getContext()); + funcAttrs.set(cirKernelAttr.getMnemonic(), cirKernelAttr); assert(!MissingFeatures::openCL()); } diff --git a/clang/test/CIR/CodeGen/OpenCL/kernel-unit-attr.cl b/clang/test/CIR/CodeGen/OpenCL/kernel-unit-attr.cl new file mode 100644 index 000000000000..01348013bbf0 --- /dev/null +++ b/clang/test/CIR/CodeGen/OpenCL/kernel-unit-attr.cl @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fclangir -emit-cir -triple spirv64-unknown-unknown %s -o %t.cir +// RUN: FileCheck %s --input-file=%t.cir --check-prefix=CIR + + +// CIR: #fn_attr[[KERNEL1:[0-9]*]] = {{.+}}cl.kernel = #cir.cl.kernel +// CIR-NEXT: #fn_attr[[FUNC1:[0-9]*]] = +// CIR-NOT: cl.kernel = #cir.cl.kernel + +kernel void kernel1() {} +// CIR: cir.func @kernel1{{.+}} extra(#fn_attr[[KERNEL1]]) + +void func1() {} + +// CIR: cir.func @func1{{.+}} extra(#fn_attr[[FUNC1]])