Skip to content

[CIR][Dialect][CodeGen] Add a unit attribute for OpenCL kernels #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROpenCLAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ void CIRGenModule::constructAttributeList(StringRef Name,
}

if (TargetDecl->hasAttr<OpenCLKernelAttr>()) {
auto cirKernelAttr =
mlir::cir::OpenCLKernelAttr::get(builder.getContext());
funcAttrs.set(cirKernelAttr.getMnemonic(), cirKernelAttr);
assert(!MissingFeatures::openCL());
}

Expand Down
14 changes: 14 additions & 0 deletions clang/test/CIR/CodeGen/OpenCL/kernel-unit-attr.cl
Original file line number Diff line number Diff line change
@@ -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]])