clang 24.0.0git
SPIRV.cpp
Go to the documentation of this file.
1//===---- SPIRV.cpp - SPIR-V-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 SPIR/SPIRV-specific CIR CodeGen logic for function attributes.
10//
11//===----------------------------------------------------------------------===//
12
13#include "../CIRGenModule.h"
14#include "../TargetInfo.h"
15
16#include "clang/AST/Attr.h"
17#include "clang/AST/Decl.h"
19
20using namespace clang;
21using namespace clang::CIRGen;
22
23namespace {
24
25class CommonSPIRABIInfo : public ABIInfo {
26public:
27 CommonSPIRABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
28};
29
30class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo {
31public:
32 CommonSPIRTargetCIRGenInfo(CIRGenTypes &cgt)
33 : TargetCIRGenInfo(std::make_unique<CommonSPIRABIInfo>(cgt)) {}
34
35 mlir::ptr::MemorySpaceAttrInterface
36 getCIRAllocaAddressSpace() const override {
37 return cir::LangAddressSpaceAttr::get(
38 &getABIInfo().cgt.getMLIRContext(),
39 cir::LangAddressSpace::OffloadPrivate);
40 }
41
42 cir::CallingConv getDeviceKernelCallingConv() const override {
43 return cir::CallingConv::SpirKernel;
44 }
45
46 void setCUDAKernelCallingConvention(const FunctionType *&ft) const override {
47 // Convert HIP kernels to SPIR-V kernels.
48 if (getABIInfo().cgt.getASTContext().getLangOpts().HIP)
49 ft = getABIInfo().cgt.getASTContext().adjustFunctionType(
51 }
52};
53
54} // namespace
55
56std::unique_ptr<TargetCIRGenInfo>
58 return std::make_unique<CommonSPIRTargetCIRGenInfo>(cgt);
59}
static void setCUDAKernelCallingConvention(CanQualType &funcTy, CIRGenModule &cgm, const FunctionDecl *fd)
Set calling convention for CUDA/HIP kernel.
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition CIRGenTypes.h:51
ExtInfo withCallingConv(CallingConv cc) const
Definition TypeBase.h:4817
ExtInfo getExtInfo() const
Definition TypeBase.h:4950
std::unique_ptr< TargetCIRGenInfo > createCommonSPIRTargetCIRGenInfo(CIRGenTypes &cgt)
Definition SPIRV.cpp:57
Top level wrappers for InstallAPI frontend operations.
@ CC_DeviceKernel
Definition Specifiers.h:292