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 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046
|
/*
* Copyright (C) 2011-2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if ENABLE(DFG_JIT)
#include "BlockDirectory.h"
#include "DFGAbstractInterpreter.h"
#include "DFGGenerationInfo.h"
#include "DFGInPlaceAbstractState.h"
#include "DFGJITCompiler.h"
#include "DFGOSRExit.h"
#include "DFGOSRExitJumpPlaceholder.h"
#include "DFGRegisterBank.h"
#include "DFGSilentRegisterSavePlan.h"
#include "JITMathIC.h"
#include "JITOperations.h"
#include "SpillRegistersMode.h"
#include "StructureStubInfo.h"
#include "ValueRecovery.h"
#include "VirtualRegister.h"
#include <wtf/TZoneMalloc.h>
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
namespace JSC { namespace DFG {
class GPRTemporary;
class JSValueRegsTemporary;
class JSValueOperand;
class SlowPathGenerator;
class SpeculativeJIT;
class SpeculateInt32Operand;
class SpeculateStrictInt32Operand;
class SpeculateDoubleOperand;
class SpeculateCellOperand;
class SpeculateBooleanOperand;
enum GeneratedOperandType { GeneratedOperandTypeUnknown, GeneratedOperandInteger, GeneratedOperandJSValue};
// === SpeculativeJIT ===
//
// The SpeculativeJIT is used to generate a fast, but potentially
// incomplete code path for the dataflow. When code generating
// we may make assumptions about operand types, dynamically check,
// and bail-out to an alternate code path if these checks fail.
// Importantly, the speculative code path cannot be reentered once
// a speculative check has failed. This allows the SpeculativeJIT
// to propagate type information (including information that has
// only speculatively been asserted) through the dataflow.
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(SpeculativeJIT);
class SpeculativeJIT : public JITCompiler {
using Base = JITCompiler;
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(SpeculativeJIT);
friend struct OSRExit;
private:
typedef JITCompiler::TrustedImm32 TrustedImm32;
typedef JITCompiler::Imm32 Imm32;
typedef JITCompiler::ImmPtr ImmPtr;
typedef JITCompiler::TrustedImm64 TrustedImm64;
typedef JITCompiler::Imm64 Imm64;
// These constants are used to set priorities for spill order for
// the register allocator.
#if USE(JSVALUE64)
enum SpillOrder {
SpillOrderConstant = 1, // no spill, and cheap fill
SpillOrderSpilled = 2, // no spill
SpillOrderJS = 4, // needs spill
SpillOrderCell = 4, // needs spill
SpillOrderStorage = 4, // needs spill
SpillOrderInteger = 5, // needs spill and box
SpillOrderBoolean = 5, // needs spill and box
SpillOrderDouble = 6, // needs spill and convert
};
#elif USE(JSVALUE32_64)
enum SpillOrder {
SpillOrderConstant = 1, // no spill, and cheap fill
SpillOrderSpilled = 2, // no spill
SpillOrderJS = 4, // needs spill
SpillOrderStorage = 4, // needs spill
SpillOrderDouble = 4, // needs spill
SpillOrderInteger = 5, // needs spill and box
SpillOrderCell = 5, // needs spill and box
SpillOrderBoolean = 5, // needs spill and box
};
#endif
enum UseChildrenMode { CallUseChildren, UseChildrenCalledExplicitly };
public:
SpeculativeJIT(Graph& dfg);
~SpeculativeJIT();
void compile();
void compileFunction();
struct TrustedImmPtr {
template <typename T>
explicit TrustedImmPtr(T* value)
: m_value(value)
{
static_assert(!std::is_base_of<JSCell, T>::value, "To use a GC pointer, the graph must be aware of it. Use SpeculativeJIT::JITCompiler::LinkableConstant instead.");
}
explicit TrustedImmPtr(RegisteredStructure structure)
: m_value(structure.get())
{ }
explicit TrustedImmPtr(std::nullptr_t)
: m_value(nullptr)
{ }
explicit TrustedImmPtr(FrozenValue* value)
: m_value(value->cell())
{
RELEASE_ASSERT(value->value().isCell());
}
explicit TrustedImmPtr(size_t value)
: m_value(std::bit_cast<void*>(value))
{
}
operator MacroAssembler::TrustedImmPtr() const { return m_value; }
operator MacroAssembler::TrustedImm() const { return m_value; }
intptr_t asIntptr()
{
return m_value.asIntptr();
}
private:
MacroAssembler::TrustedImmPtr m_value;
};
void compileBody();
void createOSREntries();
void linkOSREntries(LinkBuffer&);
Vector<VariableEvent> finalizeEventStream() { return m_stream.finalize(); }
BasicBlock* nextBlock()
{
for (BlockIndex resultIndex = m_block->index + 1; ; resultIndex++) {
if (resultIndex >= m_graph.numBlocks())
return nullptr;
if (BasicBlock* result = m_graph.block(resultIndex))
return result;
}
}
#if USE(JSVALUE64)
GPRReg fillJSValue(Edge);
#elif USE(JSVALUE32_64)
bool fillJSValue(Edge, GPRReg&, GPRReg&, FPRReg&);
#endif
GPRReg fillStorage(Edge);
// lock and unlock GPR & FPR registers.
void lock(GPRReg reg)
{
m_gprs.lock(reg);
}
void lock(FPRReg reg)
{
m_fprs.lock(reg);
}
void unlock(GPRReg reg)
{
m_gprs.unlock(reg);
}
void unlock(FPRReg reg)
{
m_fprs.unlock(reg);
}
// Used to check whether a child node is on its last use,
// and its machine registers may be reused.
bool canReuse(Node* node)
{
return generationInfo(node).useCount() == 1;
}
bool canReuse(Node* nodeA, Node* nodeB)
{
return nodeA == nodeB && generationInfo(nodeA).useCount() == 2;
}
bool canReuse(Edge nodeUse)
{
return canReuse(nodeUse.node());
}
GPRReg reuse(GPRReg reg)
{
m_gprs.lock(reg);
return reg;
}
FPRReg reuse(FPRReg reg)
{
m_fprs.lock(reg);
return reg;
}
// Allocate a gpr/fpr.
GPRReg allocate()
{
#if ENABLE(DFG_REGISTER_ALLOCATION_VALIDATION)
addRegisterAllocationAtOffset(debugOffset());
#endif
VirtualRegister spillMe;
GPRReg gpr = m_gprs.allocate(spillMe);
if (spillMe.isValid()) {
#if USE(JSVALUE32_64)
GenerationInfo& info = generationInfoFromVirtualRegister(spillMe);
if ((info.registerFormat() & DataFormatJS))
m_gprs.release(info.tagGPR() == gpr ? info.payloadGPR() : info.tagGPR());
#endif
spill(spillMe);
}
return gpr;
}
GPRReg allocate(GPRReg specific)
{
if (specific == InvalidGPRReg)
allocate();
#if ENABLE(DFG_REGISTER_ALLOCATION_VALIDATION)
addRegisterAllocationAtOffset(debugOffset());
#endif
VirtualRegister spillMe = m_gprs.allocateSpecific(specific);
if (spillMe.isValid()) {
#if USE(JSVALUE32_64)
GenerationInfo& info = generationInfoFromVirtualRegister(spillMe);
RELEASE_ASSERT(info.registerFormat() != DataFormatJSDouble);
if ((info.registerFormat() & DataFormatJS))
m_gprs.release(info.tagGPR() == specific ? info.payloadGPR() : info.tagGPR());
#endif
spill(spillMe);
}
return specific;
}
GPRReg tryAllocate()
{
return m_gprs.tryAllocate();
}
FPRReg fprAllocate()
{
#if ENABLE(DFG_REGISTER_ALLOCATION_VALIDATION)
addRegisterAllocationAtOffset(debugOffset());
#endif
VirtualRegister spillMe;
FPRReg fpr = m_fprs.allocate(spillMe);
if (spillMe.isValid())
spill(spillMe);
return fpr;
}
// Check whether a VirtualRegsiter is currently in a machine register.
// We use this when filling operands to fill those that are already in
// machine registers first (by locking VirtualRegsiters that are already
// in machine register before filling those that are not we attempt to
// avoid spilling values we will need immediately).
bool isFilled(Node* node)
{
return generationInfo(node).registerFormat() != DataFormatNone;
}
bool isFilledDouble(Node* node)
{
return generationInfo(node).registerFormat() == DataFormatDouble;
}
// Called on an operand once it has been consumed by a parent node.
void use(Node* node)
{
if (!node->hasResult())
return;
GenerationInfo& info = generationInfo(node);
// use() returns true when the value becomes dead, and any
// associated resources may be freed.
if (!info.use(m_stream))
return;
// Release the associated machine registers.
DataFormat registerFormat = info.registerFormat();
#if USE(JSVALUE64)
if (registerFormat == DataFormatDouble)
m_fprs.release(info.fpr());
else if (registerFormat != DataFormatNone)
m_gprs.release(info.gpr());
#elif USE(JSVALUE32_64)
if (registerFormat == DataFormatDouble)
m_fprs.release(info.fpr());
else if (registerFormat & DataFormatJS) {
m_gprs.release(info.tagGPR());
m_gprs.release(info.payloadGPR());
} else if (registerFormat != DataFormatNone)
m_gprs.release(info.gpr());
#endif
}
void use(Edge nodeUse)
{
use(nodeUse.node());
}
RegisterSetBuilder usedRegisters();
bool masqueradesAsUndefinedWatchpointSetIsStillValid()
{
return m_graph.isWatchingMasqueradesAsUndefinedWatchpointSet(m_currentNode);
}
void compileStoreBarrier(Node*);
// Called by the speculative operand types, below, to fill operand to
// machine registers, implicitly generating speculation checks as needed.
GPRReg fillSpeculateInt32(Edge, DataFormat& returnFormat);
GPRReg fillSpeculateInt32Strict(Edge);
GPRReg fillSpeculateInt52(Edge, DataFormat desiredFormat);
FPRReg fillSpeculateDouble(Edge);
GPRReg fillSpeculateCell(Edge);
GPRReg fillSpeculateBoolean(Edge);
#if USE(BIGINT32)
GPRReg fillSpeculateBigInt32(Edge);
#endif
GeneratedOperandType checkGeneratedTypeForToInt32(Node*);
void addSlowPathGenerator(std::unique_ptr<SlowPathGenerator>);
void addSlowPathGeneratorLambda(Function<void()>&&);
void runSlowPathGenerators(PCToCodeOriginMapBuilder&);
void compile(Node*);
void noticeOSRBirth(Node*);
void bail(AbortReason);
void compileCurrentBlock();
void exceptionCheck(GPRReg exceptionReg = InvalidGPRReg);
CallSiteIndex recordCallSiteAndGenerateExceptionHandlingOSRExitIfNeeded(const CodeOrigin& callSiteCodeOrigin, unsigned eventStreamIndex);
void checkArgumentTypes();
void clearGenerationInfo();
// These methods are used when generating 'unexpected'
// calls out from JIT code to C++ helper routines -
// they spill all live values to the appropriate
// slots in the JSStack without changing any state
// in the GenerationInfo.
SilentRegisterSavePlan silentSavePlanForGPR(VirtualRegister spillMe, GPRReg source);
SilentRegisterSavePlan silentSavePlanForFPR(VirtualRegister spillMe, FPRReg source);
void silentSpillImpl(const SilentRegisterSavePlan&);
void silentFillImpl(const SilentRegisterSavePlan&);
RegisterSetBuilder spilledRegsForSilentSpillPlans(const auto& plans)
{
RegisterSetBuilder usedRegisters;
for (auto& plan : plans)
usedRegisters.add(plan.reg(), IgnoreVectors);
return usedRegisters;
}
template<typename CollectionType>
void silentSpill(const CollectionType& savePlans)
{
ASSERT(!m_underSilentSpill);
m_underSilentSpill = true;
for (unsigned i = 0; i < savePlans.size(); ++i)
silentSpillImpl(savePlans[i]);
}
template<typename CollectionType>
void silentFill(const CollectionType& savePlans)
{
ASSERT(m_underSilentSpill);
for (unsigned i = savePlans.size(); i--;)
silentFillImpl(savePlans[i]);
m_underSilentSpill = false;
}
template<typename CollectionType>
void silentSpillAllRegistersImpl(bool doSpill, CollectionType& plans, GPRReg exclude, GPRReg exclude2 = InvalidGPRReg, FPRReg fprExclude = InvalidFPRReg)
{
ASSERT(plans.isEmpty());
ASSERT(!m_underSilentSpill);
if (doSpill)
m_underSilentSpill = true;
for (gpr_iterator iter = m_gprs.begin(); iter != m_gprs.end(); ++iter) {
GPRReg gpr = iter.regID();
if (iter.name().isValid() && gpr != exclude && gpr != exclude2) {
SilentRegisterSavePlan plan = silentSavePlanForGPR(iter.name(), gpr);
if (doSpill)
silentSpillImpl(plan);
plans.append(plan);
}
}
for (fpr_iterator iter = m_fprs.begin(); iter != m_fprs.end(); ++iter) {
if (iter.name().isValid() && iter.regID() != fprExclude) {
SilentRegisterSavePlan plan = silentSavePlanForFPR(iter.name(), iter.regID());
if (doSpill)
silentSpillImpl(plan);
plans.append(plan);
}
}
}
template<typename CollectionType>
void silentSpillAllRegistersImpl(bool doSpill, CollectionType& plans, NoResultTag)
{
silentSpillAllRegistersImpl(doSpill, plans, InvalidGPRReg, InvalidGPRReg, InvalidFPRReg);
}
template<typename CollectionType>
void silentSpillAllRegistersImpl(bool doSpill, CollectionType& plans, FPRReg exclude)
{
silentSpillAllRegistersImpl(doSpill, plans, InvalidGPRReg, InvalidGPRReg, exclude);
}
template<typename CollectionType>
void silentSpillAllRegistersImpl(bool doSpill, CollectionType& plans, JSValueRegs exclude)
{
#if USE(JSVALUE32_64)
silentSpillAllRegistersImpl(doSpill, plans, exclude.tagGPR(), exclude.payloadGPR());
#else
silentSpillAllRegistersImpl(doSpill, plans, exclude.gpr());
#endif
}
void silentSpillAllRegisters(GPRReg exclude, GPRReg exclude2 = InvalidGPRReg, FPRReg fprExclude = InvalidFPRReg)
{
silentSpillAllRegistersImpl(true, m_plans, exclude, exclude2, fprExclude);
}
void silentSpillAllRegisters(FPRReg exclude)
{
silentSpillAllRegisters(InvalidGPRReg, InvalidGPRReg, exclude);
}
void silentSpillAllRegisters(JSValueRegs exclude)
{
#if USE(JSVALUE64)
silentSpillAllRegisters(exclude.payloadGPR());
#else
silentSpillAllRegisters(exclude.payloadGPR(), exclude.tagGPR());
#endif
}
void silentFillAllRegisters()
{
silentFill(m_plans);
m_plans.clear();
}
// These methods convert between doubles, and doubles boxed and JSValues.
#if USE(JSVALUE64)
using Base::boxDouble;
GPRReg boxDouble(FPRReg fpr)
{
return boxDouble(fpr, allocate());
}
using Base::boxInt52;
void boxInt52(GPRReg sourceGPR, GPRReg targetGPR, DataFormat);
#endif
// Spill a VirtualRegister to the JSStack.
void spill(VirtualRegister spillMe)
{
GenerationInfo& info = generationInfoFromVirtualRegister(spillMe);
#if USE(JSVALUE32_64)
if (info.registerFormat() == DataFormatNone) // it has been spilled. JS values which have two GPRs can reach here
return;
#endif
// Check the GenerationInfo to see if this value need writing
// to the JSStack - if not, mark it as spilled & return.
if (!info.needsSpill()) {
info.setSpilled(m_stream, spillMe);
return;
}
DataFormat spillFormat = info.registerFormat();
switch (spillFormat) {
case DataFormatStorage: {
// This is special, since it's not a JS value - as in it's not visible to JS
// code.
storePtr(info.gpr(), JITCompiler::addressFor(spillMe));
info.spill(m_stream, spillMe, DataFormatStorage);
return;
}
case DataFormatInt32: {
store32(info.gpr(), JITCompiler::payloadFor(spillMe));
info.spill(m_stream, spillMe, DataFormatInt32);
return;
}
#if USE(JSVALUE64)
case DataFormatDouble: {
storeDouble(info.fpr(), JITCompiler::addressFor(spillMe));
info.spill(m_stream, spillMe, DataFormatDouble);
return;
}
case DataFormatInt52:
case DataFormatStrictInt52: {
store64(info.gpr(), JITCompiler::addressFor(spillMe));
info.spill(m_stream, spillMe, spillFormat);
return;
}
default:
// The following code handles JSValues, int32s, and cells.
RELEASE_ASSERT(spillFormat == DataFormatCell || spillFormat & DataFormatJS);
GPRReg reg = info.gpr();
// We need to box int32 and cell values ...
// but on JSVALUE64 boxing a cell is a no-op!
if (spillFormat == DataFormatInt32)
or64(GPRInfo::numberTagRegister, reg);
// Spill the value, and record it as spilled in its boxed form.
store64(reg, JITCompiler::addressFor(spillMe));
info.spill(m_stream, spillMe, (DataFormat)(spillFormat | DataFormatJS));
return;
#elif USE(JSVALUE32_64)
case DataFormatCell:
case DataFormatBoolean: {
store32(info.gpr(), JITCompiler::payloadFor(spillMe));
info.spill(m_stream, spillMe, spillFormat);
return;
}
case DataFormatDouble: {
// On JSVALUE32_64 boxing a double is a no-op.
storeDouble(info.fpr(), JITCompiler::addressFor(spillMe));
info.spill(m_stream, spillMe, DataFormatDouble);
return;
}
default:
// The following code handles JSValues.
RELEASE_ASSERT(spillFormat & DataFormatJS);
store32(info.tagGPR(), JITCompiler::tagFor(spillMe));
store32(info.payloadGPR(), JITCompiler::payloadFor(spillMe));
info.spill(m_stream, spillMe, spillFormat);
return;
#endif
}
}
bool isKnownInteger(Node* node) { return m_state.forNode(node).isType(SpecInt32Only); }
bool isKnownCell(Node* node) { return m_state.forNode(node).isType(SpecCell); }
bool isKnownNotInteger(Node* node) { return !(m_state.forNode(node).m_type & SpecInt32Only); }
bool isKnownNotNumber(Node* node) { return !(m_state.forNode(node).m_type & SpecFullNumber); }
bool isKnownNotCell(Node* node) { return !(m_state.forNode(node).m_type & SpecCell); }
bool isKnownNotOther(Node* node) { return !(m_state.forNode(node).m_type & SpecOther); }
bool canBeRope(Edge&);
UniquedStringImpl* identifierUID(unsigned index)
{
return m_graph.identifiers()[index];
}
// Spill all VirtualRegisters back to the JSStack.
void flushRegisters()
{
for (gpr_iterator iter = m_gprs.begin(); iter != m_gprs.end(); ++iter) {
if (iter.name().isValid()) {
spill(iter.name());
iter.release();
}
}
for (fpr_iterator iter = m_fprs.begin(); iter != m_fprs.end(); ++iter) {
if (iter.name().isValid()) {
spill(iter.name());
iter.release();
}
}
}
// Used to ASSERT flushRegisters() has been called prior to
// calling out from JIT code to a C helper function.
bool isFlushed()
{
for (gpr_iterator iter = m_gprs.begin(); iter != m_gprs.end(); ++iter) {
if (iter.name().isValid())
return false;
}
for (fpr_iterator iter = m_fprs.begin(); iter != m_fprs.end(); ++iter) {
if (iter.name().isValid())
return false;
}
return true;
}
#if USE(JSVALUE64)
static Imm64 valueOfJSConstantAsImm64(Node* node)
{
return Imm64(JSValue::encode(node->asJSValue()));
}
#endif
// Helper functions to enable code sharing in implementations of bit/shift ops.
void bitOp(NodeType op, int32_t imm, GPRReg op1, GPRReg result)
{
switch (op) {
case ArithBitAnd:
and32(Imm32(imm), op1, result);
break;
case ArithBitOr:
or32(Imm32(imm), op1, result);
break;
case ArithBitXor:
xor32(Imm32(imm), op1, result);
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
void bitOp(NodeType op, GPRReg op1, GPRReg op2, GPRReg result)
{
switch (op) {
case ArithBitAnd:
and32(op1, op2, result);
break;
case ArithBitOr:
or32(op1, op2, result);
break;
case ArithBitXor:
xor32(op1, op2, result);
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
void shiftOp(NodeType op, GPRReg op1, int32_t shiftAmount, GPRReg result)
{
switch (op) {
case ArithBitRShift:
rshift32(op1, Imm32(shiftAmount), result);
break;
case ArithBitLShift:
lshift32(op1, Imm32(shiftAmount), result);
break;
case BitURShift:
urshift32(op1, Imm32(shiftAmount), result);
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
void shiftOp(NodeType op, GPRReg op1, GPRReg shiftAmount, GPRReg result)
{
switch (op) {
case ArithBitRShift:
rshift32(op1, shiftAmount, result);
break;
case ArithBitLShift:
lshift32(op1, shiftAmount, result);
break;
case BitURShift:
urshift32(op1, shiftAmount, result);
break;
default:
RELEASE_ASSERT_NOT_REACHED();
}
}
// Returns the index of the branch node if peephole is okay, UINT_MAX otherwise.
unsigned detectPeepHoleBranch()
{
// Check that no intervening nodes will be generated.
for (unsigned index = m_indexInBlock + 1; index < m_block->size() - 1; ++index) {
Node* node = m_block->at(index);
if (!node->shouldGenerate())
continue;
// Check if it's a Phantom that can be safely ignored.
if (node->op() == Phantom && !node->child1())
continue;
return UINT_MAX;
}
// Check if the lastNode is a branch on this node.
Node* lastNode = m_block->terminal();
return lastNode->op() == Branch && lastNode->child1() == m_currentNode ? m_block->size() - 1 : UINT_MAX;
}
void compileCheckTraps(Node*);
void compileLoopHint(Node*);
void compileMovHint(Node*);
void compileMovHintAndCheck(Node*);
void compileCheckDetached(Node*);
#if USE(JSVALUE64)
void cachedGetById(Node*, CodeOrigin, JSValueRegs base, JSValueRegs result, CacheableIdentifier, bool needsBaseCellCheck, AccessType, CacheType);
void cachedPutById(Node*, CodeOrigin, GPRReg baseGPR, JSValueRegs valueRegs, CacheableIdentifier, AccessType);
void cachedGetByIdWithThis(Node*, CodeOrigin, JSValueRegs baseRegs, JSValueRegs thisRegs, JSValueRegs resultRegs, CacheableIdentifier, bool needsBaseAndThisCellCheck);
#elif USE(JSVALUE32_64)
void cachedGetById(Node*, CodeOrigin, JSValueRegs base, JSValueRegs result, GPRReg stubInfoGPR, GPRReg scratchGPR, CacheableIdentifier, JITCompiler::Jump slowPathTarget, SpillRegistersMode, AccessType);
void cachedPutById(Node*, CodeOrigin, GPRReg baseGPR, JSValueRegs valueRegs, GPRReg stubInfoGPR, GPRReg scratchGPR, GPRReg scratch2GPR, CacheableIdentifier, AccessType, JITCompiler::Jump slowPathTarget = JITCompiler::Jump(), SpillRegistersMode = NeedToSpill);
void cachedGetById(Node*, CodeOrigin, GPRReg baseGPR, GPRReg resultGPR, GPRReg stubInfoGPR, GPRReg scratchGPR, CacheableIdentifier, JITCompiler::Jump slowPathTarget, SpillRegistersMode, AccessType);
void cachedGetByIdWithThis(Node*, CodeOrigin, GPRReg baseGPR, GPRReg thisGPR, GPRReg resultGPR, GPRReg stubInfoGPR, GPRReg scratchGPR, CacheableIdentifier, const JITCompiler::JumpList& slowPathTarget = JITCompiler::JumpList());
void cachedGetById(Node*, CodeOrigin, GPRReg baseTagGPROrNone, GPRReg basePayloadGPR, GPRReg resultTagGPR, GPRReg resultPayloadGPR, GPRReg stubInfoGPR, GPRReg scratchGPR, CacheableIdentifier, JITCompiler::Jump slowPathTarget, SpillRegistersMode, AccessType);
void cachedGetByIdWithThis(Node*, CodeOrigin, GPRReg baseTagGPROrNone, GPRReg basePayloadGPR, GPRReg thisTagGPROrNone, GPRReg thisPayloadGPR, GPRReg resultTagGPR, GPRReg resultPayloadGPR, GPRReg stubInfoGPR, GPRReg scratchGPR, CacheableIdentifier, const JITCompiler::JumpList& slowPathTarget = JITCompiler::JumpList());
void compileGetByIdFlush(Node*, AccessType);
void compilePutByIdFlush(Node*);
void compileInstanceOfForCells(Node*, JSValueRegs, JSValueRegs, GPRReg, GPRReg, Jump);
#endif
void compileDeleteById(Node*);
void compileDeleteByVal(Node*);
void compilePushWithScope(Node*);
void compileGetById(Node*, AccessType);
void compileGetByIdMegamorphic(Node*);
void compileGetByIdWithThisMegamorphic(Node*);
void compileInById(Node*);
void compileInByIdMegamorphic(Node*);
void compileInByVal(Node*);
void compileInByValMegamorphic(Node*);
void compileHasPrivate(Node*, AccessType);
void compileHasPrivateName(Node*);
void compileHasPrivateBrand(Node*);
void nonSpeculativeNonPeepholeCompareNullOrUndefined(Edge operand);
void nonSpeculativePeepholeBranchNullOrUndefined(Edge operand, Node* branchNode);
void genericJSValuePeepholeBranch(Node*, Node* branchNode, RelationalCondition, S_JITOperation_GJJ helperFunction);
void genericJSValueNonPeepholeCompare(Node*, RelationalCondition, S_JITOperation_GJJ helperFunction);
void nonSpeculativePeepholeStrictEq(Node*, Node* branchNode, bool invert = false);
void genericJSValueNonPeepholeStrictEq(Node*, bool invert = false);
bool genericJSValueStrictEq(Node*, bool invert = false);
void compileInstanceOf(Node*);
void compileInstanceOfCustom(Node*);
void compileInstanceOfMegamorphic(Node*);
void compileOverridesHasInstance(Node*);
void compileIsCellWithType(Node*);
void compileIsTypedArrayView(Node*);
void emitCall(Node*);
void emitAllocateButterfly(GPRReg storageGPR, GPRReg sizeGPR, GPRReg scratch1, GPRReg scratch2, GPRReg scratch3, JumpList& slowCases);
void emitInitializeButterfly(GPRReg storageGPR, GPRReg sizeGPR, JSValueRegs emptyValueRegs, GPRReg scratchGPR);
void compileAllocateNewArrayWithSize(Node*, GPRReg resultGPR, GPRReg sizeGPR, RegisteredStructure, bool shouldConvertLargeSizeToArrayStorage = true);
void compileAllocateNewArrayWithSize(Node*, GPRReg resultGPR, GPRReg sizeGPR, IndexingType, bool shouldConvertLargeSizeToArrayStorage = true);
// Called once a node has completed code generation but prior to setting
// its result, to free up its children. (This must happen prior to setting
// the nodes result, since the node may have the same VirtualRegister as
// a child, and as such will use the same GeneratioInfo).
void useChildren(Node*);
// These method called to initialize the GenerationInfo
// to describe the result of an operation.
void strictInt32Result(GPRReg reg, Node* node, DataFormat format = DataFormatInt32, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
if (format == DataFormatInt32) {
jitAssertIsInt32(reg);
m_gprs.retain(reg, virtualRegister, SpillOrderInteger);
info.initInt32(node, node->refCount(), reg);
} else {
#if USE(JSVALUE64)
RELEASE_ASSERT(format == DataFormatJSInt32);
jitAssertIsJSInt32(reg);
m_gprs.retain(reg, virtualRegister, SpillOrderJS);
info.initJSValue(node, node->refCount(), reg, format);
#elif USE(JSVALUE32_64)
RELEASE_ASSERT_NOT_REACHED();
#endif
}
}
void strictInt32Result(GPRReg reg, Node* node, UseChildrenMode mode)
{
strictInt32Result(reg, node, DataFormatInt32, mode);
}
void int52Result(GPRReg reg, Node* node, DataFormat format, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
m_gprs.retain(reg, virtualRegister, SpillOrderJS);
info.initInt52(node, node->refCount(), reg, format);
}
void int52Result(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
int52Result(reg, node, DataFormatInt52, mode);
}
void strictInt52Result(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
int52Result(reg, node, DataFormatStrictInt52, mode);
}
void noResult(Node* node, UseChildrenMode mode = CallUseChildren)
{
if (mode == UseChildrenCalledExplicitly)
return;
useChildren(node);
}
void cellResult(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
m_gprs.retain(reg, virtualRegister, SpillOrderCell);
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
info.initCell(node, node->refCount(), reg);
}
void blessedBooleanResult(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
#if USE(JSVALUE64)
jsValueResult(reg, node, DataFormatJSBoolean, mode);
#else
booleanResult(reg, node, mode);
#endif
}
void unblessedBooleanResult(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
#if USE(JSVALUE64)
blessBoolean(reg);
#endif
blessedBooleanResult(reg, node, mode);
}
#if USE(JSVALUE64)
void jsValueResult(GPRReg reg, Node* node, DataFormat format = DataFormatJS, UseChildrenMode mode = CallUseChildren)
{
if (format == DataFormatJSInt32)
jitAssertIsJSInt32(reg);
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
m_gprs.retain(reg, virtualRegister, SpillOrderJS);
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
info.initJSValue(node, node->refCount(), reg, format);
}
void jsValueResult(GPRReg reg, Node* node, UseChildrenMode mode)
{
jsValueResult(reg, node, DataFormatJS, mode);
}
#elif USE(JSVALUE32_64)
void booleanResult(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
m_gprs.retain(reg, virtualRegister, SpillOrderBoolean);
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
info.initBoolean(node, node->refCount(), reg);
}
void jsValueResult(GPRReg tag, GPRReg payload, Node* node, DataFormat format = DataFormatJS, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
m_gprs.retain(tag, virtualRegister, SpillOrderJS);
m_gprs.retain(payload, virtualRegister, SpillOrderJS);
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
info.initJSValue(node, node->refCount(), tag, payload, format);
}
void jsValueResult(GPRReg tag, GPRReg payload, Node* node, UseChildrenMode mode)
{
jsValueResult(tag, payload, node, DataFormatJS, mode);
}
#endif
void jsValueResult(JSValueRegs regs, Node* node, DataFormat format = DataFormatJS, UseChildrenMode mode = CallUseChildren)
{
#if USE(JSVALUE64)
jsValueResult(regs.gpr(), node, format, mode);
#else
jsValueResult(regs.tagGPR(), regs.payloadGPR(), node, format, mode);
#endif
}
void storageResult(GPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
m_gprs.retain(reg, virtualRegister, SpillOrderStorage);
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
info.initStorage(node, node->refCount(), reg);
}
void doubleResult(FPRReg reg, Node* node, UseChildrenMode mode = CallUseChildren)
{
if (mode == CallUseChildren)
useChildren(node);
VirtualRegister virtualRegister = node->virtualRegister();
m_fprs.retain(reg, virtualRegister, SpillOrderDouble);
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
info.initDouble(node, node->refCount(), reg);
}
void initConstantInfo(Node* node)
{
ASSERT(node->hasConstant());
generationInfo(node).initConstant(node, node->refCount());
}
void strictInt32TupleResultWithoutUsingChildren(GPRReg reg, Node* node, unsigned index, DataFormat format = DataFormatInt32)
{
ASSERT(index < node->tupleSize());
unsigned refCount = m_graph.m_tupleData.at(node->tupleOffset() + index).refCount;
if (!refCount)
return;
ASSERT(refCount == 1);
VirtualRegister virtualRegister = m_graph.m_tupleData.at(node->tupleOffset() + index).virtualRegister;
GenerationInfo& info = generationInfoFromVirtualRegister(virtualRegister);
if (format == DataFormatInt32) {
jitAssertIsInt32(reg);
m_gprs.retain(reg, virtualRegister, SpillOrderInteger);
info.initInt32(node, refCount, reg);
} else {
#if USE(JSVALUE64)
RELEASE_ASSERT(format == DataFormatJSInt32);
jitAssertIsJSInt32(reg);
m_gprs.retain(reg, virtualRegister, SpillOrderJS);
info.initJSValue(node, refCount, reg, format);
#elif USE(JSVALUE32_64)
RELEASE_ASSERT_NOT_REACHED();
#endif
}
}
template<typename OperationType>
void operationExceptionCheck()
{
using ResultType = typename FunctionTraits<OperationType>::ResultType;
ASSERT(!m_underSilentSpill);
exceptionCheck(operationExceptionRegister<ResultType>());
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>)
JITCompiler::Call callOperation(OperationType operation, ResultRegType result, Args... args)
{
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
operationExceptionCheck<OperationType>();
setupResults(result);
return call;
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>)
JITCompiler::Call callOperation(OperationType operation, Args... args)
{
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
operationExceptionCheck<OperationType>();
return call;
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>)
JITCompiler::Call callOperation(const CodePtr<OperationPtrTag> operation, ResultRegType result, Args... args)
{
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
operationExceptionCheck<OperationType>();
setupResults(result);
return call;
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>)
JITCompiler::Call callOperation(const CodePtr<OperationPtrTag> operation, Args... args)
{
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
operationExceptionCheck<OperationType>();
return call;
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>)
void callOperation(Address address, ResultRegType result, Args... args)
{
setupArgumentsForIndirectCall<OperationType>(address, args...);
appendCall(Address(GPRInfo::nonArgGPR0, address.offset));
operationExceptionCheck<OperationType>();
setupResults(result);
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>)
void callOperation(Address address, Args... args)
{
setupArgumentsForIndirectCall<OperationType>(address, args...);
appendCall(Address(GPRInfo::nonArgGPR0, address.offset));
operationExceptionCheck<OperationType>();
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>
&& !isExceptionOperationResult<typename FunctionTraits<OperationType>::ResultType>) // Sanity check
void callOperationWithoutExceptionCheck(Address address, Args... args)
{
setupArgumentsForIndirectCall<OperationType>(address, args...);
appendCall(Address(GPRInfo::nonArgGPR0, address.offset));
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>
&& !isExceptionOperationResult<typename FunctionTraits<OperationType>::ResultType>) // Sanity check
JITCompiler::Call callOperationWithoutExceptionCheck(OperationType operation, ResultRegType result, Args... args)
{
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
setupResults(result);
return call;
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>
&& !isExceptionOperationResult<typename FunctionTraits<OperationType>::ResultType>) // Sanity check
JITCompiler::Call callOperationWithoutExceptionCheck(OperationType operation, Args... args)
{
setupArguments<OperationType>(args...);
return appendCall(operation);
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>
&& !isExceptionOperationResult<typename FunctionTraits<OperationType>::ResultType>) // Sanity check
void callOperationWithoutExceptionCheck(Address address, ResultRegType result, Args... args)
{
setupArgumentsForIndirectCall<OperationType>(address, args...);
appendCall(Address(GPRInfo::nonArgGPR0, address.offset), result);
setupResults(result);
}
// There are three cases here:
// 1) nullopt the exception was handled
// 2) valid GPRReg containing the exception that won't interfere with silentFill.
// 3) InvalidGPRReg meaning the exception needs to be loaded from VM.
template<typename OperationType, typename ResultRegType, typename... OtherSpilledRegTypes>
std::optional<GPRReg> tryHandleOrGetExceptionUnderSilentSpill(const auto& plans, ResultRegType result, OtherSpilledRegTypes... otherSpilledRegs)
{
ASSERT(m_underSilentSpill);
using ResultType = typename FunctionTraits<OperationType>::ResultType;
GPRReg exceptionReg = operationExceptionRegister<ResultType>();
CodeOrigin opCatchOrigin;
HandlerInfo* exceptionHandler;
bool willCatchException = m_graph.willCatchExceptionInMachineFrame(m_currentNode->origin.forExit, opCatchOrigin, exceptionHandler);
// The simplest (and most common) case is when we're not going to catch in this frame, then we don't need to fill since
// no one's going to look.
if (!willCatchException) {
exceptionCheck(exceptionReg);
return std::nullopt;
}
if (exceptionReg != InvalidGPRReg) {
RegisterSetBuilder spilledRegs = spilledRegsForSilentSpillPlans(plans);
if constexpr (std::is_same_v<GPRReg, ResultRegType> || std::is_same_v<JSValueRegs, ResultRegType>) {
spilledRegs.add(GPRInfo::returnValueGPR, IgnoreVectors);
spilledRegs.add(result, IgnoreVectors);
}
if constexpr (sizeof...(OtherSpilledRegTypes) > 0) {
constexpr auto addRegIfNeeded = [](auto& spilledRegs, auto& reg) ALWAYS_INLINE_LAMBDA {
static_assert(std::is_same_v<GPRReg, std::decay_t<decltype(reg)>> || std::is_same_v<JSValueRegs, std::decay_t<decltype(reg)>>);
spilledRegs.add(reg, IgnoreVectors);
};
(addRegIfNeeded(spilledRegs, otherSpilledRegs), ...);
}
if (spilledRegs.buildAndValidate().contains(exceptionReg, IgnoreVectors)) {
// It would be nice if we could do m_gprs.tryAllocate() but we're possibly on a slow path and register allocation state is
// probably garbage.
constexpr RegisterSetBuilder registersInBank = decltype(m_gprs)::registersInBank();
// Move to a non-constexpr local so we can call exclude.
RegisterSetBuilder possibleRegisters = registersInBank;
RegisterSet freeRegs = possibleRegisters.exclude(spilledRegs).buildAndValidate();
auto iter = freeRegs.begin();
if (iter != freeRegs.end()) {
move(exceptionReg, iter.gpr());
exceptionReg = iter.gpr();
} else {
// We tried but there were no free regs.
exceptionReg = InvalidGPRReg;
}
}
}
return exceptionReg;
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>)
JITCompiler::Call callOperationWithSilentSpill(OperationType operation, ResultRegType result, Args... args)
{
silentSpillAllRegisters(result);
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
std::optional<GPRReg> exceptionReg = tryHandleOrGetExceptionUnderSilentSpill<OperationType>(m_plans, result);
setupResults(result);
silentFillAllRegisters();
if (exceptionReg)
exceptionCheck(*exceptionReg);
return call;
}
template<typename OperationType, typename ResultRegType, typename... Args>
requires (OperationHasResult<OperationType>)
JITCompiler::Call callOperationWithSilentSpill(std::span<const SilentRegisterSavePlan> plans, OperationType operation, ResultRegType result, Args... args)
{
silentSpill(plans);
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
std::optional<GPRReg> exceptionReg = tryHandleOrGetExceptionUnderSilentSpill<OperationType>(plans, result);
setupResults(result);
silentFill(plans);
if (exceptionReg)
exceptionCheck(*exceptionReg);
return call;
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>)
JITCompiler::Call callOperationWithSilentSpill(OperationType operation, Args... args)
{
silentSpillAllRegisters(InvalidGPRReg);
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
std::optional<GPRReg> exceptionReg = tryHandleOrGetExceptionUnderSilentSpill<OperationType>(m_plans, NoResult);
silentFillAllRegisters();
if (exceptionReg)
exceptionCheck(*exceptionReg);
return call;
}
template<typename OperationType, typename... Args>
requires (OperationIsVoid<OperationType>)
JITCompiler::Call callOperationWithSilentSpill(std::span<const SilentRegisterSavePlan> plans, OperationType operation, Args... args)
{
silentSpill(plans);
setupArguments<OperationType>(args...);
auto call = appendCall(operation);
std::optional<GPRReg> exceptionReg = tryHandleOrGetExceptionUnderSilentSpill<OperationType>(plans, NoResult);
silentFill(plans);
if (exceptionReg)
exceptionCheck(*exceptionReg);
return call;
}
void prepareForExternalCall()
{
#if !defined(NDEBUG) && !CPU(ARM_THUMB2)
// We're about to call out to a "native" helper function. The helper
// function is expected to set topCallFrame itself with the CallFrame
// that is passed to it.
//
// We explicitly trash topCallFrame here so that we'll know if some of
// the helper functions are not setting topCallFrame when they should
// be doing so. Note: the previous value in topcallFrame was not valid
// anyway since it was not being updated by JIT'ed code by design.
for (unsigned i = 0; i < sizeof(void*) / 4; i++)
store32(TrustedImm32(0xbadbeef), reinterpret_cast<char*>(&vm().topCallFrame) + i * 4);
#endif
prepareCallOperation(vm());
}
// These methods add call instructions, optionally setting results, and optionally rolling back the call frame on an exception.
JITCompiler::Call appendCall(const CodePtr<OperationPtrTag> function)
{
prepareForExternalCall();
emitStoreCodeOrigin(m_currentNode->origin.semantic);
return Base::appendCall(function);
}
void appendCall(Address address)
{
prepareForExternalCall();
emitStoreCodeOrigin(m_currentNode->origin.semantic);
Base::appendCall(address);
}
JITCompiler::Call appendOperationCall(const CodePtr<OperationPtrTag> function)
{
prepareForExternalCall();
emitStoreCodeOrigin(m_currentNode->origin.semantic);
return Base::appendOperationCall(function);
}
// FIXME: We can remove this when we don't support MSVC since on clang-cl we could use systemV ABI for JIT operations.
JITCompiler::Call appendCallSetResult(const CodePtr<OperationPtrTag> function, GPRReg result1, GPRReg result2)
{
JITCompiler::Call call = appendCall(function);
setupResults(result1, result2);
return call;
}
using Base::branchDouble;
void branchDouble(JITCompiler::DoubleCondition cond, FPRReg left, FPRReg right, BasicBlock* destination)
{
return addBranch(Base::branchDouble(cond, left, right), destination);
}
using Base::branchDoubleNonZero;
void branchDoubleNonZero(FPRReg value, FPRReg scratch, BasicBlock* destination)
{
return addBranch(Base::branchDoubleNonZero(value, scratch), destination);
}
using Base::branchDoubleZeroOrNaN;
void branchDoubleZeroOrNaN(FPRReg value, FPRReg scratch, BasicBlock* destination)
{
return addBranch(Base::branchDoubleZeroOrNaN(value, scratch), destination);
}
using Base::branch32;
template<typename T, typename U>
void branch32(JITCompiler::RelationalCondition cond, T left, U right, BasicBlock* destination)
{
return addBranch(Base::branch32(cond, left, right), destination);
}
using Base::branchTest32;
template<typename T, typename U>
void branchTest32(JITCompiler::ResultCondition cond, T value, U mask, BasicBlock* destination)
{
return addBranch(Base::branchTest32(cond, value, mask), destination);
}
template<typename T>
void branchTest32(JITCompiler::ResultCondition cond, T value, BasicBlock* destination)
{
return addBranch(Base::branchTest32(cond, value), destination);
}
#if USE(JSVALUE64)
using Base::branch64;
template<typename T, typename U>
void branch64(JITCompiler::RelationalCondition cond, T left, U right, BasicBlock* destination)
{
return addBranch(Base::branch64(cond, left, right), destination);
}
#endif
using Base::branch8;
template<typename T, typename U>
void branch8(JITCompiler::RelationalCondition cond, T left, U right, BasicBlock* destination)
{
return addBranch(Base::branch8(cond, left, right), destination);
}
using Base::branchPtr;
template<typename T, typename U>
void branchPtr(JITCompiler::RelationalCondition cond, T left, U right, BasicBlock* destination)
{
return addBranch(Base::branchPtr(cond, left, right), destination);
}
using Base::branchLinkableConstant;
template<typename T, typename U>
void branchLinkableConstant(JITCompiler::RelationalCondition cond, T left, U right, BasicBlock* destination)
{
return addBranch(Base::branchLinkableConstant(cond, left, right), destination);
}
using Base::branchTestPtr;
template<typename T, typename U>
void branchTestPtr(JITCompiler::ResultCondition cond, T value, U mask, BasicBlock* destination)
{
return addBranch(Base::branchTestPtr(cond, value, mask), destination);
}
template<typename T>
void branchTestPtr(JITCompiler::ResultCondition cond, T value, BasicBlock* destination)
{
return addBranch(Base::branchTestPtr(cond, value), destination);
}
using Base::branchTest8;
template<typename T, typename U>
void branchTest8(JITCompiler::ResultCondition cond, T value, U mask, BasicBlock* destination)
{
return addBranch(Base::branchTest8(cond, value, mask), destination);
}
template<typename T>
void branchTest8(JITCompiler::ResultCondition cond, T value, BasicBlock* destination)
{
return addBranch(Base::branchTest8(cond, value), destination);
}
enum FallThroughMode {
AtFallThroughPoint,
ForceJump
};
using Base::jump;
void jump(BasicBlock* destination, FallThroughMode fallThroughMode = AtFallThroughPoint)
{
if (destination == nextBlock()
&& fallThroughMode == AtFallThroughPoint)
return;
addBranch(jump(), destination);
}
void addBranch(const Jump& jump, BasicBlock* destination)
{
m_branches.append(BranchRecord(jump, destination));
}
void addBranch(const JumpList&, BasicBlock* destination);
void linkBranches();
void dump(const char* label = nullptr);
bool betterUseStrictInt52(Node* node)
{
return !generationInfo(node).isInt52();
}
bool betterUseStrictInt52(Edge edge)
{
return betterUseStrictInt52(edge.node());
}
bool compare(Node*, RelationalCondition, DoubleCondition, S_JITOperation_GJJ);
void compileCompareUnsigned(Node*, RelationalCondition);
bool compilePeepHoleBranch(Node*, RelationalCondition, DoubleCondition, S_JITOperation_GJJ);
void compilePeepHoleInt32Branch(Node*, Node* branchNode, JITCompiler::RelationalCondition);
void compilePeepHoleInt52Branch(Node*, Node* branchNode, JITCompiler::RelationalCondition);
#if USE(BIGINT32)
void compilePeepHoleBigInt32Branch(Node*, Node* branchNode, JITCompiler::RelationalCondition);
#endif
void compilePeepHoleBooleanBranch(Node*, Node* branchNode, JITCompiler::RelationalCondition);
void compilePeepHoleDoubleBranch(Node*, Node* branchNode, JITCompiler::DoubleCondition);
void compilePeepHoleObjectEquality(Node*, Node* branchNode);
void compilePeepHoleObjectStrictEquality(Edge objectChild, Edge otherChild, Node* branchNode);
void compilePeepHoleObjectToObjectOrOtherEquality(Edge leftChild, Edge rightChild, Node* branchNode);
void compileObjectEquality(Node*);
void compileObjectStrictEquality(Edge objectChild, Edge otherChild);
void compileObjectToObjectOrOtherEquality(Edge leftChild, Edge rightChild);
void compileToBoolean(Node*, bool invert);
void compileToBooleanObjectOrOther(Edge value, bool invert);
void compileToBooleanString(Node*, bool invert);
void compileToBooleanStringOrOther(Node*, bool invert);
void compileStringEquality(
Node*, GPRReg leftGPR, GPRReg rightGPR, GPRReg lengthGPR,
GPRReg leftTempGPR, GPRReg rightTempGPR, GPRReg leftTemp2GPR,
GPRReg rightTemp2GPR, const JITCompiler::JumpList& fastTrue,
const JITCompiler::JumpList& fastSlow);
void compileStringEquality(Node*);
void compileStringIdentEquality(Node*);
void compileStringToUntypedEquality(Node*, Edge stringEdge, Edge untypedEdge);
void compileStringIdentToNotStringVarEquality(Node*, Edge stringEdge, Edge notStringVarEdge);
void compileBitwiseStrictEq(Node*);
void compileSymbolEquality(Node*);
void compileHeapBigIntEquality(Node*);
void compilePeepHoleSymbolEquality(Node*, Node* branchNode);
#if USE(JSVALUE64)
void compileNeitherDoubleNorHeapBigIntToNotDoubleStrictEquality(Node*, Edge neitherDoubleNorHeapBigInt, Edge notDouble);
#endif
void emitBitwiseJSValueEquality(JSValueRegs&, JSValueRegs&, GPRReg& result);
void emitBranchOnBitwiseJSValueEquality(JSValueRegs&, JSValueRegs&, BasicBlock* taken, BasicBlock* notTaken);
void compileNotDoubleNeitherDoubleNorHeapBigIntNorStringStrictEquality(Node*, Edge notDoubleEdge, Edge neitherDoubleNorHeapBigIntNorStringEdge);
void compilePeepHoleNotDoubleNeitherDoubleNorHeapBigIntNorStringStrictEquality(Node*, Node* branchNode, Edge notDoubleEdge, Edge neitherDoubleNorHeapBigIntNorStringEdge);
void compileSymbolUntypedEquality(Node*, Edge symbolEdge, Edge untypedEdge);
void emitObjectOrOtherBranch(Edge value, BasicBlock* taken, BasicBlock* notTaken);
void emitStringBranch(Edge value, BasicBlock* taken, BasicBlock* notTaken);
void emitStringOrOtherBranch(Edge value, BasicBlock* taken, BasicBlock* notTaken);
void emitUntypedBranch(Edge value, BasicBlock* taken, BasicBlock* notTaken);
void emitBranch(Node*);
struct StringSwitchCase {
StringSwitchCase() { }
StringSwitchCase(StringImpl* string, BasicBlock* target)
: string(string)
, target(target)
{
}
bool operator<(const StringSwitchCase& other) const
{
return stringLessThan(*string, *other.string);
}
StringImpl* string;
BasicBlock* target;
};
void emitSwitchIntJump(SwitchData*, GPRReg value, GPRReg scratch);
void emitSwitchImm(Node*, SwitchData*);
void emitSwitchCharStringJump(Node*, SwitchData*, GPRReg value, GPRReg scratch);
void emitSwitchChar(Node*, SwitchData*);
void emitBinarySwitchStringRecurse(
SwitchData*, const Vector<StringSwitchCase>&, unsigned numChecked,
unsigned begin, unsigned end, GPRReg buffer, GPRReg length, GPRReg temp,
unsigned alreadyCheckedLength, bool checkedExactLength);
void emitSwitchStringOnString(Node*, SwitchData*, GPRReg string);
void emitSwitchString(Node*, SwitchData*);
void emitSwitch(Node*);
void compileToStringOrCallStringConstructorOrStringValueOf(Node*);
void compileFunctionToString(Node*);
void compileFunctionBind(Node*);
void compileNumberToStringWithRadix(Node*);
void compileNumberToStringWithValidRadixConstant(Node*);
void compileNumberToStringWithValidRadixConstant(Node*, int32_t radix);
void compileNewStringObject(Node*);
void compileNewSymbol(Node*);
void compileNewMap(Node*);
void compileNewSet(Node*);
void emitNewTypedArrayWithSizeInRegister(Node*, TypedArrayType, RegisteredStructure, GPRReg sizeGPR);
void compileNewTypedArrayWithSize(Node*);
#if USE(LARGE_TYPED_ARRAYS)
void compileNewTypedArrayWithInt52Size(Node*);
#endif
void compileInt32Compare(Node*, RelationalCondition);
void compileInt52Compare(Node*, RelationalCondition);
#if USE(BIGINT32)
void compileBigInt32Compare(Node*, RelationalCondition);
#endif
void compileBooleanCompare(Node*, RelationalCondition);
void compileDoubleCompare(Node*, DoubleCondition);
void compileStringCompare(Node*, RelationalCondition);
void compileStringIdentCompare(Node*, RelationalCondition);
bool compileStrictEq(Node*);
void compileSameValue(Node*);
void compileAllocatePropertyStorage(Node*);
void compileReallocatePropertyStorage(Node*);
void compileNukeStructureAndSetButterfly(Node*);
void compileGetButterfly(Node*);
void compileCallDOMGetter(Node*);
void compileCallDOM(Node*);
void compileCheckJSCast(Node*);
void compileCallCustomAccessorGetter(Node*);
void compileCallCustomAccessorSetter(Node*);
void compileNormalizeMapKey(Node*);
template<typename MapOrSet>
ALWAYS_INLINE void compileMapGetImpl(Node*);
void compileMapGet(Node*);
void compileLoadMapValue(Node*);
void compileIsEmptyStorage(Node*);
void compileMapIteratorNext(Node*);
void compileMapIteratorKey(Node*);
void compileMapIteratorValue(Node*);
template<typename Operation>
ALWAYS_INLINE void compileMapStorageImpl(Node*, Operation, Operation);
void compileMapStorage(Node*);
void compileMapStorageOrSentinel(Node*);
void compileMapIterationNext(Node*);
void compileMapIterationEntry(Node*);
void compileMapIterationEntryKey(Node*);
void compileMapIterationEntryValue(Node*);
void compileSetAdd(Node*);
void compileMapSet(Node*);
void compileMapOrSetDelete(Node*);
void compileWeakMapGet(Node*);
void compileWeakSetAdd(Node*);
void compileWeakMapSet(Node*);
void compileExtractValueFromWeakMapGet(Node*);
void compileGetPrototypeOf(Node*);
void compileGetWebAssemblyInstanceExports(Node*);
void compileIdentity(Node*);
void compileContiguousPutByVal(Node*);
void compileDoublePutByVal(Node*);
bool putByValWillNeedExtraRegister(ArrayMode arrayMode)
{
return arrayMode.mayStoreToHole();
}
GPRReg temporaryRegisterForPutByVal(GPRTemporary&, ArrayMode);
GPRReg temporaryRegisterForPutByVal(GPRTemporary& temporary, Node* node)
{
return temporaryRegisterForPutByVal(temporary, node->arrayMode());
}
void compilePutByVal(Node*);
void compilePutByValMegamorphic(Node*);
// We use a scopedLambda to placate register allocation validation.
void compileGetByVal(Node*, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compileGetCharCodeAt(Node*);
void compileGetByValOnString(Node*, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compileFromCharCode(Node*);
void compileGetByValMegamorphic(Node*);
void compileGetByValOnDirectArguments(Node*, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compileGetByValOnScopedArguments(Node*, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compileGetPrivateName(Node*);
void compileGetPrivateNameById(Node*);
void compileGetPrivateNameByVal(Node*, JSValueRegs base, JSValueRegs property);
void compileGetScope(Node*);
void compileSkipScope(Node*);
void compileGetGlobalObject(Node*);
void compileGetGlobalThis(Node*);
void compileUnwrapGlobalProxy(Node*);
void compileGetArrayLength(Node*);
#if USE(LARGE_TYPED_ARRAYS)
void compileGetTypedArrayLengthAsInt52(Node*);
#endif
void compileCheckTypeInfoFlags(Node*);
void compileCheckIdent(Node*);
void compileHasStructureWithFlags(Node*);
void compileParseInt(Node*);
void compileValueRep(Node*);
void compileDoubleRep(Node*);
void compileValueToInt32(Node*);
void compileUInt32ToNumber(Node*);
void compileDoubleAsInt32(Node*);
void compileValueBitNot(Node*);
void compileBitwiseNot(Node*);
template<typename SnippetGenerator, J_JITOperation_GJJ slowPathFunction>
void emitUntypedOrAnyBigIntBitOp(Node*);
void compileBitwiseOp(Node*);
void compileValueBitwiseOp(Node*);
void emitUntypedOrBigIntRightShiftBitOp(Node*);
void compileValueLShiftOp(Node*);
void compileValueBitRShift(Node*);
void compileShiftOp(Node*);
template <typename Generator, typename RepatchingFunction, typename NonRepatchingFunction>
void compileMathIC(Node*, JITBinaryMathIC<Generator>*, RepatchingFunction, NonRepatchingFunction);
template <typename Generator, typename RepatchingFunction, typename NonRepatchingFunction>
void compileMathIC(Node*, JITUnaryMathIC<Generator>*, RepatchingFunction, NonRepatchingFunction);
void compileArithDoubleUnaryOp(Node*, Arith::UnaryFunction, Arith::UnaryOperation);
void compileValueAdd(Node*);
void compileValueSub(Node*);
void compileArithAdd(Node*);
void compileMakeRope(Node*);
void compileMakeAtomString(Node*);
void compileArithAbs(Node*);
void compileArithClz32(Node*);
void compileArithSub(Node*);
void compileIncOrDec(Node*);
void compileValueNegate(Node*);
void compileArithNegate(Node*);
void compileValueMul(Node*);
void compileArithMul(Node*);
void compileValueDiv(Node*);
void compileArithDiv(Node*);
void compileArithFRound(Node*);
void compileArithF16Round(Node*);
void compileValueMod(Node*);
void compileArithMod(Node*);
void compileArithPow(Node*);
void compileValuePow(Node*);
void compileArithRounding(Node*);
void compileArithRandom(Node*);
void compileArithUnary(Node*);
void compileArithSqrt(Node*);
void compileArithMinMax(Node*);
void compilePurifyNaN(Node*);
void compileConstantStoragePointer(Node*);
void compileGetIndexedPropertyStorage(Node*);
void compileResolveRope(Node*);
JITCompiler::Jump jumpForTypedArrayOutOfBounds(Node*, GPRReg baseGPR, GPRReg indexGPR, GPRReg scratchGPR, GPRReg scratch2GPR);
void compileGetTypedArrayByteOffset(Node*);
#if USE(LARGE_TYPED_ARRAYS)
void compileGetTypedArrayByteOffsetAsInt52(Node*);
#endif
void compileGetByValOnIntTypedArray(Node*, TypedArrayType, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compilePutByValForIntTypedArray(Node*, TypedArrayType);
void compileGetByValOnFloatTypedArray(Node*, TypedArrayType, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compilePutByValForFloatTypedArray(Node*, TypedArrayType);
void compileGetByValForObjectWithString(Node*, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compileGetByValForObjectWithSymbol(Node*, const ScopedLambda<std::tuple<JSValueRegs, DataFormat>(DataFormat preferredFormat, bool needsFlush)>& prefix);
void compilePutByValForCellWithString(Node*);
void compilePutByValForCellWithSymbol(Node*);
void compileGetByValWithThis(Node*);
void compileGetByValWithThisMegamorphic(Node*);
void compilePutPrivateName(Node*);
void compilePutPrivateNameById(Node*);
void compileCheckPrivateBrand(Node*);
void compileSetPrivateBrand(Node*);
void compileGetByOffset(Node*);
void compilePutByOffset(Node*);
void compileMatchStructure(Node*);
// If this returns false it means that we terminated speculative execution.
bool getIntTypedArrayStoreOperand(
GPRTemporary& value,
GPRReg property,
#if USE(JSVALUE32_64)
GPRTemporary& propertyTag,
GPRTemporary& valueTag,
#endif
Edge valueUse, JITCompiler::JumpList& slowPathCases, bool isClamped = false);
bool getIntTypedArrayStoreOperandForAtomics(
GPRTemporary& value,
GPRReg property,
#if USE(JSVALUE32_64)
GPRTemporary& propertyTag,
GPRTemporary& valueTag,
#endif
Edge valueUse);
void loadFromIntTypedArray(GPRReg storageReg, GPRReg propertyReg, GPRReg resultReg, TypedArrayType);
void setIntTypedArrayLoadResult(Node*, JSValueRegs resultRegs, TypedArrayType, bool canSpeculate, bool shouldBox, FPRReg, Jump);
template <typename ClassType> void compileNewFunctionCommon(GPRReg, RegisteredStructure, GPRReg, GPRReg, GPRReg, JumpList&, size_t, FunctionExecutable*);
void compileNewFunction(Node*);
void compileSetFunctionName(Node*);
void compileNewBoundFunction(Node*);
void compileNewRegexp(Node*);
void compileForwardVarargs(Node*);
void compileVarargsLength(Node*);
void compileLoadVarargs(Node*);
void compileCreateActivation(Node*);
void compileCreateDirectArguments(Node*);
void compileGetFromArguments(Node*);
void compilePutToArguments(Node*);
void compileGetArgument(Node*);
void compileCreateScopedArguments(Node*);
void compileCreateClonedArguments(Node*);
void compileCreateRest(Node*);
void compileSpread(Node*);
void compileNewArray(Node*);
void compileNewArrayWithSpread(Node*);
void compileGetRestLength(Node*);
void compileArraySlice(Node*);
void compileArraySplice(Node*);
void compileArrayIndexOfOrArrayIncludes(Node*);
void compileArrayPush(Node*);
void compileNotifyWrite(Node*);
void compileRegExpExec(Node*);
void compileRegExpExecNonGlobalOrSticky(Node*);
void compileRegExpMatchFast(Node*);
void compileRegExpMatchFastGlobal(Node*);
void compileRegExpTest(Node*);
void compileRegExpTestInline(Node*);
void compileStringReplace(Node*);
void compileStringReplaceString(Node*);
void compileIsObject(Node*);
void compileTypeOfIsObject(Node*);
void compileIsCallable(Node*, S_JITOperation_GC);
void compileIsConstructor(Node*);
void compileTypeOf(Node*);
void compileCheckIsConstant(Node*);
void compileCheckNotEmpty(Node*);
void compileCheckStructure(Node*);
void emitStructureCheck(Node*, GPRReg cellGPR, GPRReg tempGPR);
void compilePutAccessorById(Node*);
void compilePutGetterSetterById(Node*);
void compilePutAccessorByVal(Node*);
void compileGetRegExpObjectLastIndex(Node*);
void compileSetRegExpObjectLastIndex(Node*);
void compileLazyJSConstant(Node*);
void compileMaterializeNewObject(Node*);
void compileMaterializeNewArrayWithConstantSize(Node*);
void compileRecordRegExpCachedResult(Node*);
void compileToObjectOrCallObjectConstructor(Node*);
void compileResolveScope(Node*);
void compileResolveScopeForHoistingFuncDeclInEval(Node*);
void compileGetGlobalVariable(Node*);
void compilePutGlobalVariable(Node*);
void compileGetDynamicVar(Node*);
void compilePutDynamicVar(Node*);
void compileGetClosureVar(Node*);
void compilePutClosureVar(Node*);
void compileGetInternalField(Node*);
void compilePutInternalField(Node*);
void compileCompareEqPtr(Node*);
void compileDefineDataProperty(Node*);
void compileDefineAccessorProperty(Node*);
void compileStringSlice(Node*);
void compileStringSubstring(Node*);
void compileToLowerCase(Node*);
void compileThrow(Node*);
void compileThrowStaticError(Node*);
void compileExtractFromTuple(Node*);
void compileEnumeratorNextUpdateIndexAndMode(Node*);
void compileEnumeratorNextUpdatePropertyName(Node*);
void compileEnumeratorGetByVal(Node*);
template<typename SlowPathFunctionType>
void compileEnumeratorHasProperty(Node*, SlowPathFunctionType);
void compileEnumeratorInByVal(Node*);
void compileEnumeratorHasOwnProperty(Node*);
void compileEnumeratorPutByVal(Node*);
void compilePutById(Node*);
void compilePutByIdDirect(Node*);
void compilePutByIdWithThis(Node*);
void compilePutByIdMegamorphic(Node*);
void compileGetPropertyEnumerator(Node*);
void compileGetExecutable(Node*);
void compileGetGetter(Node*);
void compileGetSetter(Node*);
void compileGetCallee(Node*);
void compileSetCallee(Node*);
void compileGetArgumentCountIncludingThis(Node*);
void compileSetArgumentCountIncludingThis(Node*);
void compileStrCat(Node*);
void compileNewArrayBuffer(Node*);
void compileNewArrayWithSize(Node*);
void compileNewArrayWithConstantSizeImpl(Node*, GPRReg, GPRReg);
void compileNewArrayWithConstantSize(Node*);
void compileNewArrayWithSpecies(Node*);
void compileNewArrayWithSizeAndStructure(Node*);
void compileNewTypedArray(Node*);
void compileToThis(Node*);
void compileOwnPropertyKeysVariant(Node*);
void compileObjectAssign(Node*);
void compileObjectCreate(Node*);
void compileObjectToString(Node*);
void compileCreateThis(Node*);
void compileCreatePromise(Node*);
void compileCreateGenerator(Node*);
void compileCreateAsyncGenerator(Node*);
void compileNewObject(Node*);
void compileNewGenerator(Node*);
void compileNewAsyncGenerator(Node*);
void compileNewInternalFieldObject(Node*);
void compileToPrimitive(Node*);
void compileToPropertyKey(Node*);
void compileToPropertyKeyOrNumber(Node*);
void compileToNumeric(Node*);
void compileCallNumberConstructor(Node*);
void compileLogShadowChickenPrologue(Node*);
void compileLogShadowChickenTail(Node*);
void compileHasIndexedProperty(Node*, S_JITOperation_GCZ, const ScopedLambda<std::tuple<GPRReg, GPRReg>()>& prefix, bool = false);
void compileExtractCatchLocal(Node*);
void compileClearCatchLocals(Node*);
void compileProfileType(Node*);
void compileStringCodePointAt(Node*);
void compileStringLocaleCompare(Node*);
void compileStringIndexOf(Node*);
void compileDateGet(Node*);
void compileDateSet(Node*);
void compileGlobalIsNaN(Node*);
void compileNumberIsNaN(Node*);
void compileToIntegerOrInfinity(Node*);
void compileToLength(Node*);
template<typename JSClass, typename Operation>
void compileCreateInternalFieldObject(Node*, Operation);
template<typename JSClass, typename Operation>
void compileNewInternalFieldObjectImpl(Node*, Operation);
void moveTrueTo(GPRReg);
void moveFalseTo(GPRReg);
void blessBoolean(GPRReg);
using Base::emitAllocateJSCell;
// Allocator for a cell of a specific size.
template <typename StructureType> // StructureType can be GPR or ImmPtr.
void emitAllocateJSCell(
GPRReg resultGPR, const JITAllocator& allocator, GPRReg allocatorGPR, StructureType structure,
GPRReg scratchGPR, JumpList& slowPath, SlowAllocationResult slowAllocationResult = SlowAllocationResult::ClearToNull)
{
Base::emitAllocateJSCell(resultGPR, allocator, allocatorGPR, structure, scratchGPR, slowPath, slowAllocationResult);
}
using Base::emitAllocateJSObject;
// Allocator for an object of a specific size.
template <typename StructureType, typename StorageType> // StructureType and StorageType can be GPR or ImmPtr.
void emitAllocateJSObject(
GPRReg resultGPR, const JITAllocator& allocator, GPRReg allocatorGPR, StructureType structure,
StorageType storage, GPRReg scratchGPR, JumpList& slowPath, SlowAllocationResult slowAllocationResult = SlowAllocationResult::ClearToNull)
{
Base::emitAllocateJSObject(
resultGPR, allocator, allocatorGPR, structure, storage, scratchGPR, slowPath, slowAllocationResult);
}
using Base::emitAllocateJSObjectWithKnownSize;
template <typename ClassType, typename StructureType, typename StorageType> // StructureType and StorageType can be GPR or ImmPtr.
void emitAllocateJSObjectWithKnownSize(
GPRReg resultGPR, StructureType structure, StorageType storage, GPRReg scratchGPR1,
GPRReg scratchGPR2, JumpList& slowPath, size_t size, SlowAllocationResult slowAllocationResult = SlowAllocationResult::ClearToNull)
{
emitAllocateJSObjectWithKnownSize<ClassType>(vm(), resultGPR, structure, storage, scratchGPR1, scratchGPR2, slowPath, size, slowAllocationResult);
}
// Convenience allocator for a built-in object.
template <typename ClassType, typename StructureType, typename StorageType> // StructureType and StorageType can be GPR or ImmPtr.
void emitAllocateJSObject(GPRReg resultGPR, StructureType structure, StorageType storage,
GPRReg scratchGPR1, GPRReg scratchGPR2, JumpList& slowPath, SlowAllocationResult slowAllocationResult = SlowAllocationResult::ClearToNull)
{
emitAllocateJSObject<ClassType>(vm(), resultGPR, structure, storage, scratchGPR1, scratchGPR2, slowPath, slowAllocationResult);
}
using Base::emitAllocateVariableSizedJSObject;
template <typename ClassType, typename StructureType> // StructureType and StorageType can be GPR or ImmPtr.
void emitAllocateVariableSizedJSObject(GPRReg resultGPR, StructureType structure, GPRReg allocationSize, GPRReg scratchGPR1, GPRReg scratchGPR2, JumpList& slowPath, SlowAllocationResult slowAllocationResult = SlowAllocationResult::ClearToNull)
{
emitAllocateVariableSizedJSObject<ClassType>(vm(), resultGPR, structure, allocationSize, scratchGPR1, scratchGPR2, slowPath, slowAllocationResult);
}
void emitAllocateRawObject(GPRReg resultGPR, RegisteredStructure, GPRReg storageGPR, unsigned numElements, unsigned vectorLength);
void emitGetLength(InlineCallFrame*, GPRReg lengthGPR, bool includeThis = false);
void emitGetLength(CodeOrigin, GPRReg lengthGPR, bool includeThis = false);
void emitGetCallee(CodeOrigin, GPRReg calleeGPR);
void emitGetArgumentStart(CodeOrigin, GPRReg startGPR);
void emitPopulateSliceIndex(Edge&, std::optional<GPRReg> indexGPR, GPRReg lengthGPR, GPRReg resultGPR);
// Generate an OSR exit fuzz check. Returns Jump() if OSR exit fuzz is not enabled, or if
// it's in training mode.
Jump emitOSRExitFuzzCheck();
// Add a speculation check.
void speculationCheck(ExitKind, JSValueSource, Node*, Jump jumpToFail);
void speculationCheck(ExitKind, JSValueSource, Node*, const JumpList& jumpsToFail);
// Add a speculation check without additional recovery, and with a promise to supply a jump later.
OSRExitJumpPlaceholder speculationCheck(ExitKind, JSValueSource, Node*);
OSRExitJumpPlaceholder speculationCheck(ExitKind, JSValueSource, Edge);
void speculationCheck(ExitKind, JSValueSource, Edge, Jump jumpToFail);
void speculationCheck(ExitKind, JSValueSource, Edge, const JumpList& jumpsToFail);
// Add a speculation check with additional recovery.
void speculationCheck(ExitKind, JSValueSource, Node*, Jump jumpToFail, const SpeculationRecovery&);
void speculationCheck(ExitKind, JSValueSource, Edge, Jump jumpToFail, const SpeculationRecovery&);
void compileInvalidationPoint(Node*);
void unreachable(Node*);
// Called when we statically determine that a speculation will fail.
void terminateSpeculativeExecution(ExitKind, JSValueRegs, Node*);
void terminateSpeculativeExecution(ExitKind, JSValueRegs, Edge);
// Helpers for performing type checks on an edge stored in the given registers.
bool needsTypeCheck(Edge edge, SpeculatedType typesPassedThrough) { return m_interpreter.needsTypeCheck(edge, typesPassedThrough); }
void typeCheck(JSValueSource, Edge, SpeculatedType typesPassedThrough, Jump jumpToFail, ExitKind = BadType);
void typeCheck(JSValueSource, Edge, SpeculatedType typesPassedThrough, JumpList jumpListToFail, ExitKind = BadType);
void speculateCellTypeWithoutTypeFiltering(Edge, GPRReg cellGPR, JSType);
void speculateCellType(Edge, GPRReg cellGPR, SpeculatedType, JSType);
void speculateInt32(Edge);
void speculateInt32(Edge, JSValueRegs);
#if USE(JSVALUE64)
void convertAnyInt(Edge, GPRReg resultGPR);
void speculateAnyInt(Edge);
void speculateDoubleRepAnyInt(Edge);
#endif // USE(JSVALUE64)
#if USE(BIGINT32)
void speculateBigInt32(Edge);
void speculateAnyBigInt(Edge);
#endif // USE(BIGINT32)
void speculateNumber(Edge);
void speculateRealNumber(Edge);
void speculateDoubleRepReal(Edge);
void speculateBoolean(Edge);
void speculateCell(Edge);
void speculateCellOrOther(Edge);
void speculateObject(Edge, GPRReg cell);
void speculateObject(Edge);
void speculateArray(Edge, GPRReg cell);
void speculateArray(Edge);
void speculateFunction(Edge, GPRReg cell);
void speculateFunction(Edge);
void speculateFinalObject(Edge, GPRReg cell);
void speculateFinalObject(Edge);
void speculateRegExpObject(Edge, GPRReg cell);
void speculateRegExpObject(Edge);
void speculatePromiseObject(Edge);
void speculatePromiseObject(Edge, GPRReg cell);
void speculateProxyObject(Edge, GPRReg cell);
void speculateProxyObject(Edge);
void speculateGlobalProxy(Edge, GPRReg cell);
void speculateGlobalProxy(Edge);
void speculateDerivedArray(Edge, GPRReg cell);
void speculateDerivedArray(Edge);
void speculateDateObject(Edge);
void speculateDateObject(Edge, GPRReg cell);
void speculateMapObject(Edge);
void speculateImmutableButterfly(Edge, GPRReg);
void speculateImmutableButterfly(Edge);
void speculateMapObject(Edge, GPRReg cell);
void speculateSetObject(Edge);
void speculateSetObject(Edge, GPRReg cell);
void speculateMapIteratorObject(Edge);
void speculateMapIteratorObject(Edge, GPRReg cell);
void speculateSetIteratorObject(Edge);
void speculateSetIteratorObject(Edge, GPRReg cell);
void speculateWeakMapObject(Edge);
void speculateWeakMapObject(Edge, GPRReg cell);
void speculateWeakSetObject(Edge);
void speculateWeakSetObject(Edge, GPRReg cell);
void speculateDataViewObject(Edge);
void speculateDataViewObject(Edge, GPRReg cell);
void speculateObjectOrOther(Edge);
void speculateString(Edge edge, GPRReg cell);
void speculateStringIdentAndLoadStorage(Edge edge, GPRReg string, GPRReg storage);
void speculateStringIdent(Edge edge, GPRReg string);
void speculateStringIdent(Edge);
void speculateString(Edge);
void speculateStringOrOther(Edge, JSValueRegs, GPRReg scratch);
void speculateStringOrOther(Edge);
void speculateNotStringVar(Edge);
void speculateNotSymbol(Edge);
void speculateStringObject(Edge, GPRReg);
void speculateStringObject(Edge);
void speculateStringOrStringObject(Edge);
void speculateSymbol(Edge, GPRReg cell);
void speculateSymbol(Edge);
void speculateHeapBigInt(Edge, GPRReg cell);
void speculateHeapBigInt(Edge);
void speculateNotCell(Edge, JSValueRegs);
void speculateNotCell(Edge);
void speculateNotCellNorBigInt(Edge);
void speculateNotDouble(Edge, JSValueRegs, GPRReg temp);
void speculateNotDouble(Edge);
void speculateNeitherDoubleNorHeapBigInt(Edge, JSValueRegs, GPRReg temp);
void speculateNeitherDoubleNorHeapBigInt(Edge);
void speculateNeitherDoubleNorHeapBigIntNorString(Edge, JSValueRegs, GPRReg temp);
void speculateNeitherDoubleNorHeapBigIntNorString(Edge);
void speculateOther(Edge, JSValueRegs, GPRReg temp);
void speculateOther(Edge, JSValueRegs);
void speculateOther(Edge);
void speculateMisc(Edge, JSValueRegs);
void speculateMisc(Edge);
void speculate(Node*, Edge);
JITCompiler::JumpList jumpSlowForUnwantedArrayMode(GPRReg tempWithIndexingTypeReg, ArrayMode);
void checkArray(Node*);
void arrayify(Node*, GPRReg baseReg, GPRReg propertyReg);
void arrayify(Node*);
template<bool strict>
GPRReg fillSpeculateInt32Internal(Edge, DataFormat& returnFormat);
void cageTypedArrayStorage(GPRReg, GPRReg);
void recordSetLocal(
Operand bytecodeReg, VirtualRegister machineReg, DataFormat format)
{
ASSERT(!bytecodeReg.isArgument() || bytecodeReg.virtualRegister().toArgument() >= 0);
m_stream.appendAndLog(VariableEvent::setLocal(bytecodeReg, machineReg, format));
}
void recordSetLocal(DataFormat format)
{
VariableAccessData* variable = m_currentNode->variableAccessData();
recordSetLocal(variable->operand(), variable->machineLocal(), format);
}
GenerationInfo& generationInfoFromVirtualRegister(VirtualRegister virtualRegister)
{
return m_generationInfo[virtualRegister.toLocal()];
}
GenerationInfo& generationInfo(Node* node)
{
return generationInfoFromVirtualRegister(node->virtualRegister());
}
GenerationInfo& generationInfo(Edge edge)
{
return generationInfo(edge.node());
}
Graph& m_graph;
// The current node being generated.
BasicBlock* m_block;
Node* m_currentNode;
NodeType m_lastGeneratedNode;
unsigned m_indexInBlock;
// Virtual and physical register maps.
Vector<GenerationInfo, 32> m_generationInfo;
RegisterBank<GPRInfo> m_gprs;
RegisterBank<FPRInfo> m_fprs;
// It is possible, during speculative generation, to reach a situation in which we
// can statically determine a speculation will fail (for example, when two nodes
// will make conflicting speculations about the same operand). In such cases this
// flag is cleared, indicating no further code generation should take place.
bool m_compileOkay;
Vector<Label> m_osrEntryHeads;
struct BranchRecord {
BranchRecord(Jump jump, BasicBlock* destination)
: jump(jump)
, destination(destination)
{
}
Jump jump;
BasicBlock* destination;
};
Vector<BranchRecord, 8> m_branches;
NodeOrigin m_origin;
InPlaceAbstractState m_state;
AbstractInterpreter<InPlaceAbstractState> m_interpreter;
VariableEventStreamBuilder m_stream;
MinifiedGraph* m_minifiedGraph;
Vector<std::unique_ptr<SlowPathGenerator>, 8> m_slowPathGenerators;
struct SlowPathLambda {
Function<void()> generator;
Node* currentNode;
unsigned streamIndex;
};
Vector<SlowPathLambda> m_slowPathLambdas;
Vector<SilentRegisterSavePlan> m_plans;
bool m_underSilentSpill { false };
std::optional<unsigned> m_outOfLineStreamIndex;
};
// === Operand types ===
//
// These classes are used to lock the operands to a node into machine
// registers. These classes implement of pattern of locking a value
// into register at the point of construction only if it is already in
// registers, and otherwise loading it lazily at the point it is first
// used. We do so in order to attempt to avoid spilling one operand
// in order to make space available for another.
class JSValueOperand {
WTF_MAKE_TZONE_ALLOCATED(JSValueOperand);
public:
explicit JSValueOperand(SpeculativeJIT* jit, Edge edge, OperandSpeculationMode mode = AutomaticOperandSpeculation)
: m_jit(jit)
, m_edge(edge)
#if USE(JSVALUE64)
, m_gprOrInvalid(InvalidGPRReg)
#elif USE(JSVALUE32_64)
, m_isDouble(false)
#endif
{
ASSERT(m_jit);
if (!edge)
return;
ASSERT_UNUSED(mode, mode == ManualOperandSpeculation || edge.useKind() == UntypedUse);
#if USE(JSVALUE64)
if (jit->isFilled(node()))
gpr();
#elif USE(JSVALUE32_64)
m_register.pair.tagGPR = InvalidGPRReg;
m_register.pair.payloadGPR = InvalidGPRReg;
if (jit->isFilled(node()))
fill();
#endif
}
explicit JSValueOperand(JSValueOperand&& other)
: m_jit(other.m_jit)
, m_edge(other.m_edge)
{
#if USE(JSVALUE64)
m_gprOrInvalid = other.m_gprOrInvalid;
#elif USE(JSVALUE32_64)
m_register.pair.tagGPR = InvalidGPRReg;
m_register.pair.payloadGPR = InvalidGPRReg;
m_isDouble = other.m_isDouble;
if (m_edge) {
if (m_isDouble)
m_register.fpr = other.m_register.fpr;
else
m_register.pair = other.m_register.pair;
}
#endif
other.m_edge = Edge();
#if USE(JSVALUE64)
other.m_gprOrInvalid = InvalidGPRReg;
#elif USE(JSVALUE32_64)
other.m_isDouble = false;
#endif
}
~JSValueOperand()
{
if (!m_edge)
return;
#if USE(JSVALUE64)
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
#elif USE(JSVALUE32_64)
if (m_isDouble) {
ASSERT(m_register.fpr != InvalidFPRReg);
m_jit->unlock(m_register.fpr);
} else {
ASSERT(m_register.pair.tagGPR != InvalidGPRReg && m_register.pair.payloadGPR != InvalidGPRReg);
m_jit->unlock(m_register.pair.tagGPR);
m_jit->unlock(m_register.pair.payloadGPR);
}
#endif
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
JSValueRegs regs() { return jsValueRegs(); }
#if USE(JSVALUE64)
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillJSValue(m_edge);
return m_gprOrInvalid;
}
JSValueRegs jsValueRegs()
{
return JSValueRegs(gpr());
}
#elif USE(JSVALUE32_64)
bool isDouble() { return m_isDouble; }
void fill()
{
if (m_register.pair.tagGPR == InvalidGPRReg && m_register.pair.payloadGPR == InvalidGPRReg)
m_isDouble = !m_jit->fillJSValue(m_edge, m_register.pair.tagGPR, m_register.pair.payloadGPR, m_register.fpr);
}
GPRReg tagGPR()
{
fill();
ASSERT(!m_isDouble);
return m_register.pair.tagGPR;
}
GPRReg payloadGPR()
{
fill();
ASSERT(!m_isDouble);
return m_register.pair.payloadGPR;
}
JSValueRegs jsValueRegs()
{
return JSValueRegs(tagGPR(), payloadGPR());
}
GPRReg gpr(WhichValueWord which = PayloadWord)
{
return jsValueRegs().gpr(which);
}
FPRReg fpr()
{
fill();
ASSERT(m_isDouble);
return m_register.fpr;
}
#endif
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
#if USE(JSVALUE64)
GPRReg m_gprOrInvalid;
#elif USE(JSVALUE32_64)
union {
struct {
GPRReg tagGPR;
GPRReg payloadGPR;
} pair;
FPRReg fpr;
} m_register;
bool m_isDouble;
#endif
};
class StorageOperand {
WTF_MAKE_TZONE_ALLOCATED(StorageOperand);
public:
StorageOperand() = default;
explicit StorageOperand(SpeculativeJIT* jit, Edge edge)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
emplace(jit, edge);
}
~StorageOperand()
{
if (m_gprOrInvalid != InvalidGPRReg)
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillStorage(edge());
return m_gprOrInvalid;
}
void emplace(SpeculativeJIT* jit, Edge edge)
{
m_jit = jit;
m_edge = edge;
ASSERT(m_gprOrInvalid == InvalidGPRReg);
ASSERT(m_jit);
ASSERT(edge.useKind() == UntypedUse || edge.useKind() == KnownCellUse);
if (jit->isFilled(node()))
gpr();
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit { nullptr };
Edge m_edge;
GPRReg m_gprOrInvalid { InvalidGPRReg };
};
// === Temporaries ===
//
// These classes are used to allocate temporary registers.
// A mechanism is provided to attempt to reuse the registers
// currently allocated to child nodes whose value is consumed
// by, and not live after, this operation.
enum ReuseTag { Reuse };
class GPRTemporary {
WTF_MAKE_TZONE_ALLOCATED(GPRTemporary);
public:
GPRTemporary();
GPRTemporary(SpeculativeJIT*);
GPRTemporary(SpeculativeJIT*, GPRReg specific);
template<typename T>
GPRTemporary(SpeculativeJIT* jit, ReuseTag, T& operand)
: m_jit(jit)
, m_gpr(InvalidGPRReg)
{
if (m_jit->canReuse(operand.node()))
m_gpr = m_jit->reuse(operand.gpr());
else
m_gpr = m_jit->allocate();
}
template<typename T1, typename T2>
GPRTemporary(SpeculativeJIT* jit, ReuseTag, T1& op1, T2& op2)
: m_jit(jit)
, m_gpr(InvalidGPRReg)
{
if (m_jit->canReuse(op1.node()))
m_gpr = m_jit->reuse(op1.gpr());
else if (m_jit->canReuse(op2.node()))
m_gpr = m_jit->reuse(op2.gpr());
else if (m_jit->canReuse(op1.node(), op2.node()) && op1.gpr() == op2.gpr())
m_gpr = m_jit->reuse(op1.gpr());
else
m_gpr = m_jit->allocate();
}
GPRTemporary(SpeculativeJIT*, ReuseTag, JSValueOperand&, WhichValueWord);
GPRTemporary(const GPRTemporary&) = delete;
GPRTemporary(GPRTemporary&& other)
{
ASSERT(other.m_jit);
ASSERT(other.m_gpr != InvalidGPRReg);
m_jit = other.m_jit;
m_gpr = other.m_gpr;
other.m_jit = nullptr;
other.m_gpr = InvalidGPRReg;
}
GPRTemporary& operator=(GPRTemporary&& other)
{
ASSERT(!m_jit);
ASSERT(m_gpr == InvalidGPRReg);
std::swap(m_jit, other.m_jit);
std::swap(m_gpr, other.m_gpr);
return *this;
}
void adopt(GPRTemporary&);
~GPRTemporary()
{
if (m_jit && m_gpr != InvalidGPRReg)
m_jit->unlock(gpr());
}
GPRReg gpr()
{
return m_gpr;
}
private:
SpeculativeJIT* m_jit;
GPRReg m_gpr;
};
class JSValueRegsTemporary {
WTF_MAKE_TZONE_ALLOCATED(JSValueRegsTemporary);
public:
JSValueRegsTemporary();
JSValueRegsTemporary(SpeculativeJIT*);
JSValueRegsTemporary(SpeculativeJIT*, GPRReg specificPayload);
#if USE(JSVALUE32_64)
JSValueRegsTemporary(SpeculativeJIT*, GPRReg specificPayload, GPRReg specificTag);
#endif
template<typename T>
JSValueRegsTemporary(SpeculativeJIT*, ReuseTag, T& operand, WhichValueWord resultRegWord = PayloadWord);
JSValueRegsTemporary(SpeculativeJIT*, ReuseTag, JSValueOperand&);
~JSValueRegsTemporary();
explicit operator bool() { return !!regs(); }
JSValueRegsTemporary& operator=(JSValueRegsTemporary&&) = default;
JSValueRegs regs();
private:
#if USE(JSVALUE64)
GPRTemporary m_gpr;
#else
GPRTemporary m_payloadGPR;
GPRTemporary m_tagGPR;
#endif
};
#if USE(JSVALUE64)
template<typename T>
JSValueRegsTemporary::JSValueRegsTemporary(SpeculativeJIT* jit, ReuseTag, T& operand, WhichValueWord)
: m_gpr(jit, Reuse, operand)
{
}
#else
template<typename T>
JSValueRegsTemporary::JSValueRegsTemporary(SpeculativeJIT* jit, ReuseTag, T& operand, WhichValueWord resultWord)
{
if (resultWord == PayloadWord) {
m_payloadGPR = GPRTemporary(jit, Reuse, operand);
m_tagGPR = GPRTemporary(jit);
} else {
m_payloadGPR = GPRTemporary(jit);
m_tagGPR = GPRTemporary(jit, Reuse, operand);
}
}
#endif
class FPRTemporary {
WTF_MAKE_TZONE_ALLOCATED(FPRTemporary);
public:
FPRTemporary(FPRTemporary&&);
FPRTemporary(SpeculativeJIT*);
FPRTemporary(SpeculativeJIT*, SpeculateDoubleOperand&);
FPRTemporary(SpeculativeJIT*, SpeculateDoubleOperand&, SpeculateDoubleOperand&);
#if USE(JSVALUE32_64)
FPRTemporary(SpeculativeJIT*, JSValueOperand&);
#endif
~FPRTemporary()
{
if (LIKELY(m_jit))
m_jit->unlock(fpr());
}
FPRReg fpr() const
{
ASSERT(m_jit);
ASSERT(m_fpr != InvalidFPRReg);
return m_fpr;
}
protected:
FPRTemporary(SpeculativeJIT* jit, FPRReg lockedFPR)
: m_jit(jit)
, m_fpr(lockedFPR)
{
}
private:
SpeculativeJIT* m_jit;
FPRReg m_fpr;
};
// === Results ===
//
// These classes lock the result of a call to a C++ helper function.
class GPRFlushedCallResult : public GPRTemporary {
public:
GPRFlushedCallResult(SpeculativeJIT* jit)
: GPRTemporary(jit, GPRInfo::returnValueGPR)
{
}
};
class GPRFlushedCallResult2 : public GPRTemporary {
public:
GPRFlushedCallResult2(SpeculativeJIT* jit)
: GPRTemporary(jit, GPRInfo::returnValueGPR2)
{
}
};
class FPRResult : public FPRTemporary {
public:
FPRResult(SpeculativeJIT* jit)
: FPRTemporary(jit, lockedResult(jit))
{
}
private:
static FPRReg lockedResult(SpeculativeJIT* jit)
{
jit->lock(FPRInfo::returnValueFPR);
return FPRInfo::returnValueFPR;
}
};
class JSValueRegsFlushedCallResult {
WTF_MAKE_TZONE_ALLOCATED(JSValueRegsFlushedCallResult);
public:
JSValueRegsFlushedCallResult(SpeculativeJIT* jit)
#if USE(JSVALUE64)
: m_gpr(jit)
#else
: m_payloadGPR(jit)
, m_tagGPR(jit)
#endif
{
}
JSValueRegs regs()
{
#if USE(JSVALUE64)
return JSValueRegs { m_gpr.gpr() };
#else
return JSValueRegs { m_tagGPR.gpr(), m_payloadGPR.gpr() };
#endif
}
private:
#if USE(JSVALUE64)
GPRFlushedCallResult m_gpr;
#else
GPRFlushedCallResult m_payloadGPR;
GPRFlushedCallResult2 m_tagGPR;
#endif
};
// === Speculative Operand types ===
//
// SpeculateInt32Operand, SpeculateStrictInt32Operand and SpeculateCellOperand.
//
// These are used to lock the operands to a node into machine registers within the
// SpeculativeJIT. The classes operate like those above, however these will
// perform a speculative check for a more restrictive type than we can statically
// determine the operand to have. If the operand does not have the requested type,
// a bail-out to the non-speculative path will be taken.
class SpeculateInt32Operand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateInt32Operand);
public:
explicit SpeculateInt32Operand(SpeculativeJIT* jit, Edge edge, OperandSpeculationMode mode = AutomaticOperandSpeculation)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
#ifndef NDEBUG
, m_format(DataFormatNone)
#endif
{
ASSERT(m_jit);
ASSERT_UNUSED(mode, mode == ManualOperandSpeculation || (edge.useKind() == Int32Use || edge.useKind() == KnownInt32Use));
if (jit->isFilled(node()))
gpr();
}
~SpeculateInt32Operand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
DataFormat format()
{
gpr(); // m_format is set when m_gpr is locked.
ASSERT(m_format == DataFormatInt32 || m_format == DataFormatJSInt32);
return m_format;
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateInt32(edge(), m_format);
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
DataFormat m_format;
};
class SpeculateStrictInt32Operand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateStrictInt32Operand);
public:
explicit SpeculateStrictInt32Operand(SpeculativeJIT* jit, Edge edge, OperandSpeculationMode mode = AutomaticOperandSpeculation)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
ASSERT(m_jit);
ASSERT_UNUSED(mode, mode == ManualOperandSpeculation || (edge.useKind() == Int32Use || edge.useKind() == KnownInt32Use));
if (jit->isFilled(node()))
gpr();
}
~SpeculateStrictInt32Operand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateInt32Strict(edge());
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
};
// Gives you a canonical Int52 (i.e. it's left-shifted by 12, low bits zero).
class SpeculateInt52Operand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateInt52Operand);
public:
explicit SpeculateInt52Operand(SpeculativeJIT* jit, Edge edge)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
RELEASE_ASSERT(edge.useKind() == Int52RepUse);
if (jit->isFilled(node()))
gpr();
}
~SpeculateInt52Operand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateInt52(edge(), DataFormatInt52);
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
};
// Gives you a strict Int52 (i.e. the payload is in the low 52 bits, high 12 bits are sign-extended).
class SpeculateStrictInt52Operand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateStrictInt52Operand);
public:
explicit SpeculateStrictInt52Operand(SpeculativeJIT* jit, Edge edge)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
RELEASE_ASSERT(edge.useKind() == Int52RepUse);
if (jit->isFilled(node()))
gpr();
}
~SpeculateStrictInt52Operand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateInt52(edge(), DataFormatStrictInt52);
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
};
enum OppositeShiftTag { OppositeShift };
class SpeculateWhicheverInt52Operand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateWhicheverInt52Operand);
public:
explicit SpeculateWhicheverInt52Operand(SpeculativeJIT* jit, Edge edge)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
, m_strict(jit->betterUseStrictInt52(edge))
{
RELEASE_ASSERT(edge.useKind() == Int52RepUse);
if (jit->isFilled(node()))
gpr();
}
explicit SpeculateWhicheverInt52Operand(SpeculativeJIT* jit, Edge edge, const SpeculateWhicheverInt52Operand& other)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
, m_strict(other.m_strict)
{
RELEASE_ASSERT(edge.useKind() == Int52RepUse);
if (jit->isFilled(node()))
gpr();
}
explicit SpeculateWhicheverInt52Operand(SpeculativeJIT* jit, Edge edge, OppositeShiftTag, const SpeculateWhicheverInt52Operand& other)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
, m_strict(!other.m_strict)
{
RELEASE_ASSERT(edge.useKind() == Int52RepUse);
if (jit->isFilled(node()))
gpr();
}
~SpeculateWhicheverInt52Operand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg) {
m_gprOrInvalid = m_jit->fillSpeculateInt52(
edge(), m_strict ? DataFormatStrictInt52 : DataFormatInt52);
}
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
DataFormat format() const
{
return m_strict ? DataFormatStrictInt52 : DataFormatInt52;
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
bool m_strict;
};
class SpeculateDoubleOperand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateDoubleOperand);
public:
explicit SpeculateDoubleOperand(SpeculativeJIT* jit, Edge edge)
: m_jit(jit)
, m_edge(edge)
, m_fprOrInvalid(InvalidFPRReg)
{
ASSERT(m_jit);
RELEASE_ASSERT(isDouble(edge.useKind()));
if (jit->isFilled(node()))
fpr();
}
~SpeculateDoubleOperand()
{
ASSERT(m_fprOrInvalid != InvalidFPRReg);
m_jit->unlock(m_fprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
FPRReg fpr()
{
if (m_fprOrInvalid == InvalidFPRReg)
m_fprOrInvalid = m_jit->fillSpeculateDouble(edge());
return m_fprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
FPRReg m_fprOrInvalid;
};
class SpeculateCellOperand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateCellOperand);
public:
explicit SpeculateCellOperand(SpeculativeJIT* jit, Edge edge, OperandSpeculationMode mode = AutomaticOperandSpeculation)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
ASSERT(m_jit);
if (!edge)
return;
ASSERT_UNUSED(mode, mode == ManualOperandSpeculation || isCell(edge.useKind()));
if (jit->isFilled(node()))
gpr();
}
explicit SpeculateCellOperand(SpeculateCellOperand&& other)
{
m_jit = other.m_jit;
m_edge = other.m_edge;
m_gprOrInvalid = other.m_gprOrInvalid;
other.m_gprOrInvalid = InvalidGPRReg;
other.m_edge = Edge();
}
~SpeculateCellOperand()
{
if (!m_edge)
return;
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
ASSERT(m_edge);
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateCell(edge());
return m_gprOrInvalid;
}
void use()
{
ASSERT(m_edge);
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
};
class SpeculateBooleanOperand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateBooleanOperand);
public:
explicit SpeculateBooleanOperand(SpeculativeJIT* jit, Edge edge, OperandSpeculationMode mode = AutomaticOperandSpeculation)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
ASSERT(m_jit);
ASSERT_UNUSED(mode, mode == ManualOperandSpeculation || edge.useKind() == BooleanUse || edge.useKind() == KnownBooleanUse);
if (jit->isFilled(node()))
gpr();
}
~SpeculateBooleanOperand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateBoolean(edge());
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
};
#if USE(BIGINT32)
class SpeculateBigInt32Operand {
WTF_MAKE_TZONE_ALLOCATED(SpeculateBigInt32Operand);
public:
explicit SpeculateBigInt32Operand(SpeculativeJIT* jit, Edge edge, OperandSpeculationMode mode = AutomaticOperandSpeculation)
: m_jit(jit)
, m_edge(edge)
, m_gprOrInvalid(InvalidGPRReg)
{
ASSERT(m_jit);
ASSERT_UNUSED(mode, mode == ManualOperandSpeculation || edge.useKind() == BigInt32Use);
if (jit->isFilled(node()))
gpr();
}
~SpeculateBigInt32Operand()
{
ASSERT(m_gprOrInvalid != InvalidGPRReg);
m_jit->unlock(m_gprOrInvalid);
}
Edge edge() const
{
return m_edge;
}
Node* node() const
{
return edge().node();
}
GPRReg gpr()
{
if (m_gprOrInvalid == InvalidGPRReg)
m_gprOrInvalid = m_jit->fillSpeculateBigInt32(edge());
return m_gprOrInvalid;
}
void use()
{
m_jit->use(node());
}
private:
SpeculativeJIT* m_jit;
Edge m_edge;
GPRReg m_gprOrInvalid;
};
#endif // USE(BIGINT32)
#define DFG_TYPE_CHECK_WITH_EXIT_KIND(exitKind, source, edge, typesPassedThrough, jumpToFail) do { \
JSValueSource _dtc_source = (source); \
Edge _dtc_edge = (edge); \
SpeculatedType _dtc_typesPassedThrough = typesPassedThrough; \
if (!needsTypeCheck(_dtc_edge, _dtc_typesPassedThrough)) \
break; \
typeCheck(_dtc_source, _dtc_edge, _dtc_typesPassedThrough, (jumpToFail), exitKind); \
} while (0)
#define DFG_TYPE_CHECK(source, edge, typesPassedThrough, jumpToFail) \
DFG_TYPE_CHECK_WITH_EXIT_KIND(BadType, source, edge, typesPassedThrough, jumpToFail)
} } // namespace JSC::DFG
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
#endif
|