MLIR  20.0.0git
SPIRVEnums.cpp
Go to the documentation of this file.
1 //===- SPIRVEnums.cpp - MLIR SPIR-V Enums ---------------------------------===//
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 file defines the C/C++ enums from SPIR-V spec.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/StringExtras.h"
17 
18 #include <iterator>
19 
20 using namespace mlir;
21 
22 // Pull in all enum utility function definitions
23 #include "mlir/Dialect/SPIRV/IR/SPIRVEnums.cpp.inc"
24 
25 // Pull in all enum type availability query function definitions
26 #include "mlir/Dialect/SPIRV/IR/SPIRVEnumAvailability.cpp.inc"
27 
28 //===----------------------------------------------------------------------===//
29 // Availability relationship
30 //===----------------------------------------------------------------------===//
31 
33  // Note: the following lists are from "Appendix A: Changes" of the spec.
34 
35 #define V_1_3_IMPLIED_EXTS \
36  Extension::SPV_KHR_shader_draw_parameters, Extension::SPV_KHR_16bit_storage, \
37  Extension::SPV_KHR_device_group, Extension::SPV_KHR_multiview, \
38  Extension::SPV_KHR_storage_buffer_storage_class, \
39  Extension::SPV_KHR_variable_pointers
40 
41 #define V_1_4_IMPLIED_EXTS \
42  Extension::SPV_KHR_no_integer_wrap_decoration, \
43  Extension::SPV_GOOGLE_decorate_string, \
44  Extension::SPV_GOOGLE_hlsl_functionality1, \
45  Extension::SPV_KHR_float_controls
46 
47 #define V_1_5_IMPLIED_EXTS \
48  Extension::SPV_KHR_8bit_storage, Extension::SPV_EXT_descriptor_indexing, \
49  Extension::SPV_EXT_shader_viewport_index_layer, \
50  Extension::SPV_EXT_physical_storage_buffer, \
51  Extension::SPV_KHR_physical_storage_buffer, \
52  Extension::SPV_KHR_vulkan_memory_model
53 
54 #define V_1_6_IMPLIED_EXTS \
55  Extension::SPV_KHR_non_semantic_info, \
56  Extension::SPV_KHR_integer_dot_product, \
57  Extension::SPV_KHR_terminate_invocation, \
58  Extension::SPV_EXT_demote_to_helper_invocation
59 
60  switch (version) {
61  default:
62  return {};
63  case Version::V_1_3: {
64  // The following manual ArrayRef constructor call is to satisfy GCC 5.
65  static const Extension exts[] = {V_1_3_IMPLIED_EXTS};
66  return exts;
67  }
68  case Version::V_1_4: {
69  static const Extension exts[] = {V_1_3_IMPLIED_EXTS, V_1_4_IMPLIED_EXTS};
70  return exts;
71  }
72  case Version::V_1_5: {
73  static const Extension exts[] = {V_1_3_IMPLIED_EXTS, V_1_4_IMPLIED_EXTS,
75  return exts;
76  }
77  case Version::V_1_6: {
78  static const Extension exts[] = {V_1_3_IMPLIED_EXTS, V_1_4_IMPLIED_EXTS,
80  return exts;
81  }
82  }
83 
84 #undef V_1_6_IMPLIED_EXTS
85 #undef V_1_5_IMPLIED_EXTS
86 #undef V_1_4_IMPLIED_EXTS
87 #undef V_1_3_IMPLIED_EXTS
88 }
89 
90 // Pull in utility function definition for implied capabilities
91 #include "mlir/Dialect/SPIRV/IR/SPIRVCapabilityImplication.inc"
92 
94 spirv::getRecursiveImpliedCapabilities(spirv::Capability cap) {
97  directCaps.begin(), directCaps.end());
98 
99  // TODO: This is insufficient; find a better way to handle this
100  // (e.g., using static lists) if this turns out to be a bottleneck.
101  for (unsigned i = 0; i < allCaps.size(); ++i)
102  for (Capability c : getDirectImpliedCapabilities(allCaps[i]))
103  allCaps.insert(c);
104 
105  return allCaps.takeVector();
106 }
#define V_1_6_IMPLIED_EXTS
#define V_1_3_IMPLIED_EXTS
#define V_1_4_IMPLIED_EXTS
#define V_1_5_IMPLIED_EXTS
SmallVector< Capability, 0 > getRecursiveImpliedCapabilities(Capability cap)
Returns the recursively implied capabilities for the given capability.
ArrayRef< Extension > getImpliedExtensions(Version version)
Returns the implied extensions for the given version.
ArrayRef< Capability > getDirectImpliedCapabilities(Capability cap)
Returns the directly implied capabilities for the given capability.
Include the generated interface declarations.