Skip to content

Commit c7b5c12

Browse files
steffenlarsenvmaksimo
authored andcommitted
[docs] Add documentation for decorations metadata
This commit adds documentation for two new named metadata nodes: `spirv.Decorations` and `spirv.ParameterDecorations`. These metadata nodes allow LLVM IR to directly specify SPIR-V decorations on global variable and function parameters respectively. The translator should traverse these metadata nodes and generate the corresponding SPIR-V decoration operations. Co-authored-by: Greg Lueck <[email protected]> Signed-off-by: Steffen Larsen <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@139e500
1 parent ef1a2f6 commit c7b5c12

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

llvm-spirv/docs/SPIRVRepresentationInLLVM.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,56 @@ For example:
411411
are translated for image types, but they should be encoded in LLVM IR type name
412412
rather than function metadata.
413413

414+
Function parameter and global variable decoration through metadata
415+
------------------------------------------------------------------
416+
417+
Both function parameters and global variables can be decorated using LLVM
418+
metadata through the metadata names ``spirv.ParameterDecorations`` and
419+
``spirv.Decorations`` respectively. ``spirv.ParameterDecorations`` must be tied
420+
to the kernel function while ``spirv.Decorations`` is tied directly to the
421+
global variable.
422+
423+
A "decoration-node" is a metadata node consisting of one or more operands. The
424+
first operand is an integer literal representing the SPIR-V decoration
425+
identifier. The other operands are either an integer or string literal
426+
representing the remaining extra operands of the corresponding SPIR-V
427+
decoration.
428+
429+
A "decoration-list" is a metadata node consisting of references to zero or more
430+
decoration-nodes.
431+
432+
``spirv.Decorations`` must refer to a decoration-list while
433+
``spirv.ParameterDecorations`` must refer to a metadata node that contains N
434+
references to decoration-lists, where N is the number of arguments of the
435+
function the metadata is tied to.
436+
437+
``spirv.Decorations`` example:
438+
439+
.. code-block:: llvm
440+
441+
@v = global i32 0, !spirv.Decorations !1
442+
...
443+
!1 = !{!2, !3} ; decoration-list with two decoration nodes
444+
!2 = !{i32 22} ; decoration-node with no extra operands
445+
!3 = !{i32 41, !"v", i32 0} ; decoration-node with 2 extra operands
446+
447+
decorates a global variable ``v`` with ``Constant`` and ``LinkageAttributes``
448+
with extra operands ``"v"`` and ``Export`` in SPIR-V.
449+
450+
``spirv.ParameterDecorations`` example:
451+
452+
.. code-block:: llvm
453+
454+
define spir_kernel void @k(float %a, float %b) #0 !spirv.ParameterDecorations !1
455+
...
456+
!1 = !{!2, !3} ; metadata node with 2 decoration-lists
457+
!2 = !{} ; empty decoration-list
458+
!3 = !{!4} ; decoration-list with one decoration node
459+
!4 = !{i32 19} ; decoration-node with no extra operands
460+
461+
decorates the argument ``b`` of ``k`` with ``Restrict`` in SPIR-V while not
462+
adding any decoration to argument ``a``.
463+
414464
Debug information extension
415465
===========================
416466

0 commit comments

Comments
 (0)