Skip to main content

Module metadata

Module metadata 

Source
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§

MdAttachmentsAttr
Metadata attached to an [Operation], keyed by LLVM’s metadata kind name ("tbaa", "llvm.loop", …), the way %v = load ..., !tbaa !5 attaches node !5 under kind tbaa.
MdTableAttr
The module level table of metadata node definitions. A node is referred to, from anywhere in the module, by its index in this table.
MdTableParseErr
NamedMdAttr
LLVM’s named metadata: a module level list of nodes under a name, such as !llvm.module.flags = !{!0, !1}.

Enums§

MdAddErr
Error enum for metadata addition.
MdNodeAttr
A metadata node: an entry in the module’s metadata table (MdTableAttr).
MdOperandAttr
An operand of a metadata node (MdNodeAttr).
MetadataVerifyErr

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 node to the metadata table of the module enclosing op, 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 node to op under the LLVM metadata kind kind.
attach_new_metadata
Add node to the metadata table of the module enclosing op, and attach it to op under the LLVM metadata kind kind, replacing any existing attachment for that kind.
find_enclosing_module
Starting at op and walking up its ancestors, find the enclosing [ModuleOp].
find_metadata_table
Starting at op and 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 attachments to op, 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§

MdNodeId
Index of a metadata node in the module’s metadata table (MdTableAttr).