Skip to content

Commit bab1e6a

Browse files
committed
[NFC][SYCL] Minor refactoring/fixes.
Remove outdated TODO comment. Correct spelling in the comments. Rename "Result" variable to "SYCLKernel". Sorted includes. Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent b7a122b commit bab1e6a

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// This implements Semantic Analysis for SYCL constructs.
1010
//===----------------------------------------------------------------------===//
1111

12+
#include "TreeTransform.h"
1213
#include "clang/AST/AST.h"
14+
#include "clang/AST/RecursiveASTVisitor.h"
1315
#include "clang/Sema/Sema.h"
1416
#include "llvm/ADT/SmallVector.h"
15-
#include "TreeTransform.h"
16-
#include "clang/AST/RecursiveASTVisitor.h"
1717

1818
using namespace clang;
1919

@@ -43,9 +43,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
4343
if (!Def->hasAttr<SYCLDeviceAttr>()) {
4444
Def->addAttr(SYCLDeviceAttr::CreateImplicit(SemaRef.Context));
4545
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
4747
// 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
4949
// this function again.
5050
SemaRef.AddSyclKernel(Def);
5151
}
@@ -101,29 +101,28 @@ FunctionDecl *CreateSYCLKernelFunction(ASTContext &Context, StringRef Name,
101101
QualType RetTy = Context.VoidTy;
102102
QualType FuncTy = Context.getFunctionType(RetTy, ArgTys, Info);
103103
DeclarationName DN = DeclarationName(&Context.Idents.get(Name));
104-
FunctionDecl *Result = FunctionDecl::Create(
104+
FunctionDecl *SYCLKernel = FunctionDecl::Create(
105105
Context, DC, SourceLocation(), SourceLocation(), DN, FuncTy,
106106
Context.getTrivialTypeSourceInfo(RetTy), SC_None);
107107
llvm::SmallVector<ParmVarDecl *, 16> Params;
108108
int i = 0;
109109
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);
114114
P->setScopeInfo(0, i++);
115115
P->setIsUsed();
116116
Params.push_back(P);
117117
}
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;
127126
}
128127

129128
CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
@@ -147,7 +146,7 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
147146
S.Context, NestedNameSpecifierLoc(), SourceLocation(), LambdaVD, false,
148147
DeclarationNameInfo(), QualType(LC->getTypeForDecl(), 0), VK_LValue);
149148

150-
// Init Lambda fields
149+
// Initialize Lambda fields
151150
llvm::SmallVector<Expr *, 16> InitCaptures;
152151

153152
auto TargetFunc = dyn_cast<FunctionDecl>(DC);
@@ -191,7 +190,7 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
191190
// __set_pointer needs one parameter
192191
QualType paramTy = (*(Method->param_begin()))->getOriginalType();
193192

194-
// C++ address space attribute != opencl address space attribute
193+
// C++ address space attribute != OpenCL address space attribute
195194
Expr *qualifiersCast = ImplicitCastExpr::Create(
196195
S.Context, paramTy, CK_NoOp, DRE, nullptr, VK_LValue);
197196
Expr *Res = ImplicitCastExpr::Create(

0 commit comments

Comments
 (0)