clang 23.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-V-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 SPIRVABIInfo : public ABIInfo {
26public:
27 SPIRVABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
28};
29
30class SPIRVTargetCIRGenInfo : public TargetCIRGenInfo {
31public:
32 SPIRVTargetCIRGenInfo(CIRGenTypes &cgt)
33 : TargetCIRGenInfo(std::make_unique<SPIRVABIInfo>(cgt)) {}
34
35 void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global,
36 CIRGenModule &cgm) const override {
37 auto globalValue = mlir::cast<cir::CIRGlobalValueInterface>(global);
38 if (globalValue.isDeclaration())
39 return;
40
41 const auto *fd = dyn_cast_or_null<FunctionDecl>(decl);
42 if (!fd)
43 return;
44
45 if (cgm.getLangOpts().OpenCL &&
46 DeviceKernelAttr::isOpenCLSpelling(fd->getAttr<DeviceKernelAttr>())) {
47 auto func = mlir::cast<cir::FuncOp>(global);
48 func.setCallingConv(cir::CallingConv::SpirKernel);
49 }
50 }
51};
52
53} // namespace
54
55std::unique_ptr<TargetCIRGenInfo>
57 return std::make_unique<SPIRVTargetCIRGenInfo>(cgt);
58}
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 > createSPIRVTargetCIRGenInfo(CIRGenTypes &cgt)
Definition SPIRV.cpp:56
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.