Skip to content

[clang] Use TargetInfo to determine device kernel calling convention #144728

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 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,8 @@ unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
return llvm::CallingConv::AArch64_SVE_VectorCall;
case CC_SpirFunction:
return llvm::CallingConv::SPIR_FUNC;
case CC_DeviceKernel: {
if (CGM.getLangOpts().OpenCL)
return CGM.getTargetCodeGenInfo().getOpenCLKernelCallingConv();
if (CGM.getTriple().isSPIROrSPIRV())
return llvm::CallingConv::SPIR_KERNEL;
if (CGM.getTriple().isAMDGPU())
return llvm::CallingConv::AMDGPU_KERNEL;
if (CGM.getTriple().isNVPTX())
return llvm::CallingConv::PTX_Kernel;
llvm_unreachable("Unknown kernel calling convention");
}
case CC_DeviceKernel:
return CGM.getTargetCodeGenInfo().getDeviceKernelCallingConv();
case CC_PreserveMost:
return llvm::CallingConv::PreserveMost;
case CC_PreserveAll:
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ TargetCodeGenInfo::getDependentLibraryOption(llvm::StringRef Lib,
Opt += Lib;
}

unsigned TargetCodeGenInfo::getOpenCLKernelCallingConv() const {
// OpenCL kernels are called via an explicit runtime API with arguments
// set with clSetKernelArg(), not as normal sub-functions.
unsigned TargetCodeGenInfo::getDeviceKernelCallingConv() const {
// Device kernels are called via an explicit runtime API with arguments,
// such as set with clSetKernelArg() for OpenCL, not as normal sub-functions.
// Return SPIR_KERNEL by default as the kernel calling convention to
// ensure the fingerprint is fixed such way that each OpenCL argument
// ensure the fingerprint is fixed such way that each kernel argument
// gets one matching argument in the produced kernel function argument
// list to enable feasible implementation of clSetKernelArg() with
// aggregates etc. In case we would use the default C calling conv here,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ class TargetCodeGenInfo {
llvm::StringRef Value,
llvm::SmallString<32> &Opt) const {}

/// Get LLVM calling convention for OpenCL kernel.
virtual unsigned getOpenCLKernelCallingConv() const;
/// Get LLVM calling convention for device kernels.
virtual unsigned getDeviceKernelCallingConv() const;

/// Get target specific null pointer.
/// \param T is the LLVM type of the null pointer.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo {

void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
unsigned getOpenCLKernelCallingConv() const override;
unsigned getDeviceKernelCallingConv() const override;

llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
llvm::PointerType *T, QualType QT) const override;
Expand Down Expand Up @@ -431,7 +431,7 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
F->addFnAttr("amdgpu-ieee", "false");
}

unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
unsigned AMDGPUTargetCodeGenInfo::getDeviceKernelCallingConv() const {
return llvm::CallingConv::AMDGPU_KERNEL;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/Targets/NVPTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
return true;
}

unsigned getOpenCLKernelCallingConv() const override {
unsigned getDeviceKernelCallingConv() const override {
return llvm::CallingConv::PTX_Kernel;
}

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/Targets/SPIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
getABIInfo().getDataLayout().getAllocaAddrSpace());
}

unsigned getOpenCLKernelCallingConv() const override;
unsigned getDeviceKernelCallingConv() const override;
llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const override;
llvm::Type *
getHLSLType(CodeGenModule &CGM, const Type *Ty,
Expand Down Expand Up @@ -219,7 +219,7 @@ void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI) {
}
}

unsigned CommonSPIRTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
unsigned CommonSPIRTargetCodeGenInfo::getDeviceKernelCallingConv() const {
return llvm::CallingConv::SPIR_KERNEL;
}

Expand Down
Loading