diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td @@ -48,6 +48,38 @@ let cppNamespace = "spirv"; } +//===----------------------------------------------------------------------===// +// Utility definitions +//===----------------------------------------------------------------------===// + +// A predicate that checks whether `$_self` is a known enum case for the +// enum class with `name`. +class SPV_IsKnownEnumCaseFor : + CPred<"::mlir::spirv::symbolize" # name # "(" + "$_self.cast().getValue().getZExtValue()).hasValue()">; + +// Wrapper over base I32EnumAttr to set common fields. +class SPV_I32EnumAttr cases> : + I32EnumAttr { + let predicate = And<[ + IntegerAttrBase.predicate, + SPV_IsKnownEnumCaseFor, + ]>; + let cppNamespace = "::mlir::spirv"; +} + +// Wrapper over base BitEnumAttr to set common fields. +class SPV_BitEnumAttr cases> : + BitEnumAttr { + let predicate = And<[ + IntegerAttrBase.predicate, + SPV_IsKnownEnumCaseFor, + ]>; + let cppNamespace = "::mlir::spirv"; +} + //===----------------------------------------------------------------------===// // SPIR-V availability definitions //===----------------------------------------------------------------------===// @@ -924,7 +956,7 @@ } def SPV_CapabilityAttr : - I32EnumAttr<"Capability", "valid SPIR-V Capability", [ + SPV_I32EnumAttr<"Capability", "valid SPIR-V Capability", [ SPV_C_Matrix, SPV_C_Addresses, SPV_C_Linkage, SPV_C_Kernel, SPV_C_Float16, SPV_C_Float64, SPV_C_Int64, SPV_C_Groups, SPV_C_Int16, SPV_C_Int8, SPV_C_Sampled1D, SPV_C_SampledBuffer, SPV_C_GroupNonUniform, SPV_C_ShaderLayer, @@ -986,9 +1018,7 @@ SPV_C_StorageTexelBufferArrayNonUniformIndexing, SPV_C_ShaderViewportIndexLayerEXT, SPV_C_ShaderViewportMaskNV, SPV_C_ShaderStereoViewNV - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_AM_Logical : I32EnumAttrCase<"Logical", 0>; def SPV_AM_Physical32 : I32EnumAttrCase<"Physical32", 1> { @@ -1010,12 +1040,10 @@ } def SPV_AddressingModelAttr : - I32EnumAttr<"AddressingModel", "valid SPIR-V AddressingModel", [ + SPV_I32EnumAttr<"AddressingModel", "valid SPIR-V AddressingModel", [ SPV_AM_Logical, SPV_AM_Physical32, SPV_AM_Physical64, SPV_AM_PhysicalStorageBuffer64 - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_BI_Position : I32EnumAttrCase<"Position", 0> { list availability = [ @@ -1522,7 +1550,7 @@ } def SPV_BuiltInAttr : - I32EnumAttr<"BuiltIn", "valid SPIR-V BuiltIn", [ + SPV_I32EnumAttr<"BuiltIn", "valid SPIR-V BuiltIn", [ SPV_BI_Position, SPV_BI_PointSize, SPV_BI_ClipDistance, SPV_BI_CullDistance, SPV_BI_VertexId, SPV_BI_InstanceId, SPV_BI_PrimitiveId, SPV_BI_InvocationId, SPV_BI_Layer, SPV_BI_ViewportIndex, SPV_BI_TessLevelOuter, @@ -1555,9 +1583,7 @@ SPV_BI_InstanceCustomIndexNV, SPV_BI_ObjectToWorldNV, SPV_BI_WorldToObjectNV, SPV_BI_HitTNV, SPV_BI_HitKindNV, SPV_BI_IncomingRayFlagsNV, SPV_BI_WarpsPerSMNV, SPV_BI_SMCountNV, SPV_BI_WarpIDNV, SPV_BI_SMIDNV - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_D_RelaxedPrecision : I32EnumAttrCase<"RelaxedPrecision", 0> { list availability = [ @@ -1868,7 +1894,7 @@ } def SPV_DecorationAttr : - I32EnumAttr<"Decoration", "valid SPIR-V Decoration", [ + SPV_I32EnumAttr<"Decoration", "valid SPIR-V Decoration", [ SPV_D_RelaxedPrecision, SPV_D_SpecId, SPV_D_Block, SPV_D_BufferBlock, SPV_D_RowMajor, SPV_D_ColMajor, SPV_D_ArrayStride, SPV_D_MatrixStride, SPV_D_GLSLShared, SPV_D_GLSLPacked, SPV_D_CPacked, SPV_D_BuiltIn, @@ -1887,9 +1913,7 @@ SPV_D_PerTaskNV, SPV_D_PerVertexNV, SPV_D_NonUniform, SPV_D_RestrictPointer, SPV_D_AliasedPointer, SPV_D_CounterBuffer, SPV_D_UserSemantic, SPV_D_UserTypeGOOGLE - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_D_1D : I32EnumAttrCase<"Dim1D", 0> { list availability = [ @@ -1924,12 +1948,10 @@ } def SPV_DimAttr : - I32EnumAttr<"Dim", "valid SPIR-V Dim", [ + SPV_I32EnumAttr<"Dim", "valid SPIR-V Dim", [ SPV_D_1D, SPV_D_2D, SPV_D_3D, SPV_D_Cube, SPV_D_Rect, SPV_D_Buffer, SPV_D_SubpassData - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_EM_Invocations : I32EnumAttrCase<"Invocations", 0> { list availability = [ @@ -2238,7 +2260,7 @@ } def SPV_ExecutionModeAttr : - I32EnumAttr<"ExecutionMode", "valid SPIR-V ExecutionMode", [ + SPV_I32EnumAttr<"ExecutionMode", "valid SPIR-V ExecutionMode", [ SPV_EM_Invocations, SPV_EM_SpacingEqual, SPV_EM_SpacingFractionalEven, SPV_EM_SpacingFractionalOdd, SPV_EM_VertexOrderCw, SPV_EM_VertexOrderCcw, SPV_EM_PixelCenterInteger, SPV_EM_OriginUpperLeft, SPV_EM_OriginLowerLeft, @@ -2259,9 +2281,7 @@ SPV_EM_PixelInterlockOrderedEXT, SPV_EM_PixelInterlockUnorderedEXT, SPV_EM_SampleInterlockOrderedEXT, SPV_EM_SampleInterlockUnorderedEXT, SPV_EM_ShadingRateInterlockOrderedEXT, SPV_EM_ShadingRateInterlockUnorderedEXT - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_EM_Vertex : I32EnumAttrCase<"Vertex", 0> { list availability = [ @@ -2340,14 +2360,12 @@ } def SPV_ExecutionModelAttr : - I32EnumAttr<"ExecutionModel", "valid SPIR-V ExecutionModel", [ + SPV_I32EnumAttr<"ExecutionModel", "valid SPIR-V ExecutionModel", [ SPV_EM_Vertex, SPV_EM_TessellationControl, SPV_EM_TessellationEvaluation, SPV_EM_Geometry, SPV_EM_Fragment, SPV_EM_GLCompute, SPV_EM_Kernel, SPV_EM_TaskNV, SPV_EM_MeshNV, SPV_EM_RayGenerationNV, SPV_EM_IntersectionNV, SPV_EM_AnyHitNV, SPV_EM_ClosestHitNV, SPV_EM_MissNV, SPV_EM_CallableNV - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_FC_None : BitEnumAttrCase<"None", 0x0000>; def SPV_FC_Inline : BitEnumAttrCase<"Inline", 0x0001>; @@ -2356,11 +2374,9 @@ def SPV_FC_Const : BitEnumAttrCase<"Const", 0x0008>; def SPV_FunctionControlAttr : - BitEnumAttr<"FunctionControl", "valid SPIR-V FunctionControl", [ + SPV_BitEnumAttr<"FunctionControl", "valid SPIR-V FunctionControl", [ SPV_FC_None, SPV_FC_Inline, SPV_FC_DontInline, SPV_FC_Pure, SPV_FC_Const - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_IF_Unknown : I32EnumAttrCase<"Unknown", 0>; def SPV_IF_Rgba32f : I32EnumAttrCase<"Rgba32f", 1> { @@ -2560,7 +2576,7 @@ } def SPV_ImageFormatAttr : - I32EnumAttr<"ImageFormat", "valid SPIR-V ImageFormat", [ + SPV_I32EnumAttr<"ImageFormat", "valid SPIR-V ImageFormat", [ SPV_IF_Unknown, SPV_IF_Rgba32f, SPV_IF_Rgba16f, SPV_IF_R32f, SPV_IF_Rgba8, SPV_IF_Rgba8Snorm, SPV_IF_Rg32f, SPV_IF_Rg16f, SPV_IF_R11fG11fB10f, SPV_IF_R16f, SPV_IF_Rgba16, SPV_IF_Rgb10A2, SPV_IF_Rg16, SPV_IF_Rg8, @@ -2570,9 +2586,7 @@ SPV_IF_Rgba32ui, SPV_IF_Rgba16ui, SPV_IF_Rgba8ui, SPV_IF_R32ui, SPV_IF_Rgb10a2ui, SPV_IF_Rg32ui, SPV_IF_Rg16ui, SPV_IF_Rg8ui, SPV_IF_R16ui, SPV_IF_R8ui - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_LT_Export : I32EnumAttrCase<"Export", 0> { list availability = [ @@ -2586,11 +2600,9 @@ } def SPV_LinkageTypeAttr : - I32EnumAttr<"LinkageType", "valid SPIR-V LinkageType", [ + SPV_I32EnumAttr<"LinkageType", "valid SPIR-V LinkageType", [ SPV_LT_Export, SPV_LT_Import - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_LC_None : BitEnumAttrCase<"None", 0x0000>; def SPV_LC_Unroll : BitEnumAttrCase<"Unroll", 0x0001>; @@ -2632,13 +2644,11 @@ } def SPV_LoopControlAttr : - BitEnumAttr<"LoopControl", "valid SPIR-V LoopControl", [ + SPV_BitEnumAttr<"LoopControl", "valid SPIR-V LoopControl", [ SPV_LC_None, SPV_LC_Unroll, SPV_LC_DontUnroll, SPV_LC_DependencyInfinite, SPV_LC_DependencyLength, SPV_LC_MinIterations, SPV_LC_MaxIterations, SPV_LC_IterationMultiple, SPV_LC_PeelCount, SPV_LC_PartialCount - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_MA_None : BitEnumAttrCase<"None", 0x0000>; def SPV_MA_Volatile : BitEnumAttrCase<"Volatile", 0x0001>; @@ -2664,13 +2674,11 @@ } def SPV_MemoryAccessAttr : - BitEnumAttr<"MemoryAccess", "valid SPIR-V MemoryAccess", [ + SPV_BitEnumAttr<"MemoryAccess", "valid SPIR-V MemoryAccess", [ SPV_MA_None, SPV_MA_Volatile, SPV_MA_Aligned, SPV_MA_Nontemporal, SPV_MA_MakePointerAvailable, SPV_MA_MakePointerVisible, SPV_MA_NonPrivatePointer - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_MM_Simple : I32EnumAttrCase<"Simple", 0> { list availability = [ @@ -2695,11 +2703,9 @@ } def SPV_MemoryModelAttr : - I32EnumAttr<"MemoryModel", "valid SPIR-V MemoryModel", [ + SPV_I32EnumAttr<"MemoryModel", "valid SPIR-V MemoryModel", [ SPV_MM_Simple, SPV_MM_GLSL450, SPV_MM_OpenCL, SPV_MM_Vulkan - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_MS_None : BitEnumAttrCase<"None", 0x0000>; def SPV_MS_Acquire : BitEnumAttrCase<"Acquire", 0x0002>; @@ -2747,15 +2753,13 @@ } def SPV_MemorySemanticsAttr : - BitEnumAttr<"MemorySemantics", "valid SPIR-V MemorySemantics", [ + SPV_BitEnumAttr<"MemorySemantics", "valid SPIR-V MemorySemantics", [ SPV_MS_None, SPV_MS_Acquire, SPV_MS_Release, SPV_MS_AcquireRelease, SPV_MS_SequentiallyConsistent, SPV_MS_UniformMemory, SPV_MS_SubgroupMemory, SPV_MS_WorkgroupMemory, SPV_MS_CrossWorkgroupMemory, SPV_MS_AtomicCounterMemory, SPV_MS_ImageMemory, SPV_MS_OutputMemory, SPV_MS_MakeAvailable, SPV_MS_MakeVisible, SPV_MS_Volatile - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_S_CrossDevice : I32EnumAttrCase<"CrossDevice", 0>; def SPV_S_Device : I32EnumAttrCase<"Device", 1>; @@ -2770,23 +2774,19 @@ } def SPV_ScopeAttr : - I32EnumAttr<"Scope", "valid SPIR-V Scope", [ + SPV_I32EnumAttr<"Scope", "valid SPIR-V Scope", [ SPV_S_CrossDevice, SPV_S_Device, SPV_S_Workgroup, SPV_S_Subgroup, SPV_S_Invocation, SPV_S_QueueFamily - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_SC_None : BitEnumAttrCase<"None", 0x0000>; def SPV_SC_Flatten : BitEnumAttrCase<"Flatten", 0x0001>; def SPV_SC_DontFlatten : BitEnumAttrCase<"DontFlatten", 0x0002>; def SPV_SelectionControlAttr : - BitEnumAttr<"SelectionControl", "valid SPIR-V SelectionControl", [ + SPV_BitEnumAttr<"SelectionControl", "valid SPIR-V SelectionControl", [ SPV_SC_None, SPV_SC_Flatten, SPV_SC_DontFlatten - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; def SPV_SC_UniformConstant : I32EnumAttrCase<"UniformConstant", 0>; def SPV_SC_Input : I32EnumAttrCase<"Input", 1>; @@ -2876,16 +2876,14 @@ } def SPV_StorageClassAttr : - I32EnumAttr<"StorageClass", "valid SPIR-V StorageClass", [ + SPV_I32EnumAttr<"StorageClass", "valid SPIR-V StorageClass", [ SPV_SC_UniformConstant, SPV_SC_Input, SPV_SC_Uniform, SPV_SC_Output, SPV_SC_Workgroup, SPV_SC_CrossWorkgroup, SPV_SC_Private, SPV_SC_Function, SPV_SC_Generic, SPV_SC_PushConstant, SPV_SC_AtomicCounter, SPV_SC_Image, SPV_SC_StorageBuffer, SPV_SC_CallableDataNV, SPV_SC_IncomingCallableDataNV, SPV_SC_RayPayloadNV, SPV_SC_HitAttributeNV, SPV_SC_IncomingRayPayloadNV, SPV_SC_ShaderRecordBufferNV, SPV_SC_PhysicalStorageBuffer - ]> { - let cppNamespace = "::mlir::spirv"; -} + ]>; // End enum section. Generated from SPIR-V spec; DO NOT MODIFY! diff --git a/mlir/utils/spirv/gen_spirv_dialect.py b/mlir/utils/spirv/gen_spirv_dialect.py --- a/mlir/utils/spirv/gen_spirv_dialect.py +++ b/mlir/utils/spirv/gen_spirv_dialect.py @@ -379,10 +379,10 @@ case_names = ',\n'.join(case_names) # Generate the enum attribute definition - enum_attr = 'def SPV_{name}Attr :\n '\ - '{category}EnumAttr<"{name}", "valid SPIR-V {name}", [\n{cases}\n'\ - ' ]> {{\n'\ - ' let cppNamespace = "::mlir::spirv";\n}}'.format( + enum_attr = '''def SPV_{name}Attr : + SPV_{category}EnumAttr<"{name}", "valid SPIR-V {name}", [ +{cases} + ]>;'''.format( name=kind_name, category=kind_category, cases=case_names) return kind_name, case_defs + '\n\n' + enum_attr