@@ -352,6 +352,21 @@ SPIR-V Dialect op | LLVM Dialect op
352
352
` spv.ULessThan ` | ` llvm.icmp "ult" `
353
353
` spv.ULessThanEqual ` | ` llvm.icmp "ule" `
354
354
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
+
355
370
### Logical ops
356
371
357
372
Logical 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.
378
393
This section describes the conversion patterns for SPIR-V dialect operations
379
394
that concern memory.
380
395
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
+
381
415
#### ` spv.Load ` and ` spv.Store `
382
416
383
417
These ops are converted to their LLVM counterparts: ` llvm.load ` and
@@ -434,15 +468,18 @@ module {
434
468
}
435
469
```
436
470
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` ) .
442
476
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:
446
483
447
484
> By default, functions and global variables are private to a module and cannot
448
485
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:
559
596
560
597
As well as:
561
598
562
- * spv.AccessChain
563
599
* spv.CompositeConstruct
564
600
* spv.CompositeExtract
565
601
* spv.CompositeInsert
566
602
* spv.ControlBarrier
567
603
* spv.CopyMemory
568
- * spv.EntryPoint
569
- * spv.ExecutionMode
570
604
* spv.FMod
571
605
* spv.GLSL.SAbs
572
606
* spv.GLSL.SSign
@@ -743,12 +777,9 @@ to LLVM ops. At the moment, SPIR-V module attributes are ignored.
743
777
744
778
` spv._module_end ` is mapped to an equivalent terminator ` ModuleTerminatorOp ` .
745
779
746
- ## SPIR-V special ops
747
-
748
- ** Note: this section is due to be implemented in August**
780
+ ## ` mlir-spirv-cpu-runner `
749
781
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**
752
783
753
784
[ LLVMFunctionAttributes ] : https://llvm.org/docs/LangRef.html#function-attributes
754
785
[ SPIRVFunctionAttributes ] : https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_function_control_a_function_control
0 commit comments