26class CommonSPIRABIInfo :
public ABIInfo {
28 CommonSPIRABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
33 CommonSPIRTargetCIRGenInfo(CIRGenTypes &cgt)
34 : TargetCIRGenInfo(std::make_unique<CommonSPIRABIInfo>(cgt)) {}
36 mlir::ptr::MemorySpaceAttrInterface
37 getCIRAllocaAddressSpace()
const override {
38 return cir::LangAddressSpaceAttr::get(
39 &getABIInfo().cgt.getMLIRContext(),
40 cir::LangAddressSpace::OffloadPrivate);
43 mlir::ptr::MemorySpaceAttrInterface
44 getGlobalCIRAddressSpace(
LangAS as)
const override {
47 if (as == LangAS::cuda_device || as == LangAS::cuda_constant ||
48 as == LangAS::cuda_shared)
49 return cir::TargetAddressSpaceAttr::get(
50 &getABIInfo().cgt.getMLIRContext(),
51 getABIInfo().cgt.getASTContext().getTargetAddressSpace(as));
55 void setTargetAttributes(
const clang::Decl *
decl, mlir::Operation *global,
56 CIRGenModule &cgm)
const override {
57 auto func = mlir::dyn_cast<cir::FuncOp>(global);
58 if (!func || func.isDeclaration())
61 const auto *fd = dyn_cast_or_null<FunctionDecl>(
decl);
66 cgm.
getTriple().getVendor() != llvm::Triple::AMD)
69 if (!fd->hasAttr<CUDAGlobalAttr>())
72 unsigned n = cgm.
getLangOpts().GPUMaxThreadsPerBlock;
73 if (
const auto *flatWGS = fd->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
77 }
else if (
const auto *lb = fd->getAttr<CUDALaunchBoundsAttr>()) {
78 if (uint64_t maxThreads = lb->getMaxThreads()
86 cir::CIRDialect::getMaxWorkGroupSizeAttrName(),
87 cir::MaxWorkGroupSizeAttr::get(func.getContext(), n, 1, 1));
90 cir::CallingConv getDeviceKernelCallingConv()
const override {
91 return cir::CallingConv::SpirKernel;
94 bool supportsLibCall()
const override {
95 const llvm::Triple &triple = getABIInfo().cgt.getCGModule().getTriple();
96 return !(triple.isSPIRV() && triple.getVendor() == llvm::Triple::AMD);
101 if (getABIInfo().cgt.getASTContext().getLangOpts().HIP)
102 ft = getABIInfo().cgt.getASTContext().adjustFunctionType(
106 mlir::Value getNullPointer(CIRGenModule &cgm, cir::PointerType ptrTy,
107 QualType qt, mlir::Location loc)
const override;
115CommonSPIRTargetCIRGenInfo::getNullPointer(
CIRGenModule &cgm,
116 cir::PointerType ptrTy,
QualType qt,
117 mlir::Location loc)
const {
122 cir::PointerType genericPtrTy =
123 builder.
getPointerTo(ptrTy.getPointee(), LangAS::opencl_generic);
128std::unique_ptr<TargetCIRGenInfo>
130 return std::make_unique<CommonSPIRTargetCIRGenInfo>(cgt);
static void setCUDAKernelCallingConvention(CanQualType &funcTy, CIRGenModule &cgm, const FunctionDecl *fd)
Set calling convention for CUDA/HIP kernel.
cir::PointerType getPointerTo(mlir::Type ty)
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
This class organizes the cross-function state that is used while generating CIR code.
clang::ASTContext & getASTContext() const
CIRGenBuilderTy & getBuilder()
const llvm::Triple & getTriple() const
const clang::LangOptions & getLangOpts() const
This class organizes the cross-module state that is used while lowering AST types to CIR types.
virtual mlir::ptr::MemorySpaceAttrInterface getGlobalCIRAddressSpace(clang::LangAS as) const
Get the CIR address space attribute for a global in AST address space as.
ExtInfo withCallingConv(CallingConv cc) const
ExtInfo getExtInfo() const
A (possibly-)qualified type.
std::unique_ptr< TargetCIRGenInfo > createCommonSPIRTargetCIRGenInfo(CIRGenTypes &cgt)
bool spirNullPointerNeedsGenericCast(QualType QT, const llvm::Triple &Triple)
Return true if a SPIR(-V) null pointer of type QT must be materialized as an addrspacecast from a gen...
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Top level wrappers for InstallAPI frontend operations.
LangAS
Defines the address space values used by the address space qualifier of QualType.