17#include "llvm/Frontend/Offloading/OffloadWrapper.h"
18#include "llvm/Support/MemoryBuffer.h"
19#include "llvm/Support/VirtualFileSystem.h"
32 "Attempt to emit a SYCL kernel call statement during device"
40 Fn->setDoesNotRecurse();
42 Fn->addFnAttr(llvm::Attribute::MustProgress);
45void CodeGenModule::EmitSYCLKernelCaller(
const FunctionDecl *KernelEntryPointFn,
48 "SYCL kernel caller offload entry point functions can only be emitted"
49 " during device compilation");
51 const auto *KernelEntryPointAttr =
52 KernelEntryPointFn->
getAttr<SYCLKernelEntryPointAttr>();
53 assert(KernelEntryPointAttr &&
"Missing sycl_kernel_entry_point attribute");
54 assert(!KernelEntryPointAttr->isInvalidAttr() &&
55 "sycl_kernel_entry_point attribute is invalid");
58 SYCLKernelCallStmt *KernelCallStmt =
63 const OutlinedFunctionDecl *OutlinedFnDecl =
68 const CGFunctionInfo &FnInfo =
76 auto *
Fn = llvm::Function::Create(FnTy, llvm::Function::ExternalLinkage,
80 CodeGenFunction CGF(*
this);
83 addSYCLModuleIdAttr(Fn);
84 CGF.StartFunction(GlobalDecl(), Ctx.
VoidTy, Fn, FnInfo, Args,
85 SourceLocation(), SourceLocation());
86 CGF.EmitFunctionBody(OutlinedFnDecl->
getBody());
92llvm::Function *CodeGenModule::embedSYCLDeviceBinary() {
95 if (std::error_code EC = BufferOrErr.getError()) {
99 std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrErr.get());
100 llvm::Function *RegistrationFunc =
nullptr;
101 if (llvm::Error Err = llvm::offloading::wrapSYCLBinaries(
103 ArrayRef<char>(Buffer->getBufferStart(), Buffer->getBufferSize()),
104 llvm::offloading::SYCLJITOptions(),
true,
105 &RegistrationFunc)) {
107 << llvm::toString(std::move(Err));
110 return RegistrationFunc;
static void SetSYCLKernelAttributes(llvm::Function *Fn, CodeGenFunction &CGF)
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
const LangOptions & getLangOpts() const
const SYCLKernelInfo & getSYCLKernelInfo(QualType T) const
Given a type used as a SYCL kernel name, returns a reference to the metadata generated from the corre...
std::string OffloadBinaryToEmbedFile
Name of file passed with -foffload-include-binary option to forward to offloading runtime back-end fo...
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
const LangOptions & getLangOpts() const
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs={})
EmitStmt - Emit the code for the statement.
void EmitSYCLKernelCallStmt(const SYCLKernelCallStmt &S)
bool checkIfFunctionMustProgress()
Returns true if a function must make progress, which means the mustprogress attribute can be added.
void setDSOLocal(llvm::GlobalValue *GV) const
llvm::Module & getModule() const
const IntrusiveRefCntPtr< llvm::vfs::FileSystem > & getFileSystem() const
DiagnosticsEngine & getDiags() const
CodeGenTypes & getTypes()
const CodeGenOptions & getCodeGenOpts() const
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeDeviceKernelCallerDeclaration(QualType resultType, const FunctionArgList &args)
A device kernel caller function is an offload device entry point function with a target device depend...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
parameter_const_iterator param_end() const
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
parameter_const_iterator param_begin() const
SYCLKernelCallStmt represents the transformation that is applied to the body of a function declared w...
OutlinedFunctionDecl * getOutlinedFunctionDecl()
Stmt * getKernelLaunchStmt()
const std::string & GetKernelName() const
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
U cast(CodeGen::Address addr)