@@ -5622,34 +5622,106 @@ occurs on.
5622
5622
Metadata
5623
5623
========
5624
5624
5625
- LLVM IR allows metadata to be attached to instructions and global objects in the
5626
- program that can convey extra information about the code to the optimizers and
5627
- code generator. One example application of metadata is source-level
5628
- debug information. There are two metadata primitives: strings and nodes.
5625
+ LLVM IR allows metadata to be attached to instructions and global objects in
5626
+ the program that can convey extra information about the code to the optimizers
5627
+ and code generator.
5629
5628
5630
- Metadata does not have a type, and is not a value. If referenced from a
5631
- ``call`` instruction, it uses the ``metadata`` type.
5629
+ There are two metadata primitives: strings and nodes. There are
5630
+ also specialized nodes which have a distinguished name and a set of named
5631
+ arguments.
5632
+
5633
+ .. note::
5634
+
5635
+ One example application of metadata is source-level debug information,
5636
+ which is currently the only user of specialized nodes.
5637
+
5638
+ Metadata does not have a type, and is not a value.
5639
+
5640
+ A value of non-\ ``metadata`` type can be used in a metadata context using the
5641
+ syntax '``<type> <value>``'.
5642
+
5643
+ All other metadata is identified in syntax as starting with an exclamation
5644
+ point ('``!``').
5645
+
5646
+ Metadata may be used in the following value contexts by using the ``metadata``
5647
+ type:
5648
+
5649
+ - Arguments to certain intrinsic functions, as described in their specification.
5650
+ - Arguments to the ``catchpad``/``cleanuppad`` instructions.
5651
+
5652
+ .. note::
5653
+
5654
+ Metadata can be "wrapped" in a ``MetadataAsValue`` so it can be referenced
5655
+ in a value context: ``MetadataAsValue`` is-a ``Value``.
5656
+
5657
+ A typed value can be "wrapped" in ``ValueAsMetadata`` so it can be
5658
+ referenced in a metadata context: ``ValueAsMetadata`` is-a ``Metadata``.
5659
+
5660
+ There is no explicit syntax for a ``ValueAsMetadata``, and instead
5661
+ the fact that a type identifier cannot begin with an exclamation point
5662
+ is used to resolve ambiguity.
5663
+
5664
+ A ``metadata`` type implies a ``MetadataAsValue``, and when followed with a
5665
+ '``<type> <value>``' pair it wraps the typed value in a ``ValueAsMetadata``.
5632
5666
5633
- All metadata are identified in syntax by an exclamation point ('``!``').
5667
+ For example, the first argument
5668
+ to this call is a ``MetadataAsValue(ValueAsMetadata(Value))``:
5669
+
5670
+ .. code-block:: llvm
5671
+
5672
+ call void @llvm.foo(metadata i32 1)
5673
+
5674
+ Whereas the first argument to this call is a ``MetadataAsValue(MDNode)``:
5675
+
5676
+ .. code-block:: llvm
5677
+
5678
+ call void @llvm.foo(metadata !0)
5679
+
5680
+ The first element of this ``MDTuple`` is a ``MDNode``:
5681
+
5682
+ .. code-block:: llvm
5683
+
5684
+ !{!0}
5685
+
5686
+ And the first element of this ``MDTuple`` is a ``ValueAsMetadata(Value)``:
5687
+
5688
+ .. code-block:: llvm
5689
+
5690
+ !{i32 1}
5634
5691
5635
5692
.. _metadata-string:
5636
5693
5637
- Metadata Nodes and Metadata Strings
5638
- -----------------------------------
5694
+ Metadata Strings (``MDString``)
5695
+ -------------------------------
5696
+
5697
+ .. FIXME Either fix all references to "MDString" in the docs, or make that
5698
+ identifier a formal part of the document.
5639
5699
5640
5700
A metadata string is a string surrounded by double quotes. It can
5641
5701
contain any character by escaping non-printable characters with
5642
5702
"``\xx``" where "``xx``" is the two digit hex code. For example:
5643
5703
"``!"test\00"``".
5644
5704
5645
- Metadata nodes are represented with notation similar to structure
5646
- constants (a comma separated list of elements, surrounded by braces and
5647
- preceded by an exclamation point). Metadata nodes can have any values as
5705
+ .. note::
5706
+
5707
+ A metadata string is metadata, but is not a metadata node.
5708
+
5709
+ .. _metadata-node:
5710
+
5711
+ Metadata Nodes (``MDNode``)
5712
+ ---------------------------
5713
+
5714
+ .. FIXME Either fix all references to "MDNode" in the docs, or make that
5715
+ identifier a formal part of the document.
5716
+
5717
+ Metadata tuples are represented with notation similar to structure
5718
+ constants: a comma separated list of elements, surrounded by braces and
5719
+ preceded by an exclamation point. Metadata nodes can have any values as
5648
5720
their operand. For example:
5649
5721
5650
5722
.. code-block:: llvm
5651
5723
5652
- !{ !"test\00", i32 10}
5724
+ !{!"test\00", i32 10}
5653
5725
5654
5726
Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
5655
5727
@@ -5676,6 +5748,12 @@ intrinsic is using three metadata arguments:
5676
5748
5677
5749
call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
5678
5750
5751
+
5752
+ .. FIXME Attachments cannot be ValueAsMetadata, but we don't have a
5753
+ particularly clear way to refer to ValueAsMetadata without getting into
5754
+ implementation details. Ideally the restriction would be explicit somewhere,
5755
+ though?
5756
+
5679
5757
Metadata can be attached to an instruction. Here metadata ``!21`` is attached
5680
5758
to the ``add`` instruction using the ``!dbg`` identifier:
5681
5759
@@ -6309,7 +6387,7 @@ valid debug intrinsic.
6309
6387
!5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
6310
6388
6311
6389
DIAssignID
6312
- """"""""""""
6390
+ """"""""""
6313
6391
6314
6392
``DIAssignID`` nodes have no operands and are always distinct. They are used to
6315
6393
link together `@llvm.dbg.assign` intrinsics (:ref:`debug
@@ -6324,7 +6402,13 @@ Assignment Tracking <AssignmentTracking.html>`_ for more info.
6324
6402
!2 = distinct !DIAssignID()
6325
6403
6326
6404
DIArgList
6327
- """"""""""""
6405
+ """""""""
6406
+
6407
+ .. FIXME In the implementation this is not a "node", but as it can only appear
6408
+ inline in a function context that distinction isn't observable anyway. Even
6409
+ if it is not required, it would be nice to be more clear about what is a
6410
+ "node", and what that actually means. The names in the implementation could
6411
+ also be updated to mirror whatever we decide here.
6328
6412
6329
6413
``DIArgList`` nodes hold a list of constant or SSA value references. These are
6330
6414
used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in
@@ -6340,7 +6424,7 @@ inlined, and cannot appear in named metadata.
6340
6424
metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus))
6341
6425
6342
6426
DIFlags
6343
- """""""""""""""
6427
+ """""""
6344
6428
6345
6429
These flags encode various properties of DINodes.
6346
6430
@@ -6416,6 +6500,46 @@ within the file where the label is declared.
6416
6500
6417
6501
!2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7)
6418
6502
6503
+ DICommonBlock
6504
+ """""""""""""
6505
+
6506
+ ``DICommonBlock`` nodes represent Fortran common blocks. The ``scope:`` field
6507
+ is mandatory and points to a :ref:`DILexicalBlockFile`, a
6508
+ :ref:`DILexicalBlock`, or a :ref:`DISubprogram`. The ``declaration:``,
6509
+ ``name:``, ``file:``, and ``line:`` fields are optional.
6510
+
6511
+ DIModule
6512
+ """"""""
6513
+
6514
+ ``DIModule`` nodes represent a source language module, for example, a Clang
6515
+ module, or a Fortran module. The ``scope:`` field is mandatory and points to a
6516
+ :ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`.
6517
+ The ``name:`` field is mandatory. The ``configMacros:``, ``includePath:``,
6518
+ ``apinotes:``, ``file:``, ``line:``, and ``isDecl:`` fields are optional.
6519
+
6520
+ DIStringType
6521
+ """"""""""""
6522
+
6523
+ ``DIStringType`` nodes represent a Fortran ``CHARACTER(n)`` type, with a
6524
+ dynamic length and location encoded as an expression.
6525
+ The ``tag:`` field is optional and defaults to ``DW_TAG_string_type``. The ``name:``,
6526
+ ``stringLength:``, ``stringLengthExpression``, ``stringLocationExpression:``,
6527
+ ``size:``, ``align:``, and ``encoding:`` fields are optional.
6528
+
6529
+ If not present, the ``size:`` and ``align:`` fields default to the value zero.
6530
+
6531
+ The length in bits of the string is specified by the first of the following
6532
+ fields present:
6533
+
6534
+ - ``stringLength:``, which points to a ``DIVariable`` whose value is the string
6535
+ length in bits.
6536
+ - ``stringLengthExpression:``, which points to a ``DIExpression`` which
6537
+ computes the length in bits.
6538
+ - ``size``, which contains the literal length in bits.
6539
+
6540
+ The ``stringLocationExpression:`` points to a ``DIExpression`` which describes
6541
+ the "data location" of the string object, if present.
6542
+
6419
6543
'``tbaa``' Metadata
6420
6544
^^^^^^^^^^^^^^^^^^^
6421
6545
0 commit comments