Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions clang/lib/CodeGen/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,8 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
return;

const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
if (FD) {
if (FD)
setFunctionDeclAttributes(FD, F, M);
if (FD->hasAttr<DeviceKernelAttr>() && !M.getLangOpts().OpenCL)
F->setCallingConv(getDeviceKernelCallingConv());
}
if (!getABIInfo().getCodeGenOpts().EmitIEEENaNCompliantInsts)
F->addFnAttr("amdgpu-ieee", "false");
}
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/Targets/NVPTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ void NVPTXTargetCodeGenInfo::setTargetAttributes(
M.handleCUDALaunchBoundsAttr(F, Attr);
}
}
// Attach kernel metadata directly if compiling for NVPTX.
if (FD->hasAttr<DeviceKernelAttr>())
F->setCallingConv(getDeviceKernelCallingConv());
}

void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
Expand Down
21 changes: 0 additions & 21 deletions clang/lib/CodeGen/Targets/SPIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
llvm::PointerType *T,
QualType QT) const override;
void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
};
class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
public:
Expand Down Expand Up @@ -292,22 +290,6 @@ CommonSPIRTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
llvm::ConstantPointerNull::get(NPT), PT);
}

void CommonSPIRTargetCodeGenInfo::setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
if (M.getLangOpts().OpenCL || GV->isDeclaration())
return;

const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
if (!FD)
return;

llvm::Function *F = dyn_cast<llvm::Function>(GV);
assert(F && "Expected GlobalValue to be a Function");

if (FD->hasAttr<DeviceKernelAttr>())
F->setCallingConv(getDeviceKernelCallingConv());
}

LangAS
SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
const VarDecl *D) const {
Expand Down Expand Up @@ -342,9 +324,6 @@ void SPIRVTargetCodeGenInfo::setTargetAttributes(
llvm::Function *F = dyn_cast<llvm::Function>(GV);
assert(F && "Expected GlobalValue to be a Function");

if (FD->hasAttr<DeviceKernelAttr>())
F->setCallingConv(getDeviceKernelCallingConv());

if (!M.getLangOpts().HIP ||
M.getTarget().getTriple().getVendor() != llvm::Triple::AMD)
return;
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3796,8 +3796,10 @@ static CallingConv getCCForDeclaratorChunk(
}
}
}

for (const ParsedAttr &AL : llvm::concat<ParsedAttr>(
D.getDeclSpec().getAttributes(), D.getAttributes())) {
D.getDeclSpec().getAttributes(), D.getAttributes(),
D.getDeclarationAttributes())) {
if (AL.getKind() == ParsedAttr::AT_DeviceKernel) {
CC = CC_DeviceKernel;
break;
Expand Down
26 changes: 23 additions & 3 deletions clang/test/CodeGenOpenCL/ptx-calls.cl
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 6
// RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s

void device_function() {
}
// CHECK-LABEL: define{{.*}} void @device_function()

__kernel void kernel_function() {
device_function();
}
// CHECK-LABEL: define{{.*}} ptx_kernel void @kernel_function()
// CHECK: call void @device_function()
// CHECK-LABEL: define dso_local void @device_function(
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: ret void
//
//
// CHECK-LABEL: define dso_local ptx_kernel void @kernel_function(
// CHECK-SAME: ) #[[ATTR1:[0-9]+]] !kernel_arg_addr_space [[META3:![0-9]+]] !kernel_arg_access_qual [[META3]] !kernel_arg_type [[META3]] !kernel_arg_base_type [[META3]] !kernel_arg_type_qual [[META3]] {
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: call void @__clang_ocl_kern_imp_kernel_function() #[[ATTR2:[0-9]+]]
// CHECK-NEXT: ret void
//
//
// CHECK-LABEL: define dso_local void @__clang_ocl_kern_imp_kernel_function(
// CHECK-SAME: ) #[[ATTR0]] !kernel_arg_addr_space [[META3]] !kernel_arg_access_qual [[META3]] !kernel_arg_type [[META3]] !kernel_arg_base_type [[META3]] !kernel_arg_type_qual [[META3]] {
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: call void @device_function() #[[ATTR2]]
// CHECK-NEXT: ret void
//
//.
// CHECK: [[META3]] = !{}
//.
2 changes: 1 addition & 1 deletion clang/test/CodeGenOpenCL/reflect.cl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ __kernel void kernel_function(__global int *i) {
// CHECK-NEXT: ret void
//
//
// CHECK-LABEL: define dso_local ptx_kernel void @__clang_ocl_kern_imp_kernel_function(
// CHECK-LABEL: define dso_local void @__clang_ocl_kern_imp_kernel_function(
// CHECK-SAME: ptr addrspace(1) noundef align 4 [[I:%.*]]) #[[ATTR0]] !kernel_arg_addr_space [[META3]] !kernel_arg_access_qual [[META4]] !kernel_arg_type [[META5]] !kernel_arg_base_type [[META5]] !kernel_arg_type_qual [[META6]] {
// CHECK-NEXT: entry:
// CHECK-NEXT: [[I_ADDR:%.*]] = alloca ptr addrspace(1), align 4
Expand Down