10#include "TargetInfo.h"
29class SPIRVABIInfo :
public CommonSPIRABIInfo {
31 SPIRVABIInfo(
CodeGenTypes &CGT) : CommonSPIRABIInfo(CGT) {}
43 CommonSPIRTargetCodeGenInfo(std::unique_ptr<ABIInfo>
ABIInfo)
48 getABIInfo().getDataLayout().getAllocaAddrSpace());
54class SPIRVTargetCodeGenInfo :
public CommonSPIRTargetCodeGenInfo {
57 : CommonSPIRTargetCodeGenInfo(
std::make_unique<SPIRVABIInfo>(CGT)) {}
62void CommonSPIRABIInfo::setCCs() {
63 assert(getRuntimeCC() == llvm::CallingConv::C);
64 RuntimeCC = llvm::CallingConv::SPIR_FUNC;
68 if (getContext().getLangOpts().CUDAIsDevice) {
72 llvm::Type *LTy = CGT.ConvertType(Ty);
73 auto DefaultAS = getContext().getTargetAddressSpace(LangAS::Default);
74 auto GlobalAS = getContext().getTargetAddressSpace(LangAS::cuda_device);
75 auto *PtrTy = llvm::dyn_cast<llvm::PointerType>(LTy);
76 if (PtrTy && PtrTy->getAddressSpace() == DefaultAS) {
77 LTy = llvm::PointerType::get(PtrTy->getContext(), GlobalAS);
88 return getNaturalAlignIndirect(Ty,
true);
102 if (CC == llvm::CallingConv::SPIR_KERNEL) {
103 I.info = classifyKernelArgumentType(I.type);
114 SPIRVABIInfo(CGM.
getTypes()).computeInfo(FI);
116 CommonSPIRABIInfo(CGM.
getTypes()).computeInfo(FI);
121unsigned CommonSPIRTargetCodeGenInfo::getOpenCLKernelCallingConv()
const {
122 return llvm::CallingConv::SPIR_KERNEL;
125void SPIRVTargetCodeGenInfo::setCUDAKernelCallingConvention(
128 if (getABIInfo().getContext().getLangOpts().
HIP) {
129 FT = getABIInfo().getContext().adjustFunctionType(
137 StringRef OpenCLName,
138 unsigned AccessQualifier) {
149 if (OpenCLName.starts_with(
"image2d"))
151 else if (OpenCLName.starts_with(
"image3d"))
153 else if (OpenCLName ==
"image1d_buffer")
156 assert(OpenCLName.starts_with(
"image1d") &&
"Unknown image type");
161 if (OpenCLName.contains(
"_depth"))
163 if (OpenCLName.contains(
"_array"))
165 if (OpenCLName.contains(
"_msaa"))
169 IntParams.push_back(AccessQualifier);
171 return llvm::TargetExtType::get(Ctx, BaseType, {llvm::Type::getVoidTy(Ctx)},
175llvm::Type *CommonSPIRTargetCodeGenInfo::getOpenCLType(
CodeGenModule &CGM,
176 const Type *Ty)
const {
178 if (
auto *PipeTy = dyn_cast<PipeType>(Ty))
179 return llvm::TargetExtType::get(Ctx,
"spirv.Pipe", {},
180 {!PipeTy->isReadOnly()});
181 if (
auto *BuiltinTy = dyn_cast<BuiltinType>(Ty)) {
182 enum AccessQualifier :
unsigned { AQ_ro = 0, AQ_wo = 1, AQ_rw = 2 };
183 switch (BuiltinTy->getKind()) {
184#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
185 case BuiltinType::Id: \
186 return getSPIRVImageType(Ctx, "spirv.Image", #ImgType, AQ_##Suffix);
187#include "clang/Basic/OpenCLImageTypes.def"
188 case BuiltinType::OCLSampler:
189 return llvm::TargetExtType::get(Ctx,
"spirv.Sampler");
190 case BuiltinType::OCLEvent:
191 return llvm::TargetExtType::get(Ctx,
"spirv.Event");
192 case BuiltinType::OCLClkEvent:
193 return llvm::TargetExtType::get(Ctx,
"spirv.DeviceEvent");
194 case BuiltinType::OCLQueue:
195 return llvm::TargetExtType::get(Ctx,
"spirv.Queue");
196 case BuiltinType::OCLReserveID:
197 return llvm::TargetExtType::get(Ctx,
"spirv.ReserveId");
198#define INTEL_SUBGROUP_AVC_TYPE(Name, Id) \
199 case BuiltinType::OCLIntelSubgroupAVC##Id: \
200 return llvm::TargetExtType::get(Ctx, "spirv.Avc" #Id "INTEL");
201#include "clang/Basic/OpenCLExtensionTypes.def"
210std::unique_ptr<TargetCodeGenInfo>
212 return std::make_unique<CommonSPIRTargetCodeGenInfo>(CGM.
getTypes());
215std::unique_ptr<TargetCodeGenInfo>
217 return std::make_unique<SPIRVTargetCodeGenInfo>(CGM.
getTypes());
static void setCUDAKernelCallingConvention(CanQualType &FTy, CodeGenModule &CGM, const FunctionDecl *FD)
Set calling convention for CUDA/HIP kernel.
static llvm::Type * getSPIRVImageType(llvm::LLVMContext &Ctx, StringRef BaseType, StringRef OpenCLName, unsigned AccessQualifier)
Construct a SPIR-V target extension type for the given OpenCL image type.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
CGFunctionInfo - Class to encapsulate the information about a function definition.
ABIArgInfo & getReturnInfo()
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
This class organizes the cross-function state that is used while generating LLVM code.
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
llvm::LLVMContext & getLLVMContext()
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
DefaultABIInfo - The default implementation for ABI specific details.
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
virtual llvm::Type * getOpenCLType(CodeGenModule &CGM, const Type *T) const
Return an LLVM type that corresponds to an OpenCL type.
const T & getABIInfo() const
virtual unsigned getOpenCLKernelCallingConv() const
Get LLVM calling convention for OpenCL kernel.
virtual LangAS getASTAllocaAddressSpace() const
Get the AST address space for alloca.
ExtInfo withCallingConv(CallingConv cc) const
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
A (possibly-)qualified type.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
The base class of the type hierarchy.
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
bool isAggregateTypeForABI(QualType T)
std::unique_ptr< TargetCodeGenInfo > createSPIRVTargetCodeGenInfo(CodeGenModule &CGM)
std::unique_ptr< TargetCodeGenInfo > createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM)
The JSON file list parser is used to communicate input to InstallAPI.
LangAS
Defines the address space values used by the address space qualifier of QualType.
const FunctionProtoType * T
LangAS getLangASFromTargetAS(unsigned TargetAS)