Skip to content

Commit 168103d

Browse files
committed
address feedback
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 924839b commit 168103d

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ def FunctionPointer : SubsetSubject<DeclBase,
191191

192192
def OpenCLKernelFunction
193193
: SubsetSubject<Function, [{S->getASTContext().getLangOpts().OpenCL &&
194-
S->hasAttr<DeviceKernelAttr>()}],
194+
DeviceKernelAttr::isOpenCLSpelling(
195+
S->getAttr<DeviceKernelAttr>()}],
195196
"kernel functions">;
196197

197198
// HasFunctionProto is a more strict version of FunctionLike, so it should
@@ -1556,18 +1557,38 @@ def DeviceKernel : DeclOrTypeAttr {
15561557
A.getAttributeSpellingListIndex() == CXX11_clang_amdgpu_kernel ||
15571558
A.getAttributeSpellingListIndex() == C23_clang_amdgpu_kernel;
15581559
}
1560+
static inline bool isAMDGPUSpelling(const AttributeCommonInfo* A) {
1561+
if(!A) return false;
1562+
return isAMDGPUSpelling(*A);
1563+
}
15591564
static inline bool isNVPTXSpelling(const AttributeCommonInfo& A) {
15601565
return A.getAttributeSpellingListIndex() == GNU_nvptx_kernel ||
15611566
A.getAttributeSpellingListIndex() == CXX11_clang_nvptx_kernel ||
15621567
A.getAttributeSpellingListIndex() == C23_clang_nvptx_kernel;
15631568
}
1569+
static inline bool isNVPTXSpelling(const AttributeCommonInfo* A) {
1570+
if(!A) return false;
1571+
return isNVPTXSpelling(*A);
1572+
}
15641573
static inline bool isSYCLSpelling(const AttributeCommonInfo& A) {
15651574
return A.getAttributeSpellingListIndex() == GNU_sycl_kernel ||
15661575
A.getAttributeSpellingListIndex() == CXX11_clang_sycl_kernel ||
15671576
A.getAttributeSpellingListIndex() == C23_clang_sycl_kernel;
15681577
}
1578+
static inline bool isSYCLSpelling(const AttributeCommonInfo* A) {
1579+
if(!A) return false;
1580+
return isSYCLSpelling(*A);
1581+
}
15691582
static inline bool isOpenCLSpelling(const AttributeCommonInfo& A) {
1570-
return A.getAttributeSpellingListIndex() == Keyword_kernel;
1583+
// Tablegen trips underscores from spellings to build the spelling
1584+
// list, but here we have the same spelling with unscores and without,
1585+
// so handle that case manually.
1586+
return A.getAttributeSpellingListIndex() == Keyword_kernel ||
1587+
A.getAttrName()->getName() == "kernel";
1588+
}
1589+
static inline bool isOpenCLSpelling(const AttributeCommonInfo* A) {
1590+
if (!A) return false;
1591+
return isOpenCLSpelling(*A);
15711592
}
15721593
}];
15731594
}

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,7 +3541,7 @@ bool FunctionDecl::isExternC() const {
35413541
}
35423542

35433543
bool FunctionDecl::isInExternCContext() const {
3544-
if (hasAttr<DeviceKernelAttr>() && getASTContext().getLangOpts().OpenCL)
3544+
if (DeviceKernelAttr::isOpenCLSpelling(getAttr<DeviceKernelAttr>()))
35453545
return true;
35463546
return getLexicalDeclContext()->isExternCContext();
35473547
}
@@ -5510,7 +5510,8 @@ FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
55105510
}
55115511

55125512
bool FunctionDecl::isReferenceableKernel() const {
5513-
return hasAttr<CUDAGlobalAttr>() || hasAttr<DeviceKernelAttr>();
5513+
return hasAttr<CUDAGlobalAttr>() ||
5514+
DeviceKernelAttr::isOpenCLSpelling(getAttr<DeviceKernelAttr>());
55145515
}
55155516

55165517
BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,8 +1556,8 @@ void CXXNameMangler::mangleUnqualifiedName(
15561556
FD && FD->hasAttr<CUDAGlobalAttr>() &&
15571557
GD.getKernelReferenceKind() == KernelReferenceKind::Stub;
15581558
bool IsOCLDeviceStub =
1559-
getASTContext().getLangOpts().OpenCL && FD &&
1560-
FD->hasAttr<DeviceKernelAttr>() &&
1559+
FD &&
1560+
DeviceKernelAttr::isOpenCLSpelling(FD->getAttr<DeviceKernelAttr>()) &&
15611561
GD.getKernelReferenceKind() == KernelReferenceKind::Stub;
15621562
if (IsDeviceStub)
15631563
mangleDeviceStubName(II);

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,9 @@ void MicrosoftCXXNameMangler::mangleUnqualifiedName(GlobalDecl GD,
11641164
->hasAttr<CUDAGlobalAttr>())) &&
11651165
GD.getKernelReferenceKind() == KernelReferenceKind::Stub;
11661166
bool IsOCLDeviceStub =
1167-
getASTContext().getLangOpts().OpenCL && ND &&
1168-
isa<FunctionDecl>(ND) && ND->hasAttr<DeviceKernelAttr>() &&
1167+
ND && isa<FunctionDecl>(ND) &&
1168+
DeviceKernelAttr::isOpenCLSpelling(
1169+
ND->getAttr<DeviceKernelAttr>()) &&
11691170
GD.getKernelReferenceKind() == KernelReferenceKind::Stub;
11701171
if (IsDeviceStub)
11711172
mangleSourceName(

clang/lib/CodeGen/CGCall.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ CodeGenTypes::arrangeFunctionDeclaration(const GlobalDecl GD) {
539539
assert(isa<FunctionType>(FTy));
540540
setCUDAKernelCallingConvention(FTy, CGM, FD);
541541

542-
if (getContext().getLangOpts().OpenCL && FD->hasAttr<DeviceKernelAttr>() &&
542+
if (DeviceKernelAttr::isOpenCLSpelling(FD->getAttr<DeviceKernelAttr>()) &&
543543
GD.getKernelReferenceKind() == KernelReferenceKind::Stub) {
544544
const FunctionType *FT = FTy->getAs<FunctionType>();
545545
CGM.getTargetCodeGenInfo().setOCLKernelStubCallingConvention(FT);
@@ -2535,7 +2535,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
25352535
NumElemsParam);
25362536
}
25372537

2538-
if (getLangOpts().OpenCL && TargetDecl->hasAttr<DeviceKernelAttr>() &&
2538+
if (DeviceKernelAttr::isOpenCLSpelling(
2539+
TargetDecl->getAttr<DeviceKernelAttr>()) &&
25392540
CallingConv != CallingConv::CC_C &&
25402541
CallingConv != CallingConv::CC_SpirFunction) {
25412542
// Check CallingConv to avoid adding uniform-work-group-size attribute to
@@ -2918,8 +2919,10 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
29182919
// > For arguments to a __kernel function declared to be a pointer to a
29192920
// > data type, the OpenCL compiler can assume that the pointee is always
29202921
// > appropriately aligned as required by the data type.
2921-
if (getLangOpts().OpenCL && TargetDecl &&
2922-
TargetDecl->hasAttr<DeviceKernelAttr>() && ParamType->isPointerType()) {
2922+
if (TargetDecl &&
2923+
DeviceKernelAttr::isOpenCLSpelling(
2924+
TargetDecl->getAttr<DeviceKernelAttr>()) &&
2925+
ParamType->isPointerType()) {
29232926
QualType PTy = ParamType->getPointeeType();
29242927
if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
29252928
llvm::Align Alignment =

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,8 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
15881588
// Implicit copy-assignment gets the same special treatment as implicit
15891589
// copy-constructors.
15901590
emitImplicitAssignmentOperatorBody(Args);
1591-
} else if (getLangOpts().OpenCL && FD->hasAttr<DeviceKernelAttr>() &&
1591+
} else if (DeviceKernelAttr::isOpenCLSpelling(
1592+
FD->getAttr<DeviceKernelAttr>()) &&
15921593
GD.getKernelReferenceKind() == KernelReferenceKind::Kernel) {
15931594
CallArgList CallArgs;
15941595
for (unsigned i = 0; i < Args.size(); ++i) {

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,8 +1912,9 @@ static std::string getMangledNameImpl(CodeGenModule &CGM, GlobalDecl GD,
19121912
} else if (FD && FD->hasAttr<CUDAGlobalAttr>() &&
19131913
GD.getKernelReferenceKind() == KernelReferenceKind::Stub) {
19141914
Out << "__device_stub__" << II->getName();
1915-
} else if (FD && FD->hasAttr<DeviceKernelAttr>() &&
1916-
CGM.getLangOpts().OpenCL &&
1915+
} else if (FD &&
1916+
DeviceKernelAttr::isOpenCLSpelling(
1917+
FD->getAttr<DeviceKernelAttr>()) &&
19171918
GD.getKernelReferenceKind() == KernelReferenceKind::Stub) {
19181919
Out << "__clang_ocl_kern_imp_" << II->getName();
19191920
} else {
@@ -6178,7 +6179,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
61786179
(CodeGenOpts.OptimizationLevel == 0) &&
61796180
!D->hasAttr<MinSizeAttr>();
61806181

6181-
if (getLangOpts().OpenCL && D->hasAttr<DeviceKernelAttr>()) {
6182+
if (DeviceKernelAttr::isOpenCLSpelling(D->getAttr<DeviceKernelAttr>())) {
61826183
if (GD.getKernelReferenceKind() == KernelReferenceKind::Stub &&
61836184
!D->hasAttr<NoInlineAttr>() &&
61846185
!Fn->hasFnAttribute(llvm::Attribute::NoInline) &&

0 commit comments

Comments
 (0)