Expand description
pliron representation of LLVM metadata.
LLVM’s metadata graph is made of MDNodes. The graph may be cyclic, including
self referential nodes (like !0 = distinct !{!0, !"llvm.loop.unroll.disable"}).
Nodes have an identity: structural equivalence does not imply identity equivalence.
In pliron, every MDNode lives in a module level metadata table,
and the index in that table identifies the node. This is similar to LLVM’s
textual format, where every node is printed at module level and referred to by number:
%10 = load i32, ptr %9, !tbaa !5, !alias.scope !12
!5 = !{!6, !6, i64 0}
!12 = distinct !{!12, !"copy: argument 1"}becomes, in pliron:
v10 = llvm.load v9 : builtin.integer si32 !0
outlined_attributes:
!0 = [llvm_metadata = llvm.md_attachments ["tbaa" = #5, "alias.scope" = #12]]with the definitions of #5 and #12 in the module’s MdTableAttr.
Metadata attachments on an [Operation] (MdAttachmentsAttr), and the module’s named metadata (NamedMdAttr), both refer to nodes by MdNodeId too. All of MdTableAttr, MdAttachmentsAttr and NamedMdAttr are [OutlinedAttr]s, ensuring better readability and simpler formatters (custom printers and parsers don’t need to be responsible for metadata, it’s automatically taken care of).
TODO: Only generic nodes (LLVM’s MDTuple) are supported. LLVM’s specialized
debug info nodes (DILocation, DISubprogram, …) need extensions in MdNodeAttr;
until then, conversion from LLVM-IR drops them, with a warning.
Structs§
- MdAttachments
Attr - Metadata attached to an [Operation], keyed by LLVM’s metadata kind name
(
"tbaa","llvm.loop", …), the way%v = load ..., !tbaa !5attaches node!5under kindtbaa. - MdTable
Attr - The module level table of metadata node definitions. A node is referred to, from anywhere in the module, by its index in this table.
- MdTable
Parse Err - Named
MdAttr - LLVM’s named metadata:
a module level list of nodes under a name, such as
!llvm.module.flags = !{!0, !1}.
Enums§
- MdAdd
Err - Error enum for metadata addition.
- MdNode
Attr - A metadata node: an entry in the module’s metadata table (MdTableAttr).
- MdOperand
Attr - An operand of a metadata node (MdNodeAttr).
- Metadata
Verify Err
Statics§
- ATTR_
KEY_ MD_ ATTACHMENTS - The MdAttachmentsAttr on an [Operation].
- ATTR_
KEY_ MD_ TABLE - The module level MdTableAttr holding every metadata node’s definition.
- ATTR_
KEY_ NAMED_ MD - The module level NamedMdAttr, LLVM’s named metadata.
Functions§
- add_
metadata_ node - Add
nodeto the metadata table of the module enclosingop, creating the table if the module doesn’t have one yet, and get the MdNodeId to refer to it by. - attach_
metadata - Attach the node
nodetoopunder the LLVM metadata kindkind. - attach_
new_ metadata - Add
nodeto the metadata table of the module enclosingop, and attach it toopunder the LLVM metadata kindkind, replacing any existing attachment for that kind. - find_
enclosing_ module - Starting at
opand walking up its ancestors, find the enclosing [ModuleOp]. - find_
metadata_ table - Starting at
opand walking up its ancestors, find the metadata table of the enclosing [ModuleOp]. - get_
attachments - Get the metadata attached to
op. - get_
metadata_ table - Get the metadata table of
module_op. - get_
named_ metadata - Get the named metadata of
module_op. - set_
attachments - Attach
attachmentstoop, replacing whatever was attached to it. - set_
metadata_ table - Set the metadata table on
module_op. - set_
named_ metadata - Set the named metadata on
module_op. - verify_
metadata - Verify that
Type Aliases§
- MdNode
Id - Index of a metadata node in the module’s metadata table (MdTableAttr).