Skip to content

Commit b7a122b

Browse files
committed
[SYCL] Remove struct and class keywords from kernel names
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 2ad1d20 commit b7a122b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
8484
Sema &SemaRef;
8585
};
8686

87-
CXXRecordDecl* getBodyAsLambda(FunctionDecl *FD) {
87+
CXXRecordDecl *getBodyAsLambda(FunctionDecl *FD) {
8888
auto FirstArg = (*FD->param_begin());
8989
if (FirstArg)
9090
if (FirstArg->getType()->getAsCXXRecordDecl()->isLambda())
@@ -215,19 +215,18 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
215215
// to replace all refs to this lambda with our vardecl.
216216
// I used TreeTransform here, but I'm not sure that it is good solution
217217
// Also I used map and I'm not sure about it too.
218-
Stmt* FunctionBody = KernelHelper->getBody();
218+
Stmt *FunctionBody = KernelHelper->getBody();
219219
DeclMap DMap;
220-
ParmVarDecl* LambdaParam = *(KernelHelper->param_begin());
220+
ParmVarDecl *LambdaParam = *(KernelHelper->param_begin());
221221
// DeclRefExpr with valid source location but with decl which is not marked
222222
// as used is invalid.
223223
LambdaVD->setIsUsed();
224224
DMap[LambdaParam] = LambdaVD;
225225
// Without PushFunctionScope I had segfault. Maybe we also need to do pop.
226226
S.PushFunctionScope();
227227
KernelBodyTransform KBT(DMap, S);
228-
Stmt* NewBody = KBT.TransformStmt(FunctionBody).get();
228+
Stmt *NewBody = KBT.TransformStmt(FunctionBody).get();
229229
BodyStmts.push_back(NewBody);
230-
231230
}
232231
return CompoundStmt::Create(S.Context, BodyStmts, SourceLocation(),
233232
SourceLocation());
@@ -323,11 +322,19 @@ void Sema::ConstructSYCLKernel(FunctionDecl *KernelHelper) {
323322
Name += "_" + ParamType.getAsString() + "_";
324323
}
325324
}
325+
const std::string ToBeErased[2] = {"class ", "struct "};
326+
for (size_t i = 0; i < 2; ++i) {
327+
for (size_t pos = Name.find(ToBeErased[i]); pos != std::string::npos;
328+
pos = Name.find(ToBeErased[i])) {
329+
Name.erase(pos, ToBeErased[i].length());
330+
}
331+
}
326332

327333
FunctionDecl *SYCLKernel =
328334
CreateSYCLKernelFunction(getASTContext(), Name, ArgTys, NewArgDecls);
329335

330-
CompoundStmt *SYCLKernelBody = CreateSYCLKernelBody(*this, KernelHelper, SYCLKernel);
336+
CompoundStmt *SYCLKernelBody =
337+
CreateSYCLKernelBody(*this, KernelHelper, SYCLKernel);
331338
SYCLKernel->setBody(SYCLKernelBody);
332339

333340
AddSyclKernel(SYCLKernel);
@@ -337,4 +344,3 @@ void Sema::ConstructSYCLKernel(FunctionDecl *KernelHelper) {
337344
Marker.TraverseStmt(SYCLKernelBody);
338345
}
339346
}
340-

0 commit comments

Comments
 (0)