9
9
// This implements Semantic Analysis for SYCL constructs.
10
10
// ===----------------------------------------------------------------------===//
11
11
12
+ #include " TreeTransform.h"
12
13
#include " clang/AST/AST.h"
14
+ #include " clang/AST/RecursiveASTVisitor.h"
13
15
#include " clang/Sema/Sema.h"
14
16
#include " llvm/ADT/SmallVector.h"
15
- #include " TreeTransform.h"
16
- #include " clang/AST/RecursiveASTVisitor.h"
17
17
18
18
using namespace clang ;
19
19
@@ -43,9 +43,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
43
43
if (!Def->hasAttr <SYCLDeviceAttr>()) {
44
44
Def->addAttr (SYCLDeviceAttr::CreateImplicit (SemaRef.Context ));
45
45
this ->TraverseStmt (Def->getBody ());
46
- // But because parser works with top level decls and codegen
46
+ // But because parser works with top level declarations and CodeGen
47
47
// already saw and ignored our function without device attribute we
48
- // need to add this function into sycl kernels array to show it
48
+ // need to add this function into SYCL kernels array to show it
49
49
// this function again.
50
50
SemaRef.AddSyclKernel (Def);
51
51
}
@@ -101,29 +101,28 @@ FunctionDecl *CreateSYCLKernelFunction(ASTContext &Context, StringRef Name,
101
101
QualType RetTy = Context.VoidTy ;
102
102
QualType FuncTy = Context.getFunctionType (RetTy, ArgTys, Info);
103
103
DeclarationName DN = DeclarationName (&Context.Idents .get (Name));
104
- FunctionDecl *Result = FunctionDecl::Create (
104
+ FunctionDecl *SYCLKernel = FunctionDecl::Create (
105
105
Context, DC, SourceLocation (), SourceLocation (), DN, FuncTy,
106
106
Context.getTrivialTypeSourceInfo (RetTy), SC_None);
107
107
llvm::SmallVector<ParmVarDecl *, 16 > Params;
108
108
int i = 0 ;
109
109
for (auto ArgTy : ArgTys) {
110
- auto P =
111
- ParmVarDecl::Create (Context, Result, SourceLocation (), SourceLocation (),
112
- ArgDecls[i]->getIdentifier (), ArgTy ,
113
- ArgDecls[i]-> getTypeSourceInfo (), SC_None, 0 );
110
+ auto P = ParmVarDecl::Create (Context, SYCLKernel, SourceLocation (),
111
+ SourceLocation (), ArgDecls[i]-> getIdentifier (),
112
+ ArgTy, ArgDecls[i]->getTypeSourceInfo () ,
113
+ SC_None, 0 );
114
114
P->setScopeInfo (0 , i++);
115
115
P->setIsUsed ();
116
116
Params.push_back (P);
117
117
}
118
- Result->setParams (Params);
119
- // TODO: Add SYCL specific attribute for kernel and all functions called
120
- // by kernel.
121
- Result->addAttr (SYCLDeviceAttr::CreateImplicit (Context));
122
- Result->addAttr (OpenCLKernelAttr::CreateImplicit (Context));
123
- Result->addAttr (AsmLabelAttr::CreateImplicit (Context, Name));
124
- // To see kernel in ast-dump.
125
- DC->addDecl (Result);
126
- return Result;
118
+ SYCLKernel->setParams (Params);
119
+
120
+ SYCLKernel->addAttr (SYCLDeviceAttr::CreateImplicit (Context));
121
+ SYCLKernel->addAttr (OpenCLKernelAttr::CreateImplicit (Context));
122
+ SYCLKernel->addAttr (AsmLabelAttr::CreateImplicit (Context, Name));
123
+ // To see kernel in AST-dump.
124
+ DC->addDecl (SYCLKernel);
125
+ return SYCLKernel;
127
126
}
128
127
129
128
CompoundStmt *CreateSYCLKernelBody (Sema &S, FunctionDecl *KernelHelper,
@@ -147,7 +146,7 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
147
146
S.Context , NestedNameSpecifierLoc (), SourceLocation (), LambdaVD, false ,
148
147
DeclarationNameInfo (), QualType (LC->getTypeForDecl (), 0 ), VK_LValue);
149
148
150
- // Init Lambda fields
149
+ // Initialize Lambda fields
151
150
llvm::SmallVector<Expr *, 16 > InitCaptures;
152
151
153
152
auto TargetFunc = dyn_cast<FunctionDecl>(DC);
@@ -191,7 +190,7 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
191
190
// __set_pointer needs one parameter
192
191
QualType paramTy = (*(Method->param_begin ()))->getOriginalType ();
193
192
194
- // C++ address space attribute != opencl address space attribute
193
+ // C++ address space attribute != OpenCL address space attribute
195
194
Expr *qualifiersCast = ImplicitCastExpr::Create (
196
195
S.Context , paramTy, CK_NoOp, DRE, nullptr , VK_LValue);
197
196
Expr *Res = ImplicitCastExpr::Create (
0 commit comments