Skip to content

[SYCL][CodeGen] Directly disable OCL kernel stub for SYCL (NFC) #19213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 2, 2025
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
// Implicit copy-assignment gets the same special treatment as implicit
// copy-constructors.
emitImplicitAssignmentOperatorBody(Args);
} else if (FD->hasAttr<OpenCLKernelAttr>() &&
} else if (getLangOpts().OpenCL && FD->hasAttr<OpenCLKernelAttr>() &&
GD.getKernelReferenceKind() == KernelReferenceKind::Kernel) {
CallArgList CallArgs;
for (unsigned i = 0; i < Args.size(); ++i) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4341,7 +4341,8 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {

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

// Update deferred annotations with the latest declaration if the function
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ unsigned TargetCodeGenInfo::getOpenCLKernelCallingConv() const {

void TargetCodeGenInfo::setOCLKernelStubCallingConvention(
const FunctionType *&FT) const {

if (getABIInfo().getContext().getLangOpts().SYCLIsNativeCPU)
return;

FT = getABIInfo().getContext().adjustFunctionType(
FT, FT->getExtInfo().withCallingConv(CC_C));
}
Expand Down
10 changes: 0 additions & 10 deletions clang/lib/CodeGen/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo {
void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
unsigned getOpenCLKernelCallingConv() const override;
void
setOCLKernelStubCallingConvention(const FunctionType *&FT) const override;

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

void AMDGPUTargetCodeGenInfo::setOCLKernelStubCallingConvention(
const FunctionType *&FT) const {
bool IsSYCL = getABIInfo().getContext().getLangOpts().isSYCL();
FT = getABIInfo().getContext().adjustFunctionType(
FT,
FT->getExtInfo().withCallingConv(!IsSYCL ? CC_C : CC_AMDGPUKernelCall));
}

// Currently LLVM assumes null pointers always have value 0,
// which results in incorrectly transformed IR. Therefore, instead of
// emitting null pointers in private and local address spaces, a null
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/Targets/SPIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,6 @@ void SPIRVTargetCodeGenInfo::setCUDAKernelCallingConvention(

void CommonSPIRTargetCodeGenInfo::setOCLKernelStubCallingConvention(
const FunctionType *&FT) const {
// Disable kernel stub for sycl
if (getABIInfo().getContext().getLangOpts().isSYCL())
return;
FT = getABIInfo().getContext().adjustFunctionType(
FT, FT->getExtInfo().withCallingConv(CC_SpirFunction));
}
Expand Down