@@ -352,6 +352,21 @@ SPIR-V Dialect op | LLVM Dialect op
352352` spv.ULessThan ` | ` llvm.icmp "ult" `
353353` spv.ULessThanEqual ` | ` llvm.icmp "ule" `
354354
355+ ### ` spv.EntryPoint ` and ` spv.ExecutionMode `
356+
357+ ** Note: these conversions are likely to be changed in the future**
358+
359+ First of all, it is important to note that there is no direct representation of
360+ entry points in LLVM. At the moment, we choose to ** remove these ops** , assuming
361+ that the module generated from SPIR-V has no other internal functions (This
362+ assumption is actually made in [ ` mlir-spirv-cpu-runner ` ] ( #`mlir-spirv-cpu-runner` ) ).
363+
364+ However, these ops can be used to see which functions in the module are entry
365+ point functions. ` spv.ExecutionMode ` also carries the metadata associated with
366+ the entry point such as ` LocalSize ` , which indicates the workgroup size in the
367+ x, y, and z dimensions. It will be useful to represent this on the LLVM side
368+ (TODO).
369+
355370### Logical ops
356371
357372Logical ops follow a similar pattern as bitwise ops, with the difference that
@@ -378,6 +393,25 @@ modelled with `xor` operation with a mask with all bits set.
378393This section describes the conversion patterns for SPIR-V dialect operations
379394that concern memory.
380395
396+ #### ` spv.AccessChain `
397+
398+ ` spv.AccessChain ` is mapped to ` llvm.getelementptr ` op. In order to create a
399+ valid LLVM op, we also add a 0 index to the ` spv.AccessChain ` 's indices list in
400+ order to go through the pointer.
401+
402+ ``` mlir
403+ // Access the 1st element of the array
404+ %i = spv.constant 1: i32
405+ %var = spv.Variable : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
406+ %el = spv.AccessChain %var[%i, %i] : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>, i32, i32
407+
408+ // Corresponding LLVM dialect code
409+ %i = ...
410+ %var = ...
411+ %0 = llvm.mlir.constant(0 : i32) : !llvm.i32
412+ %el = llvm.getelementptr %var[%0, %i, %i] : (!llvm.ptr<struct<packed (float, array<4 x float>)>>, !llvm.i32, !llvm.i32, !llvm.i32)
413+ ```
414+
381415#### ` spv.Load ` and ` spv.Store `
382416
383417These ops are converted to their LLVM counterparts: ` llvm.load ` and
@@ -434,15 +468,18 @@ module {
434468}
435469```
436470
437- At the moment, only current invocation is in conversion's scope. This means that
438- global variables with pointers of ` Input ` , ` Output ` and ` Private ` storage
439- classes are supported. Moreover , ` bind ` that specifies the descriptor set and
440- binding number and ` built_in ` that specifies SPIR-V ` BuiltIn ` decoration have
441- also no conversion .
471+ The SPIR-V to LLVM conversion does not involve modelling of workgroups.
472+ Hence, we say that only current invocation is in conversion's scope. This means
473+ that global variables with pointers of ` Input ` , ` Output ` , and ` Private ` storage
474+ classes are supported. Also, ` StorageBuffer ` storage class is allowed for
475+ executing [ ` mlir-spirv-cpu-runner ` ] ( #`mlir-spirv-cpu-runner` ) .
442476
443- Currently ` llvm.mlir.global ` s are created with ` private ` linkage for
444- ` Private ` storage class and ` External ` for ` Input ` /` Output ` storage classes,
445- based on SPIR-V spec:
477+ Moreover, ` bind ` that specifies the descriptor set and the binding number and
478+ ` built_in ` that specifies SPIR-V ` BuiltIn ` decoration have no conversion into
479+ LLVM dialect.
480+
481+ Currently ` llvm.mlir.global ` s are created with ` private ` linkage for ` Private `
482+ storage class and ` External ` for other storage classes, based on SPIR-V spec:
446483
447484> By default, functions and global variables are private to a module and cannot
448485 be accessed by other modules. However, a module may be written to export or
@@ -559,14 +596,11 @@ There is no support of the following ops:
559596
560597As well as:
561598
562- * spv.AccessChain
563599* spv.CompositeConstruct
564600* spv.CompositeExtract
565601* spv.CompositeInsert
566602* spv.ControlBarrier
567603* spv.CopyMemory
568- * spv.EntryPoint
569- * spv.ExecutionMode
570604* spv.FMod
571605* spv.GLSL.SAbs
572606* spv.GLSL.SSign
@@ -743,12 +777,9 @@ to LLVM ops. At the moment, SPIR-V module attributes are ignored.
743777
744778` spv._module_end ` is mapped to an equivalent terminator ` ModuleTerminatorOp ` .
745779
746- ## SPIR-V special ops
747-
748- ** Note: this section is due to be implemented in August**
780+ ## ` mlir-spirv-cpu-runner `
749781
750- This section describes how SPIR-V specific ops, * e.g* ` spv.specConstant ` , are
751- modelled in LLVM. It also provides information on ` mlir-spirv-runner ` .
782+ ** Note: this is a section in progress, more information will appear soon**
752783
753784[ LLVMFunctionAttributes ] : https://llvm.org/docs/LangRef.html#function-attributes
754785[ SPIRVFunctionAttributes ] : https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_function_control_a_function_control
0 commit comments