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

Side by Side Diff: src/ia32/full-codegen-ia32.cc

Issue 8258015: Support array literals with FAST_DOUBLE_ELEMENTS ElementsKind. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: remove regressions Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 context()->Plug(eax); 1441 context()->Plug(eax);
1442 } 1442 }
1443 } 1443 }
1444 1444
1445 1445
1446 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { 1446 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1447 Comment cmnt(masm_, "[ ArrayLiteral"); 1447 Comment cmnt(masm_, "[ ArrayLiteral");
1448 1448
1449 ZoneList<Expression*>* subexprs = expr->values(); 1449 ZoneList<Expression*>* subexprs = expr->values();
1450 int length = subexprs->length(); 1450 int length = subexprs->length();
1451 Handle<FixedArray> constant_elements = expr->constant_elements();
1452 ASSERT_EQ(2, constant_elements->length());
1453 ElementsKind constant_elements_kind =
1454 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value());
1455 Handle<FixedArrayBase> constant_elements_values(
1456 FixedArrayBase::cast(constant_elements->get(1)));
1451 1457
1452 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); 1458 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1453 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); 1459 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset));
1454 __ push(Immediate(Smi::FromInt(expr->literal_index()))); 1460 __ push(Immediate(Smi::FromInt(expr->literal_index())));
1455 __ push(Immediate(expr->constant_elements())); 1461 __ push(Immediate(constant_elements));
1456 if (expr->constant_elements()->map() == 1462 if (constant_elements_values->map() ==
1457 isolate()->heap()->fixed_cow_array_map()) { 1463 isolate()->heap()->fixed_cow_array_map()) {
1458 ASSERT(expr->depth() == 1); 1464 ASSERT(expr->depth() == 1);
1459 FastCloneShallowArrayStub stub( 1465 FastCloneShallowArrayStub stub(
1460 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); 1466 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length);
1461 __ CallStub(&stub); 1467 __ CallStub(&stub);
1462 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); 1468 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1);
1463 } else if (expr->depth() > 1) { 1469 } else if (expr->depth() > 1) {
1464 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); 1470 __ CallRuntime(Runtime::kCreateArrayLiteral, 3);
1465 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { 1471 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) {
1466 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); 1472 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3);
1467 } else { 1473 } else {
1468 FastCloneShallowArrayStub stub( 1474 ASSERT(constant_elements_kind == FAST_ELEMENTS ||
1469 FastCloneShallowArrayStub::CLONE_ELEMENTS, length); 1475 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS ||
1476 FLAG_smi_only_arrays);
1477 FastCloneShallowArrayStub::Mode mode =
1478 constant_elements_kind == FAST_DOUBLE_ELEMENTS
1479 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
1480 : FastCloneShallowArrayStub::CLONE_ELEMENTS;
1481 FastCloneShallowArrayStub stub(mode, length);
1470 __ CallStub(&stub); 1482 __ CallStub(&stub);
1471 } 1483 }
1472 1484
1473 bool result_saved = false; // Is the result saved to the stack? 1485 bool result_saved = false; // Is the result saved to the stack?
1474 1486
1475 // Emit code to evaluate all the non-constant subexpressions and to store 1487 // Emit code to evaluate all the non-constant subexpressions and to store
1476 // them into the newly cloned array. 1488 // them into the newly cloned array.
1477 for (int i = 0; i < length; i++) { 1489 for (int i = 0; i < length; i++) {
1478 Expression* subexpr = subexprs->at(i); 1490 Expression* subexpr = subexprs->at(i);
1479 // If the subexpression is a literal or a simple materialized literal it 1491 // If the subexpression is a literal or a simple materialized literal it
1480 // is already set in the cloned array. 1492 // is already set in the cloned array.
1481 if (subexpr->AsLiteral() != NULL || 1493 if (subexpr->AsLiteral() != NULL ||
1482 CompileTimeValue::IsCompileTimeValue(subexpr)) { 1494 CompileTimeValue::IsCompileTimeValue(subexpr)) {
1483 continue; 1495 continue;
1484 } 1496 }
1485 1497
1486 if (!result_saved) { 1498 if (!result_saved) {
1487 __ push(eax); 1499 __ push(eax);
1488 result_saved = true; 1500 result_saved = true;
1489 increment_stack_height(); 1501 increment_stack_height();
1490 } 1502 }
1491 VisitForAccumulatorValue(subexpr); 1503 VisitForAccumulatorValue(subexpr);
1492 1504
1493 // Store the subexpression value in the array's elements. 1505 // Store the subexpression value in the array's elements.
1494 __ mov(ebx, Operand(esp, 0)); // Copy of array literal. 1506 __ mov(ebx, Operand(esp, 0)); // Copy of array literal.
1507 __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset));
1495 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); 1508 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset));
1496 int offset = FixedArray::kHeaderSize + (i * kPointerSize); 1509 int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1510
1511 Label element_done;
1512 Label double_elements;
1513 Label smi_element;
1514 Label slow_elements;
1515 Label fast_elements;
1516 __ CheckFastElements(edi, &double_elements);
1517
1518 // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS
1519 __ JumpIfSmi(result_register(), &smi_element);
1520 __ CheckFastSmiOnlyElements(edi, &fast_elements, Label::kNear);
1521
1522 // Store into the array literal requires a elements transition. Call into
1523 // the runtime.
1524 __ bind(&slow_elements);
1525 __ push(Operand(esp, 0)); // Copy of array literal.
1526 __ push(Immediate(Smi::FromInt(i)));
1527 __ push(result_register());
1528 __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes
1529 __ push(Immediate(Smi::FromInt(strict_mode_flag()))); // Strict mode.
1530 // Do tail-call to runtime routine.
1531 __ CallRuntime(Runtime::kSetProperty, 5);
1532 __ jmp(&element_done);
1533
1534 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS
1535 __ bind(&double_elements);
1536 __ mov(ecx, Immediate(Smi::FromInt(i)));
1537 __ StoreNumberToDoubleElements(result_register(),
1538 ebx,
1539 ecx,
1540 edx,
1541 xmm0,
1542 &slow_elements,
1543 false);
1544 __ jmp(&element_done);
1545
1546 // Array literal has ElementsKind of FAST_ELEMENTS and value is an object.
1547 __ bind(&fast_elements);
1497 __ mov(FieldOperand(ebx, offset), result_register()); 1548 __ mov(FieldOperand(ebx, offset), result_register());
1498
1499 Label no_map_change;
1500 __ JumpIfSmi(result_register(), &no_map_change);
1501 // Update the write barrier for the array store. 1549 // Update the write barrier for the array store.
1502 __ RecordWriteField(ebx, offset, result_register(), ecx, 1550 __ RecordWriteField(ebx, offset, result_register(), ecx,
1503 kDontSaveFPRegs, 1551 kDontSaveFPRegs,
1504 EMIT_REMEMBERED_SET, 1552 EMIT_REMEMBERED_SET,
1505 OMIT_SMI_CHECK); 1553 OMIT_SMI_CHECK);
1506 __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); 1554 __ jmp(&element_done);
1507 __ CheckFastSmiOnlyElements(edi, &no_map_change, Label::kNear); 1555
1508 __ push(Operand(esp, 0)); 1556 // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or
1509 __ CallRuntime(Runtime::kNonSmiElementStored, 1); 1557 // FAST_ELEMENTS, and value is Smi.
1510 __ bind(&no_map_change); 1558 __ bind(&smi_element);
1559 __ mov(FieldOperand(ebx, offset), result_register());
1560 // Fall through
1561
1562 __ bind(&element_done);
1511 1563
1512 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); 1564 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
1513 } 1565 }
1514 1566
1515 if (result_saved) { 1567 if (result_saved) {
1516 context()->PlugTOS(); 1568 context()->PlugTOS();
1517 } else { 1569 } else {
1518 context()->Plug(eax); 1570 context()->Plug(eax);
1519 } 1571 }
1520 } 1572 }
(...skipping 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after
4335 *context_length = 0; 4387 *context_length = 0;
4336 return previous_; 4388 return previous_;
4337 } 4389 }
4338 4390
4339 4391
4340 #undef __ 4392 #undef __
4341 4393
4342 } } // namespace v8::internal 4394 } } // namespace v8::internal
4343 4395
4344 #endif // V8_TARGET_ARCH_IA32 4396 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698