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
|
/*
* Copyright (C) 2012-2019 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.
*/
#include "config.h"
#include "DFGConstantFoldingPhase.h"
#if ENABLE(DFG_JIT)
#include "BuiltinNames.h"
#include "DFGAbstractInterpreterInlines.h"
#include "DFGArgumentsUtilities.h"
#include "DFGBasicBlockInlines.h"
#include "DFGGraph.h"
#include "DFGInPlaceAbstractState.h"
#include "DFGInsertionSet.h"
#include "DFGPhase.h"
#include "GetByStatus.h"
#include "JSCInlines.h"
#include "PutByStatus.h"
#include "StructureCache.h"
namespace JSC { namespace DFG {
class ConstantFoldingPhase : public Phase {
public:
ConstantFoldingPhase(Graph& graph)
: Phase(graph, "constant folding"_s)
, m_state(graph)
, m_interpreter(graph, m_state)
, m_insertionSet(graph)
{
}
bool run()
{
bool changed = false;
for (BasicBlock* block : m_graph.blocksInNaturalOrder())
changed |= foldConstants(block);
if (changed && m_graph.m_form == SSA) {
// It's now possible that we have Upsilons pointed at JSConstants. Fix that.
for (BasicBlock* block : m_graph.blocksInNaturalOrder())
fixUpsilons(block);
}
if (m_graph.m_form == SSA) {
// It's now possible to simplify basic blocks by placing an Unreachable terminator right
// after anything that invalidates AI.
bool didClipBlock = false;
Vector<Node*> nodesToDelete;
for (BasicBlock* block : m_graph.blocksInNaturalOrder()) {
m_state.beginBasicBlock(block);
for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
if (block->at(nodeIndex)->isTerminal()) {
// It's possible that we have something after the terminal. It could be a
// no-op Check node, for example. We don't want the logic below to turn that
// node into Unreachable, since then we'd have two terminators.
break;
}
if (!m_state.isValid()) {
NodeOrigin origin = block->at(nodeIndex)->origin;
for (unsigned killIndex = nodeIndex; killIndex < block->size(); ++killIndex)
nodesToDelete.append(block->at(killIndex));
block->resize(nodeIndex);
block->appendNode(m_graph, SpecNone, Unreachable, origin);
didClipBlock = true;
break;
}
m_interpreter.execute(nodeIndex);
}
m_state.reset();
}
if (didClipBlock) {
changed = true;
m_graph.invalidateNodeLiveness();
for (Node* node : nodesToDelete)
m_graph.deleteNode(node);
m_graph.invalidateCFG();
m_graph.resetReachability();
m_graph.killUnreachableBlocks();
}
}
return changed;
}
private:
bool foldConstants(BasicBlock* block)
{
bool changed = false;
m_state.beginBasicBlock(block);
for (unsigned indexInBlock = 0; indexInBlock < block->size(); ++indexInBlock) {
if (!m_state.isValid())
break;
Node* node = block->at(indexInBlock);
bool alreadyHandled = false;
bool eliminated = false;
switch (node->op()) {
case BooleanToNumber: {
if (node->child1().useKind() == UntypedUse
&& !m_interpreter.needsTypeCheck(node->child1(), SpecBoolean))
node->child1().setUseKind(BooleanUse);
break;
}
case CompareEq: {
// FIXME: We should add back the broken folding phase here for comparisions where we prove at least one side has type SpecOther.
// See: https://bugs.webkit.org/show_bug.cgi?id=174844
break;
}
case CompareStrictEq:
case SameValue: {
if (node->isBinaryUseKind(UntypedUse)) {
JSValue child1Constant = m_state.forNode(node->child1().node()).value();
JSValue child2Constant = m_state.forNode(node->child2().node()).value();
auto isNonStringAndNonBigIntCellConstant = [] (JSValue value) {
return value && value.isCell() && !value.isString() && !value.isHeapBigInt();
};
if (isNonStringAndNonBigIntCellConstant(child1Constant)) {
node->convertToCompareEqPtr(m_graph.freezeStrong(child1Constant.asCell()), node->child2());
changed = true;
} else if (isNonStringAndNonBigIntCellConstant(child2Constant)) {
node->convertToCompareEqPtr(m_graph.freezeStrong(child2Constant.asCell()), node->child1());
changed = true;
}
}
break;
}
case CheckStructureOrEmpty: {
const AbstractValue& value = m_state.forNode(node->child1());
if (value.m_type & SpecEmpty)
break;
node->convertCheckStructureOrEmptyToCheckStructure();
changed = true;
FALLTHROUGH;
}
case CheckStructure:
case ArrayifyToStructure: {
AbstractValue& value = m_state.forNode(node->child1());
RegisteredStructureSet set;
if (node->op() == ArrayifyToStructure) {
set = node->structure();
ASSERT(!isCopyOnWrite(node->structure()->indexingMode()));
} else {
set = node->structureSet();
if ((SpecCellCheck & SpecEmpty) && node->child1().useKind() == CellUse && m_state.forNode(node->child1()).m_type & SpecEmpty) {
m_insertionSet.insertNode(
indexInBlock, SpecNone, AssertNotEmpty, node->origin, Edge(node->child1().node(), UntypedUse));
}
}
if (value.m_structure.isSubsetOf(set)) {
m_interpreter.execute(indexInBlock); // Catch the fact that we may filter on cell.
node->remove(m_graph);
eliminated = true;
break;
}
if (node->op() == CheckStructure) {
Edge incoming = node->child1();
if (set.onlyStructure().get() == m_graph.m_vm.stringStructure.get()) {
m_interpreter.execute(indexInBlock); // Catch the fact that we may filter on cell.
node->remove(m_graph);
m_insertionSet.insertCheck(indexInBlock + 1, node->origin, Edge(incoming.node(), StringUse));
eliminated = true;
break;
}
if (set.onlyStructure().get() == m_graph.m_vm.symbolStructure.get()) {
m_interpreter.execute(indexInBlock); // Catch the fact that we may filter on cell.
node->remove(m_graph);
m_insertionSet.insertCheck(indexInBlock + 1, node->origin, Edge(incoming.node(), SymbolUse));
eliminated = true;
break;
}
if (set.onlyStructure().get() == m_graph.m_vm.bigIntStructure.get()) {
m_interpreter.execute(indexInBlock); // Catch the fact that we may filter on cell.
node->remove(m_graph);
m_insertionSet.insertCheck(indexInBlock + 1, node->origin, Edge(incoming.node(), HeapBigIntUse));
eliminated = true;
break;
}
}
break;
}
case CheckJSCast: {
JSValue constant = m_state.forNode(node->child1()).value();
if (constant) {
if (constant.isCell() && constant.asCell()->inherits(node->classInfo())) {
m_interpreter.execute(indexInBlock);
node->remove(m_graph);
eliminated = true;
break;
}
}
AbstractValue& value = m_state.forNode(node->child1());
if (value.m_structure.isSubClassOf(node->classInfo())) {
m_interpreter.execute(indexInBlock);
node->remove(m_graph);
eliminated = true;
break;
}
break;
}
case CheckNotJSCast: {
JSValue constant = m_state.forNode(node->child1()).value();
if (constant) {
if (constant.isCell() && !constant.asCell()->inherits(node->classInfo())) {
m_interpreter.execute(indexInBlock);
node->remove(m_graph);
eliminated = true;
break;
}
}
AbstractValue& value = m_state.forNode(node->child1());
if (value.m_structure.isNotSubClassOf(node->classInfo())) {
m_interpreter.execute(indexInBlock);
node->remove(m_graph);
eliminated = true;
break;
}
break;
}
case GetIndexedPropertyStorage: {
JSArrayBufferView* view = m_graph.tryGetFoldableView(
m_state.forNode(node->child1()).m_value, node->arrayMode());
if (!view)
break;
if (view->mode() == FastTypedArray) {
// FIXME: It would be awesome to be able to fold the property storage for
// these GC-allocated typed arrays. For now it doesn't matter because the
// most common use-cases for constant typed arrays involve large arrays with
// aliased buffer views.
// https://bugs.webkit.org/show_bug.cgi?id=125425
break;
}
m_interpreter.execute(indexInBlock);
eliminated = true;
m_insertionSet.insertCheck(indexInBlock, node->origin, node->children);
node->convertToConstantStoragePointer(view->vector());
break;
}
case CheckStructureImmediate: {
AbstractValue& value = m_state.forNode(node->child1());
const RegisteredStructureSet& set = node->structureSet();
if (value.value()) {
if (Structure* structure = jsDynamicCast<Structure*>(value.value())) {
if (set.contains(m_graph.registerStructure(structure))) {
m_interpreter.execute(indexInBlock);
node->remove(m_graph);
eliminated = true;
break;
}
}
}
if (PhiChildren* phiChildren = m_interpreter.phiChildren()) {
bool allGood = true;
phiChildren->forAllTransitiveIncomingValues(
node,
[&] (Node* incoming) {
if (Structure* structure = incoming->dynamicCastConstant<Structure*>()) {
if (set.contains(m_graph.registerStructure(structure)))
return;
}
allGood = false;
});
if (allGood) {
m_interpreter.execute(indexInBlock);
node->remove(m_graph);
eliminated = true;
break;
}
}
break;
}
case CheckArrayOrEmpty: {
const AbstractValue& value = m_state.forNode(node->child1());
if (!(value.m_type & SpecEmpty)) {
node->convertCheckArrayOrEmptyToCheckArray();
changed = true;
}
// Even if the input includes SpecEmpty, we can fall through to CheckArray and remove the node.
// CheckArrayOrEmpty can be removed when arrayMode meets the requirement. In that case, CellUse's
// check just remains, and it works as CheckArrayOrEmpty without ArrayMode checking.
ASSERT(typeFilterFor(node->child1().useKind()) & SpecEmpty);
FALLTHROUGH;
}
case CheckArray:
case Arrayify: {
if (!node->arrayMode().alreadyChecked(m_graph, node, m_state.forNode(node->child1())))
break;
node->remove(m_graph);
eliminated = true;
break;
}
case PutStructure: {
if (m_state.forNode(node->child1()).m_structure.onlyStructure() != node->transition()->next)
break;
node->remove(m_graph);
eliminated = true;
break;
}
case CheckIsConstant: {
if (m_state.forNode(node->child1()).value() != node->constant()->value())
break;
node->remove(m_graph);
eliminated = true;
break;
}
case AssertNotEmpty:
case CheckNotEmpty: {
if (m_state.forNode(node->child1()).m_type & SpecEmpty)
break;
node->remove(m_graph);
eliminated = true;
break;
}
case CheckIdent: {
UniquedStringImpl* uid = node->uidOperand();
const UniquedStringImpl* constantUid = nullptr;
JSValue childConstant = m_state.forNode(node->child1()).value();
if (childConstant) {
if (childConstant.isString()) {
if (const auto* impl = asString(childConstant)->tryGetValueImpl()) {
// Edge filtering requires that a value here should be StringIdent.
// However, a constant value propagated in DFG is not filtered.
// So here, we check the propagated value is actually an atomic string.
// And if it's not, we just ignore.
if (impl->isAtom())
constantUid = static_cast<const UniquedStringImpl*>(impl);
}
} else if (childConstant.isSymbol()) {
Symbol* symbol = jsCast<Symbol*>(childConstant);
constantUid = &symbol->uid();
}
}
if (constantUid == uid) {
node->remove(m_graph);
eliminated = true;
}
break;
}
case CheckInBounds: {
JSValue left = m_state.forNode(node->child1()).value();
JSValue right = m_state.forNode(node->child2()).value();
if (left && right && left.isInt32() && right.isInt32()
&& static_cast<uint32_t>(left.asInt32()) < static_cast<uint32_t>(right.asInt32())) {
Node* zero = m_insertionSet.insertConstant(indexInBlock, node->origin, jsNumber(0));
node->convertToIdentityOn(zero);
eliminated = true;
break;
}
break;
}
case CheckInBoundsInt52:
break;
case GetArrayLength: {
ArrayMode arrayMode = node->arrayMode();
AbstractValue& abstractValue = m_state.forNode(node->child1());
if (arrayMode.type() != Array::AnyTypedArray && arrayMode.isSomeTypedArrayView() && !arrayMode.mayBeResizableOrGrowableSharedTypedArray()) {
if ((abstractValue.m_type && !(abstractValue.m_type & ~SpecObject)) && abstractValue.m_structure.isFinite()) {
bool canFold = !abstractValue.m_structure.isClear();
JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
abstractValue.m_structure.forEach([&](RegisteredStructure structure) {
if (!arrayMode.structureWouldPassArrayModeFiltering(structure.get())) {
canFold = false;
return;
}
if (structure->globalObject() != globalObject) {
canFold = false;
return;
}
});
if (canFold) {
if (m_graph.isWatchingArrayBufferDetachWatchpoint(node)) {
node->setOp(GetUndetachedTypeArrayLength);
changed = true;
break;
}
}
}
}
break;
}
case GetMyArgumentByVal:
case GetMyArgumentByValOutOfBounds: {
JSValue indexValue = m_state.forNode(node->child2()).value();
if (!indexValue || !indexValue.isUInt32())
break;
CheckedUint32 checkedIndex = indexValue.asUInt32();
checkedIndex += node->numberOfArgumentsToSkip();
if (checkedIndex.hasOverflowed())
break;
unsigned index = checkedIndex;
Node* arguments = node->child1().node();
InlineCallFrame* inlineCallFrame = arguments->origin.semantic.inlineCallFrame();
// Don't try to do anything if the index is known to be outside our static bounds. Note
// that our static bounds are usually strictly larger than the dynamic bounds. The
// exception is something like this, assuming foo() is not inlined:
//
// function foo() { return arguments[5]; }
//
// Here the static bound on number of arguments is 0, and we're accessing index 5. We
// will not strength-reduce this to GetStack because GetStack is otherwise assumed by the
// compiler to access those variables that are statically accounted for; for example if
// we emitted a GetStack on arg6 we would have out-of-bounds access crashes anywhere that
// uses an Operands<> map. There is not much cost to continuing to use a
// GetMyArgumentByVal in such statically-out-of-bounds accesses; we just lose CFA unless
// GCSE removes the access entirely.
if (inlineCallFrame) {
if (index >= static_cast<unsigned>(inlineCallFrame->argumentCountIncludingThis - 1))
break;
} else {
if (index >= m_state.numberOfArguments() - 1)
break;
}
m_interpreter.execute(indexInBlock); // Push CFA over this node after we get the state before.
StackAccessData* data;
if (inlineCallFrame) {
data = m_graph.m_stackAccessData.add(
VirtualRegister(
inlineCallFrame->stackOffset +
CallFrame::argumentOffset(index)),
FlushedJSValue);
} else {
data = m_graph.m_stackAccessData.add(
virtualRegisterForArgumentIncludingThis(index + 1), FlushedJSValue);
}
if (inlineCallFrame && !inlineCallFrame->isVarargs() && index < static_cast<unsigned>(inlineCallFrame->argumentCountIncludingThis - 1)) {
node->convertToGetStack(data);
eliminated = true;
break;
}
if (node->op() == GetMyArgumentByValOutOfBounds)
break;
Node* length = emitCodeToGetArgumentsArrayLength(
m_insertionSet, arguments, indexInBlock, node->origin);
Node* check = m_insertionSet.insertNode(
indexInBlock, SpecNone, CheckInBounds, node->origin,
node->child2(), Edge(length, Int32Use));
node->convertToGetStack(data);
node->child1() = Edge(check, UntypedUse);
eliminated = true;
break;
}
case MultiGetByOffset: {
Edge baseEdge = node->child1();
Node* base = baseEdge.node();
MultiGetByOffsetData& data = node->multiGetByOffsetData();
// First prune the variants, then check if the MultiGetByOffset can be
// strength-reduced to a GetByOffset.
AbstractValue baseValue = m_state.forNode(base);
m_interpreter.execute(indexInBlock); // Push CFA over this node after we get the state before.
alreadyHandled = true; // Don't allow the default constant folder to do things to this.
for (unsigned i = 0; i < data.cases.size(); ++i) {
MultiGetByOffsetCase& getCase = data.cases[i];
getCase.set().filter(baseValue);
if (getCase.set().isEmpty()) {
data.cases[i--] = data.cases.last();
data.cases.removeLast();
changed = true;
}
}
if (data.cases.size() != 1)
break;
emitGetByOffset(indexInBlock, node, baseValue, data.cases[0], data.identifierNumber);
changed = true;
break;
}
case MultiPutByOffset: {
Edge baseEdge = node->child1();
Node* base = baseEdge.node();
MultiPutByOffsetData& data = node->multiPutByOffsetData();
AbstractValue baseValue = m_state.forNode(base);
m_interpreter.execute(indexInBlock); // Push CFA over this node after we get the state before.
alreadyHandled = true; // Don't allow the default constant folder to do things to this.
for (unsigned i = 0; i < data.variants.size(); ++i) {
PutByVariant& variant = data.variants[i];
variant.oldStructure().genericFilter([&] (Structure* structure) -> bool {
return baseValue.contains(m_graph.registerStructure(structure));
});
if (variant.oldStructure().isEmpty()) {
data.variants[i--] = data.variants.last();
data.variants.removeLast();
changed = true;
continue;
}
if (variant.kind() == PutByVariant::Transition
&& variant.oldStructure().onlyStructure() == variant.newStructure()) {
variant = PutByVariant::replace(variant.identifier(), variant.oldStructure(), variant.offset(), variant.viaGlobalProxy());
changed = true;
}
}
if (data.variants.size() != 1)
break;
emitPutByOffset(
indexInBlock, node, baseValue, data.variants[0], data.identifierNumber);
changed = true;
break;
}
case MultiDeleteByOffset: {
Edge baseEdge = node->child1();
Node* base = baseEdge.node();
MultiDeleteByOffsetData& data = node->multiDeleteByOffsetData();
AbstractValue baseValue = m_state.forNode(base);
m_interpreter.execute(indexInBlock); // Push CFA over this node after we get the state before.
alreadyHandled = true; // Don't allow the default constant folder to do things to this.
for (unsigned i = 0; i < data.variants.size(); ++i) {
DeleteByVariant& variant = data.variants[i];
if (!baseValue.contains(m_graph.registerStructure(variant.oldStructure()))) {
data.variants[i--] = data.variants.last();
data.variants.removeLast();
changed = true;
continue;
}
}
if (data.variants.size() != 1)
break;
emitDeleteByOffset(
indexInBlock, node, baseValue, data.variants[0], data.identifierNumber);
changed = true;
break;
}
case MatchStructure: {
Edge baseEdge = node->child1();
Node* base = baseEdge.node();
MatchStructureData& data = node->matchStructureData();
AbstractValue baseValue = m_state.forNode(base);
m_interpreter.execute(indexInBlock); // Push CFA over this node after we get the state before.
alreadyHandled = true; // Don't allow the default constant folder to do things to this.
BooleanLattice result = BooleanLattice::Bottom;
for (unsigned i = 0; i < data.variants.size(); ++i) {
if (!baseValue.contains(data.variants[i].structure)) {
data.variants[i--] = data.variants.last();
data.variants.removeLast();
changed = true;
continue;
}
result = leastUpperBoundOfBooleanLattices(
result,
data.variants[i].result ? BooleanLattice::True : BooleanLattice::False);
}
if (result == BooleanLattice::False || result == BooleanLattice::True) {
RegisteredStructureSet structureSet;
for (MatchStructureVariant& variant : data.variants)
structureSet.add(variant.structure);
addBaseCheck(indexInBlock, node, baseValue, structureSet);
m_graph.convertToConstant(
node, m_graph.freeze(jsBoolean(result == BooleanLattice::True)));
changed = true;
}
break;
}
case GetByIdDirect:
case GetByIdDirectFlush:
case GetById:
case GetByIdFlush:
case GetByIdMegamorphic:
case GetPrivateNameById: {
Edge childEdge = node->child1();
Node* child = childEdge.node();
UniquedStringImpl* uid = node->cacheableIdentifier().uid();
AbstractValue baseValue = m_state.forNode(child);
m_interpreter.execute(indexInBlock); // Push CFA over this node after we get the state before.
alreadyHandled = true; // Don't allow the default constant folder to do things to this.
if (!Options::useAccessInlining())
break;
if (!baseValue.m_structure.isFinite()
|| (node->child1().useKind() == UntypedUse || (baseValue.m_type & ~SpecCell)))
break;
GetByStatus status = GetByStatus::computeFor(baseValue.m_structure.toStructureSet(), uid);
if (!status.isSimple())
break;
for (unsigned i = status.numVariants(); i--;) {
if (!status[i].conditionSet().isEmpty()) {
// FIXME: We could handle prototype cases.
// https://bugs.webkit.org/show_bug.cgi?id=110386
break;
}
}
auto addFilterStatus = [&] () {
m_insertionSet.insertNode(
indexInBlock, SpecNone, FilterGetByStatus, node->origin,
OpInfo(m_graph.m_plan.recordedStatuses().addGetByStatus(node->origin.semantic, status)),
Edge(child));
};
// AI already concluded this was a constant so we're safe to do so as well.
if (AbstractValue constantResult = m_state.forNode(node); constantResult.value()) {
addFilterStatus();
m_graph.convertToConstant(node, constantResult.value());
changed = true;
break;
}
if (status.numVariants() == 1) {
unsigned identifierNumber = m_graph.identifiers().ensure(uid);
addFilterStatus();
emitGetByOffset(indexInBlock, node, baseValue, status[0], identifierNumber);
changed = true;
break;
}
if (!m_graph.m_plan.isFTL())
break;
unsigned identifierNumber = m_graph.identifiers().ensure(uid);
addFilterStatus();
MultiGetByOffsetData* data = m_graph.m_multiGetByOffsetData.add();
for (const GetByVariant& variant : status.variants()) {
data->cases.append(
MultiGetByOffsetCase(
*m_graph.addStructureSet(variant.structureSet()),
GetByOffsetMethod::load(variant.offset())));
}
data->identifierNumber = identifierNumber;
node->convertToMultiGetByOffset(data);
changed = true;
break;
}
case PutPrivateNameById: {
bool isDirect = true;
tryFoldAsPutByOffset(node, indexInBlock, node->child1(), node->child2(), isDirect, node->privateFieldPutKind(), changed, alreadyHandled);
break;
}
case PutById:
case PutByIdDirect:
case PutByIdFlush:
case PutByIdMegamorphic: {
bool isDirect = node->op() == PutByIdDirect;
tryFoldAsPutByOffset(node, indexInBlock, node->child1(), node->child2(), isDirect, PrivateFieldPutKind::none(), changed, alreadyHandled);
break;
}
case InByVal:
case InByValMegamorphic: {
AbstractValue& property = m_state.forNode(node->child2());
if (JSValue constant = property.value()) {
if (constant.isString()) {
JSString* string = asString(constant);
if (CacheableIdentifier::isCacheableIdentifierCell(string) && !parseIndex(CacheableIdentifier::createFromCell(string).uid())) {
const StringImpl* impl = string->tryGetValueImpl();
RELEASE_ASSERT(impl);
m_graph.freezeStrong(string);
m_graph.identifiers().ensure(const_cast<UniquedStringImpl*>(static_cast<const UniquedStringImpl*>(impl)));
m_insertionSet.insertCheck(indexInBlock, node->origin, m_graph.child(node, 0));
node->convertToInByIdMaybeMegamorphic(m_graph, CacheableIdentifier::createFromCell(string));
changed = true;
break;
}
}
}
break;
}
case GetByVal:
case GetByValMegamorphic: {
if (m_graph.child(node, 0).useKind() == ObjectUse && node->arrayMode().type() == Array::Generic) {
AbstractValue& property = m_state.forNode(m_graph.child(node, 1));
if (JSValue constant = property.value()) {
if (constant.isString()) {
JSString* string = asString(constant);
if (CacheableIdentifier::isCacheableIdentifierCell(string) && !parseIndex(CacheableIdentifier::createFromCell(string).uid())) {
const StringImpl* impl = string->tryGetValueImpl();
RELEASE_ASSERT(impl);
m_graph.freezeStrong(string);
m_graph.identifiers().ensure(const_cast<UniquedStringImpl*>(static_cast<const UniquedStringImpl*>(impl)));
m_insertionSet.insertCheck(indexInBlock, node->origin, m_graph.child(node, 0));
node->convertToGetByIdMaybeMegamorphic(m_graph, CacheableIdentifier::createFromCell(string));
changed = true;
break;
}
}
}
}
break;
}
case PutByVal:
case PutByValMegamorphic: {
if ((m_graph.child(node, 0).useKind() == CellUse && m_graph.child(node, 1).useKind() == StringUse) && node->arrayMode().modeForPut().type() == Array::Generic) {
AbstractValue& property = m_state.forNode(m_graph.child(node, 1));
if (JSValue constant = property.value()) {
if (constant.isString()) {
JSString* string = asString(constant);
if (CacheableIdentifier::isCacheableIdentifierCell(string) && !parseIndex(CacheableIdentifier::createFromCell(string).uid())) {
const StringImpl* impl = string->tryGetValueImpl();
RELEASE_ASSERT(impl);
m_graph.freezeStrong(string);
m_graph.identifiers().ensure(const_cast<UniquedStringImpl*>(static_cast<const UniquedStringImpl*>(impl)));
m_insertionSet.insertCheck(indexInBlock, node->origin, m_graph.child(node, 0));
m_insertionSet.insertCheck(indexInBlock, node->origin, m_graph.child(node, 1));
node->convertToPutByIdMaybeMegamorphic(m_graph, CacheableIdentifier::createFromCell(string));
changed = true;
break;
}
}
}
}
break;
}
case ToPrimitive: {
if (m_state.forNode(node->child1()).m_type & ~(SpecFullNumber | SpecBoolean | SpecString | SpecSymbol | SpecBigInt))
break;
node->convertToIdentity();
changed = true;
break;
}
case ToPropertyKey: {
if (m_state.forNode(node->child1()).m_type & ~(SpecString | SpecSymbol))
break;
node->convertToIdentity();
changed = true;
break;
}
case ToPropertyKeyOrNumber: {
if (m_state.forNode(node->child1()).m_type & ~(SpecFullNumber | SpecString | SpecSymbol))
break;
node->convertToIdentity();
changed = true;
break;
}
case ToThis: {
ToThisResult result = isToThisAnIdentity(node->ecmaMode(), m_state.forNode(node->child1()));
if (result == ToThisResult::Identity) {
node->convertToIdentity();
changed = true;
break;
}
if (result == ToThisResult::GlobalThis) {
node->convertToGetGlobalThis();
changed = true;
break;
}
break;
}
case CreateThis: {
if (JSValue base = m_state.forNode(node->child1()).m_value) {
if (auto* function = jsDynamicCast<JSFunction*>(base)) {
if (FunctionRareData* rareData = function->rareData()) {
if (rareData->allocationProfileWatchpointSet().isStillValid() && m_graph.isWatchingStructureCacheClearedWatchpoint(node)) {
Structure* structure = rareData->objectAllocationStructure();
JSObject* prototype = rareData->objectAllocationPrototype();
if (structure
&& (structure->hasMonoProto() || prototype)) {
m_graph.freeze(rareData);
m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
node->convertToNewObject(m_graph.registerStructure(structure));
if (structure->hasPolyProto()) {
StorageAccessData* data = m_graph.m_storageAccessData.add();
data->offset = knownPolyProtoOffset;
data->identifierNumber = m_graph.identifiers().ensure(m_graph.m_vm.propertyNames->builtinNames().polyProtoName().impl());
NodeOrigin origin = node->origin.withInvalidExit();
Node* prototypeNode = m_insertionSet.insertConstant(
indexInBlock + 1, origin, m_graph.freeze(prototype));
ASSERT(isInlineOffset(knownPolyProtoOffset));
m_insertionSet.insertNode(
indexInBlock + 1, SpecNone, PutByOffset, origin, OpInfo(data),
Edge(node, KnownCellUse), Edge(node, KnownCellUse), Edge(prototypeNode, UntypedUse));
}
changed = true;
break;
}
}
}
}
}
break;
}
case CreatePromise: {
JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
if (JSValue base = m_state.forNode(node->child1()).m_value) {
if (base == (node->isInternalPromise() ? globalObject->internalPromiseConstructor() : globalObject->promiseConstructor())) {
node->convertToNewInternalFieldObject(m_graph.registerStructure(node->isInternalPromise() ? globalObject->internalPromiseStructure() : globalObject->promiseStructure()));
changed = true;
break;
}
if (auto* function = jsDynamicCast<JSFunction*>(base)) {
if (FunctionRareData* rareData = function->rareData()) {
if (rareData->allocationProfileWatchpointSet().isStillValid() && m_graph.isWatchingStructureCacheClearedWatchpoint(node)) {
Structure* structure = rareData->internalFunctionAllocationStructure();
if (structure
&& structure->classInfoForCells() == (node->isInternalPromise() ? JSInternalPromise::info() : JSPromise::info())
&& structure->globalObject() == globalObject) {
m_graph.freeze(rareData);
m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
node->convertToNewInternalFieldObject(m_graph.registerStructure(structure));
changed = true;
break;
}
}
}
}
}
break;
}
case CreateGenerator:
case CreateAsyncGenerator: {
auto foldConstant = [&] (NodeType newOp, const ClassInfo* classInfo) {
JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
if (JSValue base = m_state.forNode(node->child1()).m_value) {
if (auto* function = jsDynamicCast<JSFunction*>(base)) {
if (FunctionRareData* rareData = function->rareData()) {
if (rareData->allocationProfileWatchpointSet().isStillValid() && m_graph.isWatchingStructureCacheClearedWatchpoint(node)) {
Structure* structure = rareData->internalFunctionAllocationStructure();
if (structure
&& structure->classInfoForCells() == classInfo
&& structure->globalObject() == globalObject) {
m_graph.freeze(rareData);
m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
node->convertToNewInternalFieldObjectWithInlineFields(newOp, m_graph.registerStructure(structure));
changed = true;
return;
}
}
}
}
}
};
switch (node->op()) {
case CreateGenerator:
foldConstant(NewGenerator, JSGenerator::info());
break;
case CreateAsyncGenerator:
foldConstant(NewAsyncGenerator, JSAsyncGenerator::info());
break;
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
break;
}
case ObjectCreate: {
if (JSValue base = m_state.forNode(node->child1()).m_value) {
JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
Structure* structure = nullptr;
if (base.isNull())
structure = globalObject->nullPrototypeObjectStructure();
else if (base.isObject()) {
// Having a bad time clears the structureCache, and so it should invalidate this structure.
if (m_graph.isWatchingStructureCacheClearedWatchpoint(node))
structure = globalObject->structureCache().emptyObjectStructureConcurrently(base.getObject(), JSFinalObject::defaultInlineCapacity);
}
if (structure) {
node->convertToNewObject(m_graph.registerStructure(structure));
changed = true;
break;
}
}
break;
}
case ObjectKeys:
case ObjectGetOwnPropertyNames:
case ObjectGetOwnPropertySymbols:
case ReflectOwnKeys: {
if (node->child1().useKind() == ObjectUse) {
auto& structureSet = m_state.forNode(node->child1()).m_structure;
if (structureSet.isFinite() && structureSet.size() == 1) {
RegisteredStructure structure = structureSet.onlyStructure();
if (auto* rareData = structure->rareDataConcurrently()) {
if (auto* immutableButterfly = rareData->cachedPropertyNamesConcurrently(node->cachedPropertyNamesKind())) {
if (m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
node->convertToNewArrayBuffer(m_graph.freeze(immutableButterfly));
changed = true;
break;
}
}
}
}
}
break;
}
case NewArrayWithSpread: {
if (m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
BitVector* bitVector = node->bitVector();
if (node->numChildren() == 1 && bitVector->get(0)) {
Edge use = m_graph.varArgChild(node, 0);
if (use->op() == PhantomSpread) {
if (use->child1()->op() == PhantomNewArrayBuffer) {
auto* immutableButterfly = use->child1()->castOperand<JSImmutableButterfly*>();
if (hasContiguous(immutableButterfly->indexingType())) {
node->convertToNewArrayBuffer(m_graph.freeze(immutableButterfly));
changed = true;
break;
}
}
}
}
}
break;
}
case NewArrayWithSize: {
if (m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
if (node->child1().useKind() == Int32Use && node->child1()->isInt32Constant()) {
int32_t length = node->child1()->asInt32();
if (length >= 0
&& length < MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH
&& isNewArrayWithConstantSizeIndexingType(node->indexingType())) {
node->convertToNewArrayWithConstantSize(m_graph, length);
changed = true;
}
}
}
break;
}
case ResolveRope: {
if (m_state.forNode(node->child1()).m_type & ~SpecStringIdent)
break;
node->convertToIdentity();
changed = true;
break;
}
case ToNumber:
case CallNumberConstructor: {
if (node->child1().useKind() != UntypedUse)
break;
if (m_state.forNode(node->child1()).m_type & ~SpecBytecodeNumber)
break;
node->convertToIdentity();
changed = true;
break;
}
case ToNumeric: {
if (m_state.forNode(node->child1()).m_type & ~(SpecBytecodeNumber | SpecBigInt))
break;
node->convertToIdentity();
changed = true;
break;
}
case NormalizeMapKey: {
SpeculatedType typesNeedingNormalization = (SpecFullNumber & ~SpecInt32Only) | SpecHeapBigInt;
if (m_state.forNode(node->child1()).m_type & typesNeedingNormalization)
break;
node->convertToIdentity();
changed = true;
break;
}
case ParseInt: {
AbstractValue& value = m_state.forNode(node->child1());
if (!value.m_type || (value.m_type & ~SpecInt32Only))
break;
JSValue radix;
if (!node->child2())
radix = jsNumber(0);
else
radix = m_state.forNode(node->child2()).m_value;
if (!radix.isInt32())
break;
if (radix.asNumber() == 0 || radix.asNumber() == 10) {
node->child2() = Edge();
node->convertToIdentity();
changed = true;
}
break;
}
case FunctionBind: {
if (m_graph.m_plan.isUnlinked())
break;
JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
Edge target = m_graph.child(node, 0);
AbstractValue& targetValue = m_state.forNode(target);
auto& structureSet = targetValue.m_structure;
if (!(targetValue.m_type & ~SpecFunction) && structureSet.isFinite() && structureSet.size() == 1) {
RegisteredStructure structure = structureSet.onlyStructure();
if (JSBoundFunction::canSkipNameAndLengthMaterialization(globalObject, structure.get())) {
node->convertToNewBoundFunction(m_graph.freeze(m_graph.m_vm.getBoundFunction(/* isJSFunction */ true)));
changed = true;
break;
}
}
break;
}
case NumberToStringWithRadix: {
JSValue radixValue = m_state.forNode(node->child2()).m_value;
if (radixValue && radixValue.isInt32()) {
int32_t radix = radixValue.asInt32();
if (2 <= radix && radix <= 36) {
if (radix == 10 && node->child1()->shouldSpeculateNumber()) {
node->setOpAndDefaultFlags(ToString);
node->clearFlags(NodeMustGenerate);
node->child2() = Edge();
} else
node->convertToNumberToStringWithValidRadixConstant(radix);
changed = true;
break;
}
}
break;
}
case Check: {
alreadyHandled = true;
m_interpreter.execute(indexInBlock);
for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
Edge edge = node->children.child(i);
if (!edge)
break;
if (edge.isProved() || edge.willNotHaveCheck()) {
node->children.removeEdge(i--);
changed = true;
}
}
break;
}
case CheckVarargs: {
alreadyHandled = true;
m_interpreter.execute(indexInBlock);
unsigned targetIndex = 0;
for (unsigned i = 0; i < node->numChildren(); ++i) {
Edge& edge = m_graph.varArgChild(node, i);
if (!edge)
continue;
if (edge.isProved() || edge.willNotHaveCheck()) {
edge = Edge();
changed = true;
continue;
}
Edge& dst = m_graph.varArgChild(node, targetIndex++);
std::swap(dst, edge);
}
node->children.setNumChildren(targetIndex);
break;
}
case StrCat: {
bool goodToGo = true;
m_graph.doToChildren(
node,
[&](Edge& edge) {
if (m_state.forNode(edge).isType(SpecString))
return;
goodToGo = false;
});
if (!goodToGo)
break;
node->setOpAndDefaultFlags(MakeRope);
m_graph.doToChildren(
node,
[&] (Edge& edge) {
edge.setUseKind(KnownStringUse);
});
changed = true;
FALLTHROUGH;
}
case MakeRope:
case MakeAtomString: {
for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
Edge& edge = node->children.child(i);
if (!edge)
break;
JSValue childConstant = m_state.forNode(edge).value();
if (!childConstant)
continue;
if (!childConstant.isString())
continue;
if (asString(childConstant)->length())
continue;
// Don't allow the MakeRope to have zero children.
if (!i && !node->child2())
break;
node->children.removeEdge(i--);
changed = true;
}
if (!node->child2()) {
ASSERT(!node->child3());
if (node->op() != MakeAtomString) {
node->convertToIdentity();
changed = true;
}
}
break;
}
case CheckTypeInfoFlags: {
const AbstractValue& abstractValue = m_state.forNode(node->child1());
unsigned bits = node->typeInfoOperand();
ASSERT(bits);
if (JSValue value = abstractValue.value()) {
if (value.isCell()) {
// This works because if we see a cell here, we know it's fully constructed
// and we can read its inline type info flags. These flags don't change over the
// object's lifetime.
if ((value.asCell()->inlineTypeFlags() & bits) == bits) {
eliminated = true;
node->remove(m_graph);
break;
}
}
}
if (abstractValue.m_structure.isFinite()) {
bool ok = true;
abstractValue.m_structure.forEach([&] (RegisteredStructure structure) {
ok &= (structure->typeInfo().inlineTypeFlags() & bits) == bits;
});
if (ok) {
eliminated = true;
node->remove(m_graph);
break;
}
}
break;
}
case HasStructureWithFlags: {
const AbstractValue& child = m_state.forNode(node->child1());
unsigned flags = node->structureFlags();
ASSERT(flags);
if (Structure::bitFieldFlagsCantBeChangedWithoutTransition(flags) && child.m_type && !(child.m_type & ~SpecCell) && child.m_structure.isFinite()) {
bool canFoldToTrue = true;
bool canFoldToFalse = true;
child.m_structure.forEach([&] (RegisteredStructure structure) {
bool notDictionary = !structure->isDictionary();
bool hasAnyOfBitFieldFlags = structure->hasAnyOfBitFieldFlags(flags);
canFoldToTrue &= notDictionary && hasAnyOfBitFieldFlags;
canFoldToFalse &= notDictionary && !hasAnyOfBitFieldFlags;
});
if (canFoldToTrue) {
m_graph.convertToConstant(node, jsBoolean(true));
changed = true;
} else if (canFoldToFalse) {
m_graph.convertToConstant(node, jsBoolean(false));
changed = true;
}
}
break;
}
case GetScope: {
if (JSValue base = m_state.forNode(node->child1()).m_value) {
if (JSFunction* function = jsDynamicCast<JSFunction*>(base)) {
m_graph.convertToConstant(node, function->scope());
changed = true;
break;
}
}
switch (node->child1()->op()) {
case NewFunction:
case NewGeneratorFunction:
case NewAsyncGeneratorFunction:
case NewAsyncFunction: {
node->convertToIdentityOn(node->child1()->child1().node());
node->child1().setUseKind(KnownCellUse);
eliminated = true;
break;
}
default:
break;
}
break;
}
case Construct: {
Edge calleeNode = m_graph.child(node, 0);
Edge newTargetNode = m_graph.child(node, 1);
JSValue calleeValue = m_state.forNode(calleeNode).m_value;
JSValue newTargetValue = m_state.forNode(newTargetNode).m_value;
if (calleeValue && newTargetValue) {
auto* callee = jsDynamicCast<JSObject*>(calleeValue);
auto* newTarget = jsDynamicCast<JSFunction*>(newTargetValue);
if (callee && newTarget) {
JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
if (callee->globalObject() == globalObject) {
if (FunctionRareData* rareData = newTarget->rareData()) {
if (rareData->allocationProfileWatchpointSet().isStillValid() && globalObject->structureCacheClearedWatchpointSet().isStillValid()) {
Structure* structure = rareData->internalFunctionAllocationStructure();
if (callee->classInfo() == ObjectConstructor::info() && node->numChildren() == 2) {
if (structure && structure->classInfoForCells() == JSFinalObject::info() && structure->hasMonoProto()) {
m_graph.freeze(rareData);
m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
m_graph.freeze(globalObject);
m_graph.watchpoints().addLazily(globalObject->structureCacheClearedWatchpointSet());
node->convertToNewObject(m_graph.registerStructure(structure));
changed = true;
break;
}
}
if (callee->classInfo() == ArrayConstructor::info() && node->numChildren() == 3 && !m_graph.hasExitSite(node->origin.semantic, BadType) && !m_graph.hasExitSite(node->origin.semantic, OutOfBounds)) {
if (structure && structure->classInfoForCells() == JSArray::info() && structure->hasMonoProto() && !hasAnyArrayStorage(structure->indexingType())) {
if (m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
m_graph.freeze(rareData);
m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
m_graph.freeze(globalObject);
m_graph.watchpoints().addLazily(globalObject->structureCacheClearedWatchpointSet());
node->convertToNewArrayWithSizeAndStructure(m_graph, m_graph.registerStructure(structure));
changed = true;
break;
}
}
}
}
}
}
}
}
break;
}
case ArithBitAnd: {
if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse)
break;
if ((node->child2()->isInt32Constant() && node->child2()->asInt32() == -1) || (node->child1() == node->child2())) {
m_insertionSet.insertCheck(m_graph, indexInBlock, node);
node->convertToIdentityOn(node->child1().node());
changed = true;
break;
}
break;
}
case ArithBitOr: {
if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse)
break;
if ((node->child2()->isInt32Constant() && !node->child2()->asInt32()) || (node->child1() == node->child2())) {
m_insertionSet.insertCheck(m_graph, indexInBlock, node);
node->convertToIdentityOn(node->child1().node());
changed = true;
break;
}
break;
}
case ArithBitXor: {
if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse)
break;
if (node->child2()->isInt32Constant() && !node->child2()->asInt32()) {
m_insertionSet.insertCheck(m_graph, indexInBlock, node);
node->convertToIdentityOn(node->child1().node());
changed = true;
break;
}
break;
}
case ValueBitXor:
case ValueBitAnd:
case ValueBitOr:
case ValueBitRShift:
case ValueBitLShift: {
if (node->binaryUseKind() == UntypedUse) {
auto& value1 = m_state.forNode(node->child1());
auto& value2 = m_state.forNode(node->child2());
if (value1.isType(SpecInt32Only) && value2.isType(SpecInt32Only)) {
switch (node->op()) {
case ValueBitXor:
node->setOp(ArithBitXor);
break;
case ValueBitOr:
node->setOp(ArithBitOr);
break;
case ValueBitAnd:
node->setOp(ArithBitAnd);
break;
case ValueBitLShift:
node->setOp(ArithBitLShift);
break;
case ValueBitRShift:
node->setOp(ArithBitRShift);
break;
default:
DFG_CRASH(m_graph, node, "Unexpected node");
break;
}
node->child1() = Edge(node->child1().node(), KnownInt32Use);
node->child2() = Edge(node->child2().node(), KnownInt32Use);
changed = true;
break;
}
}
break;
}
case PurifyNaN: {
auto abstractValue = m_state.forNode(node->child1());
if (!abstractValue.couldBeType(SpecDoubleImpureNaN)) {
node->convertToIdentityOn(node->child1().node());
changed = true;
}
break;
}
case ArithAdd: {
JSValue left = m_state.forNode(node->child1()).value();
JSValue right = m_state.forNode(node->child2()).value();
switch (node->binaryUseKind()) {
case DoubleRepUse: {
// Addition is subtle with doubles. Zero is not the neutral value, negative zero is:
// 0 + 0 = 0
// 0 + -0 = 0
// -0 + 0 = 0
// -0 + -0 = -0
if (left && left.isNumber()) {
if (isNegativeZero(left.asNumber())) {
node->convertToPurifyNaN(node->child2().node());
changed = true;
break;
}
}
if (right && right.isNumber()) {
if (isNegativeZero(right.asNumber())) {
node->convertToPurifyNaN(node->child1().node());
changed = true;
break;
}
}
break;
}
default:
break;
}
break;
}
case ArithMul: {
JSValue left = m_state.forNode(node->child1()).value();
JSValue right = m_state.forNode(node->child2()).value();
switch (node->binaryUseKind()) {
case DoubleRepUse: {
if (left && left.isNumber()) {
if (left.asNumber() == 1) {
node->convertToPurifyNaN(node->child2().node());
changed = true;
break;
}
}
if (right && right.isNumber()) {
if (right.asNumber() == 1) {
node->convertToPurifyNaN(node->child1().node());
changed = true;
break;
}
}
break;
}
default:
break;
}
break;
}
case PhantomNewObject:
case PhantomNewArrayWithConstantSize:
case PhantomNewFunction:
case PhantomNewGeneratorFunction:
case PhantomNewAsyncGeneratorFunction:
case PhantomNewAsyncFunction:
case PhantomNewInternalFieldObject:
case PhantomCreateActivation:
case PhantomDirectArguments:
case PhantomClonedArguments:
case PhantomCreateRest:
case PhantomSpread:
case PhantomNewArrayWithSpread:
case PhantomNewArrayBuffer:
case PhantomNewRegexp:
case BottomValue:
alreadyHandled = true;
break;
default:
break;
}
if (eliminated) {
changed = true;
continue;
}
if (alreadyHandled)
continue;
m_interpreter.execute(indexInBlock);
if (!m_state.isValid()) {
// If we invalidated then we shouldn't attempt to constant-fold. Here's an
// example:
//
// c: JSConstant(4.2)
// x: ValueToInt32(Check:Int32:@const)
//
// It would be correct for an analysis to assume that execution cannot
// proceed past @x. Therefore, constant-folding @x could be rather bad. But,
// the CFA may report that it found a constant even though it also reported
// that everything has been invalidated. This will only happen in a couple of
// the constant folding cases; most of them are also separately defensive
// about such things.
break;
}
if (!node->shouldGenerate() || m_state.didClobber() || node->hasConstant() || !node->result())
continue;
// Interesting fact: this freezing that we do right here may turn an fragile value into
// a weak value. See DFGValueStrength.h.
FrozenValue* value = m_graph.freeze(m_state.forNode(node).value());
if (!*value)
continue;
if (node->op() == GetLocal) {
// Need to preserve bytecode liveness in ThreadedCPS form. This wouldn't be necessary
// if it wasn't for https://bugs.webkit.org/show_bug.cgi?id=144086.
m_insertionSet.insertNode(
indexInBlock, SpecNone, PhantomLocal, node->origin,
OpInfo(node->variableAccessData()));
m_graph.dethread();
} else
m_insertionSet.insertCheck(m_graph, indexInBlock, node);
m_graph.convertToConstant(node, value);
changed = true;
}
if (m_graph.m_form == SSA || m_graph.m_form == ThreadedCPS)
m_state.endBasicBlock();
m_state.reset();
m_insertionSet.execute(block);
return changed;
}
void emitGetByOffset(unsigned indexInBlock, Node* node, const AbstractValue& baseValue, const MultiGetByOffsetCase& getCase, unsigned identifierNumber)
{
// When we get to here we have already emitted all of the requisite checks for everything.
// So, we just need to emit what the method object tells us to emit.
addBaseCheck(indexInBlock, node, baseValue, getCase.set());
GetByOffsetMethod method = getCase.method();
switch (method.kind()) {
case GetByOffsetMethod::Invalid:
RELEASE_ASSERT_NOT_REACHED();
return;
case GetByOffsetMethod::Constant:
m_graph.convertToConstant(node, method.constant());
return;
case GetByOffsetMethod::Load:
emitGetByOffset(indexInBlock, node, node->child1(), identifierNumber, method.offset());
return;
case GetByOffsetMethod::LoadFromPrototype: {
Node* child = m_insertionSet.insertConstant(
indexInBlock, node->origin, method.prototype());
emitGetByOffset(
indexInBlock, node, Edge(child, KnownCellUse), identifierNumber, method.offset());
return;
} }
RELEASE_ASSERT_NOT_REACHED();
}
void emitGetByOffset(unsigned indexInBlock, Node* node, const AbstractValue& baseValue, const GetByVariant& variant, unsigned identifierNumber)
{
Edge childEdge = node->child1();
addBaseCheck(indexInBlock, node, baseValue, variant.structureSet());
// We aren't set up to handle prototype stuff.
DFG_ASSERT(m_graph, node, variant.conditionSet().isEmpty());
if (JSValue value = m_graph.tryGetConstantProperty(baseValue.m_value, *m_graph.addStructureSet(variant.structureSet()), variant.offset())) {
m_graph.convertToConstant(node, m_graph.freeze(value));
return;
}
emitGetByOffset(indexInBlock, node, childEdge, identifierNumber, variant.offset());
}
void emitGetByOffset(
unsigned indexInBlock, Node* node, Edge childEdge, unsigned identifierNumber,
PropertyOffset offset)
{
childEdge.setUseKind(KnownCellUse);
Edge propertyStorage;
if (isInlineOffset(offset))
propertyStorage = childEdge;
else {
propertyStorage = Edge(m_insertionSet.insertNode(
indexInBlock, SpecNone, GetButterfly, node->origin, childEdge));
}
StorageAccessData& data = *m_graph.m_storageAccessData.add();
data.offset = offset;
data.identifierNumber = identifierNumber;
node->convertToGetByOffset(data, propertyStorage, childEdge);
}
void emitPutByOffset(unsigned indexInBlock, Node* node, const AbstractValue& baseValue, const PutByVariant& variant, unsigned identifierNumber)
{
NodeOrigin origin = node->origin;
Edge childEdge = node->child1();
addBaseCheck(indexInBlock, node, baseValue, variant.oldStructure());
node->child1().setUseKind(KnownCellUse);
childEdge.setUseKind(KnownCellUse);
Transition* transition = nullptr;
if (variant.kind() == PutByVariant::Transition) {
transition = m_graph.m_transitions.add(
m_graph.registerStructure(variant.oldStructureForTransition()), m_graph.registerStructure(variant.newStructure()));
} else {
#if ASSERT_ENABLED
for (auto structure : variant.oldStructure())
ASSERT(!structure->propertyReplacementWatchpointSet(variant.offset())->isStillValid());
#endif
}
Edge propertyStorage;
DFG_ASSERT(m_graph, node, origin.exitOK);
bool canExit = true;
bool didAllocateStorage = false;
if (isInlineOffset(variant.offset()))
propertyStorage = childEdge;
else if (!variant.reallocatesStorage()) {
propertyStorage = Edge(m_insertionSet.insertNode(
indexInBlock, SpecNone, GetButterfly, origin, childEdge));
} else if (!variant.oldStructureForTransition()->outOfLineCapacity()) {
ASSERT(variant.newStructure()->outOfLineCapacity());
ASSERT(!isInlineOffset(variant.offset()));
Node* allocatePropertyStorage = m_insertionSet.insertNode(
indexInBlock, SpecNone, AllocatePropertyStorage,
origin, OpInfo(transition), childEdge);
propertyStorage = Edge(allocatePropertyStorage);
didAllocateStorage = true;
} else {
ASSERT(variant.oldStructureForTransition()->outOfLineCapacity());
ASSERT(variant.newStructure()->outOfLineCapacity() > variant.oldStructureForTransition()->outOfLineCapacity());
ASSERT(!isInlineOffset(variant.offset()));
Node* reallocatePropertyStorage = m_insertionSet.insertNode(
indexInBlock, SpecNone, ReallocatePropertyStorage, origin,
OpInfo(transition), childEdge,
Edge(m_insertionSet.insertNode(
indexInBlock, SpecNone, GetButterfly, origin, childEdge)));
propertyStorage = Edge(reallocatePropertyStorage);
didAllocateStorage = true;
}
StorageAccessData& data = *m_graph.m_storageAccessData.add();
data.offset = variant.offset();
data.identifierNumber = identifierNumber;
node->convertToPutByOffset(data, propertyStorage, childEdge);
node->origin.exitOK = canExit;
if (variant.kind() == PutByVariant::Transition) {
if (didAllocateStorage) {
m_insertionSet.insertNode(
indexInBlock + 1, SpecNone, NukeStructureAndSetButterfly,
origin.withInvalidExit(), childEdge, propertyStorage);
}
// FIXME: PutStructure goes last until we fix either
// https://bugs.webkit.org/show_bug.cgi?id=142921 or
// https://bugs.webkit.org/show_bug.cgi?id=142924.
m_insertionSet.insertNode(
indexInBlock + 1, SpecNone, PutStructure, origin.withInvalidExit(), OpInfo(transition),
childEdge);
}
}
void emitDeleteByOffset(unsigned indexInBlock, Node* node, const AbstractValue& baseValue, const DeleteByVariant& variant, unsigned identifierNumber)
{
NodeOrigin origin = node->origin;
DFG_ASSERT(m_graph, node, origin.exitOK);
addBaseCheck(indexInBlock, node, baseValue, m_graph.registerStructure(variant.oldStructure()));
node->child1().setUseKind(KnownCellUse);
if (!variant.newStructure()) {
m_graph.convertToConstant(node, jsBoolean(variant.result()));
node->origin = node->origin.withInvalidExit();
return;
}
Transition* transition = m_graph.m_transitions.add(
m_graph.registerStructure(variant.oldStructure()), m_graph.registerStructure(variant.newStructure()));
Edge propertyStorage;
if (isInlineOffset(variant.offset()))
propertyStorage = node->child1();
else
propertyStorage = Edge(m_insertionSet.insertNode(
indexInBlock, SpecNone, GetButterfly, origin, node->child1()));
StorageAccessData& data = *m_graph.m_storageAccessData.add();
data.offset = variant.offset();
data.identifierNumber = identifierNumber;
Node* clearValue = m_insertionSet.insertNode(indexInBlock, SpecNone, JSConstant, origin, OpInfo(m_graph.freezeStrong(JSValue())));
m_insertionSet.insertNode(
indexInBlock, SpecNone, PutByOffset, origin, OpInfo(&data), propertyStorage, node->child1(), Edge(clearValue));
origin = origin.withInvalidExit();
m_insertionSet.insertNode(
indexInBlock, SpecNone, PutStructure, origin, OpInfo(transition),
node->child1());
m_graph.convertToConstant(node, jsBoolean(variant.result()));
node->origin = origin;
}
void addBaseCheck(
unsigned indexInBlock, Node* node, const AbstractValue& baseValue, const StructureSet& set)
{
addBaseCheck(indexInBlock, node, baseValue, *m_graph.addStructureSet(set));
}
void addBaseCheck(
unsigned indexInBlock, Node* node, const AbstractValue& baseValue, const RegisteredStructureSet& set)
{
if (!baseValue.m_structure.isSubsetOf(set)) {
// Arises when we prune MultiGetByOffset. We could have a
// MultiGetByOffset with a single variant that checks for structure S,
// and the input has structures S and T, for example.
ASSERT(node->child1());
m_insertionSet.insertNode(
indexInBlock, SpecNone, CheckStructure, node->origin,
OpInfo(m_graph.addStructureSet(set.toStructureSet())), node->child1());
return;
}
if (baseValue.m_type & ~SpecCell)
m_insertionSet.insertCheck(indexInBlock, node->origin, node->child1());
}
void addStructureTransitionCheck(NodeOrigin origin, unsigned indexInBlock, JSCell* cell, Structure* structure)
{
{
StructureRegistrationResult result;
m_graph.registerStructure(cell->structure(), result);
if (result == StructureRegisteredAndWatched)
return;
}
m_graph.registerStructure(structure);
Node* weakConstant = m_insertionSet.insertNode(
indexInBlock, speculationFromValue(cell), JSConstant, origin,
OpInfo(m_graph.freeze(cell)));
m_insertionSet.insertNode(
indexInBlock, SpecNone, CheckStructure, origin,
OpInfo(m_graph.addStructureSet(structure)), Edge(weakConstant, CellUse));
}
void fixUpsilons(BasicBlock* block)
{
for (unsigned nodeIndex = block->size(); nodeIndex--;) {
Node* node = block->at(nodeIndex);
if (node->op() != Upsilon)
continue;
switch (node->phi()->op()) {
case Phi:
break;
case JSConstant:
case DoubleConstant:
case Int52Constant:
node->remove(m_graph);
break;
default:
DFG_CRASH(m_graph, node, "Bad Upsilon phi() pointer");
break;
}
}
}
void tryFoldAsPutByOffset(Node* node, unsigned indexInBlock, Edge baseEdge, Edge valueEdge, bool isDirect, PrivateFieldPutKind privateFieldPutKind, bool& changed, bool& alreadyHandled)
{
if (!Options::useAccessInlining())
return;
NodeOrigin origin = node->origin;
Node* baseNode = baseEdge.node();
UniquedStringImpl* uid = node->cacheableIdentifier().uid();
ASSERT(baseEdge.useKind() == CellUse);
AbstractValue baseValue = m_state.forNode(baseNode);
AbstractValue valueValue = m_state.forNode(valueEdge);
if (!baseValue.m_structure.isFinite())
return;
PutByStatus status = PutByStatus::computeFor(
m_graph.globalObjectFor(origin.semantic),
baseValue.m_structure.toStructureSet(),
node->cacheableIdentifier(),
isDirect, privateFieldPutKind);
if (!status.isSimple())
return;
ASSERT(status.numVariants());
if (status.numVariants() > 1 && !m_graph.m_plan.isFTL())
return;
changed = true;
RegisteredStructureSet newSet;
TransitionVector transitions;
for (const PutByVariant& variant : status.variants()) {
if (variant.kind() == PutByVariant::Transition) {
for (const ObjectPropertyCondition& condition : variant.conditionSet()) {
if (m_graph.watchCondition(condition))
continue;
Structure* structure = condition.object()->structure();
if (!condition.structureEnsuresValidity(Concurrency::ConcurrentThread, structure))
return;
m_insertionSet.insertNode(
indexInBlock, SpecNone, CheckStructure, node->origin,
OpInfo(m_graph.addStructureSet(structure)),
m_insertionSet.insertConstantForUse(
indexInBlock, node->origin, condition.object(), KnownCellUse));
}
ASSERT(privateFieldPutKind.isNone() || privateFieldPutKind.isDefine());
RegisteredStructure newStructure = m_graph.registerStructure(variant.newStructure());
transitions.append(
Transition(
m_graph.registerStructure(variant.oldStructureForTransition()), newStructure));
newSet.add(newStructure);
} else {
// We do not need to handle Replace PropertyCondition here. This conversion happens only when AI proves that
// baseValue has finite number of structures. And when calling PutByStatus::computeFor to collect Replace
// PutByVariant, we already ensured that each structure in each variant has the invalidated replacement watchpoint condition.
// Thus, even though baseValue's structure gets changed whatever, it is within baseValue.m_structures (since AI proved and
// configured watchpoint to ensure that). And for each structure in this, if it gets Replace type, then we already validated
// watchpoint's status.
ASSERT(variant.kind() == PutByVariant::Replace);
ASSERT(privateFieldPutKind.isNone() || privateFieldPutKind.isSet());
DFG_ASSERT(m_graph, node, variant.conditionSet().isEmpty());
newSet.merge(*m_graph.addStructureSet(variant.oldStructure()));
}
}
// Push CFA over this node after we get the state before.
m_interpreter.didFoldClobberWorld();
m_interpreter.observeTransitions(indexInBlock, transitions);
if (m_state.forNode(baseEdge).changeStructure(m_graph, newSet) == Contradiction)
m_state.setIsValid(false);
alreadyHandled = true; // Don't allow the default constant folder to do things to this.
m_insertionSet.insertNode(
indexInBlock, SpecNone, FilterPutByStatus, node->origin,
OpInfo(m_graph.m_plan.recordedStatuses().addPutByStatus(node->origin.semantic, status)),
Edge(baseNode));
unsigned identifierNumber = m_graph.identifiers().ensure(uid);
if (status.numVariants() == 1) {
emitPutByOffset(indexInBlock, node, baseValue, status[0], identifierNumber);
return;
}
ASSERT(m_graph.m_plan.isFTL());
MultiPutByOffsetData* data = m_graph.m_multiPutByOffsetData.add();
data->variants = status.variants();
data->identifierNumber = identifierNumber;
node->convertToMultiPutByOffset(data);
}
InPlaceAbstractState m_state;
AbstractInterpreter<InPlaceAbstractState> m_interpreter;
InsertionSet m_insertionSet;
};
bool performConstantFolding(Graph& graph)
{
return runPhase<ConstantFoldingPhase>(graph);
}
} } // namespace JSC::DFG
#endif // ENABLE(DFG_JIT)
|