AArch64SchedExynosM4.td 49.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
//=- AArch64SchedExynosM4.td - Samsung Exynos M4 Sched Defs --*- tablegen -*-=//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the machine model for the Samsung Exynos M4 to support
// instruction scheduling and other instruction cost heuristics.
//
//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
// The Exynos-M4 is an advanced superscalar microprocessor with a 6-wide
// in-order stage for decode and dispatch and a wider issue stage.
// The execution units and loads and stores are out-of-order.

def ExynosM4Model : SchedMachineModel {
  let IssueWidth            =   6; // Up to 6 uops per cycle.
  let MicroOpBufferSize     = 228; // ROB size.
  let LoopMicroOpBufferSize =  48; // Based on the instruction queue size.
  let LoadLatency           =   4; // Optimistic load cases.
  let MispredictPenalty     =  16; // Minimum branch misprediction penalty.
  let CompleteModel         =   1; // Use the default model otherwise.

  list<Predicate> UnsupportedFeatures = SVEUnsupported.F;
}

//===----------------------------------------------------------------------===//
// Define each kind of processor resource and number available on the Exynos-M4.

let SchedModel = ExynosM4Model in {

def M4UnitA  : ProcResource<2>; // Simple integer
def M4UnitC  : ProcResource<2>; // Simple and complex integer
let Super =  M4UnitC, BufferSize = 1 in
def M4UnitD  : ProcResource<1>; // Integer division (inside C0, serialized)
let Super =  M4UnitC in
def M4UnitE  : ProcResource<1>; // CRC (inside C0)
def M4UnitB  : ProcResource<2>; // Branch
def M4UnitL0 : ProcResource<1>; // Load
def M4UnitS0 : ProcResource<1>; // Store
def M4PipeLS : ProcResource<1>; // Load/Store
let Super = M4PipeLS in {
  def M4UnitL1 : ProcResource<1>;
  def M4UnitS1 : ProcResource<1>;
}
def M4PipeF0 : ProcResource<1>; // FP #0
let Super = M4PipeF0 in {
  def M4UnitFMAC0 : ProcResource<1>; // FP multiplication
  def M4UnitFADD0 : ProcResource<1>; // Simple FP
  def M4UnitFCVT0 : ProcResource<1>; // FP conversion
  def M4UnitNALU0 : ProcResource<1>; // Simple vector
  def M4UnitNHAD  : ProcResource<1>; // Horizontal vector
  def M4UnitNMSC  : ProcResource<1>; // FP and vector miscellanea
  def M4UnitNMUL0 : ProcResource<1>; // Vector multiplication
  def M4UnitNSHT0 : ProcResource<1>; // Vector shifting
  def M4UnitNSHF0 : ProcResource<1>; // Vector shuffling
  def M4UnitNCRY0 : ProcResource<1>; // Cryptographic
}
def M4PipeF1 : ProcResource<1>; // FP #1
let Super = M4PipeF1 in {
  def M4UnitFMAC1 : ProcResource<1>; // FP multiplication
  def M4UnitFADD1 : ProcResource<1>; // Simple FP
  def M4UnitFDIV0 : ProcResource<2>; // FP division (serialized)
  def M4UnitFSQR0 : ProcResource<2>; // FP square root (serialized)
  def M4UnitFST0  : ProcResource<1>; // FP store
  def M4UnitNALU1 : ProcResource<1>; // Simple vector
  def M4UnitNSHT1 : ProcResource<1>; // Vector shifting
  def M4UnitNSHF1 : ProcResource<1>; // Vector shuffling
}
def M4PipeF2 : ProcResource<1>; // FP #2
let Super = M4PipeF2 in {
  def M4UnitFMAC2 : ProcResource<1>; // FP multiplication
  def M4UnitFADD2 : ProcResource<1>; // Simple FP
  def M4UnitFCVT1 : ProcResource<1>; // FP conversion
  def M4UnitFDIV1 : ProcResource<2>; // FP division (serialized)
  def M4UnitFSQR1 : ProcResource<2>; // FP square root (serialized)
  def M4UnitFST1  : ProcResource<1>; // FP store
  def M4UnitNALU2 : ProcResource<1>; // Simple vector
  def M4UnitNMUL1 : ProcResource<1>; // Vector multiplication
  def M4UnitNSHT2 : ProcResource<1>; // Vector shifting
  def M4UnitNCRY1 : ProcResource<1>; // Cryptographic
}

def M4UnitALU   : ProcResGroup<[M4UnitA,
                                M4UnitC]>;
def M4UnitL     : ProcResGroup<[M4UnitL0,
                                M4UnitL1]>;
def M4UnitS     : ProcResGroup<[M4UnitS0,
                                M4UnitS1]>;
def M4UnitFMAC  : ProcResGroup<[M4UnitFMAC0,
                                M4UnitFMAC1,
                                M4UnitFMAC2]>;
def M4UnitFMACH : ProcResGroup<[M4UnitFMAC0,
                                M4UnitFMAC1]>;
def M4UnitFADD  : ProcResGroup<[M4UnitFADD0,
                                M4UnitFADD1,
                                M4UnitFADD2]>;
def M4UnitFADDH : ProcResGroup<[M4UnitFADD0,
                                M4UnitFADD1]>;
def M4UnitFCVT  : ProcResGroup<[M4UnitFCVT0,
                                M4UnitFCVT1]>;
def M4UnitFCVTH : ProcResGroup<[M4UnitFCVT0]>;
def M4UnitFDIV  : ProcResGroup<[M4UnitFDIV0,
                                M4UnitFDIV1]>;
def M4UnitFDIVH : ProcResGroup<[M4UnitFDIV0]>;
def M4UnitFSQR  : ProcResGroup<[M4UnitFSQR0,
                                M4UnitFSQR1]>;
def M4UnitFSQRH : ProcResGroup<[M4UnitFSQR0]>;
def M4UnitFST   : ProcResGroup<[M4UnitFST0,
                                M4UnitFST1]>;
def M4UnitNALU  : ProcResGroup<[M4UnitNALU0,
                                M4UnitNALU1,
                                M4UnitNALU2]>;
def M4UnitNALUH : ProcResGroup<[M4UnitNALU0,
                                M4UnitNALU1]>;
def M4UnitNMUL  : ProcResGroup<[M4UnitNMUL0,
                                M4UnitNMUL1]>;
def M4UnitNSHT  : ProcResGroup<[M4UnitNSHT0,
                                M4UnitNSHT1,
                                M4UnitNSHT2]>;
def M4UnitNSHF  : ProcResGroup<[M4UnitNSHF0,
                                M4UnitNSHF1]>;
def M4UnitNSHFH : ProcResGroup<[M4UnitNSHF0]>;
def M4UnitNCRY  : ProcResGroup<[M4UnitNCRY0,
                                M4UnitNCRY1]>;

//===----------------------------------------------------------------------===//
// Resources details.

def M4WriteZ0 : SchedWriteRes<[]> { let Latency = 0; }
def M4WriteZ1 : SchedWriteRes<[]> { let Latency = 1;
                                    let NumMicroOps = 0; }
def M4WriteZ4 : SchedWriteRes<[]> { let Latency = 4;
                                    let NumMicroOps = 0; }

def M4WriteA1 : SchedWriteRes<[M4UnitALU]> { let Latency = 1; }
def M4WriteA2 : SchedWriteRes<[M4UnitALU]> { let Latency = 2; }
def M4WriteAA : SchedWriteRes<[M4UnitALU]> { let Latency = 2;
                                             let ResourceCycles = [2]; }
def M4WriteAB : SchedWriteRes<[M4UnitALU,
                               M4UnitC]>   { let Latency = 2;
                                             let NumMicroOps = 2; }
def M4WriteAC : SchedWriteRes<[M4UnitALU,
                               M4UnitALU,
                               M4UnitC]>   { let Latency = 3;
                                             let NumMicroOps = 3; }
def M4WriteAD : SchedWriteRes<[M4UnitALU,
                               M4UnitC]>   { let Latency = 2;
                                             let NumMicroOps = 2; }
def M4WriteAF : SchedWriteRes<[M4UnitALU]> { let Latency = 2;
                                             let NumMicroOps = 2; }
def M4WriteAU : SchedWriteVariant<[SchedVar<IsCopyIdiomPred,   [M4WriteZ0]>,
                                   SchedVar<ExynosArithPred,   [M4WriteA1]>,
                                   SchedVar<ExynosLogicExPred, [M4WriteA1]>,
                                   SchedVar<NoSchedPred,       [M4WriteAA]>]>;
def M4WriteAV : SchedWriteVariant<[SchedVar<ExynosResetPred,   [M4WriteZ0]>,
                                   SchedVar<ExynosArithPred,   [M4WriteA1]>,
                                   SchedVar<ExynosLogicExPred, [M4WriteA1]>,
                                   SchedVar<NoSchedPred,       [M4WriteAA]>]>;
def M4WriteAX : SchedWriteVariant<[SchedVar<ExynosArithPred,   [M4WriteA1]>,
                                   SchedVar<ExynosLogicExPred, [M4WriteA1]>,
                                   SchedVar<NoSchedPred,       [M4WriteAA]>]>;
def M4WriteAY : SchedWriteVariant<[SchedVar<ExynosRotateRightImmPred, [M4WriteA1]>,
                                   SchedVar<NoSchedPred,              [M4WriteAF]>]>;

def M4WriteB1 : SchedWriteRes<[M4UnitB]> { let Latency = 1; }
def M4WriteBX : SchedWriteVariant<[SchedVar<ExynosBranchLinkLRPred, [M4WriteAC]>,
                                   SchedVar<NoSchedPred,            [M4WriteAB]>]>;

def M4WriteC1 : SchedWriteRes<[M4UnitC]> { let Latency = 1; }
def M4WriteC3 : SchedWriteRes<[M4UnitC]> { let Latency = 3; }
def M4WriteCA : SchedWriteRes<[M4UnitC]> { let Latency = 4;
                                           let ResourceCycles = [2]; }

def M4WriteD12 : SchedWriteRes<[M4UnitD]> { let Latency = 12;
                                            let ResourceCycles = [12]; }
def M4WriteD21 : SchedWriteRes<[M4UnitD]> { let Latency = 21;
                                            let ResourceCycles = [21]; }

def M4WriteE2 : SchedWriteRes<[M4UnitE]> { let Latency = 2; }

def M4WriteL4 : SchedWriteRes<[M4UnitL]> { let Latency = 4; }
def M4WriteL5 : SchedWriteRes<[M4UnitL]> { let Latency = 5; }
def M4WriteLA : SchedWriteRes<[M4UnitL,
                               M4UnitL]> { let Latency = 5;
                                           let NumMicroOps = 1; }
def M4WriteLB : SchedWriteRes<[M4UnitA,
                               M4UnitL]> { let Latency = 5;
                                           let NumMicroOps = 2; }
def M4WriteLC : SchedWriteRes<[M4UnitA,
                               M4UnitL,
                               M4UnitL]> { let Latency = 5;
                                           let NumMicroOps = 2; }
def M4WriteLD : SchedWriteRes<[M4UnitA,
                               M4UnitL]> { let Latency = 4;
                                           let NumMicroOps = 2; }
def M4WriteLE : SchedWriteRes<[M4UnitA,
                               M4UnitL]> { let Latency = 6;
                                           let NumMicroOps = 2; }
def M4WriteLH : SchedWriteRes<[]>        { let Latency = 5;
                                           let NumMicroOps = 0; }
def M4WriteLX : SchedWriteVariant<[SchedVar<ExynosScaledIdxPred, [M4WriteL5]>,
                                   SchedVar<NoSchedPred,         [M4WriteL4]>]>;
def M4WriteLY : SchedWriteVariant<[SchedVar<ExynosScaledIdxPred, [M4WriteLE]>,
                                   SchedVar<NoSchedPred,         [M4WriteL5]>]>;

def M4WriteS1 : SchedWriteRes<[M4UnitS]>  { let Latency = 1; }
def M4WriteSA : SchedWriteRes<[M4UnitS0]> { let Latency = 3; }
def M4WriteSB : SchedWriteRes<[M4UnitA,
                               M4UnitS]>  { let Latency = 2;
                                            let NumMicroOps = 1; }
def M4WriteSX : SchedWriteVariant<[SchedVar<ExynosScaledIdxPred, [M4WriteSB]>,
                                   SchedVar<NoSchedPred,         [M4WriteS1]>]>;

def M4ReadAdrBase : SchedReadVariant<[SchedVar<
                                        MCSchedPredicate<
                                          CheckAny<
                                            [ScaledIdxFn,
                                             ExynosScaledIdxFn]>>, [ReadDefault]>,
                                      SchedVar<NoSchedPred,        [ReadDefault]>]>;

def M4WriteNEONA   : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitFADD]>  { let Latency = 3;
                                                    let NumMicroOps = 2; }
def M4WriteNEONB   : SchedWriteRes<[M4UnitNALU,
                                    M4UnitS0]>    { let Latency = 5;
                                                    let NumMicroOps = 2; }
def M4WriteNEOND   : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitFST]>   { let Latency = 6;
                                                    let NumMicroOps = 2; }
def M4WriteNEONH   : SchedWriteRes<[M4UnitNALU,
                                    M4UnitS0]>    { let Latency = 5;
                                                    let NumMicroOps = 2; }
def M4WriteNEONI   : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitS0]>    { let Latency = 2;
                                                    let NumMicroOps = 2; }
def M4WriteNEONJ   : SchedWriteRes<[M4UnitNMSC,
                                    M4UnitS0]>    { let Latency = 4; }
def M4WriteNEONK   : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitNMSC,
                                    M4UnitS0]>    { let Latency = 5;
                                                    let NumMicroOps = 2; }
def M4WriteNEONL   : SchedWriteRes<[M4UnitNMUL]>  { let Latency = 3; }
def M4WriteNEONN   : SchedWriteRes<[M4UnitNMSC,
                                    M4UnitNMSC]>  { let Latency = 5;
                                                    let NumMicroOps = 2; }
def M4WriteNEONO   : SchedWriteRes<[M4UnitNMSC,
                                    M4UnitNMSC,
                                    M4UnitNMSC]>  { let Latency = 8;
                                                    let NumMicroOps = 3; }
def M4WriteNEONP   : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitNMSC]>  { let Latency = 4;
                                                    let NumMicroOps = 2; }
def M4WriteNEONQ   : SchedWriteRes<[M4UnitNMSC,
                                    M4UnitC]>     { let Latency = 3;
                                                    let NumMicroOps = 1; }
def M4WriteNEONR   : SchedWriteRes<[M4UnitFCVT0,
                                    M4UnitS0]>    { let Latency = 4;
                                                    let NumMicroOps = 1; }
def M4WriteNEONV   : SchedWriteRes<[M4UnitFDIV,
                                    M4UnitFDIV]>  { let Latency = 7;
                                                    let ResourceCycles = [6, 6]; }
def M4WriteNEONVH  : SchedWriteRes<[M4UnitFDIVH,
                                    M4UnitFDIVH]> { let Latency = 7;
                                                    let ResourceCycles = [6, 6]; }
def M4WriteNEONW   : SchedWriteRes<[M4UnitFDIV,
                                    M4UnitFDIV]>  { let Latency = 12;
                                                    let ResourceCycles = [9, 9]; }
def M4WriteNEONX   : SchedWriteRes<[M4UnitFSQR,
                                    M4UnitFSQR]>  { let Latency = 8;
                                                    let ResourceCycles = [7, 7]; }
def M4WriteNEONXH  : SchedWriteRes<[M4UnitFSQRH,
                                    M4UnitFSQRH]> { let Latency = 7;
                                                    let ResourceCycles = [6, 6]; }
def M4WriteNEONY   : SchedWriteRes<[M4UnitFSQR,
                                    M4UnitFSQR]>  { let Latency = 12;
                                                    let ResourceCycles = [9, 9]; }
def M4WriteNEONZ   : SchedWriteVariant<[SchedVar<ExynosQFormPred, [M4WriteNEONO]>,
                                        SchedVar<NoSchedPred,     [M4WriteNEONN]>]>;

def M4WriteFADD2   : SchedWriteRes<[M4UnitFADD]>  { let Latency = 2; }
def M4WriteFADD2H  : SchedWriteRes<[M4UnitFADDH]> { let Latency = 2; }

def M4WriteFCVT2   : SchedWriteRes<[M4UnitFCVT]>  { let Latency = 2; }
def M4WriteFCVT2A  : SchedWriteRes<[M4UnitFCVT0]> { let Latency = 2; }
def M4WriteFCVT2H  : SchedWriteRes<[M4UnitFCVTH]> { let Latency = 2; }
def M4WriteFCVT3   : SchedWriteRes<[M4UnitFCVT]>  { let Latency = 3; }
def M4WriteFCVT3A  : SchedWriteRes<[M4UnitFCVT0]> { let Latency = 3; }
def M4WriteFCVT3H  : SchedWriteRes<[M4UnitFCVTH]> { let Latency = 3; }
def M4WriteFCVT4   : SchedWriteRes<[M4UnitFCVT]>  { let Latency = 4; }
def M4WriteFCVT4A  : SchedWriteRes<[M4UnitFCVT0]> { let Latency = 4; }
def M4WriteFCVT6A  : SchedWriteRes<[M4UnitFCVT0]> { let Latency = 6; }

def M4WriteFDIV7   : SchedWriteRes<[M4UnitFDIV]>  { let Latency = 7;
                                                    let ResourceCycles = [6]; }
def M4WriteFDIV7H  : SchedWriteRes<[M4UnitFDIVH]> { let Latency = 7;
                                                    let ResourceCycles = [6]; }
def M4WriteFDIV12  : SchedWriteRes<[M4UnitFDIV]>  { let Latency = 12;
                                                    let ResourceCycles = [9]; }

def M4WriteFMAC2H  : SchedWriteRes<[M4UnitFMACH]> { let Latency = 2; }
def M4WriteFMAC3H  : SchedWriteRes<[M4UnitFMACH]> { let Latency = 3; }
def M4WriteFMAC3   : SchedWriteRes<[M4UnitFMAC]>  { let Latency = 3; }
def M4WriteFMAC4   : SchedWriteRes<[M4UnitFMAC]>  { let Latency = 4; }
def M4WriteFMAC4H  : SchedWriteRes<[M4UnitFMACH]> { let Latency = 4; }
def M4WriteFMAC5   : SchedWriteRes<[M4UnitFMAC]>  { let Latency = 5; }

def M4WriteFSQR7H  : SchedWriteRes<[M4UnitFSQRH]> { let Latency = 7;
                                                    let ResourceCycles = [6]; }
def M4WriteFSQR8   : SchedWriteRes<[M4UnitFSQR]>  { let Latency = 8;
                                                    let ResourceCycles = [7]; }
def M4WriteFSQR12  : SchedWriteRes<[M4UnitFSQR]>  { let Latency = 12;
                                                    let ResourceCycles = [9]; }

def M4WriteNALU1   : SchedWriteRes<[M4UnitNALU]>  { let Latency = 1; }
def M4WriteNALU1H  : SchedWriteRes<[M4UnitNALUH]> { let Latency = 1; }

def M4WriteNCRY1   : SchedWriteRes<[M4UnitNCRY]>  { let Latency = 1; }
def M4WriteNCRY1A  : SchedWriteRes<[M4UnitNCRY0]> { let Latency = 1; }
def M4WriteNCRY3A  : SchedWriteRes<[M4UnitNCRY0]> { let Latency = 3; }
def M4WriteNCRY5A  : SchedWriteRes<[M4UnitNCRY]>  { let Latency = 5; }

def M4WriteNHAD1   : SchedWriteRes<[M4UnitNHAD]>  { let Latency = 1; }
def M4WriteNHAD3   : SchedWriteRes<[M4UnitNHAD]>  { let Latency = 3; }

def M4WriteNMSC1   : SchedWriteRes<[M4UnitNMSC]>  { let Latency = 1; }
def M4WriteNMSC2   : SchedWriteRes<[M4UnitNMSC]>  { let Latency = 2; }
def M4WriteNMSC3   : SchedWriteRes<[M4UnitNMSC]>  { let Latency = 3; }

def M4WriteNMUL3   : SchedWriteRes<[M4UnitNMUL]>  { let Latency = 3; }

def M4WriteNSHF1   : SchedWriteRes<[M4UnitNSHF]>  { let Latency = 1; }
def M4WriteNSHF1H  : SchedWriteRes<[M4UnitNSHFH]> { let Latency = 1; }
def M4WriteNSHF3   : SchedWriteRes<[M4UnitNSHF]>  { let Latency = 3; }
def M4WriteNSHFA   : SchedWriteRes<[M4UnitNSHF]>  { let Latency = 1;
                                                    let ResourceCycles = [2]; }
def M4WriteNSHFB   : SchedWriteRes<[M4UnitNSHF]>  { let Latency = 2;
                                                    let NumMicroOps = 2;
                                                    let ResourceCycles = [2]; }
def M4WriteNSHFC   : SchedWriteRes<[M4UnitNSHF]>  { let Latency = 3;
                                                    let NumMicroOps = 3;
                                                    let ResourceCycles = [4]; }
def M4WriteNSHFD   : SchedWriteRes<[M4UnitNSHF]>  { let Latency = 4;
                                                    let NumMicroOps = 4;
                                                    let ResourceCycles = [4]; }

def M4WriteNSHT1   : SchedWriteRes<[M4UnitNSHT]>  { let Latency = 1; }
def M4WriteNSHT2   : SchedWriteRes<[M4UnitNSHT]>  { let Latency = 2; }
def M4WriteNSHT3   : SchedWriteRes<[M4UnitNSHT]>  { let Latency = 3; }
def M4WriteNSHT4A  : SchedWriteRes<[M4UnitNSHT1]> { let Latency = 4; }

def M4WriteVLDA    : SchedWriteRes<[M4UnitL,
                                    M4UnitL]>     { let Latency = 5;
                                                    let NumMicroOps = 2; }
def M4WriteVLDB    : SchedWriteRes<[M4UnitL,
                                    M4UnitL,
                                    M4UnitL]>     { let Latency = 6;
                                                    let NumMicroOps = 3; }
def M4WriteVLDC    : SchedWriteRes<[M4UnitL,
                                    M4UnitL,
                                    M4UnitL,
                                    M4UnitL]>     { let Latency = 6;
                                                    let NumMicroOps = 4; }
def M4WriteVLDD    : SchedWriteRes<[M4UnitL,
                                    M4UnitNSHF]>  { let Latency = 6;
                                                    let NumMicroOps = 2;
                                                    let ResourceCycles = [2, 1]; }
def M4WriteVLDF    : SchedWriteRes<[M4UnitL,
                                    M4UnitL]>     { let Latency = 10;
                                                    let NumMicroOps = 2;
                                                    let ResourceCycles = [3, 3]; }
def M4WriteVLDG    : SchedWriteRes<[M4UnitL,
                                    M4UnitNSHF,
                                    M4UnitNSHF]>  { let Latency = 6;
                                                    let NumMicroOps = 3;
                                                    let ResourceCycles = [2, 1, 1]; }
def M4WriteVLDI    : SchedWriteRes<[M4UnitL,
                                    M4UnitL,
                                    M4UnitL]>     { let Latency = 12;
                                                    let NumMicroOps = 3;
                                                    let ResourceCycles = [3, 3, 3]; }
def M4WriteVLDJ    : SchedWriteRes<[M4UnitL,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitNSHF]>  { let Latency = 7;
                                                    let NumMicroOps = 4;
                                                    let ResourceCycles = [3, 1, 1, 1]; }
def M4WriteVLDK    : SchedWriteRes<[M4UnitL,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitNSHF]>  { let Latency = 7;
                                                    let NumMicroOps = 5;
                                                    let ResourceCycles = [3, 1, 1, 1, 1]; }
def M4WriteVLDL    : SchedWriteRes<[M4UnitL,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitL,
                                    M4UnitNSHF]>  { let Latency = 7;
                                                    let NumMicroOps = 5;
                                                    let ResourceCycles = [3, 1, 1, 6, 1]; }
def M4WriteVLDM    : SchedWriteRes<[M4UnitL,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitL,
                                    M4UnitNSHF,
                                    M4UnitNSHF]>  { let Latency = 7;
                                                    let NumMicroOps = 6;
                                                    let ResourceCycles = [3, 1, 1, 3, 1, 1]; }
def M4WriteVLDN    : SchedWriteRes<[M4UnitL,
                                    M4UnitL,
                                    M4UnitL,
                                    M4UnitL]>     { let Latency = 14;
                                                    let NumMicroOps = 4;
                                                    let ResourceCycles = [3, 3, 3, 3]; }

def M4WriteVST1    : SchedWriteRes<[M4UnitS,
                                    M4UnitFST]>  { let Latency = 1;
                                                   let NumMicroOps = 1; }
def M4WriteVSTA    : WriteSequence<[WriteVST], 2>;
def M4WriteVSTB    : WriteSequence<[WriteVST], 3>;
def M4WriteVSTC    : WriteSequence<[WriteVST], 4>;
def M4WriteVSTD    : SchedWriteRes<[M4UnitS,
                                    M4UnitFST]>   { let Latency = 2; }
def M4WriteVSTE    : SchedWriteRes<[M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 2;
                                                    let NumMicroOps = 2; }
def M4WriteVSTF    : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 4;
                                                    let NumMicroOps = 4;
                                                    let ResourceCycles = [1, 2, 1, 2, 1]; }
def M4WriteVSTG    : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 5;
                                                    let NumMicroOps = 6;
                                                    let ResourceCycles = [1, 1, 1, 2, 1, 2, 1, 2, 1]; }
def M4WriteVSTI    : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 8;
                                                    let NumMicroOps = 5;
                                                    let ResourceCycles = [1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1]; }
def M4WriteVSTJ    : SchedWriteRes<[M4UnitA,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 1;
                                                    let NumMicroOps = 2; }
def M4WriteVSTK    : SchedWriteRes<[M4UnitA,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 3;
                                                    let NumMicroOps = 2; }
def M4WriteVSTL    : SchedWriteRes<[M4UnitNSHF,
                                    M4UnitNSHF,
                                    M4UnitS,
                                    M4UnitFST,
                                    M4UnitS,
                                    M4UnitFST]>   { let Latency = 4;
                                                    let NumMicroOps = 4;
                                                    let ResourceCycles = [1, 1, 2, 1, 2, 1]; }
def M4WriteVSTY    : SchedWriteVariant<[SchedVar<ExynosScaledIdxPred, [M4WriteVSTK]>,
                                        SchedVar<NoSchedPred,         [WriteVST]>]>;

// Special cases.
def M4WriteCOPY    : SchedWriteVariant<[SchedVar<ExynosFPPred, [M4WriteNALU1]>,
                                        SchedVar<NoSchedPred,  [M4WriteZ0]>]>;
def M4WriteMOVI    : SchedWriteVariant<[SchedVar<IsZeroFPIdiomPred, [M4WriteZ0]>,
                                        SchedVar<NoSchedPred,       [M4WriteNALU1]>]>;

// Fast forwarding.
def M4ReadAESM1    : SchedReadAdvance<+1, [M4WriteNCRY1]>;
def M4ReadFMACM1   : SchedReadAdvance<+1, [M4WriteFMAC4,
                                           M4WriteFMAC4H,
                                           M4WriteFMAC5]>;
def M4ReadNMULM1   : SchedReadAdvance<+1, [M4WriteNMUL3]>;
def M4ReadNMULP2   : SchedReadAdvance<-2, [M4WriteNMUL3]>;


//===----------------------------------------------------------------------===//
// Coarse scheduling model.

// Branch instructions.
def : SchedAlias<WriteBr,    M4WriteZ0>;
def : SchedAlias<WriteBrReg, M4WriteC1>;

// Arithmetic and logical integer instructions.
def : SchedAlias<WriteI,     M4WriteA1>;
def : SchedAlias<WriteIEReg, M4WriteAA>; // FIXME: M4WriteAX crashes TableGen.
def : SchedAlias<WriteISReg, M4WriteAA>; // FIXME: M4WriteAX crashes TableGen.
def : SchedAlias<WriteIS,    M4WriteA1>;

// Move instructions.
def : SchedAlias<WriteImm, M4WriteA1>;

// Divide and multiply instructions.
def : SchedAlias<WriteID32, M4WriteD12>;
def : SchedAlias<WriteID64, M4WriteD21>;
def : SchedAlias<WriteIM32, M4WriteC3>;
def : SchedAlias<WriteIM64, M4WriteCA>;

// Miscellaneous instructions.
def : SchedAlias<WriteExtr, M4WriteAY>;

// Addressing modes.
def : SchedAlias<WriteAdr,    M4WriteZ1>;
def : SchedAlias<ReadAdrBase, M4ReadAdrBase>;

// Load instructions.
def : SchedAlias<WriteLD,    M4WriteL4>;
def : SchedAlias<WriteLDHi,  M4WriteZ4>;
def : SchedAlias<WriteLDIdx, M4WriteLX>;

// Store instructions.
def : SchedAlias<WriteST,    M4WriteS1>;
def : SchedAlias<WriteSTP,   M4WriteS1>;
def : SchedAlias<WriteSTX,   M4WriteS1>;
def : SchedAlias<WriteSTIdx, M4WriteSX>;

// FP data instructions.
def : SchedAlias<WriteF,    M4WriteFADD2>;
def : SchedAlias<WriteFCmp, M4WriteNMSC2>;
def : SchedAlias<WriteFDiv, M4WriteFDIV12>;
def : SchedAlias<WriteFMul, M4WriteFMAC3>;

// FP miscellaneous instructions.
def : SchedAlias<WriteFCvt,  M4WriteFCVT2>;
def : SchedAlias<WriteFImm,  M4WriteNALU1>;
def : SchedAlias<WriteFCopy, M4WriteNALU1>;

// FP load instructions.
def : SchedAlias<WriteVLD, M4WriteL5>;

// FP store instructions.
def : SchedAlias<WriteVST, M4WriteVST1>;

// ASIMD FP instructions.
def : SchedAlias<WriteV, M4WriteNALU1>;

// Other miscellaneous instructions.
def : WriteRes<WriteAtomic,  []> { let Unsupported = 1; }
def : WriteRes<WriteBarrier, []> { let Latency = 1; }
def : WriteRes<WriteHint,    []> { let Latency = 1; }
def : WriteRes<WriteSys,     []> { let Latency = 1; }

//===----------------------------------------------------------------------===//
// Generic fast forwarding.

// TODO: Add FP register forwarding rules.

def : ReadAdvance<ReadI,       0>;
def : ReadAdvance<ReadISReg,   0>;
def : ReadAdvance<ReadIEReg,   0>;
def : ReadAdvance<ReadIM,      0>;
// TODO: The forwarding for 32 bits actually saves 2 cycles.
def : ReadAdvance<ReadIMA,     3, [WriteIM32, WriteIM64]>;
def : ReadAdvance<ReadID,      0>;
def : ReadAdvance<ReadExtrHi,  0>;
def : ReadAdvance<ReadAdrBase, 0>;
def : ReadAdvance<ReadVLD,     0>;

//===----------------------------------------------------------------------===//
// Finer scheduling model.

// Branch instructions
def : InstRW<[M4WriteB1], (instrs Bcc)>;
def : InstRW<[M4WriteAF], (instrs BL)>;
def : InstRW<[M4WriteBX], (instrs BLR)>;
def : InstRW<[M4WriteC1], (instregex "^CBN?Z[WX]")>;
def : InstRW<[M4WriteAD], (instregex "^TBN?Z[WX]")>;

// Arithmetic and logical integer instructions.
def : InstRW<[M4WriteAX], (instregex "^(ADD|AND|BIC|EON|EOR|ORN|SUB)[WX]rs$")>;
def : InstRW<[M4WriteAU], (instrs ORRWrs, ORRXrs)>;
def : InstRW<[M4WriteAX], (instregex "^(ADD|AND|BIC|SUB)S[WX]rs$")>;
def : InstRW<[M4WriteAX], (instregex "^(ADD|SUB)S?[WX]rx(64)?$")>;
def : InstRW<[M4WriteAV], (instrs ADDWri, ADDXri, ORRWri, ORRXri)>;

// Move instructions.
def : InstRW<[M4WriteCOPY], (instrs COPY)>;
def : InstRW<[M4WriteZ0],   (instrs ADR, ADRP)>;
def : InstRW<[M4WriteZ0],   (instregex "^MOV[NZ][WX]i")>;

// Divide and multiply instructions.

// Miscellaneous instructions.

// Load instructions.
def : InstRW<[M4WriteLD,
              WriteLDHi,
              WriteAdr],    (instregex "^LDP(SW|W|X)(post|pre)")>;
def : InstRW<[M4WriteL5,
              ReadAdrBase], (instregex "^LDR(BB|SBW|SBX|HH|SHW|SHX|SW|W|X)roW")>;
def : InstRW<[WriteLDIdx,
              ReadAdrBase], (instregex "^LDR(BB|SBW|SBX|HH|SHW|SHX|SW|W|X)roX")>;
def : InstRW<[M4WriteL5,
              ReadAdrBase], (instrs PRFMroW)>;
def : InstRW<[WriteLDIdx,
              ReadAdrBase], (instrs PRFMroX)>;

// Store instructions.
def : InstRW<[M4WriteSB,
              ReadAdrBase], (instregex "^STR(BB|HH|W|X)roW")>;
def : InstRW<[WriteST,
              ReadAdrBase], (instregex "^STR(BB|HH|W|X)roX")>;

// FP data instructions.
def : InstRW<[M4WriteNSHF1H], (instrs FABSHr)>;
def : InstRW<[M4WriteNSHF1],  (instregex "^FABS[SD]r")>;
def : InstRW<[M4WriteFADD2H], (instregex "^F(ADD|SUB)Hrr")>;
def : InstRW<[M4WriteFADD2],  (instregex "^F(ADD|SUB)[SD]rr")>;
def : InstRW<[M4WriteFADD2H], (instregex "^FADDPv.i16")>;
def : InstRW<[M4WriteFADD2],  (instregex "^FADDPv.i(32|64)")>;
def : InstRW<[M4WriteNEONQ],  (instregex "^FCCMPE?[HSD]rr")>;
def : InstRW<[M4WriteNMSC2],  (instregex "^FCMPE?[HSD]r[ir]")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^F(AC|CM)(EQ|GE|GT|LE|LT)(16|32|64|v1)")>;
def : InstRW<[M4WriteFDIV7H], (instrs FDIVHrr)>;
def : InstRW<[M4WriteFDIV7],  (instrs FDIVSrr)>;
def : InstRW<[M4WriteFDIV12], (instrs FDIVDrr)>;
def : InstRW<[M4WriteNMSC1],  (instregex "^F(MAX|MIN)(NM)?[HSD]rr")>;
def : InstRW<[M4WriteFMAC3H], (instregex "^FN?MULHrr")>;
def : InstRW<[M4WriteFMAC3],  (instregex "^FN?MUL[SD]rr")>;
def : InstRW<[M4WriteFMAC3H], (instrs FMULX16)>;
def : InstRW<[M4WriteFMAC3],  (instregex "^FMULX(32|64)")>;
def : InstRW<[M4WriteFMAC4H,
              M4ReadFMACM1],  (instregex "^FN?M(ADD|SUB)Hrrr")>;
def : InstRW<[M4WriteFMAC4,
              M4ReadFMACM1],  (instregex "^FN?M(ADD|SUB)[SD]rrr")>;
def : InstRW<[M4WriteNALU1H], (instrs FNEGHr)>;
def : InstRW<[M4WriteNALU1],  (instregex "^FNEG[SD]r")>;
def : InstRW<[M4WriteFCVT3A], (instregex "^FRINT.+r")>;
def : InstRW<[M4WriteNEONH],  (instregex "^FCSEL[HSD]rrr")>;
def : InstRW<[M4WriteFSQR7H], (instrs FSQRTHr)>;
def : InstRW<[M4WriteFSQR8],  (instrs FSQRTSr)>;
def : InstRW<[M4WriteFSQR12], (instrs FSQRTDr)>;

// FP miscellaneous instructions.
def : InstRW<[M4WriteFCVT2H], (instregex "^FCVTH[SD]r")>;
def : InstRW<[M4WriteFCVT2H], (instregex "^FCVT[SD]Hr")>;
def : InstRW<[M4WriteFCVT2],  (instregex "^FCVT[SD][SD]r")>;
def : InstRW<[M4WriteFCVT6A], (instregex "^[SU]CVTF[SU][XW][HSD]ri")>;
def : InstRW<[M4WriteNEONR],  (instregex "^FCVT[AMNPZ][SU][SU][XW][HSD]r")>;
def : InstRW<[M4WriteNALU1],  (instregex "^FMOV[HSD][ir]")>;
def : InstRW<[M4WriteSA],     (instregex "^FMOV[WX][HSD]r")>;
def : InstRW<[M4WriteNEONJ],  (instregex "^FMOV[HSD][WX]r")>;
def : InstRW<[M4WriteNEONI],  (instregex "^FMOVXDHighr")>;
def : InstRW<[M4WriteNEONK],  (instregex "^FMOVDXHighr")>;
def : InstRW<[M4WriteFCVT3H], (instregex "^F(RECP|RSQRT)Ev1f16")>;
def : InstRW<[M4WriteFCVT3],  (instregex "^F(RECP|RSQRT)Ev1i(32|64)")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^FRECPXv1")>;
def : InstRW<[M4WriteFMAC4H], (instregex "^F(RECP|RSQRT)S16")>;
def : InstRW<[M4WriteFMAC4],  (instregex "^F(RECP|RSQRT)S(32|64)")>;

// FP load instructions.
def : InstRW<[WriteVLD],    (instregex "^LDR[SDQ]l")>;
def : InstRW<[WriteVLD],    (instregex "^LDUR[BHSDQ]i")>;
def : InstRW<[WriteVLD,
              WriteAdr],    (instregex "^LDR[BHSDQ](post|pre)")>;
def : InstRW<[WriteVLD],    (instregex "^LDR[BHSDQ]ui")>;
def : InstRW<[M4WriteLE,
              ReadAdrBase], (instregex "^LDR[BHSDQ]roW")>;
def : InstRW<[WriteVLD,
              ReadAdrBase], (instregex "^LDR[BHSD]roX")>;
def : InstRW<[M4WriteLY,
              ReadAdrBase], (instrs LDRQroX)>;
def : InstRW<[WriteVLD,
              M4WriteLH],   (instregex "^LDN?P[SD]i")>;
def : InstRW<[M4WriteLA,
              M4WriteLH],   (instregex "^LDN?PQi")>;
def : InstRW<[M4WriteL5,
              M4WriteLH,
              WriteAdr],    (instregex "^LDP[SD]post")>;
def : InstRW<[M4WriteLB,
              M4WriteLH,
              WriteAdr],    (instrs LDPQpost)>;
def : InstRW<[M4WriteLB,
              M4WriteLH,
              WriteAdr],    (instregex "^LDP[SD]pre")>;
def : InstRW<[M4WriteLC,
              M4WriteLH,
              WriteAdr],    (instrs LDPQpre)>;

// FP store instructions.
def : InstRW<[WriteVST],    (instregex "^STUR[BHSDQ]i")>;
def : InstRW<[WriteVST,
              WriteAdr],    (instregex "^STR[BHSDQ](post|pre)")>;
def : InstRW<[WriteVST],    (instregex "^STR[BHSDQ]ui")>;
def : InstRW<[M4WriteVSTK,
              ReadAdrBase], (instregex "^STR[BHSD]roW")>;
def : InstRW<[M4WriteVSTK,
              ReadAdrBase], (instrs STRQroW)>;
def : InstRW<[WriteVST,
              ReadAdrBase], (instregex "^STR[BHSD]roX")>;
def : InstRW<[M4WriteVSTY,
              ReadAdrBase], (instrs STRQroX)>;
def : InstRW<[WriteVST],    (instregex "^STN?P[SD]i")>;
def : InstRW<[M4WriteVSTJ], (instregex "^STN?PQi")>;
def : InstRW<[WriteVST,
              WriteAdr],    (instregex "^STP[SD](post|pre)")>;
def : InstRW<[M4WriteVSTJ,
              WriteAdr],    (instregex "^STPQ(post|pre)")>;

// ASIMD instructions.
def : InstRW<[M4WriteNHAD1],  (instregex "^[SU]ABDL?v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]ABAL?v")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^ABSv")>;
def : InstRW<[M4WriteNALU1],  (instregex "^(ADD|NEG|SUB)v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]?ADDL?Pv")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]H(ADD|SUB)v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU](ADD|SUB)[LW]v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^R?(ADD|SUB)HN2?v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]Q(ADD|SUB)v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^(SU|US)QADDv")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]RHADDv")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^SQ(ABS|NEG)v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]?ADDL?Vv")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^CM(EQ|GE|GT|HI|HS|LE|LT)v")>;
def : InstRW<[M4WriteNALU1],  (instregex "^CMTSTv")>;
def : InstRW<[M4WriteNALU1],  (instregex "^(AND|BIC|EOR|NOT|ORN|ORR)v")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^[SU](MIN|MAX)v")>;
def : InstRW<[M4WriteNMSC2],  (instregex "^[SU](MIN|MAX)Pv")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU](MIN|MAX)Vv")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULM1],  (instregex "^ML[AS]v")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULM1],  (instregex "^(SQR?D)?MULH?v")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULM1],  (instregex "^SQRDML[AS]H")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULM1],  (instregex "^(S|U|SQD)ML[AS]L(v1(i32|i64)|v2i32|v4i16|v8i8)")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULP2],  (instregex "^(S|U|SQD)ML[AS]L(v4i32|v8i16|v16i8)")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULM1],  (instregex "^(S|U|SQD)MULL(v1(i32|i64)|v2i32|v4i16|v8i8)")>;
def : InstRW<[M4WriteNMUL3,
              M4ReadNMULP2],  (instregex "^(S|U|SQD)MULL(v4i32|v8i16|v16i8)")>;
def : InstRW<[M4WriteNMUL3],  (instregex "^[SU]DOT(lane)?v")>;
def : InstRW<[M4WriteNHAD3],  (instregex "^[SU]ADALPv")>;
def : InstRW<[M4WriteNSHT4A], (instregex "^[SU]R?SRA[dv]")>;
def : InstRW<[M4WriteNSHT1],  (instregex "^SHL[dv]")>;
def : InstRW<[M4WriteNSHT1],  (instregex "^S[LR]I[dv]")>;
def : InstRW<[M4WriteNSHT1],  (instregex "^[SU]SH[LR][dv]")>;
def : InstRW<[M4WriteNSHT2],  (instregex "^[SU]?SHLLv")>;
def : InstRW<[M4WriteNSHT4A], (instregex "^[SU]?Q?R?SHRU?N[bhsv]")>;
def : InstRW<[M4WriteNSHT4A], (instregex "^[SU]RSH[LR][dv]")>;
def : InstRW<[M4WriteNSHT4A], (instregex "^[SU]QR?SHLU?[bhsdv]")>;

// ASIMD FP instructions.
def : InstRW<[M4WriteNSHF1H], (instregex "^FABSv.f16")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^FABSv.f(32|64)")>;
def : InstRW<[M4WriteFADD2H], (instregex "^F(ABD|ADD|SUB)v.f16")>;
def : InstRW<[M4WriteFADD2],  (instregex "^F(ABD|ADD|SUB)v.f(32|64)")>;
def : InstRW<[M4WriteFADD2H], (instregex "^FADDPv.f16")>;
def : InstRW<[M4WriteFADD2],  (instregex "^FADDPv.f(32|64)")>;
def : InstRW<[M4WriteNMSC1],  (instregex "^F(AC|CM)(EQ|GE|GT|LE|LT)v[^1]")>;
def : InstRW<[M4WriteFCVT2],  (instregex "^FCVT(L|N|XN)v")>;
def : InstRW<[M4WriteFCVT2A], (instregex "^FCVT[AMNPZ][SU]v")>;
def : InstRW<[M4WriteFCVT2H], (instregex "^[SU]CVTFv.[fi]16")>;
def : InstRW<[M4WriteFCVT2],  (instregex "^[SU]CVTFv.[fi](32|64)")>;
def : InstRW<[M4WriteFDIV7H], (instrs FDIVv4f16)>;
def : InstRW<[M4WriteNEONVH], (instrs FDIVv8f16)>;
def : InstRW<[M4WriteFDIV7],  (instrs FDIVv2f32)>;
def : InstRW<[M4WriteNEONV],  (instrs FDIVv4f32)>;
def : InstRW<[M4WriteNEONW],  (instrs FDIVv2f64)>;
def : InstRW<[M4WriteNMSC1],  (instregex "^F(MAX|MIN)(NM)?v")>;
def : InstRW<[M4WriteNMSC2],  (instregex "^F(MAX|MIN)(NM)?Pv")>;
def : InstRW<[M4WriteNEONZ],  (instregex "^F(MAX|MIN)(NM)?Vv")>;
def : InstRW<[M4WriteFMAC2H], (instregex "^FMULX?v.[fi]16")>;
def : InstRW<[M4WriteFMAC3],  (instregex "^FMULX?v.[fi](32|64)")>;
def : InstRW<[M4WriteFMAC4H,
              M4ReadFMACM1],  (instregex "^FML[AS]v.[fi]16")>;
def : InstRW<[M4WriteFMAC4,
              M4ReadFMACM1],  (instregex "^FML[AS]v.[fi](32|64)")>;
def : InstRW<[M4WriteNALU1H], (instregex "^FNEGv.f16")>;
def : InstRW<[M4WriteNALU1],  (instregex "^FNEGv.f(32|64)")>;
def : InstRW<[M4WriteFCVT3A], (instregex "^FRINT[AIMNPXZ]v")>;
def : InstRW<[M4WriteFSQR7H], (instrs FSQRTv4f16)>;
def : InstRW<[M4WriteNEONXH], (instrs FSQRTv8f16)>;
def : InstRW<[M4WriteFSQR8],  (instrs FSQRTv2f32)>;
def : InstRW<[M4WriteNEONX],  (instrs FSQRTv4f32)>;
def : InstRW<[M4WriteNEONY],  (instrs FSQRTv2f64)>;

// ASIMD miscellaneous instructions.
def : InstRW<[M4WriteNALU1],  (instregex "^RBITv")>;
def : InstRW<[M4WriteNALU1],  (instregex "^(BIF|BIT|BSL)v")>;
def : InstRW<[M4WriteNALU1],  (instregex "^CL[STZ]v")>;
def : InstRW<[M4WriteNEONB],  (instregex "^DUPv.+gpr")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^CPY")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^DUPv.+lane")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^EXTv")>;
def : InstRW<[M4WriteNSHT4A], (instregex "^XTNv")>;
def : InstRW<[M4WriteNSHT4A], (instregex "^[SU]?QXTU?Nv")>;
def : InstRW<[M4WriteNEONB],  (instregex "^INSv.+gpr")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^INSv.+lane")>;
def : InstRW<[M4WriteMOVI],   (instregex "^(MOV|MVN)I")>;
def : InstRW<[M4WriteNALU1H], (instregex "^FMOVv.f16")>;
def : InstRW<[M4WriteNALU1],  (instregex "^FMOVv.f(32|64)")>;
def : InstRW<[M4WriteFCVT3H], (instregex "^F(RECP|RSQRT)Ev[248]f16")>;
def : InstRW<[M4WriteFCVT3],  (instregex "^F(RECP|RSQRT)Ev[248]f(32|64)")>;
def : InstRW<[M4WriteFCVT3],  (instregex "^U(RECP|RSQRT)Ev[24]i32")>;
def : InstRW<[M4WriteFMAC4H], (instregex "^F(RECP|RSQRT)Sv.f16")>;
def : InstRW<[M4WriteFMAC4],  (instregex "^F(RECP|RSQRT)Sv.f(32|64)")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^REV(16|32|64)v")>;
def : InstRW<[M4WriteNSHFA],  (instregex "^TB[LX]v(8|16)i8One")>;
def : InstRW<[M4WriteNSHFB],  (instregex "^TB[LX]v(8|16)i8Two")>;
def : InstRW<[M4WriteNSHFC],  (instregex "^TB[LX]v(8|16)i8Three")>;
def : InstRW<[M4WriteNSHFD],  (instregex "^TB[LX]v(8|16)i8Four")>;
def : InstRW<[M4WriteNEONP],  (instregex "^[SU]MOVv")>;
def : InstRW<[M4WriteNSHF1],  (instregex "^(TRN|UZP|ZIP)[12]v")>;

// ASIMD load instructions.
def : InstRW<[WriteVLD],    (instregex "LD1Onev(8b|4h|2s|1d)$")>;
def : InstRW<[WriteVLD,
              M4WriteA1],   (instregex "LD1Onev(8b|4h|2s|1d)_POST$")>;
def : InstRW<[WriteVLD],    (instregex "LD1Onev(16b|8h|4s|2d)$")>;
def : InstRW<[WriteVLD,
              M4WriteA1],   (instregex "LD1Onev(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDA], (instregex "LD1Twov(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVLDA,
              M4WriteA1],   (instregex "LD1Twov(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVLDA], (instregex "LD1Twov(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDA,
              M4WriteA1],   (instregex "LD1Twov(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDB], (instregex "LD1Threev(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVLDB,
              M4WriteA1],   (instregex "LD1Threev(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVLDB], (instregex "LD1Threev(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDB,
              M4WriteA1],   (instregex "LD1Threev(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDC], (instregex "LD1Fourv(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVLDC,
              M4WriteA1],   (instregex "LD1Fourv(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVLDC], (instregex "LD1Fourv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDC,
              M4WriteA1],   (instregex "LD1Fourv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDD], (instregex "LD1i(8|16|32|64)$")>;
def : InstRW<[M4WriteVLDD,
              M4WriteA1],   (instregex "LD1i(8|16|32|64)_POST$")>;

def : InstRW<[WriteVLD],    (instregex "LD1Rv(8b|4h|2s|1d)$")>;
def : InstRW<[WriteVLD,
              M4WriteA1],   (instregex "LD1Rv(8b|4h|2s|1d)_POST$")>;
def : InstRW<[WriteVLD],    (instregex "LD1Rv(16b|8h|4s|2d)$")>;
def : InstRW<[WriteVLD,
              M4WriteA1],   (instregex "LD1Rv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDF], (instregex "LD2Twov(8b|4h|2s)$")>;
def : InstRW<[M4WriteVLDF,
              M4WriteA1],   (instregex "LD2Twov(8b|4h|2s)_POST$")>;
def : InstRW<[M4WriteVLDF], (instregex "LD2Twov(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDF,
              M4WriteA1],   (instregex "LD2Twov(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDG], (instregex "LD2i(8|16|32|64)$")>;
def : InstRW<[M4WriteVLDG,
              M4WriteA1],   (instregex "LD2i(8|16|32|64)_POST$")>;

def : InstRW<[M4WriteVLDA], (instregex "LD2Rv(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVLDA,
              M4WriteA1],   (instregex "LD2Rv(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVLDA], (instregex "LD2Rv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDA,
              M4WriteA1],   (instregex "LD2Rv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDI], (instregex "LD3Threev(8b|4h|2s)$")>;
def : InstRW<[M4WriteVLDI,
              M4WriteA1],   (instregex "LD3Threev(8b|4h|2s)_POST$")>;
def : InstRW<[M4WriteVLDI], (instregex "LD3Threev(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDI,
              M4WriteA1],   (instregex "LD3Threev(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDJ], (instregex "LD3i(8|16|32)$")>;
def : InstRW<[M4WriteVLDJ,
              M4WriteA1],   (instregex "LD3i(8|16|32)_POST$")>;
def : InstRW<[M4WriteVLDL], (instregex "LD3i64$")>;
def : InstRW<[M4WriteVLDL,
              M4WriteA1],   (instregex "LD3i64_POST$")>;

def : InstRW<[M4WriteVLDB], (instregex "LD3Rv(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVLDB,
              M4WriteA1],   (instregex "LD3Rv(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVLDB], (instregex "LD3Rv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDB,
              M4WriteA1],   (instregex "LD3Rv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDN], (instregex "LD4Fourv(8b|4h|2s)$")>;
def : InstRW<[M4WriteVLDN,
              M4WriteA1],   (instregex "LD4Fourv(8b|4h|2s)_POST$")>;
def : InstRW<[M4WriteVLDN], (instregex "LD4Fourv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDN,
              M4WriteA1],   (instregex "LD4Fourv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVLDK], (instregex "LD4i(8|16|32)$")>;
def : InstRW<[M4WriteVLDK,
              M4WriteA1],   (instregex "LD4i(8|16|32)_POST$")>;
def : InstRW<[M4WriteVLDM], (instregex "LD4i64$")>;
def : InstRW<[M4WriteVLDM,
              M4WriteA1],   (instregex "LD4i64_POST$")>;

def : InstRW<[M4WriteVLDC], (instregex "LD4Rv(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVLDC,
              M4WriteA1],   (instregex "LD4Rv(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVLDC], (instregex "LD4Rv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVLDC,
              M4WriteA1],   (instregex "LD4Rv(16b|8h|4s|2d)_POST$")>;

// ASIMD store instructions.
def : InstRW<[WriteVST],    (instregex "ST1Onev(8b|4h|2s|1d)$")>;
def : InstRW<[WriteVST,
              M4WriteA1],   (instregex "ST1Onev(8b|4h|2s|1d)_POST$")>;
def : InstRW<[WriteVST],    (instregex "ST1Onev(16b|8h|4s|2d)$")>;
def : InstRW<[WriteVST,
              M4WriteA1],   (instregex "ST1Onev(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVSTA], (instregex "ST1Twov(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVSTA,
              M4WriteA1],   (instregex "ST1Twov(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVSTA], (instregex "ST1Twov(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVSTA,
              M4WriteA1],   (instregex "ST1Twov(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVSTB], (instregex "ST1Threev(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVSTB,
              M4WriteA1],   (instregex "ST1Threev(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVSTB], (instregex "ST1Threev(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVSTB,
              M4WriteA1],   (instregex "ST1Threev(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVSTC], (instregex "ST1Fourv(8b|4h|2s|1d)$")>;
def : InstRW<[M4WriteVSTC,
              M4WriteA1],   (instregex "ST1Fourv(8b|4h|2s|1d)_POST$")>;
def : InstRW<[M4WriteVSTC], (instregex "ST1Fourv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVSTC,
              M4WriteA1],   (instregex "ST1Fourv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[WriteVST],    (instregex "ST1i(8|16|32|64)$")>;
def : InstRW<[WriteVST,
              M4WriteA1],   (instregex "ST1i(8|16|32|64)_POST$")>;

def : InstRW<[M4WriteVSTD], (instregex "ST2Twov(8b|4h|2s)$")>;
def : InstRW<[M4WriteVSTD,
              M4WriteA1],   (instregex "ST2Twov(8b|4h|2s)_POST$")>;
def : InstRW<[M4WriteVSTE], (instregex "ST2Twov(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVSTE,
              M4WriteA1],   (instregex "ST2Twov(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVSTD], (instregex "ST2i(8|16|32|64)$")>;
def : InstRW<[M4WriteVSTD,
              M4WriteA1],   (instregex "ST2i(8|16|32|64)_POST$")>;

def : InstRW<[M4WriteVSTF], (instregex "ST3Threev(8b|4h|2s)$")>;
def : InstRW<[M4WriteVSTF,
              M4WriteA1],   (instregex "ST3Threev(8b|4h|2s)_POST$")>;
def : InstRW<[M4WriteVSTG], (instregex "ST3Threev(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVSTG,
              M4WriteA1],   (instregex "ST3Threev(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVSTE], (instregex "ST3i(8|16|32|64)$")>;
def : InstRW<[M4WriteVSTE,
              M4WriteA1],   (instregex "ST3i(8|16|32|64)_POST$")>;

def : InstRW<[M4WriteVSTL], (instregex "ST4Fourv(8b|4h|2s)$")>;
def : InstRW<[M4WriteVSTL,
              M4WriteA1],   (instregex "ST4Fourv(8b|4h|2s)_POST$")>;
def : InstRW<[M4WriteVSTI], (instregex "ST4Fourv(16b|8h|4s|2d)$")>;
def : InstRW<[M4WriteVSTI,
              M4WriteA1],   (instregex "ST4Fourv(16b|8h|4s|2d)_POST$")>;

def : InstRW<[M4WriteVSTE], (instregex "ST4i(8|16|32|64)$")>;
def : InstRW<[M4WriteVSTE,
              M4WriteA1],   (instregex "ST4i(8|16|32|64)_POST$")>;

// Cryptography instructions.
def : InstRW<[M4WriteNCRY1],  (instregex "^AES[DE]")>;
def : InstRW<[M4WriteNCRY1,
              M4ReadAESM1],   (instregex "^AESI?MC")>;
def : InstRW<[M4WriteNCRY1A], (instregex "^PMULv")>;
def : InstRW<[M4WriteNCRY1A], (instregex "^PMULLv(1|8)i")>;
def : InstRW<[M4WriteNCRY3A], (instregex "^PMULLv(2|16)i")>;
def : InstRW<[M4WriteNCRY1A], (instregex "^SHA1([CHMP]|SU[01])")>;
def : InstRW<[M4WriteNCRY1A], (instrs SHA256SU0rr)>;
def : InstRW<[M4WriteNCRY5A], (instrs SHA256SU1rrr)>;
def : InstRW<[M4WriteNCRY5A], (instrs SHA256H2rrr)>;

// CRC instructions.
def : InstRW<[M4WriteE2], (instregex "^CRC32C?[BHWX]rr$")>;

} // SchedModel = ExynosM4Model