19#define DEBUG_TYPE "spirv-commandline"
23static const std::map<std::string, SPIRV::Extension::Extension, std::less<>>
25 {
"SPV_EXT_shader_atomic_float_add",
26 SPIRV::Extension::Extension::SPV_EXT_shader_atomic_float_add},
27 {
"SPV_EXT_shader_atomic_float16_add",
28 SPIRV::Extension::Extension::SPV_EXT_shader_atomic_float16_add},
29 {
"SPV_EXT_shader_atomic_float_min_max",
30 SPIRV::Extension::Extension::SPV_EXT_shader_atomic_float_min_max},
31 {
"SPV_EXT_arithmetic_fence",
32 SPIRV::Extension::Extension::SPV_EXT_arithmetic_fence},
33 {
"SPV_EXT_demote_to_helper_invocation",
34 SPIRV::Extension::Extension::SPV_EXT_demote_to_helper_invocation},
35 {
"SPV_INTEL_arbitrary_precision_integers",
36 SPIRV::Extension::Extension::SPV_INTEL_arbitrary_precision_integers},
37 {
"SPV_INTEL_cache_controls",
38 SPIRV::Extension::Extension::SPV_INTEL_cache_controls},
39 {
"SPV_INTEL_float_controls2",
40 SPIRV::Extension::Extension::SPV_INTEL_float_controls2},
41 {
"SPV_INTEL_global_variable_fpga_decorations",
42 SPIRV::Extension::Extension::
43 SPV_INTEL_global_variable_fpga_decorations},
44 {
"SPV_INTEL_global_variable_host_access",
45 SPIRV::Extension::Extension::SPV_INTEL_global_variable_host_access},
46 {
"SPV_INTEL_optnone", SPIRV::Extension::Extension::SPV_INTEL_optnone},
47 {
"SPV_EXT_optnone", SPIRV::Extension::Extension::SPV_EXT_optnone},
48 {
"SPV_INTEL_usm_storage_classes",
49 SPIRV::Extension::Extension::SPV_INTEL_usm_storage_classes},
50 {
"SPV_INTEL_split_barrier",
51 SPIRV::Extension::Extension::SPV_INTEL_split_barrier},
52 {
"SPV_INTEL_subgroups",
53 SPIRV::Extension::Extension::SPV_INTEL_subgroups},
54 {
"SPV_INTEL_media_block_io",
55 SPIRV::Extension::Extension::SPV_INTEL_media_block_io},
56 {
"SPV_INTEL_joint_matrix",
57 SPIRV::Extension::Extension::SPV_INTEL_joint_matrix},
58 {
"SPV_KHR_uniform_group_instructions",
59 SPIRV::Extension::Extension::SPV_KHR_uniform_group_instructions},
60 {
"SPV_KHR_no_integer_wrap_decoration",
61 SPIRV::Extension::Extension::SPV_KHR_no_integer_wrap_decoration},
62 {
"SPV_KHR_float_controls",
63 SPIRV::Extension::Extension::SPV_KHR_float_controls},
64 {
"SPV_KHR_expect_assume",
65 SPIRV::Extension::Extension::SPV_KHR_expect_assume},
66 {
"SPV_KHR_bit_instructions",
67 SPIRV::Extension::Extension::SPV_KHR_bit_instructions},
68 {
"SPV_KHR_integer_dot_product",
69 SPIRV::Extension::Extension::SPV_KHR_integer_dot_product},
70 {
"SPV_KHR_linkonce_odr",
71 SPIRV::Extension::Extension::SPV_KHR_linkonce_odr},
72 {
"SPV_INTEL_inline_assembly",
73 SPIRV::Extension::Extension::SPV_INTEL_inline_assembly},
74 {
"SPV_INTEL_bfloat16_conversion",
75 SPIRV::Extension::Extension::SPV_INTEL_bfloat16_conversion},
76 {
"SPV_KHR_subgroup_rotate",
77 SPIRV::Extension::Extension::SPV_KHR_subgroup_rotate},
78 {
"SPV_INTEL_variable_length_array",
79 SPIRV::Extension::Extension::SPV_INTEL_variable_length_array},
80 {
"SPV_INTEL_function_pointers",
81 SPIRV::Extension::Extension::SPV_INTEL_function_pointers},
82 {
"SPV_KHR_shader_clock",
83 SPIRV::Extension::Extension::SPV_KHR_shader_clock},
84 {
"SPV_KHR_cooperative_matrix",
85 SPIRV::Extension::Extension::SPV_KHR_cooperative_matrix},
86 {
"SPV_KHR_non_semantic_info",
87 SPIRV::Extension::Extension::SPV_KHR_non_semantic_info}};
91 std::set<SPIRV::Extension::Extension> &Vals) {
93 ArgValue.
split(Tokens,
",", -1,
false);
94 std::sort(Tokens.
begin(), Tokens.
end());
96 std::set<SPIRV::Extension::Extension> EnabledExtensions;
98 for (
const auto &Token : Tokens) {
101 EnabledExtensions.insert(ExtensionEnum);
106 if (Token.empty() || (!Token.starts_with(
"+") && !Token.starts_with(
"-")))
107 return O.error(
"Invalid extension list format: " + Token.str());
113 return O.error(
"Unknown SPIR-V extension: " + Token.str());
115 if (Token.starts_with(
"+")) {
116 EnabledExtensions.insert(NameValuePair->second);
117 }
else if (EnabledExtensions.count(NameValuePair->second)) {
118 if (std::find(Tokens.
begin(), Tokens.
end(),
"+" + ExtensionName.
str()) !=
121 "Extension cannot be allowed and disallowed at the same time: " +
122 ExtensionName.
str());
124 EnabledExtensions.erase(NameValuePair->second);
128 Vals = std::move(EnabledExtensions);
133 const std::vector<std::string> &ExtNames,
134 std::set<SPIRV::Extension::Extension> &AllowedExtensions) {
135 for (
const auto &Ext : ExtNames) {
139 AllowedExtensions.insert(It->second);
static const std::map< std::string, SPIRV::Extension::Extension, std::less<> > SPIRVExtensionMap
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
This is an optimization pass for GlobalISel generic memory operations.
static llvm::StringRef checkExtensions(const std::vector< std::string > &ExtNames, std::set< SPIRV::Extension::Extension > &AllowedExtensions)
Validates and converts extension names into internal enum values.
bool parse(cl::Option &O, StringRef ArgName, StringRef ArgValue, std::set< SPIRV::Extension::Extension > &Vals)
Parses SPIR-V extension name from CLI arguments.