clang 24.0.0git
SPIRV.cpp
Go to the documentation of this file.
1//===- SPIRV.cpp - Emit CIR for SPIR/SPIR-V -------------------------------===//
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
12
13namespace cir {
14
15namespace {
16
17// SPIR-V OpenCL storage classes, indexed by cir::LangAddressSpace.
18constexpr unsigned SPIRVAddrSpaceMap[] = {
19 0, // Function
20 0, // Function
21 3, // Workgroup
22 1, // CrossWorkgroup
23 2, // UniformConstant
24 4, // Generic
25 5, // GlobalDevice
26 6, // GlobalHost
27};
28
29class CommonSPIRTargetLoweringInfo : public TargetLoweringInfo {
30public:
31 unsigned getTargetAddrSpaceFromCIRAddrSpace(
32 cir::LangAddressSpace addrSpace) const override {
33 // TODO(cir): SYCL and CUDA/HIP device code map Default to Generic
34 // (SPIRDefIsGenMap).
36 auto idx = static_cast<unsigned>(addrSpace);
37 assert(idx < std::size(SPIRVAddrSpaceMap) &&
38 "Unknown CIR address space for SPIR-V target");
39 return SPIRVAddrSpaceMap[idx];
40 }
41};
42
43class SPIRVTargetLoweringInfo : public CommonSPIRTargetLoweringInfo {
44public:
45 cir::SyncScopeKind
46 convertSyncScope(cir::SyncScopeKind syncScope) const override {
47 return syncScope;
48 }
49};
50
51} // namespace
52
53std::unique_ptr<TargetLoweringInfo> createCommonSPIRTargetLoweringInfo() {
54 return std::make_unique<CommonSPIRTargetLoweringInfo>();
55}
56
57std::unique_ptr<TargetLoweringInfo> createSPIRVTargetLoweringInfo() {
58 return std::make_unique<SPIRVTargetLoweringInfo>();
59}
60
61} // namespace cir
std::unique_ptr< TargetLoweringInfo > createCommonSPIRTargetLoweringInfo()
Definition SPIRV.cpp:53
std::unique_ptr< TargetLoweringInfo > createSPIRVTargetLoweringInfo()
Definition SPIRV.cpp:57
static bool spirvDefaultIsGenericAddrSpace()