Skip to content

Commit 8b815fb

Browse files
authored
[SYCL][CodeGen] Directly disable OCL kernel stub for SYCL (NFC) (#19213)
The way 1ce3803 ([SYCL] Disable kernel stub for now (#28629)) and 3b170e3 ([SYCL][AMD] Fix kernel stub calling convention for AMD) disabled the OpenCL kernel stub for SYCL is weird, returning from `TargetCodeGenInfo::setOCLKernelStubCallingConvention()` in SYCL mode. Basically we were actually emitting code for the stub would but we customized it to not change its calling convention. Instead, add `getLangOpts().OpenCL` checks to `CodeGenFunction::GenerateCode` (to emit the kernel contents directly into the kernel) and to `CodeGenModule::EmitGlobal` (to disable the deferred emission of the stub). With this change, we should never come across `KernelReferenceKind::Stub` in SYCL mode.
1 parent c666567 commit 8b815fb

File tree

5 files changed

+3
-19
lines changed

5 files changed

+3
-19
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
19321932
// Implicit copy-assignment gets the same special treatment as implicit
19331933
// copy-constructors.
19341934
emitImplicitAssignmentOperatorBody(Args);
1935-
} else if (FD->hasAttr<OpenCLKernelAttr>() &&
1935+
} else if (getLangOpts().OpenCL && FD->hasAttr<OpenCLKernelAttr>() &&
19361936
GD.getKernelReferenceKind() == KernelReferenceKind::Kernel) {
19371937
CallArgList CallArgs;
19381938
for (unsigned i = 0; i < Args.size(); ++i) {

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4341,7 +4341,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
43414341

43424342
// Ignore declarations, they will be emitted on their first use.
43434343
if (const auto *FD = dyn_cast<FunctionDecl>(Global)) {
4344-
if (FD->hasAttr<OpenCLKernelAttr>() && FD->doesThisDeclarationHaveABody())
4344+
if (LangOpts.OpenCL && FD->hasAttr<OpenCLKernelAttr>() &&
4345+
FD->doesThisDeclarationHaveABody())
43454346
addDeferredDeclToEmit(GlobalDecl(FD, KernelReferenceKind::Stub));
43464347

43474348
// Update deferred annotations with the latest declaration if the function

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ unsigned TargetCodeGenInfo::getOpenCLKernelCallingConv() const {
119119

120120
void TargetCodeGenInfo::setOCLKernelStubCallingConvention(
121121
const FunctionType *&FT) const {
122-
123-
if (getABIInfo().getContext().getLangOpts().SYCLIsNativeCPU)
124-
return;
125-
126122
FT = getABIInfo().getContext().adjustFunctionType(
127123
FT, FT->getExtInfo().withCallingConv(CC_C));
128124
}

clang/lib/CodeGen/Targets/AMDGPU.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo {
305305
void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
306306
CodeGen::CodeGenModule &M) const override;
307307
unsigned getOpenCLKernelCallingConv() const override;
308-
void
309-
setOCLKernelStubCallingConvention(const FunctionType *&FT) const override;
310308

311309
llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
312310
llvm::PointerType *T, QualType QT) const override;
@@ -437,14 +435,6 @@ unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
437435
return llvm::CallingConv::AMDGPU_KERNEL;
438436
}
439437

440-
void AMDGPUTargetCodeGenInfo::setOCLKernelStubCallingConvention(
441-
const FunctionType *&FT) const {
442-
bool IsSYCL = getABIInfo().getContext().getLangOpts().isSYCL();
443-
FT = getABIInfo().getContext().adjustFunctionType(
444-
FT,
445-
FT->getExtInfo().withCallingConv(!IsSYCL ? CC_C : CC_AMDGPUKernelCall));
446-
}
447-
448438
// Currently LLVM assumes null pointers always have value 0,
449439
// which results in incorrectly transformed IR. Therefore, instead of
450440
// emitting null pointers in private and local address spaces, a null

clang/lib/CodeGen/Targets/SPIR.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,6 @@ void SPIRVTargetCodeGenInfo::setCUDAKernelCallingConvention(
394394

395395
void CommonSPIRTargetCodeGenInfo::setOCLKernelStubCallingConvention(
396396
const FunctionType *&FT) const {
397-
// Disable kernel stub for sycl
398-
if (getABIInfo().getContext().getLangOpts().isSYCL())
399-
return;
400397
FT = getABIInfo().getContext().adjustFunctionType(
401398
FT, FT->getExtInfo().withCallingConv(CC_SpirFunction));
402399
}

0 commit comments

Comments
 (0)