Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/code-stub-assembler.cc

Issue 1995453002: [stubs] Extend HasProperty stub with dictionary-mode and double-elements objects support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Drive-by fix: replace Load()s with LoadObjectField()s Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/code-stub-assembler.h ('k') | src/globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/code-stub-assembler.h" 5 #include "src/code-stub-assembler.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 7
8 namespace v8 { 8 namespace v8 {
9 namespace internal { 9 namespace internal {
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 Node* CodeStubAssembler::NullConstant() { 53 Node* CodeStubAssembler::NullConstant() {
54 return LoadRoot(Heap::kNullValueRootIndex); 54 return LoadRoot(Heap::kNullValueRootIndex);
55 } 55 }
56 56
57 Node* CodeStubAssembler::UndefinedConstant() { 57 Node* CodeStubAssembler::UndefinedConstant() {
58 return LoadRoot(Heap::kUndefinedValueRootIndex); 58 return LoadRoot(Heap::kUndefinedValueRootIndex);
59 } 59 }
60 60
61 Node* CodeStubAssembler::TheHoleConstant() {
62 return LoadRoot(Heap::kTheHoleValueRootIndex);
63 }
64
65 Node* CodeStubAssembler::HashSeed() {
66 return SmiToWord32(LoadRoot(Heap::kHashSeedRootIndex));
67 }
68
61 Node* CodeStubAssembler::StaleRegisterConstant() { 69 Node* CodeStubAssembler::StaleRegisterConstant() {
62 return LoadRoot(Heap::kStaleRegisterRootIndex); 70 return LoadRoot(Heap::kStaleRegisterRootIndex);
63 } 71 }
64 72
65 Node* CodeStubAssembler::Float64Round(Node* x) { 73 Node* CodeStubAssembler::Float64Round(Node* x) {
66 Node* one = Float64Constant(1.0); 74 Node* one = Float64Constant(1.0);
67 Node* one_half = Float64Constant(0.5); 75 Node* one_half = Float64Constant(0.5);
68 76
69 Variable var_x(this, MachineRepresentation::kFloat64); 77 Variable var_x(this, MachineRepresentation::kFloat64);
70 Label return_x(this); 78 Label return_x(this);
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 MachineType rep) { 474 MachineType rep) {
467 return Load(rep, buffer, IntPtrConstant(offset)); 475 return Load(rep, buffer, IntPtrConstant(offset));
468 } 476 }
469 477
470 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset, 478 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset,
471 MachineType rep) { 479 MachineType rep) {
472 return Load(rep, object, IntPtrConstant(offset - kHeapObjectTag)); 480 return Load(rep, object, IntPtrConstant(offset - kHeapObjectTag));
473 } 481 }
474 482
475 Node* CodeStubAssembler::LoadHeapNumberValue(Node* object) { 483 Node* CodeStubAssembler::LoadHeapNumberValue(Node* object) {
476 return Load(MachineType::Float64(), object, 484 return LoadObjectField(object, HeapNumber::kValueOffset,
477 IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag)); 485 MachineType::Float64());
478 } 486 }
479 487
480 Node* CodeStubAssembler::LoadMap(Node* object) { 488 Node* CodeStubAssembler::LoadMap(Node* object) {
481 return LoadObjectField(object, HeapObject::kMapOffset); 489 return LoadObjectField(object, HeapObject::kMapOffset);
482 } 490 }
483 491
484 Node* CodeStubAssembler::LoadInstanceType(Node* object) { 492 Node* CodeStubAssembler::LoadInstanceType(Node* object) {
485 return LoadMapInstanceType(LoadMap(object)); 493 return LoadMapInstanceType(LoadMap(object));
486 } 494 }
487 495
496 Node* CodeStubAssembler::LoadProperties(Node* object) {
497 return LoadObjectField(object, JSObject::kPropertiesOffset);
498 }
499
488 Node* CodeStubAssembler::LoadElements(Node* object) { 500 Node* CodeStubAssembler::LoadElements(Node* object) {
489 return LoadObjectField(object, JSObject::kElementsOffset); 501 return LoadObjectField(object, JSObject::kElementsOffset);
490 } 502 }
491 503
492 Node* CodeStubAssembler::LoadFixedArrayBaseLength(Node* array) { 504 Node* CodeStubAssembler::LoadFixedArrayBaseLength(Node* array) {
493 return LoadObjectField(array, FixedArrayBase::kLengthOffset); 505 return LoadObjectField(array, FixedArrayBase::kLengthOffset);
494 } 506 }
495 507
496 Node* CodeStubAssembler::LoadMapBitField(Node* map) { 508 Node* CodeStubAssembler::LoadMapBitField(Node* map) {
497 return Load(MachineType::Uint8(), map, 509 return LoadObjectField(map, Map::kBitFieldOffset, MachineType::Uint8());
498 IntPtrConstant(Map::kBitFieldOffset - kHeapObjectTag));
499 } 510 }
500 511
501 Node* CodeStubAssembler::LoadMapBitField2(Node* map) { 512 Node* CodeStubAssembler::LoadMapBitField2(Node* map) {
502 return Load(MachineType::Uint8(), map, 513 return LoadObjectField(map, Map::kBitField2Offset, MachineType::Uint8());
503 IntPtrConstant(Map::kBitField2Offset - kHeapObjectTag));
504 } 514 }
505 515
506 Node* CodeStubAssembler::LoadMapBitField3(Node* map) { 516 Node* CodeStubAssembler::LoadMapBitField3(Node* map) {
507 return Load(MachineType::Uint32(), map, 517 return LoadObjectField(map, Map::kBitField3Offset, MachineType::Uint32());
508 IntPtrConstant(Map::kBitField3Offset - kHeapObjectTag));
509 } 518 }
510 519
511 Node* CodeStubAssembler::LoadMapInstanceType(Node* map) { 520 Node* CodeStubAssembler::LoadMapInstanceType(Node* map) {
512 return Load(MachineType::Uint8(), map, 521 return LoadObjectField(map, Map::kInstanceTypeOffset, MachineType::Uint8());
513 IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag));
514 } 522 }
515 523
516 Node* CodeStubAssembler::LoadMapDescriptors(Node* map) { 524 Node* CodeStubAssembler::LoadMapDescriptors(Node* map) {
517 return LoadObjectField(map, Map::kDescriptorsOffset); 525 return LoadObjectField(map, Map::kDescriptorsOffset);
518 } 526 }
519 527
520 Node* CodeStubAssembler::LoadMapPrototype(Node* map) { 528 Node* CodeStubAssembler::LoadMapPrototype(Node* map) {
521 return LoadObjectField(map, Map::kPrototypeOffset); 529 return LoadObjectField(map, Map::kPrototypeOffset);
522 } 530 }
523 531
524 Node* CodeStubAssembler::LoadNameHash(Node* name) { 532 Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) {
525 return Load(MachineType::Uint32(), name, 533 return LoadObjectField(map, Map::kInstanceSizeOffset, MachineType::Uint8());
526 IntPtrConstant(Name::kHashFieldOffset - kHeapObjectTag)); 534 }
535
536 Node* CodeStubAssembler::LoadNameHashField(Node* name) {
537 return LoadObjectField(name, Name::kHashFieldOffset, MachineType::Uint32());
538 }
539
540 Node* CodeStubAssembler::LoadNameHash(Node* name, Label* if_hash_not_computed) {
541 Node* hash_field = LoadNameHashField(name);
542 if (if_hash_not_computed != nullptr) {
543 GotoIf(WordEqual(
544 Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)),
545 Int32Constant(0)),
546 if_hash_not_computed);
547 }
548 return Word32Shr(hash_field, Int32Constant(Name::kHashShift));
549 }
550
551 Node* CodeStubAssembler::LoadStringLength(Node* object) {
552 return LoadObjectField(object, String::kLengthOffset);
553 }
554
555 Node* CodeStubAssembler::LoadJSValueValue(Node* object) {
556 return LoadObjectField(object, JSValue::kValueOffset);
527 } 557 }
528 558
529 Node* CodeStubAssembler::AllocateUninitializedFixedArray(Node* length) { 559 Node* CodeStubAssembler::AllocateUninitializedFixedArray(Node* length) {
530 Node* header_size = IntPtrConstant(FixedArray::kHeaderSize); 560 Node* header_size = IntPtrConstant(FixedArray::kHeaderSize);
531 Node* data_size = WordShl(length, IntPtrConstant(kPointerSizeLog2)); 561 Node* data_size = WordShl(length, IntPtrConstant(kPointerSizeLog2));
532 Node* total_size = IntPtrAdd(data_size, header_size); 562 Node* total_size = IntPtrAdd(data_size, header_size);
533 563
534 Node* result = Allocate(total_size, kNone); 564 Node* result = Allocate(total_size, kNone);
535 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kFixedArrayMapRootIndex)); 565 StoreMapNoWriteBarrier(result, LoadRoot(Heap::kFixedArrayMapRootIndex));
536 StoreObjectFieldNoWriteBarrier(result, FixedArray::kLengthOffset, 566 StoreObjectFieldNoWriteBarrier(result, FixedArray::kLengthOffset,
537 SmiTag(length)); 567 SmiTag(length));
538 568
539 return result; 569 return result;
540 } 570 }
541 571
542 Node* CodeStubAssembler::LoadFixedArrayElement(Node* object, Node* index_node, 572 Node* CodeStubAssembler::LoadFixedArrayElement(Node* object, Node* index_node,
543 int additional_offset, 573 int additional_offset,
544 ParameterMode parameter_mode) { 574 ParameterMode parameter_mode) {
545 int32_t header_size = 575 int32_t header_size =
546 FixedArray::kHeaderSize + additional_offset - kHeapObjectTag; 576 FixedArray::kHeaderSize + additional_offset - kHeapObjectTag;
547 Node* offset = ElementOffsetFromIndex(index_node, FAST_HOLEY_ELEMENTS, 577 Node* offset = ElementOffsetFromIndex(index_node, FAST_HOLEY_ELEMENTS,
548 parameter_mode, header_size); 578 parameter_mode, header_size);
549 return Load(MachineType::AnyTagged(), object, offset); 579 return Load(MachineType::AnyTagged(), object, offset);
550 } 580 }
551 581
552 Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) { 582 Node* CodeStubAssembler::LoadFixedDoubleArrayElement(
553 return Load(MachineType::Uint8(), map, 583 Node* object, Node* index_node, MachineType machine_type,
554 IntPtrConstant(Map::kInstanceSizeOffset - kHeapObjectTag)); 584 int additional_offset, ParameterMode parameter_mode) {
585 int32_t header_size =
586 FixedDoubleArray::kHeaderSize + additional_offset - kHeapObjectTag;
587 Node* offset = ElementOffsetFromIndex(index_node, FAST_HOLEY_DOUBLE_ELEMENTS,
588 parameter_mode, header_size);
589 return Load(machine_type, object, offset);
555 } 590 }
556 591
557 Node* CodeStubAssembler::LoadNativeContext(Node* context) { 592 Node* CodeStubAssembler::LoadNativeContext(Node* context) {
558 return LoadFixedArrayElement(context, 593 return LoadFixedArrayElement(context,
559 Int32Constant(Context::NATIVE_CONTEXT_INDEX)); 594 Int32Constant(Context::NATIVE_CONTEXT_INDEX));
560 } 595 }
561 596
562 Node* CodeStubAssembler::LoadJSArrayElementsMap(ElementsKind kind, 597 Node* CodeStubAssembler::LoadJSArrayElementsMap(ElementsKind kind,
563 Node* native_context) { 598 Node* native_context) {
564 return LoadFixedArrayElement(native_context, 599 return LoadFixedArrayElement(native_context,
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 } 1421 }
1387 1422
1388 Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift, 1423 Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift,
1389 uint32_t mask) { 1424 uint32_t mask) {
1390 return Word32Shr(Word32And(word32, Int32Constant(mask)), 1425 return Word32Shr(Word32And(word32, Int32Constant(mask)),
1391 Int32Constant(shift)); 1426 Int32Constant(shift));
1392 } 1427 }
1393 1428
1394 void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex, 1429 void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
1395 Variable* var_index, Label* if_keyisunique, 1430 Variable* var_index, Label* if_keyisunique,
1396 Label* call_runtime) { 1431 Label* if_bailout) {
1397 DCHECK_EQ(MachineRepresentation::kWord32, var_index->rep()); 1432 DCHECK_EQ(MachineRepresentation::kWord32, var_index->rep());
1398 1433
1399 Label if_keyissmi(this), if_keyisnotsmi(this); 1434 Label if_keyissmi(this), if_keyisnotsmi(this);
1400 Branch(WordIsSmi(key), &if_keyissmi, &if_keyisnotsmi); 1435 Branch(WordIsSmi(key), &if_keyissmi, &if_keyisnotsmi);
1401 Bind(&if_keyissmi); 1436 Bind(&if_keyissmi);
1402 { 1437 {
1403 // Negative smi keys are named properties. Handle in the runtime. 1438 // Negative smi keys are named properties. Handle in the runtime.
1404 Label if_keyispositive(this); 1439 GotoUnless(WordIsPositiveSmi(key), if_bailout);
1405 Branch(WordIsPositiveSmi(key), &if_keyispositive, call_runtime);
1406 Bind(&if_keyispositive);
1407 1440
1408 var_index->Bind(SmiToWord32(key)); 1441 var_index->Bind(SmiToWord32(key));
1409 Goto(if_keyisindex); 1442 Goto(if_keyisindex);
1410 } 1443 }
1411 1444
1412 Bind(&if_keyisnotsmi); 1445 Bind(&if_keyisnotsmi);
1413 1446
1414 Node* key_instance_type = LoadInstanceType(key); 1447 Node* key_instance_type = LoadInstanceType(key);
1415 Label if_keyisnotsymbol(this); 1448 // Symbols are unique.
1416 Branch(Word32Equal(key_instance_type, Int32Constant(SYMBOL_TYPE)), 1449 GotoIf(Word32Equal(key_instance_type, Int32Constant(SYMBOL_TYPE)),
1417 if_keyisunique, &if_keyisnotsymbol); 1450 if_keyisunique);
1418 Bind(&if_keyisnotsymbol); 1451
1419 { 1452 Label if_keyisinternalized(this);
1420 Label if_keyisinternalized(this); 1453 Node* bits =
1421 Node* bits = 1454 WordAnd(key_instance_type,
1422 WordAnd(key_instance_type, 1455 Int32Constant(kIsNotStringMask | kIsNotInternalizedMask));
1423 Int32Constant(kIsNotStringMask | kIsNotInternalizedMask)); 1456 Branch(Word32Equal(bits, Int32Constant(kStringTag | kInternalizedTag)),
1424 Branch(Word32Equal(bits, Int32Constant(kStringTag | kInternalizedTag)), 1457 &if_keyisinternalized, if_bailout);
1425 &if_keyisinternalized, call_runtime); 1458 Bind(&if_keyisinternalized);
1426 Bind(&if_keyisinternalized); 1459
1427 1460 // Check whether the key is an array index passed in as string. Handle
1428 // Check whether the key is an array index passed in as string. Handle 1461 // uniform with smi keys if so.
1429 // uniform with smi keys if so. 1462 // TODO(verwaest): Also support non-internalized strings.
1430 // TODO(verwaest): Also support non-internalized strings. 1463 Node* hash = LoadNameHashField(key);
1431 Node* hash = LoadNameHash(key); 1464 Node* bit = Word32And(hash, Int32Constant(Name::kIsNotArrayIndexMask));
1432 Node* bit = 1465 GotoIf(Word32NotEqual(bit, Int32Constant(0)), if_keyisunique);
1433 Word32And(hash, Int32Constant(internal::Name::kIsNotArrayIndexMask)); 1466 // Key is an index. Check if it is small enough to be encoded in the
1434 Label if_isarrayindex(this); 1467 // hash_field. Handle too big array index in runtime.
1435 Branch(Word32Equal(bit, Int32Constant(0)), &if_isarrayindex, 1468 bit = Word32And(hash, Int32Constant(Name::kContainsCachedArrayIndexMask));
1436 if_keyisunique); 1469 GotoIf(Word32NotEqual(bit, Int32Constant(0)), if_bailout);
1437 Bind(&if_isarrayindex); 1470 var_index->Bind(BitFieldDecode<Name::ArrayIndexValueBits>(hash));
1438 var_index->Bind(BitFieldDecode<internal::Name::ArrayIndexValueBits>(hash)); 1471 Goto(if_keyisindex);
1439 Goto(if_keyisindex); 1472 }
1473
1474 template <typename Dictionary>
1475 void CodeStubAssembler::NameDictionaryLookup(
1476 Node* dictionary, Node* unique_name, Label* if_found_, Variable* var_entry,
1477 Label* if_not_found, int inlined_probes) {
1478 DCHECK_EQ(MachineRepresentation::kWord32, var_entry->rep());
1479
1480 // TODO(ishell): Remove this trampoline block once crbug/615621 is fixed.
1481 // This trampoline block is currently necessary here to generate a correct
1482 // phi for |var_entry|.
1483 Label if_found(this, var_entry);
1484
1485 const int kElementsStartOffset =
1486 Dictionary::kElementsStartIndex * kPointerSize;
1487
1488 Node* capacity = SmiToWord32(LoadFixedArrayElement(
1489 dictionary, Int32Constant(Dictionary::kCapacityIndex)));
1490 Node* mask = Int32Sub(capacity, Int32Constant(1));
1491 Node* hash = LoadNameHash(unique_name);
1492
1493 // See Dictionary::FirstProbe().
1494 Node* count = Int32Constant(0);
1495 Node* entry = Word32And(hash, mask);
1496
1497 for (int i = 0; i < inlined_probes; i++) {
1498 // See Dictionary::EntryToIndex()
1499 Node* index = Int32Mul(entry, Int32Constant(Dictionary::kEntrySize));
1500 Node* current =
1501 LoadFixedArrayElement(dictionary, index, kElementsStartOffset);
1502 var_entry->Bind(entry);
1503 GotoIf(WordEqual(current, unique_name), &if_found);
1504
1505 // See Dictionary::NextProbe().
1506 count = Int32Constant(i + 1);
1507 entry = Word32And(Int32Add(entry, count), mask);
1508 }
1509
1510 Node* undefined = UndefinedConstant();
1511
1512 Variable var_count(this, MachineRepresentation::kWord32);
1513 Variable* loop_vars[] = {&var_count, var_entry};
1514 Label loop(this, 2, loop_vars);
1515 var_count.Bind(count);
1516 var_entry->Bind(entry);
1517 Goto(&loop);
1518 Bind(&loop);
1519 {
1520 Node* count = var_count.value();
1521 Node* entry = var_entry->value();
1522
1523 // See Dictionary::EntryToIndex()
1524 Node* index = Int32Mul(entry, Int32Constant(Dictionary::kEntrySize));
1525 Node* current =
1526 LoadFixedArrayElement(dictionary, index, kElementsStartOffset);
1527 GotoIf(WordEqual(current, undefined), if_not_found);
1528 GotoIf(WordEqual(current, unique_name), &if_found);
1529
1530 // See Dictionary::NextProbe().
1531 count = Int32Add(count, Int32Constant(1));
1532 entry = Word32And(Int32Add(entry, count), mask);
1533
1534 var_count.Bind(count);
1535 var_entry->Bind(entry);
1536 Goto(&loop);
1537 }
1538 Bind(&if_found);
1539 Goto(if_found_);
1540 }
1541
1542 // Instantiate template methods to workaround GCC compilation issue.
1543 template void CodeStubAssembler::NameDictionaryLookup<NameDictionary>(
1544 Node*, Node*, Label*, Variable*, Label*, int);
1545 template void CodeStubAssembler::NameDictionaryLookup<GlobalDictionary>(
1546 Node*, Node*, Label*, Variable*, Label*, int);
1547
1548 Node* CodeStubAssembler::ComputeIntegerHash(Node* key, Node* seed) {
1549 // See v8::internal::ComputeIntegerHash()
1550 Node* hash = key;
1551 hash = Word32Xor(hash, seed);
1552 hash = Int32Add(Word32Xor(hash, Int32Constant(0xffffffff)),
1553 Word32Shl(hash, Int32Constant(15)));
1554 hash = Word32Xor(hash, Word32Shr(hash, Int32Constant(12)));
1555 hash = Int32Add(hash, Word32Shl(hash, Int32Constant(2)));
1556 hash = Word32Xor(hash, Word32Shr(hash, Int32Constant(4)));
1557 hash = Int32Mul(hash, Int32Constant(2057));
1558 hash = Word32Xor(hash, Word32Shr(hash, Int32Constant(16)));
1559 return Word32And(hash, Int32Constant(0x3fffffff));
1560 }
1561
1562 template <typename Dictionary>
1563 void CodeStubAssembler::NumberDictionaryLookup(Node* dictionary, Node* key,
1564 Label* if_found,
1565 Variable* var_entry,
1566 Label* if_not_found) {
1567 DCHECK_EQ(MachineRepresentation::kWord32, var_entry->rep());
1568
1569 const int kElementsStartOffset =
1570 Dictionary::kElementsStartIndex * kPointerSize;
1571
1572 Node* capacity = SmiToWord32(LoadFixedArrayElement(
1573 dictionary, Int32Constant(Dictionary::kCapacityIndex)));
1574 Node* mask = Int32Sub(capacity, Int32Constant(1));
1575
1576 Node* seed;
1577 if (Dictionary::ShapeT::UsesSeed) {
1578 seed = HashSeed();
1579 } else {
1580 seed = Int32Constant(kZeroHashSeed);
1581 }
1582 Node* hash = ComputeIntegerHash(key, seed);
1583 Node* key_as_float64 = ChangeUint32ToFloat64(key);
1584
1585 // See Dictionary::FirstProbe().
1586 Node* count = Int32Constant(0);
1587 Node* entry = Word32And(hash, mask);
1588
1589 Node* undefined = UndefinedConstant();
1590 Node* the_hole = TheHoleConstant();
1591
1592 Variable var_count(this, MachineRepresentation::kWord32);
1593 Variable* loop_vars[] = {&var_count, var_entry};
1594 Label loop(this, 2, loop_vars);
1595 var_count.Bind(count);
1596 var_entry->Bind(entry);
1597 Goto(&loop);
1598 Bind(&loop);
1599 {
1600 Node* count = var_count.value();
1601 Node* entry = var_entry->value();
1602
1603 // See Dictionary::EntryToIndex()
1604 Node* index = Int32Mul(entry, Int32Constant(Dictionary::kEntrySize));
1605 Node* current =
1606 LoadFixedArrayElement(dictionary, index, kElementsStartOffset);
1607 GotoIf(WordEqual(current, undefined), if_not_found);
1608 Label next_probe(this);
1609 {
1610 Label if_currentissmi(this), if_currentisnotsmi(this);
1611 Branch(WordIsSmi(current), &if_currentissmi, &if_currentisnotsmi);
1612 Bind(&if_currentissmi);
1613 {
1614 Node* current_value = SmiToWord32(current);
1615 Branch(Word32Equal(current_value, key), if_found, &next_probe);
1616 }
1617 Bind(&if_currentisnotsmi);
1618 {
1619 GotoIf(WordEqual(current, the_hole), &next_probe);
1620 // Current must be the Number.
1621 Node* current_value = LoadHeapNumberValue(current);
1622 Branch(Float64Equal(current_value, key_as_float64), if_found,
1623 &next_probe);
1624 }
1625 }
1626
1627 Bind(&next_probe);
1628 // See Dictionary::NextProbe().
1629 count = Int32Add(count, Int32Constant(1));
1630 entry = Word32And(Int32Add(entry, count), mask);
1631
1632 var_count.Bind(count);
1633 var_entry->Bind(entry);
1634 Goto(&loop);
1440 } 1635 }
1441 } 1636 }
1442 1637
1443 void CodeStubAssembler::TryLookupProperty(Node* object, Node* map, 1638 void CodeStubAssembler::TryLookupProperty(Node* object, Node* map,
1444 Node* instance_type, Node* name, 1639 Node* instance_type,
1445 Label* if_found, Label* if_not_found, 1640 Node* unique_name, Label* if_found,
1446 Label* call_runtime) { 1641 Label* if_not_found,
1447 { 1642 Label* if_bailout) {
1448 Label if_objectissimple(this); 1643 Label if_objectisspecial(this);
1449 Branch(Int32LessThanOrEqual(instance_type, 1644 STATIC_ASSERT(JS_GLOBAL_OBJECT_TYPE <= LAST_SPECIAL_RECEIVER_TYPE);
1450 Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)), 1645 GotoIf(Int32LessThanOrEqual(instance_type,
1451 call_runtime, &if_objectissimple); 1646 Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)),
1452 Bind(&if_objectissimple); 1647 &if_objectisspecial);
1453 } 1648
1454
1455 // TODO(verwaest): Perform a dictonary lookup on slow-mode receivers.
1456 Node* bit_field3 = LoadMapBitField3(map); 1649 Node* bit_field3 = LoadMapBitField3(map);
1457 Node* bit = BitFieldDecode<Map::DictionaryMap>(bit_field3); 1650 Node* bit = BitFieldDecode<Map::DictionaryMap>(bit_field3);
1458 Label if_isfastmap(this); 1651 Label if_isfastmap(this), if_isslowmap(this);
1459 Branch(Word32Equal(bit, Int32Constant(0)), &if_isfastmap, call_runtime); 1652 Branch(Word32Equal(bit, Int32Constant(0)), &if_isfastmap, &if_isslowmap);
1460 Bind(&if_isfastmap); 1653 Bind(&if_isfastmap);
1461 Node* nof = BitFieldDecode<Map::NumberOfOwnDescriptorsBits>(bit_field3); 1654 {
1462 // Bail out to the runtime for large numbers of own descriptors. The stub only 1655 Node* nof = BitFieldDecode<Map::NumberOfOwnDescriptorsBits>(bit_field3);
1463 // does linear search, which becomes too expensive in that case. 1656 // Bail out to the runtime for large numbers of own descriptors. The stub
1464 { 1657 // only does linear search, which becomes too expensive in that case.
1465 static const int32_t kMaxLinear = 210;
1466 Label above_max(this), below_max(this);
1467 Branch(Int32LessThanOrEqual(nof, Int32Constant(kMaxLinear)), &below_max,
1468 call_runtime);
1469 Bind(&below_max);
1470 }
1471 Node* descriptors = LoadMapDescriptors(map);
1472
1473 Variable var_descriptor(this, MachineRepresentation::kWord32);
1474 Label loop(this, &var_descriptor);
1475 var_descriptor.Bind(Int32Constant(0));
1476 Goto(&loop);
1477 Bind(&loop);
1478 {
1479 Node* index = var_descriptor.value();
1480 Node* offset = Int32Constant(DescriptorArray::ToKeyIndex(0));
1481 Node* factor = Int32Constant(DescriptorArray::kDescriptorSize);
1482 Label if_notdone(this);
1483 Branch(Word32Equal(index, nof), if_not_found, &if_notdone);
1484 Bind(&if_notdone);
1485 { 1658 {
1659 static const int32_t kMaxLinear = 210;
1660 GotoIf(Int32GreaterThan(nof, Int32Constant(kMaxLinear)), if_bailout);
1661 }
1662 Node* descriptors = LoadMapDescriptors(map);
1663
1664 Variable var_descriptor(this, MachineRepresentation::kWord32);
1665 Label loop(this, &var_descriptor);
1666 var_descriptor.Bind(Int32Constant(0));
1667 Goto(&loop);
1668 Bind(&loop);
1669 {
1670 Node* index = var_descriptor.value();
1671 Node* offset = Int32Constant(DescriptorArray::ToKeyIndex(0));
1672 Node* factor = Int32Constant(DescriptorArray::kDescriptorSize);
1673 GotoIf(Word32Equal(index, nof), if_not_found);
1674
1486 Node* array_index = Int32Add(offset, Int32Mul(index, factor)); 1675 Node* array_index = Int32Add(offset, Int32Mul(index, factor));
1487 Node* current = LoadFixedArrayElement(descriptors, array_index); 1676 Node* current = LoadFixedArrayElement(descriptors, array_index);
1488 Label if_unequal(this); 1677 GotoIf(WordEqual(current, unique_name), if_found);
1489 Branch(WordEqual(current, name), if_found, &if_unequal);
1490 Bind(&if_unequal);
1491 1678
1492 var_descriptor.Bind(Int32Add(index, Int32Constant(1))); 1679 var_descriptor.Bind(Int32Add(index, Int32Constant(1)));
1493 Goto(&loop); 1680 Goto(&loop);
1494 } 1681 }
1495 } 1682 }
1683 Bind(&if_isslowmap);
1684 {
1685 Variable var_entry(this, MachineRepresentation::kWord32);
1686 Node* dictionary = LoadProperties(object);
1687
1688 NameDictionaryLookup<NameDictionary>(dictionary, unique_name, if_found,
1689 &var_entry, if_not_found);
1690 }
1691 Bind(&if_objectisspecial);
1692 {
1693 // Handle global object here and other special objects in runtime.
1694 GotoUnless(Word32Equal(instance_type, Int32Constant(JS_GLOBAL_OBJECT_TYPE)),
1695 if_bailout);
1696 Variable var_entry(this, MachineRepresentation::kWord32);
1697 Node* dictionary = LoadProperties(object);
1698
1699 NameDictionaryLookup<GlobalDictionary>(dictionary, unique_name, if_found,
1700 &var_entry, if_not_found);
1701 }
1496 } 1702 }
1497 1703
1498 void CodeStubAssembler::TryLookupElement(Node* object, Node* map, 1704 void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
1499 Node* instance_type, Node* index, 1705 Node* instance_type, Node* index,
1500 Label* if_found, Label* if_not_found, 1706 Label* if_found, Label* if_not_found,
1501 Label* call_runtime) { 1707 Label* if_bailout) {
1502 { 1708 // Handle special objects in runtime.
1503 Label if_objectissimple(this); 1709 GotoIf(Int32LessThanOrEqual(instance_type,
1504 Branch(Int32LessThanOrEqual(instance_type, 1710 Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)),
1505 Int32Constant(LAST_CUSTOM_ELEMENTS_RECEIVER)), 1711 if_bailout);
1506 call_runtime, &if_objectissimple);
1507 Bind(&if_objectissimple);
1508 }
1509 1712
1510 Node* bit_field2 = LoadMapBitField2(map); 1713 Node* bit_field2 = LoadMapBitField2(map);
1511 Node* elements_kind = BitFieldDecode<Map::ElementsKindBits>(bit_field2); 1714 Node* elements_kind = BitFieldDecode<Map::ElementsKindBits>(bit_field2);
1512 1715
1513 // TODO(verwaest): Support other elements kinds as well. 1716 // TODO(verwaest): Support other elements kinds as well.
1514 Label if_isobjectorsmi(this); 1717 Label if_isobjectorsmi(this), if_isdouble(this), if_isdictionary(this),
1515 Branch( 1718 if_isfaststringwrapper(this), if_isslowstringwrapper(this);
1516 Int32LessThanOrEqual(elements_kind, Int32Constant(FAST_HOLEY_ELEMENTS)), 1719 // clang-format off
1517 &if_isobjectorsmi, call_runtime); 1720 int32_t values[] = {
1721 // Handled by {if_isobjectorsmi}.
1722 FAST_SMI_ELEMENTS, FAST_HOLEY_SMI_ELEMENTS, FAST_ELEMENTS,
1723 FAST_HOLEY_ELEMENTS,
1724 // Handled by {if_isdouble}.
1725 FAST_DOUBLE_ELEMENTS, FAST_HOLEY_DOUBLE_ELEMENTS,
1726 // Handled by {if_isdictionary}.
1727 DICTIONARY_ELEMENTS,
1728 // Handled by {if_isfaststringwrapper}.
1729 FAST_STRING_WRAPPER_ELEMENTS,
1730 // Handled by {if_isslowstringwrapper}.
1731 SLOW_STRING_WRAPPER_ELEMENTS,
1732 // Handled by {if_not_found}.
1733 NO_ELEMENTS,
1734 };
1735 Label* labels[] = {
1736 &if_isobjectorsmi, &if_isobjectorsmi, &if_isobjectorsmi,
1737 &if_isobjectorsmi,
1738 &if_isdouble, &if_isdouble,
1739 &if_isdictionary,
1740 &if_isfaststringwrapper,
1741 &if_isslowstringwrapper,
1742 if_not_found,
1743 };
1744 // clang-format on
1745 STATIC_ASSERT(arraysize(values) == arraysize(labels));
1746 Switch(elements_kind, if_bailout, values, labels, arraysize(values));
1747
1518 Bind(&if_isobjectorsmi); 1748 Bind(&if_isobjectorsmi);
1519 { 1749 {
1520 Node* elements = LoadElements(object); 1750 Node* elements = LoadElements(object);
1521 Node* length = LoadFixedArrayBaseLength(elements); 1751 Node* length = LoadFixedArrayBaseLength(elements);
1522 1752
1523 Label if_iskeyinrange(this); 1753 GotoIf(Int32GreaterThanOrEqual(index, SmiToWord32(length)), if_not_found);
1524 Branch(Int32LessThan(index, SmiToWord32(length)), &if_iskeyinrange, 1754
1525 if_not_found);
1526
1527 Bind(&if_iskeyinrange);
1528 Node* element = LoadFixedArrayElement(elements, index); 1755 Node* element = LoadFixedArrayElement(elements, index);
1529 Node* the_hole = LoadRoot(Heap::kTheHoleValueRootIndex); 1756 Node* the_hole = TheHoleConstant();
1530 Branch(WordEqual(element, the_hole), if_not_found, if_found); 1757 Branch(WordEqual(element, the_hole), if_not_found, if_found);
1531 } 1758 }
1532 } 1759 Bind(&if_isdouble);
1760 {
1761 Node* elements = LoadElements(object);
1762 Node* length = LoadFixedArrayBaseLength(elements);
1763
1764 GotoIf(Int32GreaterThanOrEqual(index, SmiToWord32(length)), if_not_found);
1765
1766 if (kPointerSize == kDoubleSize) {
1767 Node* element =
1768 LoadFixedDoubleArrayElement(elements, index, MachineType::Uint64());
1769 Node* the_hole = Int64Constant(kHoleNanInt64);
1770 Branch(Word64Equal(element, the_hole), if_not_found, if_found);
1771 } else {
1772 Node* element_upper =
1773 LoadFixedDoubleArrayElement(elements, index, MachineType::Uint32(),
1774 kIeeeDoubleExponentWordOffset);
1775 Branch(Word32Equal(element_upper, Int32Constant(kHoleNanUpper32)),
1776 if_not_found, if_found);
1777 }
1778 }
1779 Bind(&if_isdictionary);
1780 {
1781 Variable var_entry(this, MachineRepresentation::kWord32);
1782 Node* elements = LoadElements(object);
1783 NumberDictionaryLookup<SeededNumberDictionary>(elements, index, if_found,
1784 &var_entry, if_not_found);
1785 }
1786 Bind(&if_isfaststringwrapper);
1787 {
1788 Assert(Word32Equal(LoadInstanceType(object), Int32Constant(JS_VALUE_TYPE)));
1789 Node* string = LoadJSValueValue(object);
1790 Assert(Int32LessThan(LoadInstanceType(string),
1791 Int32Constant(FIRST_NONSTRING_TYPE)));
1792 Node* length = LoadStringLength(string);
1793 GotoIf(Int32LessThan(index, SmiToWord32(length)), if_found);
1794 Goto(&if_isobjectorsmi);
1795 }
1796 Bind(&if_isslowstringwrapper);
1797 {
1798 Assert(Word32Equal(LoadInstanceType(object), Int32Constant(JS_VALUE_TYPE)));
1799 Node* string = LoadJSValueValue(object);
1800 Assert(Int32LessThan(LoadInstanceType(string),
1801 Int32Constant(FIRST_NONSTRING_TYPE)));
1802 Node* length = LoadStringLength(string);
1803 GotoIf(Int32LessThan(index, SmiToWord32(length)), if_found);
1804 Goto(&if_isdictionary);
1805 }
1806 }
1807
1808 // Instantiate template methods to workaround GCC compilation issue.
1809 template void CodeStubAssembler::NumberDictionaryLookup<SeededNumberDictionary>(
1810 Node*, Node*, Label*, Variable*, Label*);
1811 template void CodeStubAssembler::NumberDictionaryLookup<
1812 UnseededNumberDictionary>(Node*, Node*, Label*, Variable*, Label*);
1533 1813
1534 Node* CodeStubAssembler::OrdinaryHasInstance(Node* context, Node* callable, 1814 Node* CodeStubAssembler::OrdinaryHasInstance(Node* context, Node* callable,
1535 Node* object) { 1815 Node* object) {
1536 Variable var_result(this, MachineRepresentation::kTagged); 1816 Variable var_result(this, MachineRepresentation::kTagged);
1537 Label return_false(this), return_true(this), 1817 Label return_false(this), return_true(this),
1538 return_runtime(this, Label::kDeferred), return_result(this); 1818 return_runtime(this, Label::kDeferred), return_result(this);
1539 1819
1540 // Goto runtime if {object} is a Smi. 1820 // Goto runtime if {object} is a Smi.
1541 GotoIf(WordIsSmi(object), &return_runtime); 1821 GotoIf(WordIsSmi(object), &return_runtime);
1542 1822
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 } 1978 }
1699 return IntPtrAdd( 1979 return IntPtrAdd(
1700 IntPtrConstant(base_size), 1980 IntPtrConstant(base_size),
1701 (element_size_shift >= 0) 1981 (element_size_shift >= 0)
1702 ? WordShl(index_node, IntPtrConstant(element_size_shift)) 1982 ? WordShl(index_node, IntPtrConstant(element_size_shift))
1703 : WordShr(index_node, IntPtrConstant(-element_size_shift))); 1983 : WordShr(index_node, IntPtrConstant(-element_size_shift)));
1704 } 1984 }
1705 1985
1706 } // namespace internal 1986 } // namespace internal
1707 } // namespace v8 1987 } // namespace v8
OLDNEW
« no previous file with comments | « src/code-stub-assembler.h ('k') | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698