aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Conversion/SPIRVCommon/AttrToLLVMConverter.cpp
blob: 7f83a474c3f93c6a4d392e2f4cf1bb38f916924f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//===- AttrToLLVMConverter.cpp - SPIR-V attributes conversion to LLVM -C++ ===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <mlir/Conversion/SPIRVCommon/AttrToLLVMConverter.h>

namespace mlir {
namespace {

//===----------------------------------------------------------------------===//
// Constants
//===----------------------------------------------------------------------===//

constexpr unsigned defaultAddressSpace = 0;

//===----------------------------------------------------------------------===//
// Utility functions
//===----------------------------------------------------------------------===//

static unsigned
storageClassToOCLAddressSpace(spirv::StorageClass storageClass) {
  // Based on
  // https://registry.khronos.org/SPIR-V/specs/unified1/OpenCL.ExtendedInstructionSet.100.html#_binary_form
  // and clang/lib/Basic/Targets/SPIR.h.
  switch (storageClass) {
  case spirv::StorageClass::Function:
    return 0;
  case spirv::StorageClass::Input:
  case spirv::StorageClass::CrossWorkgroup:
    return 1;
  case spirv::StorageClass::UniformConstant:
    return 2;
  case spirv::StorageClass::Workgroup:
    return 3;
  case spirv::StorageClass::Generic:
    return 4;
  case spirv::StorageClass::DeviceOnlyINTEL:
    return 5;
  case spirv::StorageClass::HostOnlyINTEL:
    return 6;
  default:
    return defaultAddressSpace;
  }
}
} // namespace

unsigned storageClassToAddressSpace(spirv::ClientAPI clientAPI,
                                    spirv::StorageClass storageClass) {
  switch (clientAPI) {
  case spirv::ClientAPI::OpenCL:
    return storageClassToOCLAddressSpace(storageClass);
  default:
    return defaultAddressSpace;
  }
}
} // namespace mlir