Mercurial > hg > CbC > CbC_llvm
comparison docs/MIRLangRef.rst @ 147:c2174574ed3a
LLVM 10
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 16:55:33 +0900 |
parents | 3a76565eade5 |
children |
comparison
equal
deleted
inserted
replaced
134:3a76565eade5 | 147:c2174574ed3a |
---|---|
57 for the post register allocation pseudo instruction expansion pass, you can | 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 | 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: | 59 runs just before the pass that we are trying to test: |
60 | 60 |
61 ``llc -stop-after=machine-cp bug-trigger.ll > test.mir`` | 61 ``llc -stop-after=machine-cp bug-trigger.ll > test.mir`` |
62 | |
63 If the same pass is run multiple times, a run index can be included | |
64 after the name with a comma. | |
65 | |
66 ``llc -stop-after=dead-mi-elimination,1 bug-trigger.ll > test.mir`` | |
62 | 67 |
63 After generating the input MIR file, you'll have to add a run line that uses | 68 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 | 69 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 | 70 pseudo instruction expansion pass on X86-64, a run line like the one shown |
66 below can be used: | 71 below can be used: |
133 subclasses isn't serialized at the moment. | 138 subclasses isn't serialized at the moment. |
134 | 139 |
135 - The target-specific ``MachineConstantPoolValue`` subclasses (in the ARM and | 140 - The target-specific ``MachineConstantPoolValue`` subclasses (in the ARM and |
136 SystemZ backends) aren't serialized at the moment. | 141 SystemZ backends) aren't serialized at the moment. |
137 | 142 |
138 - The ``MCSymbol`` machine operands are only printed, they can't be parsed. | 143 - The ``MCSymbol`` machine operands don't support temporary or local symbols. |
139 | 144 |
140 - A lot of the state in ``MachineModuleInfo`` isn't serialized - only the CFI | 145 - 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 | 146 instructions and the variable debug information from MMI is serialized right |
142 now. | 147 now. |
143 | 148 |
144 These limitations impose restrictions on what you can test with the MIR format. | 149 These limitations impose restrictions on what you can test with the MIR format. |
145 For now, tests that would like to test some behaviour that depends on the state | 150 For now, tests that would like to test some behaviour that depends on the state |
146 of certain ``MCSymbol`` operands or the exception handling state in MMI, can't | 151 of temporary or local ``MCSymbol`` operands or the exception handling state in |
147 use the MIR format. As well as that, tests that test some behaviour that | 152 MMI, can't use the MIR format. As well as that, tests that test some behaviour |
148 depends on the state of the target specific ``MachineFunctionInfo`` or | 153 that depends on the state of the target specific ``MachineFunctionInfo`` or |
149 ``MachineConstantPoolValue`` subclasses can't use the MIR format at the moment. | 154 ``MachineConstantPoolValue`` subclasses can't use the MIR format at the moment. |
150 | 155 |
151 High Level Structure | 156 High Level Structure |
152 ==================== | 157 ==================== |
153 | 158 |
183 | 188 |
184 --- | 189 --- |
185 name: inc | 190 name: inc |
186 tracksRegLiveness: true | 191 tracksRegLiveness: true |
187 liveins: | 192 liveins: |
188 - { reg: '%rdi' } | 193 - { reg: '$rdi' } |
194 callSites: | |
195 - { bb: 0, offset: 3, fwdArgRegs: | |
196 - { arg: 0, reg: '$edi' } } | |
189 body: | | 197 body: | |
190 bb.0.entry: | 198 bb.0.entry: |
191 liveins: %rdi | 199 liveins: $rdi |
192 | 200 |
193 %eax = MOV32rm %rdi, 1, _, 0, _ | 201 $eax = MOV32rm $rdi, 1, _, 0, _ |
194 %eax = INC32r killed %eax, implicit-def dead %eflags | 202 $eax = INC32r killed $eax, implicit-def dead $eflags |
195 MOV32mr killed %rdi, 1, _, 0, _, %eax | 203 MOV32mr killed $rdi, 1, _, 0, _, $eax |
196 RETQ %eax | 204 CALL64pcrel32 @foo <regmask...> |
205 RETQ $eax | |
197 ... | 206 ... |
198 | 207 |
199 The document above consists of attributes that represent the various | 208 The document above consists of attributes that represent the various |
200 properties and data structures in a machine function. | 209 properties and data structures in a machine function. |
201 | 210 |
202 The attribute ``name`` is required, and its value should be identical to the | 211 The attribute ``name`` is required, and its value should be identical to the |
203 name of a function that this machine function is based on. | 212 name of a function that this machine function is based on. |
204 | 213 |
205 The attribute ``body`` is a `YAML block literal string`_. Its value represents | 214 The attribute ``body`` is a `YAML block literal string`_. Its value represents |
206 the function's machine basic blocks and their machine instructions. | 215 the function's machine basic blocks and their machine instructions. |
216 | |
217 The attribute ``callSites`` is a representation of call site information which | |
218 keeps track of call instructions and registers used to transfer call arguments. | |
207 | 219 |
208 Machine Instructions Format Reference | 220 Machine Instructions Format Reference |
209 ===================================== | 221 ===================================== |
210 | 222 |
211 The machine basic blocks and their instructions are represented using a custom, | 223 The machine basic blocks and their instructions are represented using a custom, |
305 the instructions: | 317 the instructions: |
306 | 318 |
307 .. code-block:: text | 319 .. code-block:: text |
308 | 320 |
309 bb.0.entry: | 321 bb.0.entry: |
310 liveins: %edi, %esi | 322 liveins: $edi, $esi |
311 | 323 |
312 The list of live in registers and successors can be empty. The language also | 324 The list of live in registers and successors can be empty. The language also |
313 allows multiple live in register and successor lists - they are combined into | 325 allows multiple live in register and successor lists - they are combined into |
314 one list by the parser. | 326 one list by the parser. |
315 | 327 |
342 below shows an instance of the X86 ``RETQ`` instruction with a single machine | 354 below shows an instance of the X86 ``RETQ`` instruction with a single machine |
343 operand: | 355 operand: |
344 | 356 |
345 .. code-block:: text | 357 .. code-block:: text |
346 | 358 |
347 RETQ %eax | 359 RETQ $eax |
348 | 360 |
349 However, if the machine instruction has one or more explicitly defined register | 361 However, if the machine instruction has one or more explicitly defined register |
350 operands, the instruction's name has to be specified after them. The example | 362 operands, the instruction's name has to be specified after them. The example |
351 below shows an instance of the AArch64 ``LDPXpost`` instruction with three | 363 below shows an instance of the AArch64 ``LDPXpost`` instruction with three |
352 defined register operands: | 364 defined register operands: |
353 | 365 |
354 .. code-block:: text | 366 .. code-block:: text |
355 | 367 |
356 %sp, %fp, %lr = LDPXpost %sp, 2 | 368 $sp, $fp, $lr = LDPXpost $sp, 2 |
357 | 369 |
358 The instruction names are serialized using the exact definitions from the | 370 The instruction names are serialized using the exact definitions from the |
359 target's ``*InstrInfo.td`` files, and they are case sensitive. This means that | 371 target's ``*InstrInfo.td`` files, and they are case sensitive. This means that |
360 similar instruction names like ``TSTri`` and ``tSTRi`` represent different | 372 similar instruction names like ``TSTri`` and ``tSTRi`` represent different |
361 machine instructions. | 373 machine instructions. |
368 The flag ``frame-setup`` or ``frame-destroy`` can be specified before the | 380 The flag ``frame-setup`` or ``frame-destroy`` can be specified before the |
369 instruction's name: | 381 instruction's name: |
370 | 382 |
371 .. code-block:: text | 383 .. code-block:: text |
372 | 384 |
373 %fp = frame-setup ADDXri %sp, 0, 0 | 385 $fp = frame-setup ADDXri $sp, 0, 0 |
374 | 386 |
375 .. code-block:: text | 387 .. code-block:: text |
376 | 388 |
377 %x21, %x20 = frame-destroy LDPXi %sp | 389 $x21, $x20 = frame-destroy LDPXi $sp |
378 | 390 |
379 .. _registers: | 391 .. _registers: |
380 | 392 |
381 Bundled Instructions | 393 Bundled Instructions |
382 ^^^^^^^^^^^^^^^^^^^^ | 394 ^^^^^^^^^^^^^^^^^^^^ |
383 | 395 |
384 The syntax for bundled instructions is the following: | 396 The syntax for bundled instructions is the following: |
385 | 397 |
386 .. code-block:: text | 398 .. code-block:: text |
387 | 399 |
388 BUNDLE implicit-def %r0, implicit-def %r1, implicit %r2 { | 400 BUNDLE implicit-def $r0, implicit-def $r1, implicit $r2 { |
389 %r0 = SOME_OP %r2 | 401 $r0 = SOME_OP $r2 |
390 %r1 = ANOTHER_OP internal %r0 | 402 $r1 = ANOTHER_OP internal $r0 |
391 } | 403 } |
392 | 404 |
393 The first instruction is often a bundle header. The instructions between ``{`` | 405 The first instruction is often a bundle header. The instructions between ``{`` |
394 and ``}`` are bundled with the first instruction. | 406 and ``}`` are bundled with the first instruction. |
395 | 407 |
396 Registers | 408 Registers |
397 --------- | 409 --------- |
398 | 410 |
399 Registers are one of the key primitives in the machine instructions | 411 Registers are one of the key primitives in the machine instructions |
400 serialization language. They are primarly used in the | 412 serialization language. They are primarily used in the |
401 :ref:`register machine operands <register-operands>`, | 413 :ref:`register machine operands <register-operands>`, |
402 but they can also be used in a number of other places, like the | 414 but they can also be used in a number of other places, like the |
403 :ref:`basic block's live in list <bb-liveins>`. | 415 :ref:`basic block's live in list <bb-liveins>`. |
404 | 416 |
405 The physical registers are identified by their name. They use the following | 417 The physical registers are identified by their name and by the '$' prefix sigil. |
406 syntax: | 418 They use the following syntax: |
407 | 419 |
408 .. code-block:: text | 420 .. code-block:: text |
409 | 421 |
410 %<name> | 422 $<name> |
411 | 423 |
412 The example below shows three X86 physical registers: | 424 The example below shows three X86 physical registers: |
413 | 425 |
414 .. code-block:: text | 426 .. code-block:: text |
415 | 427 |
416 %eax | 428 $eax |
417 %r15 | 429 $r15 |
418 %eflags | 430 $eflags |
419 | 431 |
420 The virtual registers are identified by their ID number. They use the following | 432 The virtual registers are identified by their ID number and by the '%' sigil. |
421 syntax: | 433 They use the following syntax: |
422 | 434 |
423 .. code-block:: text | 435 .. code-block:: text |
424 | 436 |
425 %<id> | 437 %<id> |
426 | 438 |
429 .. code-block:: text | 441 .. code-block:: text |
430 | 442 |
431 %0 | 443 %0 |
432 | 444 |
433 The null registers are represented using an underscore ('``_``'). They can also be | 445 The null registers are represented using an underscore ('``_``'). They can also be |
434 represented using a '``%noreg``' named register, although the former syntax | 446 represented using a '``$noreg``' named register, although the former syntax |
435 is preferred. | 447 is preferred. |
436 | 448 |
437 .. _machine-operands: | 449 .. _machine-operands: |
438 | 450 |
439 Machine Operands | 451 Machine Operands |
440 ---------------- | 452 ---------------- |
441 | 453 |
442 There are seventeen different kinds of machine operands, and all of them, except | 454 There are seventeen different kinds of machine operands, and all of them can be |
443 the ``MCSymbol`` operand, can be serialized. The ``MCSymbol`` operands are | 455 serialized. |
444 just printed out - they can't be parsed back yet. | |
445 | 456 |
446 Immediate Operands | 457 Immediate Operands |
447 ^^^^^^^^^^^^^^^^^^ | 458 ^^^^^^^^^^^^^^^^^^ |
448 | 459 |
449 The immediate machine operands are untyped, 64-bit signed integers. The | 460 The immediate machine operands are untyped, 64-bit signed integers. The |
450 example below shows an instance of the X86 ``MOV32ri`` instruction that has an | 461 example below shows an instance of the X86 ``MOV32ri`` instruction that has an |
451 immediate machine operand ``-42``: | 462 immediate machine operand ``-42``: |
452 | 463 |
453 .. code-block:: text | 464 .. code-block:: text |
454 | 465 |
455 %eax = MOV32ri -42 | 466 $eax = MOV32ri -42 |
456 | 467 |
457 An immediate operand is also used to represent a subregister index when the | 468 An immediate operand is also used to represent a subregister index when the |
458 machine instruction has one of the following opcodes: | 469 machine instruction has one of the following opcodes: |
459 | 470 |
460 - ``EXTRACT_SUBREG`` | 471 - ``EXTRACT_SUBREG`` |
508 This example shows an instance of the X86 ``XOR32rr`` instruction that has | 519 This example shows an instance of the X86 ``XOR32rr`` instruction that has |
509 5 register operands with different register flags: | 520 5 register operands with different register flags: |
510 | 521 |
511 .. code-block:: text | 522 .. code-block:: text |
512 | 523 |
513 dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al | 524 dead $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, implicit-def $al |
514 | 525 |
515 .. _register-flags: | 526 .. _register-flags: |
516 | 527 |
517 Register Flags | 528 Register Flags |
518 ~~~~~~~~~~~~~~ | 529 ~~~~~~~~~~~~~~ |
628 The example below shows an instance of the X86 ``MOV64rm`` instruction that has | 639 The example below shows an instance of the X86 ``MOV64rm`` instruction that has |
629 a global value operand named ``G``: | 640 a global value operand named ``G``: |
630 | 641 |
631 .. code-block:: text | 642 .. code-block:: text |
632 | 643 |
633 %rax = MOV64rm %rip, 1, _, @G, _ | 644 $rax = MOV64rm $rip, 1, _, @G, _ |
634 | 645 |
635 The named global values are represented using an identifier with the '@' prefix. | 646 The named global values are represented using an identifier with the '@' prefix. |
636 If the identifier doesn't match the regular expression | 647 If the identifier doesn't match the regular expression |
637 `[-a-zA-Z$._][-a-zA-Z$._0-9]*`, then this identifier must be quoted. | 648 `[-a-zA-Z$._][-a-zA-Z$._0-9]*`, then this identifier must be quoted. |
638 | 649 |
650 in the AMDGPU backend. So if we have a target index operand with the index 0 | 661 in the AMDGPU backend. So if we have a target index operand with the index 0 |
651 and the offset 8: | 662 and the offset 8: |
652 | 663 |
653 .. code-block:: text | 664 .. code-block:: text |
654 | 665 |
655 %sgpr2 = S_ADD_U32 _, target-index(amdgpu-constdata-start) + 8, implicit-def _, implicit-def _ | 666 $sgpr2 = S_ADD_U32 _, target-index(amdgpu-constdata-start) + 8, implicit-def _, implicit-def _ |
656 | 667 |
657 Jump-table Index Operands | 668 Jump-table Index Operands |
658 ^^^^^^^^^^^^^^^^^^^^^^^^^ | 669 ^^^^^^^^^^^^^^^^^^^^^^^^^ |
659 | 670 |
660 A jump-table index operand with the index 0 is printed as following: | 671 A jump-table index operand with the index 0 is printed as following: |
661 | 672 |
662 .. code-block:: text | 673 .. code-block:: text |
663 | 674 |
664 tBR_JTr killed %r0, %jump-table.0 | 675 tBR_JTr killed $r0, %jump-table.0 |
665 | 676 |
666 A machine jump-table entry contains a list of ``MachineBasicBlocks``. When serializing all the function's jump-table entries, the following format is used: | 677 A machine jump-table entry contains a list of ``MachineBasicBlocks``. When serializing all the function's jump-table entries, the following format is used: |
667 | 678 |
668 .. code-block:: text | 679 .. code-block:: text |
669 | 680 |
688 blocks: [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ] | 699 blocks: [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ] |
689 | 700 |
690 External Symbol Operands | 701 External Symbol Operands |
691 ^^^^^^^^^^^^^^^^^^^^^^^^^ | 702 ^^^^^^^^^^^^^^^^^^^^^^^^^ |
692 | 703 |
693 An external symbol operand is represented using an identifier with the ``$`` | 704 An external symbol operand is represented using an identifier with the ``&`` |
694 prefix. The identifier is surrounded with ""'s and escaped if it has any | 705 prefix. The identifier is surrounded with ""'s and escaped if it has any |
695 special non-printable characters in it. | 706 special non-printable characters in it. |
696 | 707 |
697 Example: | 708 Example: |
698 | 709 |
699 .. code-block:: text | 710 .. code-block:: text |
700 | 711 |
701 CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp | 712 CALL64pcrel32 &__stack_chk_fail, csr_64, implicit $rsp, implicit-def $rsp |
702 | 713 |
703 MCSymbol Operands | 714 MCSymbol Operands |
704 ^^^^^^^^^^^^^^^^^ | 715 ^^^^^^^^^^^^^^^^^ |
705 | 716 |
706 A MCSymbol operand is holding a pointer to a ``MCSymbol``. For the limitations | 717 A MCSymbol operand is holding a pointer to a ``MCSymbol``. For the limitations |
723 | 734 |
724 The syntax is: | 735 The syntax is: |
725 | 736 |
726 .. code-block:: text | 737 .. code-block:: text |
727 | 738 |
728 CFI_INSTRUCTION offset %w30, -16 | 739 CFI_INSTRUCTION offset $w30, -16 |
729 | 740 |
730 which may be emitted later in the MC layer as: | 741 which may be emitted later in the MC layer as: |
731 | 742 |
732 .. code-block:: text | 743 .. code-block:: text |
733 | 744 |
740 | 751 |
741 The syntax for the ``returnaddress`` intrinsic is: | 752 The syntax for the ``returnaddress`` intrinsic is: |
742 | 753 |
743 .. code-block:: text | 754 .. code-block:: text |
744 | 755 |
745 %x0 = COPY intrinsic(@llvm.returnaddress) | 756 $x0 = COPY intrinsic(@llvm.returnaddress) |
746 | 757 |
747 Predicate Operands | 758 Predicate Operands |
748 ^^^^^^^^^^^^^^^^^^ | 759 ^^^^^^^^^^^^^^^^^^ |
749 | 760 |
750 A Predicate operand contains an IR predicate from ``CmpInst::Predicate``, like | 761 A Predicate operand contains an IR predicate from ``CmpInst::Predicate``, like |