clang 23.0.0git
StmtSYCL.h
Go to the documentation of this file.
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
16#include "clang/AST/Decl.h"
17#include "clang/AST/Stmt.h"
19
20namespace 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 a kernel launch statement to execute on a
32/// SYCL host and an OutlinedFunctionDecl that holds the kernel parameters and
33/// the transformed body to execute on a SYCL device. During code generation,
34/// the OutlinedFunctionDecl is used to emit an offload kernel entry point
35/// suitable for invocation from a SYCL library implementation.
36class SYCLKernelCallStmt : public Stmt {
37 friend class ASTStmtReader;
38 friend class ASTStmtWriter;
39
40private:
41 Stmt *OriginalStmt = nullptr;
42 Stmt *KernelLaunchStmt = nullptr;
43 OutlinedFunctionDecl *OFDecl = nullptr;
44
45public:
46 /// Construct a SYCL kernel call statement.
48 : Stmt(SYCLKernelCallStmtClass), OriginalStmt(CS), KernelLaunchStmt(S),
49 OFDecl(OFD) {}
50
51 /// Construct an empty SYCL kernel call statement.
52 SYCLKernelCallStmt(EmptyShell Empty) : Stmt(SYCLKernelCallStmtClass, Empty) {}
53
54 CompoundStmt *getOriginalStmt() { return cast<CompoundStmt>(OriginalStmt); }
56 return cast<CompoundStmt>(OriginalStmt);
57 }
58
59 void setOriginalStmt(CompoundStmt *CS) { OriginalStmt = CS; }
60
61 Stmt *getKernelLaunchStmt() { return KernelLaunchStmt; }
62 const Stmt *getKernelLaunchStmt() const { return KernelLaunchStmt; }
63
64 void setKernelLaunchStmt(Stmt *S) { KernelLaunchStmt = S; }
65
67 const OutlinedFunctionDecl *getOutlinedFunctionDecl() const { return OFDecl; }
68
69 void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD) { OFDecl = OFD; }
70
71 SourceLocation getBeginLoc() const LLVM_READONLY {
72 return getOriginalStmt()->getBeginLoc();
73 }
74
75 SourceLocation getEndLoc() const LLVM_READONLY {
76 return getOriginalStmt()->getEndLoc();
77 }
78
79 SourceRange getSourceRange() const LLVM_READONLY {
81 }
82
83 static bool classof(const Stmt *T) {
84 return T->getStmtClass() == SYCLKernelCallStmtClass;
85 }
86
88 return child_range(&OriginalStmt, &OriginalStmt + 1);
89 }
90
92 return const_child_range(&OriginalStmt, &OriginalStmt + 1);
93 }
94};
95
96// UnresolvedSYCLKernelCallStmt represents an invocation of a SYCL kernel in
97// a dependent context for which lookup of the sycl_kernel_launch identifier
98// cannot be performed. These statements are transformed to SYCLKernelCallStmt
99// during template instantiation.
100class UnresolvedSYCLKernelCallStmt : public Stmt {
101 friend class ASTStmtReader;
102 friend class ASTStmtWriter;
103
104private:
105 Stmt *OriginalStmt = nullptr;
106 // KernelLaunchIdExpr stores an UnresolvedLookupExpr or UnresolvedMemberExpr
107 // corresponding to the SYCL kernel launch function for which a call
108 // will be synthesized during template instantiation.
109 Expr *KernelLaunchIdExpr = nullptr;
110
111 UnresolvedSYCLKernelCallStmt(CompoundStmt *CS, Expr *IdExpr)
112 : Stmt(UnresolvedSYCLKernelCallStmtClass), OriginalStmt(CS),
113 KernelLaunchIdExpr(IdExpr) {}
114
115 void setOriginalStmt(CompoundStmt *CS) { OriginalStmt = CS; }
116
117 void setKernelLaunchIdExpr(Expr *IdExpr) { KernelLaunchIdExpr = IdExpr; }
118
119public:
120 static UnresolvedSYCLKernelCallStmt *Create(const ASTContext &C,
121 CompoundStmt *CS, Expr *IdExpr) {
122 return new (C) UnresolvedSYCLKernelCallStmt(CS, IdExpr);
123 }
124
125 static UnresolvedSYCLKernelCallStmt *CreateEmpty(const ASTContext &C) {
126 return new (C) UnresolvedSYCLKernelCallStmt(nullptr, nullptr);
127 }
128
131 return cast<CompoundStmt>(OriginalStmt);
132 }
133
134 Expr *getKernelLaunchIdExpr() { return KernelLaunchIdExpr; }
135 const Expr *getKernelLaunchIdExpr() const { return KernelLaunchIdExpr; }
136
137 SourceLocation getBeginLoc() const LLVM_READONLY {
138 return getOriginalStmt()->getBeginLoc();
139 }
140
141 SourceLocation getEndLoc() const LLVM_READONLY {
142 return getOriginalStmt()->getEndLoc();
143 }
144 static bool classof(const Stmt *T) {
145 return T->getStmtClass() == UnresolvedSYCLKernelCallStmtClass;
146 }
148 return child_range(&OriginalStmt, &OriginalStmt + 1);
149 }
150
152 return const_child_range(&OriginalStmt, &OriginalStmt + 1);
153 }
154};
155
156} // end namespace clang
157
158#endif // LLVM_CLANG_AST_STMTSYCL_H
Defines the clang::ASTContext interface.
Defines the clang::SourceLocation class and associated facilities.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1732
SourceLocation getBeginLoc() const
Definition Stmt.h:1846
SourceLocation getEndLoc() const
Definition Stmt.h:1847
This represents one expression.
Definition Expr.h:112
Represents a partial function definition.
Definition Decl.h:4881
CompoundStmt * getOriginalStmt()
Definition StmtSYCL.h:54
void setOriginalStmt(CompoundStmt *CS)
Definition StmtSYCL.h:59
static bool classof(const Stmt *T)
Definition StmtSYCL.h:83
SourceRange getSourceRange() const LLVM_READONLY
Definition StmtSYCL.h:79
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtSYCL.h:71
const OutlinedFunctionDecl * getOutlinedFunctionDecl() const
Definition StmtSYCL.h:67
child_range children()
Definition StmtSYCL.h:87
const CompoundStmt * getOriginalStmt() const
Definition StmtSYCL.h:55
SYCLKernelCallStmt(EmptyShell Empty)
Construct an empty SYCL kernel call statement.
Definition StmtSYCL.h:52
void setKernelLaunchStmt(Stmt *S)
Definition StmtSYCL.h:64
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtSYCL.h:75
const_child_range children() const
Definition StmtSYCL.h:91
friend class ASTStmtWriter
Definition StmtSYCL.h:38
SYCLKernelCallStmt(CompoundStmt *CS, Stmt *S, OutlinedFunctionDecl *OFD)
Construct a SYCL kernel call statement.
Definition StmtSYCL.h:47
const Stmt * getKernelLaunchStmt() const
Definition StmtSYCL.h:62
OutlinedFunctionDecl * getOutlinedFunctionDecl()
Definition StmtSYCL.h:66
void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD)
Definition StmtSYCL.h:69
friend class ASTStmtReader
Definition StmtSYCL.h:37
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1467
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1574
llvm::iterator_range< const_child_iterator > const_child_range
Definition Stmt.h:1575
const CompoundStmt * getOriginalStmt() const
Definition StmtSYCL.h:130
const Expr * getKernelLaunchIdExpr() const
Definition StmtSYCL.h:135
static UnresolvedSYCLKernelCallStmt * CreateEmpty(const ASTContext &C)
Definition StmtSYCL.h:125
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtSYCL.h:137
const_child_range children() const
Definition StmtSYCL.h:151
static UnresolvedSYCLKernelCallStmt * Create(const ASTContext &C, CompoundStmt *CS, Expr *IdExpr)
Definition StmtSYCL.h:120
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtSYCL.h:141
static bool classof(const Stmt *T)
Definition StmtSYCL.h:144
The JSON file list parser is used to communicate input to InstallAPI.
U cast(CodeGen::Address addr)
Definition Address.h:327
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1425