Skip to content

Commit be82182

Browse files
authored
[CIR][CUDA][NFC] Skeleton of setCUDAKernelCallingConvention (#1344)
This is only a skeleton following OG, and shouldn't have changed any visible behaviour.
1 parent 0bdd896 commit be82182

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3350,11 +3350,12 @@ def DerivedDataMemberOp : CIR_Op<"derived_data_member", [Pure]> {
33503350
def CC_C : I32EnumAttrCase<"C", 1, "c">;
33513351
def CC_SpirKernel : I32EnumAttrCase<"SpirKernel", 2, "spir_kernel">;
33523352
def CC_SpirFunction : I32EnumAttrCase<"SpirFunction", 3, "spir_function">;
3353+
def CC_OpenCLKernel : I32EnumAttrCase<"OpenCLKernel", 4, "opencl_kernel">;
33533354

33543355
def CallingConv : I32EnumAttr<
33553356
"CallingConv",
33563357
"calling convention",
3357-
[CC_C, CC_SpirKernel, CC_SpirFunction]> {
3358+
[CC_C, CC_SpirKernel, CC_SpirFunction, CC_OpenCLKernel]> {
33583359
let cppNamespace = "::cir";
33593360
}
33603361

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,9 @@ const CIRGenFunctionInfo &CIRGenTypes::arrangeFreeFunctionCall(
15311531
static void setCUDAKernelCallingConvention(CanQualType &FTy, CIRGenModule &CGM,
15321532
const FunctionDecl *FD) {
15331533
if (FD->hasAttr<CUDAGlobalAttr>()) {
1534-
llvm_unreachable("NYI");
1534+
const FunctionType *FT = FTy->getAs<FunctionType>();
1535+
CGM.getTargetCIRGenInfo().setCUDAKernelCallingConvention(FT);
1536+
FTy = FT->getCanonicalTypeUnqualified();
15351537
}
15361538
}
15371539

clang/lib/CIR/CodeGen/TargetInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ class SPIRVTargetCIRGenInfo : public CommonSPIRTargetCIRGenInfo {
301301
public:
302302
SPIRVTargetCIRGenInfo(CIRGenTypes &CGT)
303303
: CommonSPIRTargetCIRGenInfo(std::make_unique<SPIRVABIInfo>(CGT)) {}
304+
305+
void setCUDAKernelCallingConvention(const FunctionType *&ft) const override {
306+
llvm_unreachable("NYI");
307+
}
304308
};
305309

306310
} // namespace
@@ -349,6 +353,10 @@ class AMDGPUTargetCIRGenInfo : public TargetCIRGenInfo {
349353
public:
350354
AMDGPUTargetCIRGenInfo(CIRGenTypes &cgt)
351355
: TargetCIRGenInfo(std::make_unique<AMDGPUABIInfo>(cgt)) {}
356+
357+
void setCUDAKernelCallingConvention(const FunctionType *&ft) const override {
358+
llvm_unreachable("NYI");
359+
}
352360
};
353361

354362
} // namespace

clang/lib/CIR/CodeGen/TargetInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ class TargetCIRGenInfo {
113113
return cir::CallingConv::SpirKernel;
114114
}
115115

116+
// Set calling convention for CUDA Kernels.
117+
// Some targets, such as AMD GPU or SPIRV, treat CUDA kernels as OpenCL
118+
// kernels. They should reset the calling convention to OpenCLKernel,
119+
// which will be further resolved by getOpenCLKernelCallingConv().
120+
virtual void setCUDAKernelCallingConvention(const FunctionType *&ft) const {}
121+
116122
virtual ~TargetCIRGenInfo() {}
117123
};
118124

0 commit comments

Comments
 (0)