Skip to content

Commit e56e6b9

Browse files
seven-milelanza
authored andcommitted
[CIR][CodeGen][NFCI] Target-independent ABI handling for SpirKernel call conv (#778)
This PR follows OG CodeGen to use SPIR ABI info whatever the target is when analysing the function info of SPIR-V kernels (identified by its calling convention). For example, when compiling OpenCL kernels to x86-64 target, the kernel should still use SPIR-V's ABIInfo. As we haven't implemented SPIR-V ABI handling for complex constructs, there should be no functional changes. There is a test for this logic in OG CodeGen: `clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl`. It mainly involves structs, which is beyond the progress of CIR ABI stuff.
1 parent 4ebe6f1 commit e56e6b9

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,16 @@ const CIRGenFunctionInfo &CIRGenTypes::arrangeCIRFunctionInfo(
783783
(void)inserted;
784784
assert(inserted && "Recursively being processed?");
785785

786-
// Compute ABI inforamtion.
787-
assert(info.getCC() != clang::CallingConv::CC_SpirFunction && "NYI");
788-
assert(info.getCC() != CC_Swift && info.getCC() != CC_SwiftAsync &&
789-
"Swift NYI");
790-
getABIInfo().computeInfo(*FI);
786+
// Compute ABI information.
787+
if (CC == mlir::cir::CallingConv::SpirKernel) {
788+
// Force target independent argument handling for the host visible
789+
// kernel functions.
790+
computeSPIRKernelABIInfo(CGM, *FI);
791+
} else if (info.getCC() == CC_Swift || info.getCC() == CC_SwiftAsync) {
792+
llvm_unreachable("Swift NYI");
793+
} else {
794+
getABIInfo().computeInfo(*FI);
795+
}
791796

792797
// Loop over all of the computed argument and return value info. If any of
793798
// them are direct or extend without a specified coerce type, specify the

clang/lib/CIR/CodeGen/TargetInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ class SPIRVABIInfo : public CommonSPIRABIInfo {
264264
}
265265
};
266266
} // namespace
267+
268+
namespace cir {
269+
void computeSPIRKernelABIInfo(CIRGenModule &CGM, CIRGenFunctionInfo &FI) {
270+
if (CGM.getTarget().getTriple().isSPIRV())
271+
SPIRVABIInfo(CGM.getTypes()).computeInfo(FI);
272+
else
273+
CommonSPIRABIInfo(CGM.getTypes()).computeInfo(FI);
274+
}
275+
} // namespace cir
276+
267277
namespace {
268278

269279
class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo {

clang/lib/CIR/CodeGen/TargetInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class TargetCIRGenInfo {
9999
virtual ~TargetCIRGenInfo() {}
100100
};
101101

102+
void computeSPIRKernelABIInfo(CIRGenModule &CGM, CIRGenFunctionInfo &FI);
103+
102104
} // namespace cir
103105

104106
#endif

0 commit comments

Comments
 (0)