diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp index 0ed97f5b41c51..d6b6079810471 100644 --- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp +++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp @@ -38,8 +38,15 @@ struct CapabilityEntry { Capability::Capability ReqCapability; }; +struct EnvironmentEntry { + OperandCategory::OperandCategory Category; + uint32_t Value; + Environment::Environment AllowedEnvironment; +}; + using namespace OperandCategory; using namespace Extension; +using namespace Environment; using namespace Capability; using namespace InstructionSet; #define GET_SymbolicOperands_DECL @@ -48,6 +55,8 @@ using namespace InstructionSet; #define GET_ExtensionEntries_IMPL #define GET_CapabilityEntries_DECL #define GET_CapabilityEntries_IMPL +#define GET_EnvironmentEntries_DECL +#define GET_EnvironmentEntries_IMPL #define GET_ExtendedBuiltins_DECL #define GET_ExtendedBuiltins_IMPL #include "SPIRVGenTables.inc" @@ -133,6 +142,23 @@ getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category, return Capabilities; } +EnvironmentList getSymbolicOperandAllowedEnvironments( + SPIRV::OperandCategory::OperandCategory Category, uint32_t Value) { + EnvironmentList Environments; + const SPIRV::EnvironmentEntry *Environment = + SPIRV::lookupEnvironmentByCategoryAndValue(Category, Value); + auto TableEnd = ArrayRef(SPIRV::EnvironmentEntries).end(); + while (Environment && Environment->Category == Category && + Environment->Value == Value) { + Environments.push_back(static_cast( + Environment->AllowedEnvironment)); + if (++Environment == TableEnd) + break; + } + + return Environments; +} + CapabilityList getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension) { const SPIRV::ExtensionEntry *Entry = diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h index b8c467fef8e8e..c2c08f8831307 100644 --- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h +++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h @@ -37,6 +37,11 @@ namespace Capability { #include "SPIRVGenTables.inc" } // namespace Capability +namespace Environment { +#define GET_Environment_DECL +#include "SPIRVGenTables.inc" +} // namespace Environment + namespace SourceLanguage { #define GET_SourceLanguage_DECL #include "SPIRVGenTables.inc" @@ -241,6 +246,7 @@ enum InstFlags { using CapabilityList = SmallVector; using ExtensionList = SmallVector; +using EnvironmentList = SmallVector; std::string getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category, @@ -254,6 +260,8 @@ getSymbolicOperandMaxVersion(SPIRV::OperandCategory::OperandCategory Category, CapabilityList getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category, uint32_t Value); +EnvironmentList getSymbolicOperandAllowedEnvironments( + SPIRV::OperandCategory::OperandCategory Category, uint32_t Value); CapabilityList getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension); ExtensionList diff --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp index d9265f498973e..5a5860ac1c24f 100644 --- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp @@ -12,7 +12,8 @@ //===----------------------------------------------------------------------===// #include "SPIRVCommandLine.h" -#include "llvm/ADT/StringRef.h" +#include "MCTargetDesc/SPIRVBaseInfo.h" +#include "llvm/TargetParser/Triple.h" #include #include @@ -171,3 +172,23 @@ StringRef SPIRVExtensionsParser::checkExtensions( } return StringRef(); } + +std::set +SPIRVExtensionsParser::getValidExtensions(const Triple &TT) { + std::set R; + SPIRV::Environment::Environment CurrentEnvironment = + SPIRV::Environment::Environment::EnvOpenCL; + if (TT.getOS() == Triple::Vulkan) + CurrentEnvironment = SPIRV::Environment::Environment::EnvVulkan; + + for (const auto &[ExtensionName, ExtensionEnum] : SPIRVExtensionMap) { + EnvironmentList AllowedEnv = getSymbolicOperandAllowedEnvironments( + SPIRV::OperandCategory::OperandCategory::ExtensionOperand, + ExtensionEnum); + + if (std::count(AllowedEnv.begin(), AllowedEnv.end(), CurrentEnvironment)) + R.insert(ExtensionEnum); + } + + return R; +} diff --git a/llvm/lib/Target/SPIRV/SPIRVCommandLine.h b/llvm/lib/Target/SPIRV/SPIRVCommandLine.h index 3e3b22bde8603..02e847b322a77 100644 --- a/llvm/lib/Target/SPIRV/SPIRVCommandLine.h +++ b/llvm/lib/Target/SPIRV/SPIRVCommandLine.h @@ -21,6 +21,7 @@ namespace llvm { class StringRef; +class Triple; /// Command line parser for toggling SPIR-V extensions. struct SPIRVExtensionsParser @@ -42,6 +43,11 @@ struct SPIRVExtensionsParser static StringRef checkExtensions(const std::vector &ExtNames, std::set &AllowedExtensions); + + /// Returns the list of extensions that are valid for a particular + /// target environment (i.e., OpenCL or Vulkan). + static std::set + getValidExtensions(const Triple &TT); }; } // namespace llvm diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp index cdf3c6224d4c8..690493fb426bc 100644 --- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp @@ -166,7 +166,13 @@ void SPIRVSubtarget::initAvailableExtInstSets() { void SPIRVSubtarget::initAvailableExtensions( const std::set &AllowedExtIds) { AvailableExtensions.clear(); - AvailableExtensions.insert_range(AllowedExtIds); + const std::set &ValidExtensions = + SPIRVExtensionsParser::getValidExtensions(TargetTriple); + + for (const auto &Ext : AllowedExtIds) { + if (ValidExtensions.count(Ext)) + AvailableExtensions.insert(Ext); + } accountForAMDShaderTrinaryMinmax(); } diff --git a/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td b/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td index 614e83ae9b286..d2824ee2d2caf 100644 --- a/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td +++ b/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td @@ -109,23 +109,59 @@ def CapabilityEntries : GenericTable { let PrimaryKeyName = "lookupCapabilityByCategoryAndValue"; } +//===----------------------------------------------------------------------===// +// Lookup table for matching symbolic operands (category + 32-bit value) to +// SPIR-V environments. If an operand is allows in more than one environment, +// there will be multiple consecutive entries present in the table. +//===----------------------------------------------------------------------===// + +// Forward-declare classes used in ExtensionEntry +class Environment; + +class EnvironmentEntry value, + Environment allowedEnvironment> { + OperandCategory Category = category; + bits<32> Value = value; + Environment AllowedEnvironment = allowedEnvironment; +} + +def EnvironmentEntries : GenericTable { + let FilterClass = "EnvironmentEntry"; + let Fields = ["Category", "Value", "AllowedEnvironment"]; + string TypeOf_Category = "OperandCategory"; + string TypeOf_AllowedEnvironment = "Environment"; + let PrimaryKey = ["Category", "Value"]; + // Function for looking up a (the first) environment by category + value. Next + // environment should be consecutive. + let PrimaryKeyName = "lookupEnvironmentByCategoryAndValue"; +} + //===----------------------------------------------------------------------===// // Multiclass used to define a SymbolicOperand and at the same time declare // required extension and capabilities. //===----------------------------------------------------------------------===// -multiclass SymbolicOperandWithRequirements value, string mnemonic, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { - assert !ge(!size(mnemonic), 1), "No mnemonic/string representation provided for symbolic operand with value " # value; - def : SymbolicOperand; +multiclass SymbolicOperandWithRequirements< + OperandCategory category, bits<32> value, string mnemonic, + bits<32> minVersion, bits<32> maxVersion, list reqExtensions, + list reqCapabilities, list allowedEnvironments> { + assert !ge(!size(mnemonic), 1), "No mnemonic/string representation provided " + "for symbolic operand with value "#value; + def : SymbolicOperand; + + assert !le(!size(reqExtensions), 1), + "Too many required extensions for a symbolic/named operand: "#mnemonic; + if !eq(!size(reqExtensions), 1) then { + def : ExtensionEntry; + } - assert !le(!size(reqExtensions), 1), "Too many required extensions for a symbolic/named operand: " # mnemonic; - if !eq(!size(reqExtensions), 1) then { - def : ExtensionEntry; - } + foreach capability = reqCapabilities in { + def : CapabilityEntry; + } - foreach capability = reqCapabilities in { - def : CapabilityEntry; - } + foreach environment = allowedEnvironments in { + def : EnvironmentEntry; + } } //===----------------------------------------------------------------------===// @@ -175,6 +211,20 @@ def CooperativeMatrixOperandsOperand : OperandCategory; def SpecConstantOpOperandsOperand : OperandCategory; def MatrixMultiplyAccumulateOperandsOperand : OperandCategory; +//===----------------------------------------------------------------------===// +// Definition of the Environments +//===----------------------------------------------------------------------===// + +def Environment : GenericEnum, Operand { + let FilterClass = "Environment"; + let ValueField = "Value"; +} + +class Environment value> { bits<32> Value = value; } + +def EnvOpenCL : Environment<0>; +def EnvVulkan : Environment<1>; + //===----------------------------------------------------------------------===// // Multiclass used to define Extesions enum values and at the same time // SymbolicOperand entries. @@ -192,135 +242,146 @@ class Extension value> { bits<32> Value = value; } -multiclass ExtensionOperand value> { +multiclass ExtensionOperand value, + list allowedEnvironments> { def NAME : Extension; - defm : SymbolicOperandWithRequirements; -} - -defm SPV_AMD_shader_explicit_vertex_parameter : ExtensionOperand<1>; -defm SPV_AMD_shader_trinary_minmax_extension : ExtensionOperand<2>; -defm SPV_AMD_gcn_shader : ExtensionOperand<3>; -defm SPV_KHR_shader_ballot : ExtensionOperand<4>; -defm SPV_AMD_shader_ballot : ExtensionOperand<5>; -defm SPV_AMD_gpu_shader_half_float : ExtensionOperand<6>; -defm SPV_KHR_shader_draw_parameters : ExtensionOperand<7>; -defm SPV_KHR_subgroup_vote : ExtensionOperand<8>; -defm SPV_KHR_16bit_storage : ExtensionOperand<9>; -defm SPV_KHR_device_group : ExtensionOperand<10>; -defm SPV_KHR_multiview : ExtensionOperand<11>; -defm SPV_NVX_multiview_per_view_attributes : ExtensionOperand<12>; -defm SPV_NV_viewport_array2 : ExtensionOperand<13>; -defm SPV_NV_stereo_view_rendering : ExtensionOperand<14>; -defm SPV_NV_sample_mask_override_coverage : ExtensionOperand<15>; -defm SPV_NV_geometry_shader_passthrough : ExtensionOperand<16>; -defm SPV_AMD_texture_gather_bias_lod : ExtensionOperand<17>; -defm SPV_KHR_storage_buffer_storage_class : ExtensionOperand<18>; -defm SPV_KHR_variable_pointers : ExtensionOperand<19>; -defm SPV_AMD_gpu_shader_int16 : ExtensionOperand<20>; -defm SPV_KHR_post_depth_coverage : ExtensionOperand<21>; -defm SPV_KHR_shader_atomic_counter_ops : ExtensionOperand<22>; -defm SPV_EXT_shader_stencil_export : ExtensionOperand<23>; -defm SPV_EXT_shader_viewport_index_layer : ExtensionOperand<24>; -defm SPV_AMD_shader_image_load_store_lod : ExtensionOperand<25>; -defm SPV_AMD_shader_fragment_mask : ExtensionOperand<26>; -defm SPV_EXT_fragment_fully_covered : ExtensionOperand<27>; -defm SPV_AMD_gpu_shader_half_float_fetch : ExtensionOperand<28>; -defm SPV_GOOGLE_decorate_string : ExtensionOperand<29>; -defm SPV_GOOGLE_hlsl_functionality1 : ExtensionOperand<30>; -defm SPV_NV_shader_subgroup_partitioned : ExtensionOperand<31>; -defm SPV_EXT_descriptor_indexing : ExtensionOperand<32>; -defm SPV_KHR_8bit_storage : ExtensionOperand<33>; -defm SPV_KHR_vulkan_memory_model : ExtensionOperand<34>; -defm SPV_NV_ray_tracing : ExtensionOperand<35>; -defm SPV_NV_compute_shader_derivatives : ExtensionOperand<36>; -defm SPV_NV_fragment_shader_barycentric : ExtensionOperand<37>; -defm SPV_NV_mesh_shader : ExtensionOperand<38>; -defm SPV_NV_shader_image_footprint : ExtensionOperand<39>; -defm SPV_NV_shading_rate : ExtensionOperand<40>; -defm SPV_INTEL_subgroups : ExtensionOperand<41>; -defm SPV_INTEL_media_block_io : ExtensionOperand<42>; -defm SPV_EXT_fragment_invocation_density : ExtensionOperand<44>; -defm SPV_KHR_no_integer_wrap_decoration : ExtensionOperand<45>; -defm SPV_KHR_float_controls : ExtensionOperand<46>; -defm SPV_EXT_physical_storage_buffer : ExtensionOperand<47>; -defm SPV_INTEL_fpga_memory_attributes : ExtensionOperand<48>; -defm SPV_NV_cooperative_matrix : ExtensionOperand<49>; -defm SPV_INTEL_shader_integer_functions2 : ExtensionOperand<50>; -defm SPV_INTEL_fpga_loop_controls : ExtensionOperand<51>; -defm SPV_EXT_fragment_shader_interlock : ExtensionOperand<52>; -defm SPV_NV_shader_sm_builtins : ExtensionOperand<53>; -defm SPV_KHR_shader_clock : ExtensionOperand<54>; -defm SPV_INTEL_unstructured_loop_controls : ExtensionOperand<55>; -defm SPV_EXT_demote_to_helper_invocation : ExtensionOperand<56>; -defm SPV_INTEL_fpga_reg : ExtensionOperand<57>; -defm SPV_INTEL_blocking_pipes : ExtensionOperand<58>; -defm SPV_GOOGLE_user_type : ExtensionOperand<59>; -defm SPV_KHR_physical_storage_buffer : ExtensionOperand<60>; -defm SPV_INTEL_kernel_attributes : ExtensionOperand<61>; -defm SPV_KHR_non_semantic_info : ExtensionOperand<62>; -defm SPV_INTEL_io_pipes : ExtensionOperand<63>; -defm SPV_KHR_ray_tracing : ExtensionOperand<64>; -defm SPV_KHR_ray_query : ExtensionOperand<65>; -defm SPV_INTEL_fpga_memory_accesses : ExtensionOperand<66>; -defm SPV_INTEL_arbitrary_precision_integers : ExtensionOperand<67>; -defm SPV_EXT_shader_atomic_float_add : ExtensionOperand<68>; -defm SPV_KHR_terminate_invocation : ExtensionOperand<69>; -defm SPV_KHR_fragment_shading_rate : ExtensionOperand<70>; -defm SPV_EXT_shader_image_int64 : ExtensionOperand<71>; -defm SPV_INTEL_fp_fast_math_mode : ExtensionOperand<72>; -defm SPV_INTEL_fpga_cluster_attributes : ExtensionOperand<73>; -defm SPV_INTEL_loop_fuse : ExtensionOperand<74>; -defm SPV_EXT_shader_atomic_float_min_max : ExtensionOperand<75>; -defm SPV_KHR_workgroup_memory_explicit_layout : ExtensionOperand<76>; -defm SPV_KHR_linkonce_odr : ExtensionOperand<77>; -defm SPV_KHR_expect_assume : ExtensionOperand<78>; -defm SPV_INTEL_fpga_dsp_control : ExtensionOperand<79>; -defm SPV_NV_bindless_texture : ExtensionOperand<80>; -defm SPV_INTEL_fpga_invocation_pipelining_attributes : ExtensionOperand<81>; -defm SPV_KHR_subgroup_uniform_control_flow : ExtensionOperand<82>; -defm SPV_HUAWEI_subpass_shading : ExtensionOperand<83>; -defm SPV_KHR_integer_dot_product : ExtensionOperand<84>; -defm SPV_EXT_shader_atomic_float16_add : ExtensionOperand<85>; -defm SPV_INTEL_runtime_aligned : ExtensionOperand<86>; -defm SPV_KHR_bit_instructions : ExtensionOperand<87>; -defm SPV_NV_ray_tracing_motion_blur : ExtensionOperand<88>; -defm SPV_KHR_uniform_group_instructions : ExtensionOperand<89>; -defm SPV_KHR_subgroup_rotate : ExtensionOperand<90>; -defm SPV_INTEL_split_barrier : ExtensionOperand<91>; -defm SPV_KHR_ray_cull_mask : ExtensionOperand<92>; -defm SPV_KHR_fragment_shader_barycentric : ExtensionOperand<93>; -defm SPV_EXT_relaxed_printf_string_address_space : ExtensionOperand<94>; -defm SPV_EXT_ycbcr_attachments : ExtensionOperand<95>; -defm SPV_EXT_mesh_shader : ExtensionOperand<96>; -defm SPV_ARM_core_builtins : ExtensionOperand<97>; -defm SPV_EXT_opacity_micromap : ExtensionOperand<98>; -defm SPV_NV_shader_invocation_reorder : ExtensionOperand<99>; -defm SPV_INTEL_usm_storage_classes : ExtensionOperand<100>; -defm SPV_INTEL_fpga_latency_control : ExtensionOperand<101>; -defm SPV_INTEL_fpga_argument_interfaces : ExtensionOperand<102>; -defm SPV_INTEL_optnone : ExtensionOperand<103>; -defm SPV_INTEL_function_pointers : ExtensionOperand<104>; -defm SPV_INTEL_variable_length_array : ExtensionOperand<105>; -defm SPV_INTEL_bfloat16_conversion : ExtensionOperand<106>; -defm SPV_INTEL_inline_assembly : ExtensionOperand<107>; -defm SPV_INTEL_cache_controls : ExtensionOperand<108>; -defm SPV_INTEL_global_variable_host_access : ExtensionOperand<109>; -defm SPV_INTEL_global_variable_fpga_decorations : ExtensionOperand<110>; -defm SPV_KHR_cooperative_matrix : ExtensionOperand<111>; -defm SPV_EXT_arithmetic_fence : ExtensionOperand<112>; -defm SPV_EXT_optnone : ExtensionOperand<113>; -defm SPV_INTEL_joint_matrix : ExtensionOperand<114>; -defm SPV_INTEL_float_controls2 : ExtensionOperand<115>; -defm SPV_INTEL_bindless_images : ExtensionOperand<116>; -defm SPV_INTEL_long_composites : ExtensionOperand<117>; -defm SPV_INTEL_memory_access_aliasing : ExtensionOperand<118>; -defm SPV_INTEL_fp_max_error : ExtensionOperand<119>; -defm SPV_INTEL_ternary_bitwise_function : ExtensionOperand<120>; -defm SPV_INTEL_subgroup_matrix_multiply_accumulate : ExtensionOperand<121>; -defm SPV_INTEL_2d_block_io : ExtensionOperand<122>; -defm SPV_INTEL_int4 : ExtensionOperand<123>; -defm SPV_KHR_float_controls2 : ExtensionOperand<124>; -defm SPV_INTEL_tensor_float32_conversion : ExtensionOperand<125>; + defm : SymbolicOperandWithRequirements; +} + +defm SPV_AMD_shader_explicit_vertex_parameter + : ExtensionOperand<1, [EnvVulkan]>; +defm SPV_AMD_shader_trinary_minmax_extension : ExtensionOperand<2, [EnvVulkan]>; +defm SPV_AMD_gcn_shader : ExtensionOperand<3, [EnvVulkan]>; +defm SPV_KHR_shader_ballot : ExtensionOperand<4, [EnvVulkan]>; +defm SPV_AMD_shader_ballot : ExtensionOperand<5, [EnvVulkan]>; +defm SPV_AMD_gpu_shader_half_float : ExtensionOperand<6, [EnvVulkan]>; +defm SPV_KHR_shader_draw_parameters : ExtensionOperand<7, [EnvVulkan]>; +defm SPV_KHR_subgroup_vote : ExtensionOperand<8, [EnvVulkan]>; +defm SPV_KHR_16bit_storage : ExtensionOperand<9, [EnvVulkan]>; +defm SPV_KHR_device_group : ExtensionOperand<10, [EnvVulkan]>; +defm SPV_KHR_multiview : ExtensionOperand<11, [EnvVulkan]>; +defm SPV_NVX_multiview_per_view_attributes : ExtensionOperand<12, [EnvVulkan]>; +defm SPV_NV_viewport_array2 : ExtensionOperand<13, [EnvVulkan]>; +defm SPV_NV_stereo_view_rendering : ExtensionOperand<14, [EnvVulkan]>; +defm SPV_NV_sample_mask_override_coverage : ExtensionOperand<15, [EnvVulkan]>; +defm SPV_NV_geometry_shader_passthrough : ExtensionOperand<16, [EnvVulkan]>; +defm SPV_AMD_texture_gather_bias_lod : ExtensionOperand<17, [EnvVulkan]>; +defm SPV_KHR_storage_buffer_storage_class : ExtensionOperand<18, [EnvVulkan]>; +defm SPV_KHR_variable_pointers : ExtensionOperand<19, [EnvVulkan]>; +defm SPV_AMD_gpu_shader_int16 : ExtensionOperand<20, [EnvVulkan]>; +defm SPV_KHR_post_depth_coverage : ExtensionOperand<21, [EnvVulkan]>; +defm SPV_KHR_shader_atomic_counter_ops : ExtensionOperand<22, []>; +defm SPV_EXT_shader_stencil_export : ExtensionOperand<23, [EnvVulkan]>; +defm SPV_EXT_shader_viewport_index_layer : ExtensionOperand<24, [EnvVulkan]>; +defm SPV_AMD_shader_image_load_store_lod : ExtensionOperand<25, [EnvVulkan]>; +defm SPV_AMD_shader_fragment_mask : ExtensionOperand<26, [EnvVulkan]>; +defm SPV_EXT_fragment_fully_covered : ExtensionOperand<27, [EnvVulkan]>; +defm SPV_AMD_gpu_shader_half_float_fetch : ExtensionOperand<28, [EnvVulkan]>; +defm SPV_GOOGLE_decorate_string : ExtensionOperand<29, [EnvVulkan]>; +defm SPV_GOOGLE_hlsl_functionality1 : ExtensionOperand<30, [EnvVulkan]>; +defm SPV_NV_shader_subgroup_partitioned : ExtensionOperand<31, [EnvVulkan]>; +defm SPV_EXT_descriptor_indexing : ExtensionOperand<32, [EnvVulkan]>; +defm SPV_KHR_8bit_storage : ExtensionOperand<33, [EnvVulkan]>; +defm SPV_KHR_vulkan_memory_model : ExtensionOperand<34, [EnvVulkan]>; +defm SPV_NV_ray_tracing : ExtensionOperand<35, [EnvVulkan]>; +defm SPV_NV_compute_shader_derivatives : ExtensionOperand<36, [EnvVulkan]>; +defm SPV_NV_fragment_shader_barycentric : ExtensionOperand<37, [EnvVulkan]>; +defm SPV_NV_mesh_shader : ExtensionOperand<38, [EnvVulkan]>; +defm SPV_NV_shader_image_footprint : ExtensionOperand<39, [EnvVulkan]>; +defm SPV_NV_shading_rate : ExtensionOperand<40, [EnvVulkan]>; +defm SPV_INTEL_subgroups : ExtensionOperand<41, [EnvOpenCL]>; +defm SPV_INTEL_media_block_io : ExtensionOperand<42, [EnvOpenCL]>; +defm SPV_EXT_fragment_invocation_density : ExtensionOperand<44, [EnvVulkan]>; +defm SPV_KHR_no_integer_wrap_decoration : ExtensionOperand<45, [EnvOpenCL]>; +defm SPV_KHR_float_controls : ExtensionOperand<46, [EnvVulkan, EnvOpenCL]>; +defm SPV_EXT_physical_storage_buffer : ExtensionOperand<47, [EnvVulkan]>; +defm SPV_INTEL_fpga_memory_attributes : ExtensionOperand<48, [EnvOpenCL]>; +defm SPV_NV_cooperative_matrix : ExtensionOperand<49, [EnvVulkan]>; +defm SPV_INTEL_shader_integer_functions2 + : ExtensionOperand<50, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_fpga_loop_controls : ExtensionOperand<51, [EnvOpenCL]>; +defm SPV_EXT_fragment_shader_interlock : ExtensionOperand<52, [EnvVulkan]>; +defm SPV_NV_shader_sm_builtins : ExtensionOperand<53, [EnvVulkan]>; +defm SPV_KHR_shader_clock : ExtensionOperand<54, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_unstructured_loop_controls : ExtensionOperand<55, [EnvOpenCL]>; +defm SPV_EXT_demote_to_helper_invocation : ExtensionOperand<56, [EnvVulkan]>; +defm SPV_INTEL_fpga_reg : ExtensionOperand<57, [EnvOpenCL]>; +defm SPV_INTEL_blocking_pipes : ExtensionOperand<58, [EnvOpenCL]>; +defm SPV_GOOGLE_user_type : ExtensionOperand<59, [EnvVulkan]>; +defm SPV_KHR_physical_storage_buffer : ExtensionOperand<60, [EnvVulkan]>; +defm SPV_INTEL_kernel_attributes : ExtensionOperand<61, [EnvOpenCL]>; +defm SPV_KHR_non_semantic_info : ExtensionOperand<62, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_io_pipes : ExtensionOperand<63, [EnvOpenCL]>; +defm SPV_KHR_ray_tracing : ExtensionOperand<64, [EnvVulkan]>; +defm SPV_KHR_ray_query : ExtensionOperand<65, [EnvVulkan]>; +defm SPV_INTEL_fpga_memory_accesses : ExtensionOperand<66, [EnvOpenCL]>; +defm SPV_INTEL_arbitrary_precision_integers : ExtensionOperand<67, [EnvOpenCL]>; +defm SPV_EXT_shader_atomic_float_add + : ExtensionOperand<68, [EnvVulkan, EnvOpenCL]>; +defm SPV_KHR_terminate_invocation : ExtensionOperand<69, [EnvVulkan]>; +defm SPV_KHR_fragment_shading_rate : ExtensionOperand<70, [EnvVulkan]>; +defm SPV_EXT_shader_image_int64 : ExtensionOperand<71, [EnvVulkan]>; +defm SPV_INTEL_fp_fast_math_mode : ExtensionOperand<72, [EnvOpenCL]>; +defm SPV_INTEL_fpga_cluster_attributes : ExtensionOperand<73, [EnvOpenCL]>; +defm SPV_INTEL_loop_fuse : ExtensionOperand<74, [EnvOpenCL]>; +defm SPV_EXT_shader_atomic_float_min_max + : ExtensionOperand<75, [EnvVulkan, EnvOpenCL]>; +defm SPV_KHR_workgroup_memory_explicit_layout + : ExtensionOperand<76, [EnvVulkan]>; +defm SPV_KHR_linkonce_odr : ExtensionOperand<77, [EnvOpenCL]>; +defm SPV_KHR_expect_assume : ExtensionOperand<78, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_fpga_dsp_control : ExtensionOperand<79, [EnvOpenCL]>; +defm SPV_NV_bindless_texture : ExtensionOperand<80, [EnvVulkan]>; +defm SPV_INTEL_fpga_invocation_pipelining_attributes + : ExtensionOperand<81, [EnvOpenCL]>; +defm SPV_KHR_subgroup_uniform_control_flow : ExtensionOperand<82, [EnvVulkan]>; +defm SPV_HUAWEI_subpass_shading : ExtensionOperand<83, [EnvVulkan]>; +defm SPV_KHR_integer_dot_product : ExtensionOperand<84, [EnvVulkan, EnvOpenCL]>; +defm SPV_EXT_shader_atomic_float16_add + : ExtensionOperand<85, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_runtime_aligned : ExtensionOperand<86, [EnvOpenCL]>; +defm SPV_KHR_bit_instructions : ExtensionOperand<87, [EnvOpenCL]>; +defm SPV_NV_ray_tracing_motion_blur : ExtensionOperand<88, [EnvVulkan]>; +defm SPV_KHR_uniform_group_instructions : ExtensionOperand<89, [EnvOpenCL]>; +defm SPV_KHR_subgroup_rotate : ExtensionOperand<90, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_split_barrier : ExtensionOperand<91, [EnvOpenCL]>; +defm SPV_KHR_ray_cull_mask : ExtensionOperand<92, [EnvVulkan]>; +defm SPV_KHR_fragment_shader_barycentric : ExtensionOperand<93, [EnvVulkan]>; +defm SPV_EXT_relaxed_printf_string_address_space + : ExtensionOperand<94, [EnvOpenCL]>; +defm SPV_EXT_mesh_shader : ExtensionOperand<96, [EnvVulkan]>; +defm SPV_ARM_core_builtins : ExtensionOperand<97, [EnvVulkan]>; +defm SPV_EXT_opacity_micromap : ExtensionOperand<98, [EnvVulkan]>; +defm SPV_NV_shader_invocation_reorder : ExtensionOperand<99, [EnvVulkan]>; +defm SPV_INTEL_usm_storage_classes : ExtensionOperand<100, [EnvOpenCL]>; +defm SPV_INTEL_fpga_latency_control : ExtensionOperand<101, [EnvOpenCL]>; +defm SPV_INTEL_fpga_argument_interfaces : ExtensionOperand<102, [EnvOpenCL]>; +defm SPV_INTEL_optnone : ExtensionOperand<103, [EnvOpenCL]>; +defm SPV_INTEL_function_pointers : ExtensionOperand<104, [EnvOpenCL]>; +defm SPV_INTEL_variable_length_array : ExtensionOperand<105, [EnvOpenCL]>; +defm SPV_INTEL_bfloat16_conversion : ExtensionOperand<106, [EnvOpenCL]>; +defm SPV_INTEL_inline_assembly : ExtensionOperand<107, [EnvOpenCL]>; +defm SPV_INTEL_cache_controls : ExtensionOperand<108, [EnvOpenCL]>; +defm SPV_INTEL_global_variable_host_access : ExtensionOperand<109, [EnvOpenCL]>; +defm SPV_INTEL_global_variable_fpga_decorations + : ExtensionOperand<110, [EnvOpenCL]>; +defm SPV_KHR_cooperative_matrix : ExtensionOperand<111, [EnvVulkan, EnvOpenCL]>; +defm SPV_EXT_arithmetic_fence : ExtensionOperand<112, [EnvOpenCL]>; +defm SPV_EXT_optnone : ExtensionOperand<113, [EnvOpenCL]>; +defm SPV_INTEL_joint_matrix : ExtensionOperand<114, [EnvOpenCL]>; +defm SPV_INTEL_float_controls2 : ExtensionOperand<115, [EnvOpenCL]>; +defm SPV_INTEL_bindless_images : ExtensionOperand<116, [EnvOpenCL]>; +defm SPV_INTEL_long_composites : ExtensionOperand<117, [EnvOpenCL]>; +defm SPV_INTEL_memory_access_aliasing : ExtensionOperand<118, [EnvOpenCL]>; +defm SPV_INTEL_fp_max_error : ExtensionOperand<119, [EnvOpenCL]>; +defm SPV_INTEL_ternary_bitwise_function : ExtensionOperand<120, [EnvOpenCL]>; +defm SPV_INTEL_subgroup_matrix_multiply_accumulate + : ExtensionOperand<121, [EnvOpenCL]>; +defm SPV_INTEL_2d_block_io : ExtensionOperand<122, [EnvOpenCL]>; +defm SPV_INTEL_int4 : ExtensionOperand<123, [EnvOpenCL]>; +defm SPV_KHR_float_controls2 : ExtensionOperand<124, [EnvVulkan, EnvOpenCL]>; +defm SPV_INTEL_tensor_float32_conversion : ExtensionOperand<125, [EnvOpenCL]>; //===----------------------------------------------------------------------===// // Multiclass used to define Capabilities enum values and at the same time @@ -342,7 +403,9 @@ class Capability value> { multiclass CapabilityOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def NAME : Capability; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Matrix : CapabilityOperand<0, 0, 0, [], []>; @@ -551,7 +614,8 @@ class SourceLanguage value> { multiclass SourceLanguageOperand value> { def : SourceLanguage; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Unknown : SourceLanguageOperand<0>; @@ -580,7 +644,8 @@ class AddressingModel value> { multiclass AddressingModelOperand value, list reqCapabilities> { def : AddressingModel; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Logical : AddressingModelOperand<0, []>; @@ -607,7 +672,8 @@ class ExecutionModel value> { multiclass ExecutionModelOperand value, list reqCapabilities> { def : ExecutionModel; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Vertex : ExecutionModelOperand<0, [Shader]>; @@ -645,7 +711,8 @@ class MemoryModel value> { multiclass MemoryModelOperand value, list reqCapabilities> { def : MemoryModel; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Simple : MemoryModelOperand<0, [Shader]>; @@ -672,7 +739,8 @@ class ExecutionMode value> { multiclass ExecutionModeOperand value, list reqCapabilities> { def : ExecutionMode; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Invocations : ExecutionModeOperand<0, [Geometry]>; @@ -748,7 +816,8 @@ class StorageClass value> { multiclass StorageClassOperand value, list reqExtensions, list reqCapabilities> { def : StorageClass; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm UniformConstant : StorageClassOperand<0, [], []>; @@ -794,7 +863,8 @@ class Dim value> { multiclass DimOperand value, string mnemonic, list reqCapabilities> { def NAME : Dim; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm DIM_1D : DimOperand<0, "1D", [Sampled1D, Image1D]>; @@ -824,7 +894,8 @@ class SamplerAddressingMode value> { multiclass SamplerAddressingModeOperand value, list reqCapabilities> { def : SamplerAddressingMode; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : SamplerAddressingModeOperand<0, [Kernel]>; @@ -852,7 +923,8 @@ class SamplerFilterMode value> { multiclass SamplerFilterModeOperand value, list reqCapabilities> { def : SamplerFilterMode; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Nearest : SamplerFilterModeOperand<0, [Kernel]>; @@ -877,7 +949,8 @@ class ImageFormat value> { multiclass ImageFormatOperand value, list reqCapabilities> { def NAME : ImageFormat; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Unknown : ImageFormatOperand<0, []>; @@ -940,7 +1013,8 @@ class ImageChannelOrder value> { multiclass ImageChannelOrderOperand value, list reqCapabilities> { def : ImageChannelOrder; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm R : ImageChannelOrderOperand<0, [Kernel]>; @@ -983,7 +1057,8 @@ class ImageChannelDataType value> { multiclass ImageChannelDataTypeOperand value, list reqCapabilities> { def : ImageChannelDataType; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm SnormInt8 : ImageChannelDataTypeOperand<0, []>; @@ -1023,7 +1098,8 @@ class ImageOperand value> { multiclass ImageOperandOperand value, list reqCapabilities> { def : ImageOperand; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : ImageOperandOperand<0x0, []>; @@ -1061,7 +1137,8 @@ class FPFastMathMode value> { multiclass FPFastMathModeOperand value, list reqCapabilities> { def : FPFastMathMode; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : FPFastMathModeOperand<0x0, []>; @@ -1090,7 +1167,8 @@ class FPRoundingMode value> { multiclass FPRoundingModeOperand value> { def NAME : FPRoundingMode; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm RTE : FPRoundingModeOperand<0>; @@ -1117,7 +1195,8 @@ class LinkageType value> { multiclass LinkageTypeOperand value, list reqCapabilities> { def : LinkageType; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Export : LinkageTypeOperand<0, [Linkage]>; @@ -1143,7 +1222,8 @@ class AccessQualifier value> { multiclass AccessQualifierOperand value, list reqCapabilities> { def NAME : AccessQualifier; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm ReadOnly : AccessQualifierOperand<0, [Kernel]>; @@ -1170,7 +1250,9 @@ class FunctionParameterAttribute value> { multiclass FunctionParameterAttributeOperand value, list reqCapabilities> { def : FunctionParameterAttribute; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Zext : FunctionParameterAttributeOperand<0, [Kernel]>; @@ -1202,7 +1284,9 @@ class Decoration value> { multiclass DecorationOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def : Decoration; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm RelaxedPrecision : DecorationOperand<0, 0, 0, [], [Shader]>; @@ -1303,7 +1387,9 @@ class BuiltIn value> { multiclass BuiltInOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def NAME : BuiltIn; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Position : BuiltInOperand<0, 0, 0, [], [Shader]>; @@ -1417,7 +1503,8 @@ class SelectionControl value> { multiclass SelectionControlOperand value> { def : SelectionControl; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : SelectionControlOperand<0x0>; @@ -1443,7 +1530,8 @@ class LoopControl value> { multiclass LoopControlOperand value> { def : LoopControl; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : LoopControlOperand<0x0>; @@ -1476,7 +1564,8 @@ class FunctionControl value> { multiclass FunctionControlOperand value> { def : FunctionControl; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : FunctionControlOperand<0x0>; @@ -1506,7 +1595,9 @@ class MemorySemantics value> { multiclass MemorySemanticsOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def : MemorySemantics; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : MemorySemanticsOperand<0x0, 0, 0, [], []>; @@ -1544,7 +1635,9 @@ class MemoryOperand value> { multiclass MemoryOperandOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def : MemoryOperand; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : MemoryOperandOperand<0x0, 0, 0, [], []>; @@ -1577,7 +1670,9 @@ class Scope value> { multiclass ScopeOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def : Scope; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm CrossDevice : ScopeOperand<0, 0, 0, [], []>; @@ -1607,7 +1702,9 @@ class GroupOperation value> { multiclass GroupOperationOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def NAME : GroupOperation; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm Reduce : GroupOperationOperand<0, 0, 0, [], [Kernel, GroupNonUniformArithmetic, GroupNonUniformBallot]>; @@ -1638,7 +1735,9 @@ class KernelEnqueueFlags value> { multiclass KernelEnqueueFlagsOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def : KernelEnqueueFlags; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm NoWait : KernelEnqueueFlagsOperand<0, 0, 0, [], [Kernel]>; @@ -1665,7 +1764,9 @@ class KernelProfilingInfo value> { multiclass KernelProfilingInfoOperand value, bits<32> minVersion, bits<32> maxVersion, list reqExtensions, list reqCapabilities> { def : KernelProfilingInfo; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm None : KernelProfilingInfoOperand<0x0, 0, 0, [], []>; @@ -1690,7 +1791,8 @@ class Opcode value> { multiclass OpcodeOperand value> { def : Opcode; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } // TODO: implement other mnemonics. defm InBoundsAccessChain : OpcodeOperand<66>; @@ -1720,7 +1822,9 @@ class CooperativeMatrixLayout value> { multiclass CooperativeMatrixLayoutOperand value, list reqExtensions, list reqCapabilities> { def : CooperativeMatrixLayout; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm RowMajorKHR : CooperativeMatrixLayoutOperand<0x0, [SPV_KHR_cooperative_matrix], [CooperativeMatrixKHR]>; @@ -1747,7 +1851,9 @@ class CooperativeMatrixOperands value> { multiclass CooperativeMatrixOperandsOperand value, list reqExtensions, list reqCapabilities> { def : CooperativeMatrixOperands; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } defm NoneKHR : CooperativeMatrixOperandsOperand<0x0, [SPV_KHR_cooperative_matrix], [CooperativeMatrixKHR]>; @@ -1780,7 +1886,9 @@ class SpecConstantOpOperands value> { multiclass SpecConstantOpOperandsOperand value, list reqExtensions, list reqCapabilities> { def : SpecConstantOpOperands; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements; } // Conversion @@ -1868,7 +1976,9 @@ class MatrixMultiplyAccumulateOperands value> { multiclass MatrixMultiplyAccumulateOperandsOperand value, list reqExtensions> { def : MatrixMultiplyAccumulateOperands; - defm : SymbolicOperandWithRequirements; + defm : SymbolicOperandWithRequirements< + MatrixMultiplyAccumulateOperandsOperand, value, NAME, 0, 0, + reqExtensions, [], []>; } defm None : MatrixMultiplyAccumulateOperandsOperand<0x0, [SPV_INTEL_subgroup_matrix_multiply_accumulate]>; diff --git a/llvm/test/CodeGen/SPIRV/extensions/enable-all-extensions-avoid-invalid.ll b/llvm/test/CodeGen/SPIRV/extensions/enable-all-extensions-avoid-invalid.ll new file mode 100644 index 0000000000000..2de7fff0bc900 --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/extensions/enable-all-extensions-avoid-invalid.ll @@ -0,0 +1,16 @@ +; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv1.6-vulkan1.3-compute --spirv-ext=all %s -o - | FileCheck %s +; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-compute --spirv-ext=all %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %} + +; CHECK-NOT: OpExtension "SPV_KHR_no_integer_wrap_decoration" + +define internal void @foo(i32 %i) local_unnamed_addr { + %sub.i = sub nsw i32 0, %i + ret void +} + +define internal void @main() local_unnamed_addr #0 { +entry: + ret void +} + +attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } \ No newline at end of file