1 //===- StmtSYCL.h - Classes for SYCL kernel calls ---------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// \file 9 /// This file defines SYCL AST classes used to represent calls to SYCL kernels. 10 //===----------------------------------------------------------------------===// 11 12 #ifndef LLVM_CLANG_AST_STMTSYCL_H 13 #define LLVM_CLANG_AST_STMTSYCL_H 14 15 #include "clang/AST/ASTContext.h" 16 #include "clang/AST/Decl.h" 17 #include "clang/AST/Stmt.h" 18 #include "clang/Basic/SourceLocation.h" 19 20 namespace clang { 21 22 //===----------------------------------------------------------------------===// 23 // AST classes for SYCL kernel calls. 24 //===----------------------------------------------------------------------===// 25 26 /// SYCLKernelCallStmt represents the transformation that is applied to the body 27 /// of a function declared with the sycl_kernel_entry_point attribute. The body 28 /// of such a function specifies the statements to be executed on a SYCL device 29 /// to invoke a SYCL kernel with a particular set of kernel arguments. The 30 /// SYCLKernelCallStmt associates an original statement (the compound statement 31 /// that is the function body) with an OutlinedFunctionDecl that holds the 32 /// kernel parameters and the transformed body. During code generation, the 33 /// OutlinedFunctionDecl is used to emit an offload kernel entry point suitable 34 /// for invocation from a SYCL library implementation. If executed, the 35 /// SYCLKernelCallStmt behaves as a no-op; no code generation is performed for 36 /// it. 37 class SYCLKernelCallStmt : public Stmt { 38 friend class ASTStmtReader; 39 friend class ASTStmtWriter; 40 41 private: 42 Stmt *OriginalStmt = nullptr; 43 OutlinedFunctionDecl *OFDecl = nullptr; 44 45 public: 46 /// Construct a SYCL kernel call statement. SYCLKernelCallStmt(CompoundStmt * CS,OutlinedFunctionDecl * OFD)47 SYCLKernelCallStmt(CompoundStmt *CS, OutlinedFunctionDecl *OFD) 48 : Stmt(SYCLKernelCallStmtClass), OriginalStmt(CS), OFDecl(OFD) {} 49 50 /// Construct an empty SYCL kernel call statement. SYCLKernelCallStmt(EmptyShell Empty)51 SYCLKernelCallStmt(EmptyShell Empty) : Stmt(SYCLKernelCallStmtClass, Empty) {} 52 53 /// Retrieve the model statement. getOriginalStmt()54 CompoundStmt *getOriginalStmt() { return cast<CompoundStmt>(OriginalStmt); } getOriginalStmt()55 const CompoundStmt *getOriginalStmt() const { 56 return cast<CompoundStmt>(OriginalStmt); 57 } setOriginalStmt(CompoundStmt * CS)58 void setOriginalStmt(CompoundStmt *CS) { OriginalStmt = CS; } 59 60 /// Retrieve the outlined function declaration. getOutlinedFunctionDecl()61 OutlinedFunctionDecl *getOutlinedFunctionDecl() { return OFDecl; } getOutlinedFunctionDecl()62 const OutlinedFunctionDecl *getOutlinedFunctionDecl() const { return OFDecl; } 63 64 /// Set the outlined function declaration. setOutlinedFunctionDecl(OutlinedFunctionDecl * OFD)65 void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD) { OFDecl = OFD; } 66 getBeginLoc()67 SourceLocation getBeginLoc() const LLVM_READONLY { 68 return getOriginalStmt()->getBeginLoc(); 69 } 70 getEndLoc()71 SourceLocation getEndLoc() const LLVM_READONLY { 72 return getOriginalStmt()->getEndLoc(); 73 } 74 getSourceRange()75 SourceRange getSourceRange() const LLVM_READONLY { 76 return getOriginalStmt()->getSourceRange(); 77 } 78 classof(const Stmt * T)79 static bool classof(const Stmt *T) { 80 return T->getStmtClass() == SYCLKernelCallStmtClass; 81 } 82 children()83 child_range children() { 84 return child_range(&OriginalStmt, &OriginalStmt + 1); 85 } 86 children()87 const_child_range children() const { 88 return const_child_range(&OriginalStmt, &OriginalStmt + 1); 89 } 90 }; 91 92 } // end namespace clang 93 94 #endif // LLVM_CLANG_AST_STMTSYCL_H 95