From 5fdef60fe5a3c42f425cbbda9f354851a87e3072 Mon Sep 17 00:00:00 2001 From: seven-mile Date: Thu, 1 Aug 2024 22:07:18 +0800 Subject: [PATCH] [CIR][CodeGen][NFC] Target-independent ABI handling for SpirKernel call conv --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 15 ++++++++++----- clang/lib/CIR/CodeGen/TargetInfo.cpp | 10 ++++++++++ clang/lib/CIR/CodeGen/TargetInfo.h | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index e2ce60e25f07..aad52c9c0290 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -774,11 +774,16 @@ const CIRGenFunctionInfo &CIRGenTypes::arrangeCIRFunctionInfo( (void)inserted; assert(inserted && "Recursively being processed?"); - // Compute ABI inforamtion. - assert(info.getCC() != clang::CallingConv::CC_SpirFunction && "NYI"); - assert(info.getCC() != CC_Swift && info.getCC() != CC_SwiftAsync && - "Swift NYI"); - getABIInfo().computeInfo(*FI); + // Compute ABI information. + if (CC == mlir::cir::CallingConv::SpirKernel) { + // Force target independent argument handling for the host visible + // kernel functions. + computeSPIRKernelABIInfo(CGM, *FI); + } else if (info.getCC() == CC_Swift || info.getCC() == CC_SwiftAsync) { + llvm_unreachable("Swift NYI"); + } else { + getABIInfo().computeInfo(*FI); + } // Loop over all of the computed argument and return value info. If any of // them are direct or extend without a specified coerce type, specify the diff --git a/clang/lib/CIR/CodeGen/TargetInfo.cpp b/clang/lib/CIR/CodeGen/TargetInfo.cpp index a3db79645320..02850dad8bf8 100644 --- a/clang/lib/CIR/CodeGen/TargetInfo.cpp +++ b/clang/lib/CIR/CodeGen/TargetInfo.cpp @@ -264,6 +264,16 @@ class SPIRVABIInfo : public CommonSPIRABIInfo { } }; } // namespace + +namespace cir { +void computeSPIRKernelABIInfo(CIRGenModule &CGM, CIRGenFunctionInfo &FI) { + if (CGM.getTarget().getTriple().isSPIRV()) + SPIRVABIInfo(CGM.getTypes()).computeInfo(FI); + else + CommonSPIRABIInfo(CGM.getTypes()).computeInfo(FI); +} +} // namespace cir + namespace { class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo { diff --git a/clang/lib/CIR/CodeGen/TargetInfo.h b/clang/lib/CIR/CodeGen/TargetInfo.h index f56c68d59732..d2f4f3cdbf88 100644 --- a/clang/lib/CIR/CodeGen/TargetInfo.h +++ b/clang/lib/CIR/CodeGen/TargetInfo.h @@ -99,6 +99,8 @@ class TargetCIRGenInfo { virtual ~TargetCIRGenInfo() {} }; +void computeSPIRKernelABIInfo(CIRGenModule &CGM, CIRGenFunctionInfo &FI); + } // namespace cir #endif