Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 1 | ======================================== |
| 2 | Machine IR (MIR) Format Reference Manual |
| 3 | ======================================== |
| 4 | |
| 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | .. warning:: |
| 9 | This is a work in progress. |
| 10 | |
| 11 | Introduction |
| 12 | ============ |
| 13 | |
| 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>`. |
| 18 | |
| 19 | The MIR serialization format is designed to be used for testing the code |
| 20 | generation passes in LLVM. |
| 21 | |
| 22 | Overview |
| 23 | ======== |
| 24 | |
| 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 |
| 27 | `yaml.org |
| 28 | <http://www.yaml.org/spec/1.2/spec.html#Introduction>`_. |
| 29 | |
| 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. |
| 33 | |
| 34 | .. _YAML documents: http://www.yaml.org/spec/1.2/spec.html#id2800132 |
| 35 | |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 36 | MIR Testing Guide |
| 37 | ================= |
| 38 | |
| 39 | You 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 Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 42 | ``-run-pass`` option in llc. |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 43 | |
Matthias Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 44 | - You can use llc's ``-stop-after`` option with existing or new LLVM assembly |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 45 | tests and check the MIR output of a specific code generation pass. |
| 46 | |
| 47 | Testing Individual Code Generation Passes |
| 48 | ----------------------------------------- |
| 49 | |
Matthias Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 50 | The ``-run-pass`` option in llc allows you to create MIR tests that invoke just |
| 51 | a single code generation pass. When this option is used, llc will parse an |
| 52 | input MIR file, run the specified code generation pass(es), and output the |
| 53 | resulting MIR code. |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 54 | |
Matthias Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 55 | You 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 |
| 57 | for the post register allocation pseudo instruction expansion pass, you can |
| 58 | specify the machine copy propagation pass in the ``-stop-after`` option, as it |
| 59 | runs just before the pass that we are trying to test: |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 60 | |
Matthias Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 61 | ``llc -stop-after=machine-cp bug-trigger.ll > test.mir`` |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 62 | |
| 63 | After generating the input MIR file, you'll have to add a run line that uses |
| 64 | the ``-run-pass`` option to it. In order to test the post register allocation |
| 65 | pseudo instruction expansion pass on X86-64, a run line like the one shown |
| 66 | below can be used: |
| 67 | |
Matthias Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 68 | ``# RUN: llc -o - %s -mtriple=x86_64-- -run-pass=postrapseudos | FileCheck %s`` |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 69 | |
| 70 | The MIR files are target dependent, so they have to be placed in the target |
Matthias Braun | e6185b7 | 2017-04-13 22:14:45 +0000 | [diff] [blame] | 71 | specific test directories (``lib/CodeGen/TARGETNAME``). They also need to |
| 72 | specify a target triple or a target architecture either in the run line or in |
| 73 | the embedded LLVM IR module. |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 74 | |
Matthias Braun | 836c383 | 2017-04-13 23:45:14 +0000 | [diff] [blame] | 75 | Simplifying MIR files |
| 76 | ^^^^^^^^^^^^^^^^^^^^^ |
| 77 | |
| 78 | The MIR code coming out of ``-stop-after``/``-stop-before`` is very verbose; |
| 79 | Tests are more accessible and future proof when simplified: |
| 80 | |
Matthias Braun | 8940114 | 2017-05-05 21:09:30 +0000 | [diff] [blame] | 81 | - Use the ``-simplify-mir`` option with llc. |
| 82 | |
Matthias Braun | 836c383 | 2017-04-13 23:45:14 +0000 | [diff] [blame] | 83 | - 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 | |
Alex Lorenz | ea788c4 | 2015-08-21 22:58:33 +0000 | [diff] [blame] | 124 | Limitations |
| 125 | ----------- |
| 126 | |
| 127 | Currently the MIR format has several limitations in terms of which state it |
| 128 | can serialize: |
| 129 | |
| 130 | - The target-specific state in the target-specific ``MachineFunctionInfo`` |
| 131 | subclasses isn't serialized at the moment. |
| 132 | |
| 133 | - The target-specific ``MachineConstantPoolValue`` subclasses (in the ARM and |
| 134 | SystemZ backends) aren't serialized at the moment. |
| 135 | |
| 136 | - The ``MCSymbol`` machine operands are only printed, they can't be parsed. |
| 137 | |
| 138 | - A lot of the state in ``MachineModuleInfo`` isn't serialized - only the CFI |
| 139 | instructions and the variable debug information from MMI is serialized right |
| 140 | now. |
| 141 | |
| 142 | These limitations impose restrictions on what you can test with the MIR format. |
| 143 | For now, tests that would like to test some behaviour that depends on the state |
| 144 | of certain ``MCSymbol`` operands or the exception handling state in MMI, can't |
| 145 | use the MIR format. As well as that, tests that test some behaviour that |
| 146 | depends on the state of the target specific ``MachineFunctionInfo`` or |
| 147 | ``MachineConstantPoolValue`` subclasses can't use the MIR format at the moment. |
| 148 | |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 149 | High Level Structure |
| 150 | ==================== |
| 151 | |
Alex Lorenz | d4990eb | 2015-09-08 11:38:16 +0000 | [diff] [blame] | 152 | .. _embedded-module: |
| 153 | |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 154 | Embedded Module |
| 155 | --------------- |
| 156 | |
| 157 | When the first YAML document contains a `YAML block literal string`_, the MIR |
| 158 | parser will treat this string as an LLVM assembly language string that |
| 159 | represents an embedded LLVM IR module. |
| 160 | Here is an example of a YAML document that contains an LLVM module: |
| 161 | |
| 162 | .. code-block:: llvm |
| 163 | |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 164 | define i32 @inc(i32* %x) { |
| 165 | entry: |
| 166 | %0 = load i32, i32* %x |
| 167 | %1 = add i32 %0, 1 |
| 168 | store i32 %1, i32* %x |
| 169 | ret i32 %1 |
| 170 | } |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 171 | |
| 172 | .. _YAML block literal string: http://www.yaml.org/spec/1.2/spec.html#id2795688 |
| 173 | |
| 174 | Machine Functions |
| 175 | ----------------- |
| 176 | |
| 177 | The remaining YAML documents contain the machine functions. This is an example |
| 178 | of such YAML document: |
| 179 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 180 | .. code-block:: text |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 181 | |
| 182 | --- |
| 183 | name: inc |
| 184 | tracksRegLiveness: true |
| 185 | liveins: |
| 186 | - { reg: '%rdi' } |
Alex Lorenz | 9846167 | 2015-08-14 00:36:10 +0000 | [diff] [blame] | 187 | body: | |
| 188 | bb.0.entry: |
| 189 | liveins: %rdi |
| 190 | |
| 191 | %eax = MOV32rm %rdi, 1, _, 0, _ |
| 192 | %eax = INC32r killed %eax, implicit-def dead %eflags |
| 193 | MOV32mr killed %rdi, 1, _, 0, _, %eax |
| 194 | RETQ %eax |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 195 | ... |
| 196 | |
| 197 | The document above consists of attributes that represent the various |
| 198 | properties and data structures in a machine function. |
| 199 | |
| 200 | The attribute ``name`` is required, and its value should be identical to the |
| 201 | name of a function that this machine function is based on. |
| 202 | |
Alex Lorenz | 9846167 | 2015-08-14 00:36:10 +0000 | [diff] [blame] | 203 | The attribute ``body`` is a `YAML block literal string`_. Its value represents |
| 204 | the function's machine basic blocks and their machine instructions. |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 205 | |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 206 | Machine Instructions Format Reference |
| 207 | ===================================== |
| 208 | |
| 209 | The machine basic blocks and their instructions are represented using a custom, |
| 210 | human readable serialization language. This language is used in the |
| 211 | `YAML block literal string`_ that corresponds to the machine function's body. |
| 212 | |
| 213 | A source string that uses this language contains a list of machine basic |
| 214 | blocks, which are described in the section below. |
| 215 | |
| 216 | Machine Basic Blocks |
| 217 | -------------------- |
| 218 | |
| 219 | A machine basic block is defined in a single block definition source construct |
| 220 | that contains the block's ID. |
| 221 | The example below defines two blocks that have an ID of zero and one: |
| 222 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 223 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 224 | |
| 225 | bb.0: |
| 226 | <instructions> |
| 227 | bb.1: |
| 228 | <instructions> |
| 229 | |
| 230 | A machine basic block can also have a name. It should be specified after the ID |
| 231 | in the block's definition: |
| 232 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 233 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 234 | |
| 235 | bb.0.entry: ; This block's name is "entry" |
| 236 | <instructions> |
| 237 | |
| 238 | The block's name should be identical to the name of the IR block that this |
| 239 | machine block is based on. |
| 240 | |
| 241 | Block References |
| 242 | ^^^^^^^^^^^^^^^^ |
| 243 | |
| 244 | The machine basic blocks are identified by their ID numbers. Individual |
| 245 | blocks are referenced using the following syntax: |
| 246 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 247 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 248 | |
| 249 | %bb.<id>[.<name>] |
| 250 | |
| 251 | Examples: |
| 252 | |
| 253 | .. code-block:: llvm |
| 254 | |
| 255 | %bb.0 |
| 256 | %bb.1.then |
| 257 | |
| 258 | Successors |
| 259 | ^^^^^^^^^^ |
| 260 | |
| 261 | The machine basic block's successors have to be specified before any of the |
| 262 | instructions: |
| 263 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 264 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 265 | |
| 266 | bb.0.entry: |
| 267 | successors: %bb.1.then, %bb.2.else |
| 268 | <instructions> |
| 269 | bb.1.then: |
| 270 | <instructions> |
| 271 | bb.2.else: |
| 272 | <instructions> |
| 273 | |
| 274 | The branch weights can be specified in brackets after the successor blocks. |
| 275 | The example below defines a block that has two successors with branch weights |
| 276 | of 32 and 16: |
| 277 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 278 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 279 | |
| 280 | bb.0.entry: |
| 281 | successors: %bb.1.then(32), %bb.2.else(16) |
| 282 | |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 283 | .. _bb-liveins: |
| 284 | |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 285 | Live In Registers |
| 286 | ^^^^^^^^^^^^^^^^^ |
| 287 | |
| 288 | The machine basic block's live in registers have to be specified before any of |
| 289 | the instructions: |
| 290 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 291 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 292 | |
| 293 | bb.0.entry: |
| 294 | liveins: %edi, %esi |
| 295 | |
| 296 | The list of live in registers and successors can be empty. The language also |
| 297 | allows multiple live in register and successor lists - they are combined into |
| 298 | one list by the parser. |
| 299 | |
| 300 | Miscellaneous Attributes |
| 301 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 302 | |
| 303 | The attributes ``IsAddressTaken``, ``IsLandingPad`` and ``Alignment`` can be |
| 304 | specified in brackets after the block's definition: |
| 305 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 306 | .. code-block:: text |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 307 | |
| 308 | bb.0.entry (address-taken): |
| 309 | <instructions> |
| 310 | bb.2.else (align 4): |
| 311 | <instructions> |
| 312 | bb.3(landing-pad, align 4): |
| 313 | <instructions> |
| 314 | |
| 315 | .. TODO: Describe the way the reference to an unnamed LLVM IR block can be |
| 316 | preserved. |
| 317 | |
Alex Lorenz | 8eadc3f | 2015-08-21 17:26:38 +0000 | [diff] [blame] | 318 | Machine Instructions |
| 319 | -------------------- |
| 320 | |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 321 | A machine instruction is composed of a name, |
| 322 | :ref:`machine operands <machine-operands>`, |
Alex Lorenz | 8eadc3f | 2015-08-21 17:26:38 +0000 | [diff] [blame] | 323 | :ref:`instruction flags <instruction-flags>`, and machine memory operands. |
| 324 | |
| 325 | The instruction's name is usually specified before the operands. The example |
| 326 | below shows an instance of the X86 ``RETQ`` instruction with a single machine |
| 327 | operand: |
| 328 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 329 | .. code-block:: text |
Alex Lorenz | 8eadc3f | 2015-08-21 17:26:38 +0000 | [diff] [blame] | 330 | |
| 331 | RETQ %eax |
| 332 | |
| 333 | However, if the machine instruction has one or more explicitly defined register |
| 334 | operands, the instruction's name has to be specified after them. The example |
| 335 | below shows an instance of the AArch64 ``LDPXpost`` instruction with three |
| 336 | defined register operands: |
| 337 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 338 | .. code-block:: text |
Alex Lorenz | 8eadc3f | 2015-08-21 17:26:38 +0000 | [diff] [blame] | 339 | |
| 340 | %sp, %fp, %lr = LDPXpost %sp, 2 |
| 341 | |
| 342 | The instruction names are serialized using the exact definitions from the |
| 343 | target's ``*InstrInfo.td`` files, and they are case sensitive. This means that |
| 344 | similar instruction names like ``TSTri`` and ``tSTRi`` represent different |
| 345 | machine instructions. |
| 346 | |
| 347 | .. _instruction-flags: |
| 348 | |
| 349 | Instruction Flags |
| 350 | ^^^^^^^^^^^^^^^^^ |
| 351 | |
| 352 | The flag ``frame-setup`` can be specified before the instruction's name: |
| 353 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 354 | .. code-block:: text |
Alex Lorenz | 8eadc3f | 2015-08-21 17:26:38 +0000 | [diff] [blame] | 355 | |
| 356 | %fp = frame-setup ADDXri %sp, 0, 0 |
| 357 | |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 358 | .. _registers: |
| 359 | |
| 360 | Registers |
| 361 | --------- |
| 362 | |
| 363 | Registers are one of the key primitives in the machine instructions |
| 364 | serialization language. They are primarly used in the |
| 365 | :ref:`register machine operands <register-operands>`, |
| 366 | but they can also be used in a number of other places, like the |
| 367 | :ref:`basic block's live in list <bb-liveins>`. |
| 368 | |
| 369 | The physical registers are identified by their name. They use the following |
| 370 | syntax: |
| 371 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 372 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 373 | |
| 374 | %<name> |
| 375 | |
| 376 | The example below shows three X86 physical registers: |
| 377 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 378 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 379 | |
| 380 | %eax |
| 381 | %r15 |
| 382 | %eflags |
| 383 | |
| 384 | The virtual registers are identified by their ID number. They use the following |
| 385 | syntax: |
| 386 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 387 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 388 | |
| 389 | %<id> |
| 390 | |
| 391 | Example: |
| 392 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 393 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 394 | |
| 395 | %0 |
| 396 | |
| 397 | The null registers are represented using an underscore ('``_``'). They can also be |
| 398 | represented using a '``%noreg``' named register, although the former syntax |
| 399 | is preferred. |
| 400 | |
| 401 | .. _machine-operands: |
| 402 | |
| 403 | Machine Operands |
| 404 | ---------------- |
| 405 | |
| 406 | There are seventeen different kinds of machine operands, and all of them, except |
| 407 | the ``MCSymbol`` operand, can be serialized. The ``MCSymbol`` operands are |
| 408 | just printed out - they can't be parsed back yet. |
| 409 | |
| 410 | Immediate Operands |
| 411 | ^^^^^^^^^^^^^^^^^^ |
| 412 | |
| 413 | The immediate machine operands are untyped, 64-bit signed integers. The |
| 414 | example below shows an instance of the X86 ``MOV32ri`` instruction that has an |
| 415 | immediate machine operand ``-42``: |
| 416 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 417 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 418 | |
| 419 | %eax = MOV32ri -42 |
| 420 | |
| 421 | .. TODO: Describe the CIMM (Rare) and FPIMM immediate operands. |
| 422 | |
| 423 | .. _register-operands: |
| 424 | |
| 425 | Register Operands |
| 426 | ^^^^^^^^^^^^^^^^^ |
| 427 | |
| 428 | The :ref:`register <registers>` primitive is used to represent the register |
| 429 | machine operands. The register operands can also have optional |
| 430 | :ref:`register flags <register-flags>`, |
Alex Lorenz | 37e0262 | 2015-09-08 11:39:47 +0000 | [diff] [blame] | 431 | :ref:`a subregister index <subregister-indices>`, |
| 432 | and a reference to the tied register operand. |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 433 | The full syntax of a register operand is shown below: |
| 434 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 435 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 436 | |
| 437 | [<flags>] <register> [ :<subregister-idx-name> ] [ (tied-def <tied-op>) ] |
| 438 | |
| 439 | This example shows an instance of the X86 ``XOR32rr`` instruction that has |
| 440 | 5 register operands with different register flags: |
| 441 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 442 | .. code-block:: text |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 443 | |
| 444 | dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al |
| 445 | |
| 446 | .. _register-flags: |
| 447 | |
| 448 | Register Flags |
| 449 | ~~~~~~~~~~~~~~ |
| 450 | |
| 451 | The table below shows all of the possible register flags along with the |
| 452 | corresponding internal ``llvm::RegState`` representation: |
| 453 | |
| 454 | .. list-table:: |
| 455 | :header-rows: 1 |
| 456 | |
| 457 | * - Flag |
| 458 | - Internal Value |
| 459 | |
| 460 | * - ``implicit`` |
| 461 | - ``RegState::Implicit`` |
| 462 | |
| 463 | * - ``implicit-def`` |
| 464 | - ``RegState::ImplicitDefine`` |
| 465 | |
| 466 | * - ``def`` |
| 467 | - ``RegState::Define`` |
| 468 | |
| 469 | * - ``dead`` |
| 470 | - ``RegState::Dead`` |
| 471 | |
| 472 | * - ``killed`` |
| 473 | - ``RegState::Kill`` |
| 474 | |
| 475 | * - ``undef`` |
| 476 | - ``RegState::Undef`` |
| 477 | |
| 478 | * - ``internal`` |
| 479 | - ``RegState::InternalRead`` |
| 480 | |
| 481 | * - ``early-clobber`` |
| 482 | - ``RegState::EarlyClobber`` |
| 483 | |
| 484 | * - ``debug-use`` |
| 485 | - ``RegState::Debug`` |
Alex Lorenz | 3a4a60c | 2015-08-15 01:06:06 +0000 | [diff] [blame] | 486 | |
Alex Lorenz | 37e0262 | 2015-09-08 11:39:47 +0000 | [diff] [blame] | 487 | .. _subregister-indices: |
| 488 | |
| 489 | Subregister Indices |
| 490 | ~~~~~~~~~~~~~~~~~~~ |
| 491 | |
| 492 | The register machine operands can reference a portion of a register by using |
| 493 | the subregister indices. The example below shows an instance of the ``COPY`` |
| 494 | pseudo instruction that uses the X86 ``sub_8bit`` subregister index to copy 8 |
| 495 | lower bits from the 32-bit virtual register 0 to the 8-bit virtual register 1: |
| 496 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 497 | .. code-block:: text |
Alex Lorenz | 37e0262 | 2015-09-08 11:39:47 +0000 | [diff] [blame] | 498 | |
| 499 | %1 = COPY %0:sub_8bit |
| 500 | |
| 501 | The names of the subregister indices are target specific, and are typically |
| 502 | defined in the target's ``*RegisterInfo.td`` file. |
| 503 | |
Alex Lorenz | d4990eb | 2015-09-08 11:38:16 +0000 | [diff] [blame] | 504 | Global Value Operands |
| 505 | ^^^^^^^^^^^^^^^^^^^^^ |
| 506 | |
| 507 | The global value machine operands reference the global values from the |
| 508 | :ref:`embedded LLVM IR module <embedded-module>`. |
| 509 | The example below shows an instance of the X86 ``MOV64rm`` instruction that has |
| 510 | a global value operand named ``G``: |
| 511 | |
Renato Golin | 124f259 | 2016-07-20 12:16:38 +0000 | [diff] [blame] | 512 | .. code-block:: text |
Alex Lorenz | d4990eb | 2015-09-08 11:38:16 +0000 | [diff] [blame] | 513 | |
| 514 | %rax = MOV64rm %rip, 1, _, @G, _ |
| 515 | |
| 516 | The named global values are represented using an identifier with the '@' prefix. |
| 517 | If the identifier doesn't match the regular expression |
| 518 | `[-a-zA-Z$._][-a-zA-Z$._0-9]*`, then this identifier must be quoted. |
| 519 | |
| 520 | The unnamed global values are represented using an unsigned numeric value with |
| 521 | the '@' prefix, like in the following examples: ``@0``, ``@989``. |
| 522 | |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 523 | .. TODO: Describe the parsers default behaviour when optional YAML attributes |
| 524 | are missing. |
Alex Lorenz | 8eadc3f | 2015-08-21 17:26:38 +0000 | [diff] [blame] | 525 | .. TODO: Describe the syntax for the bundled instructions. |
Alex Lorenz | b981d37 | 2015-08-21 21:17:01 +0000 | [diff] [blame] | 526 | .. TODO: Describe the syntax for virtual register YAML definitions. |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 527 | .. TODO: Describe the machine function's YAML flag attributes. |
Alex Lorenz | d4990eb | 2015-09-08 11:38:16 +0000 | [diff] [blame] | 528 | .. TODO: Describe the syntax for the external symbol and register |
Alex Lorenz | 3d31177 | 2015-08-06 22:55:19 +0000 | [diff] [blame] | 529 | mask machine operands. |
| 530 | .. TODO: Describe the frame information YAML mapping. |
| 531 | .. TODO: Describe the syntax of the stack object machine operands and their |
| 532 | YAML definitions. |
| 533 | .. TODO: Describe the syntax of the constant pool machine operands and their |
| 534 | YAML definitions. |
| 535 | .. TODO: Describe the syntax of the jump table machine operands and their |
| 536 | YAML definitions. |
| 537 | .. TODO: Describe the syntax of the block address machine operands. |
| 538 | .. TODO: Describe the syntax of the CFI index machine operands. |
| 539 | .. TODO: Describe the syntax of the metadata machine operands, and the |
| 540 | instructions debug location attribute. |
| 541 | .. TODO: Describe the syntax of the target index machine operands. |
| 542 | .. TODO: Describe the syntax of the register live out machine operands. |
| 543 | .. TODO: Describe the syntax of the machine memory operands. |