blob: 541c024bdecb3aed70abc1f4dfc4e80098107dfa [file] [log] [blame]
Alex Lorenz3d311772015-08-06 22:55:19 +00001========================================
2Machine IR (MIR) Format Reference Manual
3========================================
4
5.. contents::
6 :local:
7
8.. warning::
9 This is a work in progress.
10
11Introduction
12============
13
14This document is a reference manual for the Machine IR (MIR) serialization
15format. MIR is a human readable serialization format that is used to represent
16LLVM's :ref:`machine specific intermediate representation
17<machine code representation>`.
18
19The MIR serialization format is designed to be used for testing the code
20generation passes in LLVM.
21
22Overview
23========
24
25The MIR serialization format uses a YAML container. YAML is a standard
26data serialization language, and the full YAML language spec can be read at
27`yaml.org
28<http://www.yaml.org/spec/1.2/spec.html#Introduction>`_.
29
30A MIR file is split up into a series of `YAML documents`_. The first document
31can contain an optional embedded LLVM IR module, and the rest of the documents
32contain the serialized machine functions.
33
34.. _YAML documents: http://www.yaml.org/spec/1.2/spec.html#id2800132
35
Alex Lorenzea788c42015-08-21 22:58:33 +000036MIR Testing Guide
37=================
38
39You can use the MIR format for testing in two different ways:
40
41- You can write MIR tests that invoke a single code generation pass using the
Matthias Braune6185b72017-04-13 22:14:45 +000042 ``-run-pass`` option in llc.
Alex Lorenzea788c42015-08-21 22:58:33 +000043
Matthias Braune6185b72017-04-13 22:14:45 +000044- You can use llc's ``-stop-after`` option with existing or new LLVM assembly
Alex Lorenzea788c42015-08-21 22:58:33 +000045 tests and check the MIR output of a specific code generation pass.
46
47Testing Individual Code Generation Passes
48-----------------------------------------
49
Matthias Braune6185b72017-04-13 22:14:45 +000050The ``-run-pass`` option in llc allows you to create MIR tests that invoke just
51a single code generation pass. When this option is used, llc will parse an
52input MIR file, run the specified code generation pass(es), and output the
53resulting MIR code.
Alex Lorenzea788c42015-08-21 22:58:33 +000054
Matthias Braune6185b72017-04-13 22:14:45 +000055You can generate an input MIR file for the test by using the ``-stop-after`` or
56``-stop-before`` option in llc. For example, if you would like to write a test
57for the post register allocation pseudo instruction expansion pass, you can
58specify the machine copy propagation pass in the ``-stop-after`` option, as it
59runs just before the pass that we are trying to test:
Alex Lorenzea788c42015-08-21 22:58:33 +000060
Matthias Braune6185b72017-04-13 22:14:45 +000061 ``llc -stop-after=machine-cp bug-trigger.ll > test.mir``
Alex Lorenzea788c42015-08-21 22:58:33 +000062
63After generating the input MIR file, you'll have to add a run line that uses
64the ``-run-pass`` option to it. In order to test the post register allocation
65pseudo instruction expansion pass on X86-64, a run line like the one shown
66below can be used:
67
Matthias Braune6185b72017-04-13 22:14:45 +000068 ``# RUN: llc -o - %s -mtriple=x86_64-- -run-pass=postrapseudos | FileCheck %s``
Alex Lorenzea788c42015-08-21 22:58:33 +000069
70The MIR files are target dependent, so they have to be placed in the target
Matthias Braune6185b72017-04-13 22:14:45 +000071specific test directories (``lib/CodeGen/TARGETNAME``). They also need to
72specify a target triple or a target architecture either in the run line or in
73the embedded LLVM IR module.
Alex Lorenzea788c42015-08-21 22:58:33 +000074
Matthias Braun836c3832017-04-13 23:45:14 +000075Simplifying MIR files
76^^^^^^^^^^^^^^^^^^^^^
77
78The MIR code coming out of ``-stop-after``/``-stop-before`` is very verbose;
79Tests are more accessible and future proof when simplified:
80
Matthias Braun89401142017-05-05 21:09:30 +000081- Use the ``-simplify-mir`` option with llc.
82
Matthias Braun836c3832017-04-13 23:45:14 +000083- Machine function attributes often have default values or the test works just
84 as well with default values. Typical candidates for this are: `alignment:`,
85 `exposesReturnsTwice`, `legalized`, `regBankSelected`, `selected`.
86 The whole `frameInfo` section is often unnecessary if there is no special
87 frame usage in the function. `tracksRegLiveness` on the other hand is often
88 necessary for some passes that care about block livein lists.
89
90- The (global) `liveins:` list is typically only interesting for early
91 instruction selection passes and can be removed when testing later passes.
92 The per-block `liveins:` on the other hand are necessary if
93 `tracksRegLiveness` is true.
94
95- Branch probability data in block `successors:` lists can be dropped if the
96 test doesn't depend on it. Example:
97 `successors: %bb.1(0x40000000), %bb.2(0x40000000)` can be replaced with
98 `successors: %bb.1, %bb.2`.
99
100- MIR code contains a whole IR module. This is necessary because there are
101 no equivalents in MIR for global variables, references to external functions,
102 function attributes, metadata, debug info. Instead some MIR data references
103 the IR constructs. You can often remove them if the test doesn't depend on
104 them.
105
106- Alias Analysis is performed on IR values. These are referenced by memory
107 operands in MIR. Example: `:: (load 8 from %ir.foobar, !alias.scope !9)`.
108 If the test doesn't depend on (good) alias analysis the references can be
109 dropped: `:: (load 8)`
110
111- MIR blocks can reference IR blocks for debug printing, profile information
112 or debug locations. Example: `bb.42.myblock` in MIR references the IR block
113 `myblock`. It is usually possible to drop the `.myblock` reference and simply
114 use `bb.42`.
115
116- If there are no memory operands or blocks referencing the IR then the
117 IR function can be replaced by a parameterless dummy function like
118 `define @func() { ret void }`.
119
120- It is possible to drop the whole IR section of the MIR file if it only
121 contains dummy functions (see above). The .mir loader will create the
122 IR functions automatically in this case.
123
Francis Visoiu Mistrih3c993712017-12-14 10:03:23 +0000124.. _limitations:
125
Alex Lorenzea788c42015-08-21 22:58:33 +0000126Limitations
127-----------
128
129Currently the MIR format has several limitations in terms of which state it
130can serialize:
131
132- The target-specific state in the target-specific ``MachineFunctionInfo``
133 subclasses isn't serialized at the moment.
134
135- The target-specific ``MachineConstantPoolValue`` subclasses (in the ARM and
136 SystemZ backends) aren't serialized at the moment.
137
138- The ``MCSymbol`` machine operands are only printed, they can't be parsed.
139
140- A lot of the state in ``MachineModuleInfo`` isn't serialized - only the CFI
141 instructions and the variable debug information from MMI is serialized right
142 now.
143
144These limitations impose restrictions on what you can test with the MIR format.
145For now, tests that would like to test some behaviour that depends on the state
146of certain ``MCSymbol`` operands or the exception handling state in MMI, can't
147use the MIR format. As well as that, tests that test some behaviour that
148depends on the state of the target specific ``MachineFunctionInfo`` or
149``MachineConstantPoolValue`` subclasses can't use the MIR format at the moment.
150
Alex Lorenz3d311772015-08-06 22:55:19 +0000151High Level Structure
152====================
153
Alex Lorenzd4990eb2015-09-08 11:38:16 +0000154.. _embedded-module:
155
Alex Lorenz3d311772015-08-06 22:55:19 +0000156Embedded Module
157---------------
158
159When the first YAML document contains a `YAML block literal string`_, the MIR
160parser will treat this string as an LLVM assembly language string that
161represents an embedded LLVM IR module.
162Here is an example of a YAML document that contains an LLVM module:
163
164.. code-block:: llvm
165
Alex Lorenz3d311772015-08-06 22:55:19 +0000166 define i32 @inc(i32* %x) {
167 entry:
168 %0 = load i32, i32* %x
169 %1 = add i32 %0, 1
170 store i32 %1, i32* %x
171 ret i32 %1
172 }
Alex Lorenz3d311772015-08-06 22:55:19 +0000173
174.. _YAML block literal string: http://www.yaml.org/spec/1.2/spec.html#id2795688
175
176Machine Functions
177-----------------
178
179The remaining YAML documents contain the machine functions. This is an example
180of such YAML document:
181
Renato Golin124f2592016-07-20 12:16:38 +0000182.. code-block:: text
Alex Lorenz3d311772015-08-06 22:55:19 +0000183
184 ---
185 name: inc
186 tracksRegLiveness: true
187 liveins:
188 - { reg: '%rdi' }
Alex Lorenz98461672015-08-14 00:36:10 +0000189 body: |
190 bb.0.entry:
191 liveins: %rdi
192
193 %eax = MOV32rm %rdi, 1, _, 0, _
194 %eax = INC32r killed %eax, implicit-def dead %eflags
195 MOV32mr killed %rdi, 1, _, 0, _, %eax
196 RETQ %eax
Alex Lorenz3d311772015-08-06 22:55:19 +0000197 ...
198
199The document above consists of attributes that represent the various
200properties and data structures in a machine function.
201
202The attribute ``name`` is required, and its value should be identical to the
203name of a function that this machine function is based on.
204
Alex Lorenz98461672015-08-14 00:36:10 +0000205The attribute ``body`` is a `YAML block literal string`_. Its value represents
206the function's machine basic blocks and their machine instructions.
Alex Lorenz3d311772015-08-06 22:55:19 +0000207
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000208Machine Instructions Format Reference
209=====================================
210
211The machine basic blocks and their instructions are represented using a custom,
212human readable serialization language. This language is used in the
213`YAML block literal string`_ that corresponds to the machine function's body.
214
215A source string that uses this language contains a list of machine basic
216blocks, which are described in the section below.
217
218Machine Basic Blocks
219--------------------
220
221A machine basic block is defined in a single block definition source construct
222that contains the block's ID.
223The example below defines two blocks that have an ID of zero and one:
224
Renato Golin124f2592016-07-20 12:16:38 +0000225.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000226
227 bb.0:
228 <instructions>
229 bb.1:
230 <instructions>
231
232A machine basic block can also have a name. It should be specified after the ID
233in the block's definition:
234
Renato Golin124f2592016-07-20 12:16:38 +0000235.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000236
237 bb.0.entry: ; This block's name is "entry"
238 <instructions>
239
240The block's name should be identical to the name of the IR block that this
241machine block is based on.
242
Francis Visoiu Mistrihb41dbbe2017-12-13 10:30:59 +0000243.. _block-references:
244
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000245Block References
246^^^^^^^^^^^^^^^^
247
248The machine basic blocks are identified by their ID numbers. Individual
249blocks are referenced using the following syntax:
250
Renato Golin124f2592016-07-20 12:16:38 +0000251.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000252
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000253 %bb.<id>
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000254
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000255Example:
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000256
257.. code-block:: llvm
258
259 %bb.0
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000260
261The following syntax is also supported, but the former syntax is preferred for
262block references:
263
264.. code-block:: text
265
266 %bb.<id>[.<name>]
267
268Example:
269
270.. code-block:: llvm
271
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000272 %bb.1.then
273
274Successors
275^^^^^^^^^^
276
277The machine basic block's successors have to be specified before any of the
278instructions:
279
Renato Golin124f2592016-07-20 12:16:38 +0000280.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000281
282 bb.0.entry:
283 successors: %bb.1.then, %bb.2.else
284 <instructions>
285 bb.1.then:
286 <instructions>
287 bb.2.else:
288 <instructions>
289
290The branch weights can be specified in brackets after the successor blocks.
291The example below defines a block that has two successors with branch weights
292of 32 and 16:
293
Renato Golin124f2592016-07-20 12:16:38 +0000294.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000295
296 bb.0.entry:
297 successors: %bb.1.then(32), %bb.2.else(16)
298
Alex Lorenzb981d372015-08-21 21:17:01 +0000299.. _bb-liveins:
300
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000301Live In Registers
302^^^^^^^^^^^^^^^^^
303
304The machine basic block's live in registers have to be specified before any of
305the instructions:
306
Renato Golin124f2592016-07-20 12:16:38 +0000307.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000308
309 bb.0.entry:
310 liveins: %edi, %esi
311
312The list of live in registers and successors can be empty. The language also
313allows multiple live in register and successor lists - they are combined into
314one list by the parser.
315
316Miscellaneous Attributes
317^^^^^^^^^^^^^^^^^^^^^^^^
318
319The attributes ``IsAddressTaken``, ``IsLandingPad`` and ``Alignment`` can be
320specified in brackets after the block's definition:
321
Renato Golin124f2592016-07-20 12:16:38 +0000322.. code-block:: text
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000323
324 bb.0.entry (address-taken):
325 <instructions>
326 bb.2.else (align 4):
327 <instructions>
328 bb.3(landing-pad, align 4):
329 <instructions>
330
331.. TODO: Describe the way the reference to an unnamed LLVM IR block can be
332 preserved.
333
Alex Lorenz8eadc3f2015-08-21 17:26:38 +0000334Machine Instructions
335--------------------
336
Alex Lorenzb981d372015-08-21 21:17:01 +0000337A machine instruction is composed of a name,
338:ref:`machine operands <machine-operands>`,
Alex Lorenz8eadc3f2015-08-21 17:26:38 +0000339:ref:`instruction flags <instruction-flags>`, and machine memory operands.
340
341The instruction's name is usually specified before the operands. The example
342below shows an instance of the X86 ``RETQ`` instruction with a single machine
343operand:
344
Renato Golin124f2592016-07-20 12:16:38 +0000345.. code-block:: text
Alex Lorenz8eadc3f2015-08-21 17:26:38 +0000346
347 RETQ %eax
348
349However, if the machine instruction has one or more explicitly defined register
350operands, the instruction's name has to be specified after them. The example
351below shows an instance of the AArch64 ``LDPXpost`` instruction with three
352defined register operands:
353
Renato Golin124f2592016-07-20 12:16:38 +0000354.. code-block:: text
Alex Lorenz8eadc3f2015-08-21 17:26:38 +0000355
356 %sp, %fp, %lr = LDPXpost %sp, 2
357
358The instruction names are serialized using the exact definitions from the
359target's ``*InstrInfo.td`` files, and they are case sensitive. This means that
360similar instruction names like ``TSTri`` and ``tSTRi`` represent different
361machine instructions.
362
363.. _instruction-flags:
364
365Instruction Flags
366^^^^^^^^^^^^^^^^^
367
368The flag ``frame-setup`` can be specified before the instruction's name:
369
Renato Golin124f2592016-07-20 12:16:38 +0000370.. code-block:: text
Alex Lorenz8eadc3f2015-08-21 17:26:38 +0000371
372 %fp = frame-setup ADDXri %sp, 0, 0
373
Alex Lorenzb981d372015-08-21 21:17:01 +0000374.. _registers:
375
376Registers
377---------
378
379Registers are one of the key primitives in the machine instructions
380serialization language. They are primarly used in the
381:ref:`register machine operands <register-operands>`,
382but they can also be used in a number of other places, like the
383:ref:`basic block's live in list <bb-liveins>`.
384
385The physical registers are identified by their name. They use the following
386syntax:
387
Renato Golin124f2592016-07-20 12:16:38 +0000388.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000389
390 %<name>
391
392The example below shows three X86 physical registers:
393
Renato Golin124f2592016-07-20 12:16:38 +0000394.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000395
396 %eax
397 %r15
398 %eflags
399
400The virtual registers are identified by their ID number. They use the following
401syntax:
402
Renato Golin124f2592016-07-20 12:16:38 +0000403.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000404
405 %<id>
406
407Example:
408
Renato Golin124f2592016-07-20 12:16:38 +0000409.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000410
411 %0
412
413The null registers are represented using an underscore ('``_``'). They can also be
414represented using a '``%noreg``' named register, although the former syntax
415is preferred.
416
417.. _machine-operands:
418
419Machine Operands
420----------------
421
422There are seventeen different kinds of machine operands, and all of them, except
423the ``MCSymbol`` operand, can be serialized. The ``MCSymbol`` operands are
424just printed out - they can't be parsed back yet.
425
426Immediate Operands
427^^^^^^^^^^^^^^^^^^
428
429The immediate machine operands are untyped, 64-bit signed integers. The
430example below shows an instance of the X86 ``MOV32ri`` instruction that has an
431immediate machine operand ``-42``:
432
Renato Golin124f2592016-07-20 12:16:38 +0000433.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000434
435 %eax = MOV32ri -42
436
Francis Visoiu Mistrih440f69c2017-12-08 22:53:21 +0000437An immediate operand is also used to represent a subregister index when the
438machine instruction has one of the following opcodes:
439
440- ``EXTRACT_SUBREG``
441
442- ``INSERT_SUBREG``
443
444- ``REG_SEQUENCE``
445
446- ``SUBREG_TO_REG``
447
448In case this is true, the Machine Operand is printed according to the target.
449
450For example:
451
452In AArch64RegisterInfo.td:
453
454.. code-block:: text
455
456 def sub_32 : SubRegIndex<32>;
457
458If the third operand is an immediate with the value ``15`` (target-dependent
459value), based on the instruction's opcode and the operand's index the operand
460will be printed as ``%subreg.sub_32``:
461
462.. code-block:: text
463
464 %1:gpr64 = SUBREG_TO_REG 0, %0, %subreg.sub_32
465
Francis Visoiu Mistrih6c4ca712017-12-08 11:40:06 +0000466For integers > 64bit, we use a special machine operand, ``MO_CImmediate``,
467which stores the immediate in a ``ConstantInt`` using an ``APInt`` (LLVM's
468arbitrary precision integers).
469
470.. TODO: Describe the FPIMM immediate operands.
Alex Lorenzb981d372015-08-21 21:17:01 +0000471
472.. _register-operands:
473
474Register Operands
475^^^^^^^^^^^^^^^^^
476
477The :ref:`register <registers>` primitive is used to represent the register
478machine operands. The register operands can also have optional
479:ref:`register flags <register-flags>`,
Alex Lorenz37e02622015-09-08 11:39:47 +0000480:ref:`a subregister index <subregister-indices>`,
481and a reference to the tied register operand.
Alex Lorenzb981d372015-08-21 21:17:01 +0000482The full syntax of a register operand is shown below:
483
Renato Golin124f2592016-07-20 12:16:38 +0000484.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000485
486 [<flags>] <register> [ :<subregister-idx-name> ] [ (tied-def <tied-op>) ]
487
488This example shows an instance of the X86 ``XOR32rr`` instruction that has
4895 register operands with different register flags:
490
Renato Golin124f2592016-07-20 12:16:38 +0000491.. code-block:: text
Alex Lorenzb981d372015-08-21 21:17:01 +0000492
493 dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al
494
495.. _register-flags:
496
497Register Flags
498~~~~~~~~~~~~~~
499
500The table below shows all of the possible register flags along with the
501corresponding internal ``llvm::RegState`` representation:
502
503.. list-table::
504 :header-rows: 1
505
506 * - Flag
507 - Internal Value
508
509 * - ``implicit``
510 - ``RegState::Implicit``
511
512 * - ``implicit-def``
513 - ``RegState::ImplicitDefine``
514
515 * - ``def``
516 - ``RegState::Define``
517
518 * - ``dead``
519 - ``RegState::Dead``
520
521 * - ``killed``
522 - ``RegState::Kill``
523
524 * - ``undef``
525 - ``RegState::Undef``
526
527 * - ``internal``
528 - ``RegState::InternalRead``
529
530 * - ``early-clobber``
531 - ``RegState::EarlyClobber``
532
533 * - ``debug-use``
534 - ``RegState::Debug``
Alex Lorenz3a4a60c2015-08-15 01:06:06 +0000535
Geoff Berry60c43102017-12-12 17:53:59 +0000536 * - ``renamable``
537 - ``RegState::Renamable``
538
Alex Lorenz37e02622015-09-08 11:39:47 +0000539.. _subregister-indices:
540
541Subregister Indices
542~~~~~~~~~~~~~~~~~~~
543
544The register machine operands can reference a portion of a register by using
545the subregister indices. The example below shows an instance of the ``COPY``
546pseudo instruction that uses the X86 ``sub_8bit`` subregister index to copy 8
547lower bits from the 32-bit virtual register 0 to the 8-bit virtual register 1:
548
Renato Golin124f2592016-07-20 12:16:38 +0000549.. code-block:: text
Alex Lorenz37e02622015-09-08 11:39:47 +0000550
551 %1 = COPY %0:sub_8bit
552
553The names of the subregister indices are target specific, and are typically
554defined in the target's ``*RegisterInfo.td`` file.
555
Francis Visoiu Mistrih26ae8a62017-12-13 10:30:45 +0000556Constant Pool Indices
557^^^^^^^^^^^^^^^^^^^^^
558
559A constant pool index (CPI) operand is printed using its index in the
560function's ``MachineConstantPool`` and an offset.
561
562For example, a CPI with the index 1 and offset 8:
563
564.. code-block:: text
565
566 %1:gr64 = MOV64ri %const.1 + 8
567
568For a CPI with the index 0 and offset -12:
569
570.. code-block:: text
571
572 %1:gr64 = MOV64ri %const.0 - 12
573
574A constant pool entry is bound to a LLVM IR ``Constant`` or a target-specific
575``MachineConstantPoolValue``. When serializing all the function's constants the
576following format is used:
577
578.. code-block:: text
579
580 constants:
581 - id: <index>
582 value: <value>
583 alignment: <alignment>
584 isTargetSpecific: <target-specific>
585
586where ``<index>`` is a 32-bit unsigned integer, ``<value>`` is a `LLVM IR Constant
587<https://www.llvm.org/docs/LangRef.html#constants>`_, alignment is a 32-bit
588unsigned integer, and ``<target-specific>`` is either true or false.
589
590Example:
591
592.. code-block:: text
593
594 constants:
595 - id: 0
596 value: 'double 3.250000e+00'
597 alignment: 8
598 - id: 1
599 value: 'g-(LPC0+8)'
600 alignment: 4
601 isTargetSpecific: true
602
Alex Lorenzd4990eb2015-09-08 11:38:16 +0000603Global Value Operands
604^^^^^^^^^^^^^^^^^^^^^
605
606The global value machine operands reference the global values from the
607:ref:`embedded LLVM IR module <embedded-module>`.
608The example below shows an instance of the X86 ``MOV64rm`` instruction that has
609a global value operand named ``G``:
610
Renato Golin124f2592016-07-20 12:16:38 +0000611.. code-block:: text
Alex Lorenzd4990eb2015-09-08 11:38:16 +0000612
613 %rax = MOV64rm %rip, 1, _, @G, _
614
615The named global values are represented using an identifier with the '@' prefix.
616If the identifier doesn't match the regular expression
617`[-a-zA-Z$._][-a-zA-Z$._0-9]*`, then this identifier must be quoted.
618
619The unnamed global values are represented using an unsigned numeric value with
620the '@' prefix, like in the following examples: ``@0``, ``@989``.
621
Francis Visoiu Mistrihb3a0d512017-12-13 10:30:51 +0000622Target-dependent Index Operands
623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
624
625A target index operand is a target-specific index and an offset. The
626target-specific index is printed using target-specific names and a positive or
627negative offset.
628
629For example, the ``amdgpu-constdata-start`` is associated with the index ``0``
630in the AMDGPU backend. So if we have a target index operand with the index 0
631and the offset 8:
632
633.. code-block:: text
634
635 %sgpr2 = S_ADD_U32 _, target-index(amdgpu-constdata-start) + 8, implicit-def _, implicit-def _
636
Francis Visoiu Mistrihb41dbbe2017-12-13 10:30:59 +0000637Jump-table Index Operands
638^^^^^^^^^^^^^^^^^^^^^^^^^
639
640A jump-table index operand with the index 0 is printed as following:
641
642.. code-block:: text
643
644 tBR_JTr killed %r0, %jump-table.0
645
646A machine jump-table entry contains a list of ``MachineBasicBlocks``. When serializing all the function's jump-table entries, the following format is used:
647
648.. code-block:: text
649
650 jumpTable:
651 kind: <kind>
652 entries:
653 - id: <index>
654 blocks: [ <bbreference>, <bbreference>, ... ]
655
656where ``<kind>`` is describing how the jump table is represented and emitted (plain address, relocations, PIC, etc.), and each ``<index>`` is a 32-bit unsigned integer and ``blocks`` contains a list of :ref:`machine basic block references <block-references>`.
657
658Example:
659
660.. code-block:: text
661
662 jumpTable:
663 kind: inline
664 entries:
665 - id: 0
666 blocks: [ '%bb.3', '%bb.9', '%bb.4.d3' ]
667 - id: 1
668 blocks: [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ]
669
Francis Visoiu Mistrihe76c5fc2017-12-14 10:02:58 +0000670External Symbol Operands
671^^^^^^^^^^^^^^^^^^^^^^^^^
672
673An external symbol operand is represented using an identifier with the ``$``
674prefix. The identifier is surrounded with ""'s and escaped if it has any
675special non-printable characters in it.
676
677Example:
678
679.. code-block:: text
680
681 CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp
682
Francis Visoiu Mistrih3c993712017-12-14 10:03:23 +0000683MCSymbol Operands
684^^^^^^^^^^^^^^^^^
685
686A MCSymbol operand is holding a pointer to a ``MCSymbol``. For the limitations
687of this operand in MIR, see :ref:`limitations <limitations>`.
688
689The syntax is:
690
691.. code-block:: text
692
693 EH_LABEL <mcsymbol Ltmp1>
Francis Visoiu Mistrihe76c5fc2017-12-14 10:02:58 +0000694
Francis Visoiu Mistrih874ae6f2017-12-19 16:51:52 +0000695CFIIndex Operands
696^^^^^^^^^^^^^^^^^
697
698A CFI Index operand is holding an index into a per-function side-table,
699``MachineFunction::getFrameInstructions()``, which references all the frame
700instructions in a ``MachineFunction``. A ``CFI_INSTRUCTION`` may look like it
701contains multiple operands, but the only operand it contains is the CFI Index.
702The other operands are tracked by the ``MCCFIInstruction`` object.
703
704The syntax is:
705
706.. code-block:: text
707
708 CFI_INSTRUCTION offset %w30, -16
709
710which may be emitted later in the MC layer as:
711
712.. code-block:: text
713
714 .cfi_offset w30, -16
715
Alex Lorenz3d311772015-08-06 22:55:19 +0000716.. TODO: Describe the parsers default behaviour when optional YAML attributes
717 are missing.
Alex Lorenz8eadc3f2015-08-21 17:26:38 +0000718.. TODO: Describe the syntax for the bundled instructions.
Alex Lorenzb981d372015-08-21 21:17:01 +0000719.. TODO: Describe the syntax for virtual register YAML definitions.
Alex Lorenz3d311772015-08-06 22:55:19 +0000720.. TODO: Describe the machine function's YAML flag attributes.
Francis Visoiu Mistrihe76c5fc2017-12-14 10:02:58 +0000721.. TODO: Describe the syntax for the register mask machine operands.
Alex Lorenz3d311772015-08-06 22:55:19 +0000722.. TODO: Describe the frame information YAML mapping.
723.. TODO: Describe the syntax of the stack object machine operands and their
724 YAML definitions.
Alex Lorenz3d311772015-08-06 22:55:19 +0000725.. TODO: Describe the syntax of the block address machine operands.
Alex Lorenz3d311772015-08-06 22:55:19 +0000726.. TODO: Describe the syntax of the metadata machine operands, and the
727 instructions debug location attribute.
Alex Lorenz3d311772015-08-06 22:55:19 +0000728.. TODO: Describe the syntax of the register live out machine operands.
729.. TODO: Describe the syntax of the machine memory operands.