| 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 | |
| 9 | #include "../TargetLoweringInfo.h" |
| 10 | #include "clang/CIR/Dialect/IR/CIROpsEnums.h" |
| 11 | #include "clang/CIR/MissingFeatures.h" |
| 12 | |
| 13 | namespace cir { |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | // SPIR-V OpenCL storage classes, indexed by cir::LangAddressSpace. |
| 18 | constexpr 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 | |
| 29 | class CommonSPIRTargetLoweringInfo : public TargetLoweringInfo { |
| 30 | public: |
| 31 | unsigned getTargetAddrSpaceFromCIRAddrSpace( |
| 32 | cir::LangAddressSpace addrSpace) const override { |
| 33 | // TODO(cir): SYCL and CUDA/HIP device code map Default to Generic |
| 34 | // (SPIRDefIsGenMap). |
| 35 | assert(!cir::MissingFeatures::spirvDefaultIsGenericAddrSpace()); |
| 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 | |
| 43 | class SPIRVTargetLoweringInfo : public CommonSPIRTargetLoweringInfo { |
| 44 | public: |
| 45 | cir::SyncScopeKind |
| 46 | convertSyncScope(cir::SyncScopeKind syncScope) const override { |
| 47 | return syncScope; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | } // namespace |
| 52 | |
| 53 | std::unique_ptr<TargetLoweringInfo> createCommonSPIRTargetLoweringInfo() { |
| 54 | return std::make_unique<CommonSPIRTargetLoweringInfo>(); |
| 55 | } |
| 56 | |
| 57 | std::unique_ptr<TargetLoweringInfo> createSPIRVTargetLoweringInfo() { |
| 58 | return std::make_unique<SPIRVTargetLoweringInfo>(); |
| 59 | } |
| 60 | |
| 61 | } // namespace cir |
| 62 | |