Skip to content

Commit 4a119dd

Browse files
committed
Changes based on reviewer comments.
1 parent d058180 commit 4a119dd

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

clang/lib/Sema/SemaDecl.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -16683,9 +16683,11 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1668316683
if (FD && !FD->isDeleted())
1668416684
checkTypeSupport(FD->getType(), FD->getLocation(), FD);
1668516685

16686-
// Handle non-templated free function.
16686+
// Handle free functions.
1668716687
if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLDeviceAttr>() && Body &&
16688-
!FD->isTemplated())
16688+
(FD->getTemplatedKind() == FunctionDecl::TK_NonTemplate ||
16689+
FD->getTemplatedKind() ==
16690+
FunctionDecl::TK_FunctionTemplateSpecialization))
1668916691
ProcessFreeFunction(FD);
1669016692

1669116693
return dcl;

clang/lib/Sema/SemaSYCL.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,7 @@ static bool IsFreeFunction(Sema &SemaRef, const FunctionDecl *FD) {
11311131
SmallVector<std::pair<std::string, std::string>, 4> NameValuePairs =
11321132
AnAttr->getAttributeNameValuePairs(SemaRef.Context);
11331133
for (const auto &NameValuePair : NameValuePairs) {
1134-
if (NameValuePair.first == "sycl-range-kernel" ||
1135-
NameValuePair.first == "sycl-nd-range-kernel" ||
1134+
if (NameValuePair.first == "sycl-nd-range-kernel" ||
11361135
NameValuePair.first == "sycl-single-task-kernel")
11371136
return true;
11381137
}
@@ -1142,8 +1141,7 @@ static bool IsFreeFunction(Sema &SemaRef, const FunctionDecl *FD) {
11421141
return false;
11431142
}
11441143

1145-
static std::string constructFFKernelName(ASTContext &Ctx,
1146-
const FunctionDecl *FD) {
1144+
static std::string constructFFKernelName(const FunctionDecl *FD) {
11471145
IdentifierInfo *Id = FD->getIdentifier();
11481146
std::string NewIdent = (Twine("__free_function_") + Id->getName()).str();
11491147
return NewIdent;
@@ -1152,18 +1150,18 @@ static std::string constructFFKernelName(ASTContext &Ctx,
11521150
// Gets a name for the free function kernel function. The suffix allows a normal
11531151
// device function to coexist with the kernel function.
11541152
static std::pair<std::string, std::string>
1155-
constructFreeFunctionKernelName(Sema &S, const FunctionDecl *KernelCallerFunc,
1153+
constructFreeFunctionKernelName(Sema &S, const FunctionDecl *FreeFunc,
11561154
MangleContext &MC) {
11571155
SmallString<256> Result;
11581156
llvm::raw_svector_ostream Out(Result);
11591157
std::string MangledName;
11601158
std::string StableName;
11611159

1162-
if (KernelCallerFunc->getTemplateSpecializationArgs()) {
1163-
MC.mangleName(KernelCallerFunc, Out);
1160+
if (FreeFunc->getTemplateSpecializationArgs()) {
1161+
MC.mangleName(FreeFunc, Out);
11641162
MangledName = (Twine("__free_function") + Out.str()).str();
11651163
} else {
1166-
MangledName = constructFFKernelName(S.getASTContext(), KernelCallerFunc);
1164+
MangledName = constructFFKernelName(FreeFunc);
11671165
}
11681166
StableName = MangledName;
11691167
return {MangledName, StableName};
@@ -2759,7 +2757,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
27592757
FunctionProtoType::ExtProtoInfo Info(CC_OpenCLKernel);
27602758
QualType FuncType = Ctx.getFunctionType(Ctx.VoidTy, {}, Info);
27612759
const IdentifierInfo *NewIdent =
2762-
&Ctx.Idents.get(constructFFKernelName(Ctx, FD));
2760+
&Ctx.Idents.get(constructFFKernelName(FD));
27632761
FD = FunctionDecl::Create(
27642762
Ctx, Ctx.getTranslationUnitDecl(), Loc, Loc, DeclarationName(NewIdent),
27652763
FuncType, Ctx.getTrivialTypeSourceInfo(Ctx.VoidTy), SC_None);

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -7034,10 +7034,6 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
70347034
TUKind == TU_Prefix && Function->instantiationIsPending())
70357035
delayedPCHInstantiations.push_back(Inst);
70367036
continue;
7037-
7038-
// Handle SYCL free function.
7039-
if (LangOpts.SYCLIsDevice && Function->hasAttr<SYCLDeviceAttr>())
7040-
ProcessFreeFunction(Function);
70417037
}
70427038

70437039
// Instantiate variable definitions

clang/test/SemaSYCL/free_function_kernel_params.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Simple {
1313
};
1414

1515
__attribute__((sycl_device))
16-
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 2)]]
16+
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
1717
void ff_2(int *ptr, int start, int end, struct Simple S) {
1818
for (int i = start; i <= end; i++)
1919
ptr[i] = start + S.x + S.f + S.c[2];
@@ -22,4 +22,23 @@ void ff_2(int *ptr, int start, int end, struct Simple S) {
2222
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_ptr '__global int *'
2323
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_start 'int'
2424
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_end 'int'
25-
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_S 'struct Simple':'Simple'
25+
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_S 'struct Simple':'Simple'
26+
27+
28+
// Templated free function definition.
29+
template <typename T>
30+
__attribute__((sycl_device))
31+
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
32+
void ff_3(T* ptr, T start, int end, struct Simple S) {
33+
for (int i = start; i <= end; i++)
34+
ptr[i] = start + S.x + S.f + S.c[2];
35+
}
36+
37+
// Explicit instantiation with “int*”
38+
template void ff_3(int* ptr, int start, int end, struct Simple S);
39+
40+
// CHECK: FunctionDecl {{.*}} __free_function_Z4ff_3IiEvPT_S0_i6Simple 'void (__global int *, int, int, struct Simple)'
41+
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_ptr '__global int *'
42+
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_start 'int'
43+
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_end 'int'
44+
// CHECK-NEXT: ParmVarDecl {{.*}} _arg_S 'struct Simple':'Simple'

0 commit comments

Comments
 (0)