Skip to content

Commit 7c024bc

Browse files
authored
fix merge with upstream kernel attribute refactor (#18868)
Fix merge with my upstream change to refactor the device kernel attribute [here](llvm/llvm-project@3b9ebe9). --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent fb5b04b commit 7c024bc

32 files changed

+102
-95
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ def DeviceKernel : DeclOrTypeAttr {
16501650
// list, but here we have the same spelling with unscores and without,
16511651
// so handle that case manually.
16521652
return A.getAttributeSpellingListIndex() == Keyword_kernel ||
1653-
A.getAttrName()->getName() == "kernel";
1653+
(A.getAttrName() && A.getAttrName()->getName() == "kernel");
16541654
}
16551655
static inline bool isOpenCLSpelling(const AttributeCommonInfo* A) {
16561656
if (!A) return false;

clang/lib/Basic/Targets/X86.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
796796
case CC_X86RegCall:
797797
return CCCR_OK;
798798
case CC_DeviceKernel:
799-
return IsOpenCL ? CCCR_OK : CCCR_Warning;
799+
return IsOpenCL || IsSYCLDevice ? CCCR_OK : CCCR_Warning;
800800
default:
801801
return CCCR_Warning;
802802
}
@@ -842,10 +842,12 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
842842
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
843843
TargetInfo::adjust(Diags, Opts);
844844
IsOpenCL = Opts.OpenCL;
845+
IsSYCLDevice = Opts.SYCLIsDevice;
845846
}
846847

847848
private:
848849
bool IsOpenCL = false;
850+
bool IsSYCLDevice = false;
849851
};
850852

851853
// x86-64 UEFI target

clang/lib/CodeGen/CGCall.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
9494
return llvm::CallingConv::AMDGPU_KERNEL;
9595
if (CGM.getTriple().isNVPTX())
9696
return llvm::CallingConv::PTX_Kernel;
97+
if (CGM.getLangOpts().SYCLIsNativeCPU)
98+
return CGM.getTarget().getDefaultCallingConv();
99+
if (CGM.getLangOpts().SYCLIsDevice)
100+
return CGM.getTarget().getDefaultCallingConv();
97101
llvm_unreachable("Unknown kernel calling convention");
98102
}
99103
case CC_PreserveMost:
@@ -2628,8 +2632,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
26282632
NumElemsParam);
26292633
}
26302634

2631-
if (DeviceKernelAttr::isOpenCLSpelling(
2632-
TargetDecl->getAttr<DeviceKernelAttr>()) &&
2635+
if (TargetDecl->hasAttr<DeviceKernelAttr>() &&
2636+
(getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) &&
26332637
CallingConv != CallingConv::CC_C &&
26342638
CallingConv != CallingConv::CC_SpirFunction) {
26352639
// Check CallingConv to avoid adding uniform-work-group-size attribute to
@@ -3013,8 +3017,9 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
30133017
// > data type, the OpenCL compiler can assume that the pointee is always
30143018
// > appropriately aligned as required by the data type.
30153019
if (TargetDecl &&
3016-
DeviceKernelAttr::isOpenCLSpelling(
3017-
TargetDecl->getAttr<DeviceKernelAttr>()) &&
3020+
3021+
(TargetDecl->hasAttr<DeviceKernelAttr>() &&
3022+
(getLangOpts().OpenCL || getLangOpts().SYCLIsDevice)) &&
30183023
ParamType->isPointerType()) {
30193024
QualType PTy = ParamType->getPointeeType();
30203025
if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,7 +4014,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
40144014
if (FD)
40154015
diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
40164016

4017-
if (FD && FD->hasAttr<DeviceKernelAttr>())
4017+
if (FD && FD->hasAttr<DeviceKernelAttr>() && getLangOpts().isSYCL())
40184018
SYCL().CheckSYCLKernelCall(FD, Args);
40194019

40204020
// Diagnose variadic calls in SYCL.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20762,7 +20762,8 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(const FunctionDecl *FD,
2076220762
return FunctionEmissionStatus::TemplateDiscarded;
2076320763

2076420764
if (LangOpts.SYCLIsDevice &&
20765-
(FD->hasAttr<SYCLDeviceAttr>() || FD->hasAttr<DeviceKernelAttr>()))
20765+
(FD->hasAttr<SYCLDeviceAttr>() || FD->hasAttr<DeviceKernelAttr>()) &&
20766+
!FD->hasAttr<ArtificialAttr>())
2076620767
return FunctionEmissionStatus::Emitted;
2076720768

2076820769
// Check whether this function is an externally visible definition.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5355,7 +5355,7 @@ static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
53555355
static void handleDeviceKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
53565356
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
53575357
bool IsFunctionTemplate = FD && FD->getDescribedFunctionTemplate();
5358-
if (S.getLangOpts().SYCLIsDevice) {
5358+
if (S.getLangOpts().isSYCL()) {
53595359
if (!IsFunctionTemplate) {
53605360
S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str)
53615361
<< AL << AL.isRegularKeywordAttribute() << "function templates";

clang/lib/Sema/SemaType.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,12 +3785,11 @@ static CallingConv getCCForDeclaratorChunk(
37853785
}
37863786
}
37873787
}
3788-
if (!S.getLangOpts().isSYCL()) {
3789-
for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) {
3790-
if (AL.getKind() == ParsedAttr::AT_DeviceKernel) {
3791-
CC = CC_DeviceKernel;
3792-
break;
3793-
}
3788+
for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) {
3789+
if (AL.getKind() == ParsedAttr::AT_DeviceKernel &&
3790+
!DeviceKernelAttr::isSYCLSpelling(AL)) {
3791+
CC = CC_DeviceKernel;
3792+
break;
37943793
}
37953794
}
37963795
return CC;

clang/test/CodeGenSYCL/kernel-op-calls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main() {
5353

5454
Q.submit([&](sycl::handler& cgh) {
5555
ESIMDFunctor EF;
56-
// CHECK: define dso_local spir_kernel void @_ZTS12ESIMDFunctor() {{.*}} !intel_reqd_sub_group_size !{{[0-9]+}} !work_group_size_hint !{{[0-9]+}} !kernel_arg_accessor_ptr !{{[0-9]+}} !sycl_explicit_simd !{{[0-9]+}} !sycl_fixed_targets !{{[0-9]+}} {
56+
// CHECK: define dso_local spir_kernel void @_ZTS12ESIMDFunctor() {{.*}} !sycl_explicit_simd !{{[0-9]+}} !intel_reqd_sub_group_size !{{[0-9]+}} !work_group_size_hint !{{[0-9]+}} !kernel_arg_accessor_ptr !{{[0-9]+}} !sycl_fixed_targets !{{[0-9]+}} {
5757
cgh.parallel_for(sycl::range<1>(10), EF);
5858
});
5959

clang/test/CodeGenSYCL/usm-int-header.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ int main() {
3030
});
3131
}
3232

33-
// CHECK: FunctionDecl {{.*}}usm_test{{.*}} 'void (__global int *, __global float *)'
33+
// CHECK: FunctionDecl {{.*}}usm_test{{.*}} 'void (__global int *, __global float *) __attribute__((device_kernel))'

clang/test/SemaOpenCL/sampled_image_overload.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
void __attribute__((overloadable)) foo(__ocl_sampled_image1d_ro_t);
44
void __attribute__((overloadable)) foo(__ocl_sampled_image2d_ro_t);
55

6-
// CHECK: FunctionDecl {{.*}} <{{.*}}> line:{{.*}} ker 'void (__private __ocl_sampled_image1d_ro_t, __private __ocl_sampled_image2d_ro_t)'
6+
// CHECK: FunctionDecl {{.*}} <{{.*}}> line:{{.*}} ker 'void (__private __ocl_sampled_image1d_ro_t, __private __ocl_sampled_image2d_ro_t) __attribute__((device_kernel))'
77
void kernel ker(__ocl_sampled_image1d_ro_t src1, __ocl_sampled_image2d_ro_t src2) {
88
// CHECK: CallExpr
99
// CHECK-NEXT: ImplicitCastExpr {{.*}} <{{.*}}> 'void (*)(__private __ocl_sampled_image1d_ro_t)'

0 commit comments

Comments
 (0)