18#include "llvm/ADT/StringExtras.h"
19#include "llvm/Support/NVVMAttributes.h"
28static void handleCUDALaunchBoundsAttr(
const CUDALaunchBoundsAttr *
attr,
31 auto setNVVMAttr = [&](llvm::StringRef
name,
const llvm::APSInt &value) {
32 func->setAttr((
"cir." + name).str(),
33 builder.getStringAttr(llvm::utostr(value.getExtValue())));
36 llvm::APSInt maxThreads(32);
40 setNVVMAttr(llvm::NVVMAttr::MaxNTID, maxThreads);
45 if (
attr->getMinBlocks()) {
46 llvm::APSInt minBlocks(32);
50 setNVVMAttr(llvm::NVVMAttr::MinCTASm, minBlocks);
53 if (
attr->getMaxBlocks()) {
54 llvm::APSInt maxBlocks(32);
58 setNVVMAttr(llvm::NVVMAttr::MaxClusterRank, maxBlocks);
62class NVPTXABIInfo :
public ABIInfo {
64 NVPTXABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
69 NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
70 : TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}
72 void setTargetAttributes(
const clang::Decl *
decl, mlir::Operation *global,
73 CIRGenModule &cgm)
const override {
74 auto globalValue = mlir::dyn_cast<cir::CIRGlobalValueInterface>(global);
75 if (globalValue && globalValue.isDeclaration())
78 const auto *vd = dyn_cast_or_null<VarDecl>(
decl);
81 if (vd->getType()->isCUDADeviceBuiltinSurfaceType() ||
82 vd->getType()->isCUDADeviceBuiltinTextureType())
88 const auto *fd = dyn_cast_or_null<FunctionDecl>(
decl);
92 auto func = mlir::cast<cir::FuncOp>(global);
98 if (fd->hasAttr<DeviceKernelAttr>() || fd->hasAttr<CUDAGlobalAttr>()) {
101 func.setInlineKind(cir::InlineKind::NoInline);
102 if (fd->hasAttr<CUDAGlobalAttr>()) {
103 func.setCallingConv(cir::CallingConv::PTXKernel);
106 if (
const auto *attr = fd->getAttr<CUDALaunchBoundsAttr>())
107 handleCUDALaunchBoundsAttr(attr, func, cgm, cgm.
getBuilder());
112 mlir::Type getCUDADeviceBuiltinSurfaceDeviceType()
const override {
115 return cir::IntType::get(&getABIInfo().cgt.getMLIRContext(), 64,
122std::unique_ptr<TargetCIRGenInfo>
124 return std::make_unique<NVPTXTargetCIRGenInfo>(cgt);
This class organizes the cross-function state that is used while generating CIR code.
clang::ASTContext & getASTContext() const
CIRGenBuilderTy & getBuilder()
const clang::LangOptions & getLangOpts() const
This class organizes the cross-module state that is used while lowering AST types to CIR types.
std::unique_ptr< TargetCIRGenInfo > createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Top level wrappers for InstallAPI frontend operations.
static bool emitNVVMMetadata()
static bool opFuncParameterAttributes()