1 ========================================
2 Machine IR (MIR) Format Reference Manual
3 ========================================
9 This is a work in progress.
14 This document is a reference manual for the Machine IR (MIR) serialization
15 format. MIR is a human readable serialization format that is used to represent
16 LLVM's :ref:`machine specific intermediate representation
17 <machine code representation>`.
19 The MIR serialization format is designed to be used for testing the code
20 generation passes in LLVM.
25 The MIR serialization format uses a YAML container. YAML is a standard
26 data serialization language, and the full YAML language spec can be read at
28 <http://www.yaml.org/spec/1.2/spec.html#Introduction>`_.
30 A MIR file is split up into a series of `YAML documents`_. The first document
31 can contain an optional embedded LLVM IR module, and the rest of the documents
32 contain the serialized machine functions.
34 .. _YAML documents: http://www.yaml.org/spec/1.2/spec.html#id2800132
42 When the first YAML document contains a `YAML block literal string`_, the MIR
43 parser will treat this string as an LLVM assembly language string that
44 represents an embedded LLVM IR module.
45 Here is an example of a YAML document that contains an LLVM module:
50 define i32 @inc(i32* %x) {
52 %0 = load i32, i32* %x
59 .. _YAML block literal string: http://www.yaml.org/spec/1.2/spec.html#id2795688
64 The remaining YAML documents contain the machine functions. This is an example
65 of such YAML document:
71 tracksRegLiveness: true
78 %eax = MOV32rm %rdi, 1, _, 0, _
79 %eax = INC32r killed %eax, implicit-def dead %eflags
80 MOV32mr killed %rdi, 1, _, 0, _, %eax
84 The document above consists of attributes that represent the various
85 properties and data structures in a machine function.
87 The attribute ``name`` is required, and its value should be identical to the
88 name of a function that this machine function is based on.
90 The attribute ``body`` is a `YAML block literal string`_. Its value represents
91 the function's machine basic blocks and their machine instructions.
93 Machine Instructions Format Reference
94 =====================================
96 The machine basic blocks and their instructions are represented using a custom,
97 human readable serialization language. This language is used in the
98 `YAML block literal string`_ that corresponds to the machine function's body.
100 A source string that uses this language contains a list of machine basic
101 blocks, which are described in the section below.
106 A machine basic block is defined in a single block definition source construct
107 that contains the block's ID.
108 The example below defines two blocks that have an ID of zero and one:
117 A machine basic block can also have a name. It should be specified after the ID
118 in the block's definition:
122 bb.0.entry: ; This block's name is "entry"
125 The block's name should be identical to the name of the IR block that this
126 machine block is based on.
131 The machine basic blocks are identified by their ID numbers. Individual
132 blocks are referenced using the following syntax:
148 The machine basic block's successors have to be specified before any of the
154 successors: %bb.1.then, %bb.2.else
161 The branch weights can be specified in brackets after the successor blocks.
162 The example below defines a block that has two successors with branch weights
168 successors: %bb.1.then(32), %bb.2.else(16)
173 The machine basic block's live in registers have to be specified before any of
181 The list of live in registers and successors can be empty. The language also
182 allows multiple live in register and successor lists - they are combined into
183 one list by the parser.
185 Miscellaneous Attributes
186 ^^^^^^^^^^^^^^^^^^^^^^^^
188 The attributes ``IsAddressTaken``, ``IsLandingPad`` and ``Alignment`` can be
189 specified in brackets after the block's definition:
193 bb.0.entry (address-taken):
197 bb.3(landing-pad, align 4):
200 .. TODO: Describe the way the reference to an unnamed LLVM IR block can be
206 A machine instruction is composed of a name, machine operands,
207 :ref:`instruction flags <instruction-flags>`, and machine memory operands.
209 The instruction's name is usually specified before the operands. The example
210 below shows an instance of the X86 ``RETQ`` instruction with a single machine
217 However, if the machine instruction has one or more explicitly defined register
218 operands, the instruction's name has to be specified after them. The example
219 below shows an instance of the AArch64 ``LDPXpost`` instruction with three
220 defined register operands:
224 %sp, %fp, %lr = LDPXpost %sp, 2
226 The instruction names are serialized using the exact definitions from the
227 target's ``*InstrInfo.td`` files, and they are case sensitive. This means that
228 similar instruction names like ``TSTri`` and ``tSTRi`` represent different
229 machine instructions.
231 .. _instruction-flags:
236 The flag ``frame-setup`` can be specified before the instruction's name:
240 %fp = frame-setup ADDXri %sp, 0, 0
243 .. TODO: Describe the parsers default behaviour when optional YAML attributes
245 .. TODO: Describe the syntax for the bundled instructions.
246 .. TODO: Describe the syntax of the immediate machine operands.
247 .. TODO: Describe the syntax of the register machine operands.
248 .. TODO: Describe the syntax of the virtual register operands and their YAML
250 .. TODO: Describe the syntax of the register operand flags and the subregisters.
251 .. TODO: Describe the machine function's YAML flag attributes.
252 .. TODO: Describe the syntax for the global value, external symbol and register
253 mask machine operands.
254 .. TODO: Describe the frame information YAML mapping.
255 .. TODO: Describe the syntax of the stack object machine operands and their
257 .. TODO: Describe the syntax of the constant pool machine operands and their
259 .. TODO: Describe the syntax of the jump table machine operands and their
261 .. TODO: Describe the syntax of the block address machine operands.
262 .. TODO: Describe the syntax of the CFI index machine operands.
263 .. TODO: Describe the syntax of the metadata machine operands, and the
264 instructions debug location attribute.
265 .. TODO: Describe the syntax of the target index machine operands.
266 .. TODO: Describe the syntax of the register live out machine operands.
267 .. TODO: Describe the syntax of the machine memory operands.