clang 23.0.0git
NVPTX.cpp
Go to the documentation of this file.
1//===---- NVPTX.cpp - NVPTX-specific CIR CodeGen --------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This provides NVPTX-specific CIR CodeGen logic.
10//
11//===----------------------------------------------------------------------===//
12
13#include "../ABIInfo.h"
14#include "../CIRGenModule.h"
15#include "../TargetInfo.h"
16
18
19using namespace clang;
20using namespace clang::CIRGen;
21
22namespace {
23
24class NVPTXABIInfo : public ABIInfo {
25public:
26 NVPTXABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
27};
28
29class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo {
30public:
31 NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
32 : TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}
33
34 void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global,
35 CIRGenModule &cgm) const override {
36 auto globalValue = mlir::dyn_cast<cir::CIRGlobalValueInterface>(global);
37 if (globalValue && globalValue.isDeclaration())
38 return;
39
40 const auto *vd = dyn_cast_or_null<VarDecl>(decl);
41 if (vd) {
42 if (cgm.getLangOpts().CUDA) {
43 if (vd->getType()->isCUDADeviceBuiltinSurfaceType() ||
44 vd->getType()->isCUDADeviceBuiltinTextureType())
46 return;
47 }
48 }
49
50 const auto *fd = dyn_cast_or_null<FunctionDecl>(decl);
51 if (!fd)
52 return;
53
54 auto func = mlir::cast<cir::FuncOp>(global);
55
56 // Perform special handling in OpenCL/CUDA mode.
57 if (cgm.getLangOpts().OpenCL || cgm.getLangOpts().CUDA) {
58 // Use function attributes to check for kernel functions. By default, all
59 // functions are device functions.
60 if (fd->hasAttr<DeviceKernelAttr>() || fd->hasAttr<CUDAGlobalAttr>()) {
61 // OpenCL/CUDA kernel functions get kernel metadata. Kernel functions
62 // are also not subject to inlining.
63 func.setInlineKind(cir::InlineKind::NoInline);
64 if (fd->hasAttr<CUDAGlobalAttr>()) {
65 func.setCallingConv(cir::CallingConv::PTXKernel);
67 }
68 if (fd->hasAttr<CUDALaunchBoundsAttr>())
70 }
71 }
72 }
73
74 mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const override {
75 // On the device side, surface reference is represented as an object handle
76 // in 64-bit integer.
77 return cir::IntType::get(&getABIInfo().cgt.getMLIRContext(), 64,
78 /*isSigned=*/true);
79 }
80};
81
82} // namespace
83
84std::unique_ptr<TargetCIRGenInfo>
86 return std::make_unique<NVPTXTargetCIRGenInfo>(cgt);
87}
const clang::LangOptions & getLangOpts() const
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition CIRGenTypes.h:50
std::unique_ptr< TargetCIRGenInfo > createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
Definition NVPTX.cpp:85
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
static bool emitNVVMMetadata()
static bool handleCUDALaunchBoundsAttr()
static bool opFuncParameterAttributes()