| 1 | //===- AttrToLLVMConverter.cpp - SPIR-V attributes conversion to LLVM -C++ ===// |
| 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 <mlir/Conversion/SPIRVCommon/AttrToLLVMConverter.h> |
| 10 | |
| 11 | namespace mlir { |
| 12 | namespace { |
| 13 | |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | // Constants |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | constexpr unsigned defaultAddressSpace = 0; |
| 19 | |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | // Utility functions |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
| 24 | static unsigned |
| 25 | storageClassToOCLAddressSpace(spirv::StorageClass storageClass) { |
| 26 | // Based on |
| 27 | // https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.ExtendedInstructionSet.100.html#_binary_form |
| 28 | // and clang/lib/Basic/Targets/SPIR.h. |
| 29 | switch (storageClass) { |
| 30 | case spirv::StorageClass::Function: |
| 31 | return 0; |
| 32 | case spirv::StorageClass::Input: |
| 33 | case spirv::StorageClass::CrossWorkgroup: |
| 34 | return 1; |
| 35 | case spirv::StorageClass::UniformConstant: |
| 36 | return 2; |
| 37 | case spirv::StorageClass::Workgroup: |
| 38 | return 3; |
| 39 | case spirv::StorageClass::Generic: |
| 40 | return 4; |
| 41 | case spirv::StorageClass::DeviceOnlyINTEL: |
| 42 | return 5; |
| 43 | case spirv::StorageClass::HostOnlyINTEL: |
| 44 | return 6; |
| 45 | default: |
| 46 | return defaultAddressSpace; |
| 47 | } |
| 48 | } |
| 49 | } // namespace |
| 50 | |
| 51 | unsigned storageClassToAddressSpace(spirv::ClientAPI clientAPI, |
| 52 | spirv::StorageClass storageClass) { |
| 53 | switch (clientAPI) { |
| 54 | case spirv::ClientAPI::OpenCL: |
| 55 | return storageClassToOCLAddressSpace(storageClass); |
| 56 | default: |
| 57 | return defaultAddressSpace; |
| 58 | } |
| 59 | } |
| 60 | } // namespace mlir |
| 61 | |