-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SYCL] Basic code generation for SYCL kernel caller offload entry point functions. #133030
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1431cbf
[SYCL] Basic code generation for SYCL kernel caller offload entry poi…
elizabethandrews 390193a
Updates to address code review feedback from Mariya Podchishchaeva an…
tahonermann 0601aa3
Updates to address code review feedback from Erich Keane.
tahonermann 7ab070c
Addressed clang-format complaints.
tahonermann 54d3282
Updates to address code review feedback from Erich Keane.
tahonermann 12d3f63
Updates to address code review feedback from Erich Keane.
tahonermann 5d5a52b
UnsignedOrNone required following rebase for the discriminator overri…
tahonermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//===--------- CodeGenSYCL.cpp - Code for SYCL kernel generation ----------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This contains code required for generation of SYCL kernel caller offload | ||
// entry point functions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "CodeGenFunction.h" | ||
#include "CodeGenModule.h" | ||
|
||
using namespace clang; | ||
using namespace CodeGen; | ||
|
||
static void SetSYCLKernelAttributes(llvm::Function *Fn, CodeGenFunction &CGF) { | ||
// SYCL 2020 device language restrictions require forward progress and | ||
// disallow recursion. | ||
Fn->setDoesNotRecurse(); | ||
if (CGF.checkIfFunctionMustProgress()) | ||
Fn->addFnAttr(llvm::Attribute::MustProgress); | ||
} | ||
|
||
void CodeGenModule::EmitSYCLKernelCaller(const FunctionDecl *KernelEntryPointFn, | ||
ASTContext &Ctx) { | ||
assert(Ctx.getLangOpts().SYCLIsDevice && | ||
"SYCL kernel caller offload entry point functions can only be emitted" | ||
" during device compilation"); | ||
|
||
const auto *KernelEntryPointAttr = | ||
KernelEntryPointFn->getAttr<SYCLKernelEntryPointAttr>(); | ||
tahonermann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(KernelEntryPointAttr && "Missing sycl_kernel_entry_point attribute"); | ||
assert(!KernelEntryPointAttr->isInvalidAttr() && | ||
"sycl_kernel_entry_point attribute is invalid"); | ||
|
||
// Find the SYCLKernelCallStmt. | ||
SYCLKernelCallStmt *KernelCallStmt = | ||
cast<SYCLKernelCallStmt>(KernelEntryPointFn->getBody()); | ||
|
||
// Retrieve the SYCL kernel caller parameters from the OutlinedFunctionDecl. | ||
FunctionArgList Args; | ||
const OutlinedFunctionDecl *OutlinedFnDecl = | ||
KernelCallStmt->getOutlinedFunctionDecl(); | ||
Args.append(OutlinedFnDecl->param_begin(), OutlinedFnDecl->param_end()); | ||
|
||
// Compute the function info and LLVM function type. | ||
const CGFunctionInfo &FnInfo = | ||
getTypes().arrangeSYCLKernelCallerDeclaration(Ctx.VoidTy, Args); | ||
llvm::FunctionType *FnTy = getTypes().GetFunctionType(FnInfo); | ||
|
||
// Retrieve the generated name for the SYCL kernel caller function. | ||
CanQualType KernelNameType = | ||
Ctx.getCanonicalType(KernelEntryPointAttr->getKernelName()); | ||
const SYCLKernelInfo &KernelInfo = Ctx.getSYCLKernelInfo(KernelNameType); | ||
auto *Fn = llvm::Function::Create(FnTy, llvm::Function::ExternalLinkage, | ||
KernelInfo.GetKernelName(), &getModule()); | ||
|
||
// Emit the SYCL kernel caller function. | ||
CodeGenFunction CGF(*this); | ||
SetLLVMFunctionAttributes(GlobalDecl(), FnInfo, Fn, false); | ||
SetSYCLKernelAttributes(Fn, CGF); | ||
CGF.StartFunction(GlobalDecl(), Ctx.VoidTy, Fn, FnInfo, Args, | ||
SourceLocation(), SourceLocation()); | ||
CGF.EmitFunctionBody(OutlinedFnDecl->getBody()); | ||
setDSOLocal(Fn); | ||
SetLLVMFunctionAttributesForDefinition(cast<Decl>(OutlinedFnDecl), Fn); | ||
CGF.FinishFunction(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.