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

Side by Side Diff: src/arm/lithium-codegen-arm.cc

Issue 12880017: Build fast literals in hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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
« no previous file with comments | « src/arm/lithium-arm.cc ('k') | src/handles.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 5551 matching lines...) Expand 10 before | Expand all | Expand 10 after
5562 FastCloneShallowArrayStub::Mode mode = 5562 FastCloneShallowArrayStub::Mode mode =
5563 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS 5563 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS
5564 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS 5564 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
5565 : FastCloneShallowArrayStub::CLONE_ELEMENTS; 5565 : FastCloneShallowArrayStub::CLONE_ELEMENTS;
5566 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); 5566 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length);
5567 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); 5567 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr);
5568 } 5568 }
5569 } 5569 }
5570 5570
5571 5571
5572 void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
5573 Register result,
5574 Register source,
5575 int* offset,
5576 AllocationSiteMode mode) {
5577 ASSERT(!source.is(r2));
5578 ASSERT(!result.is(r2));
5579
5580 bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE &&
5581 object->map()->CanTrackAllocationSite();
5582
5583 // Only elements backing stores for non-COW arrays need to be copied.
5584 Handle<FixedArrayBase> elements(object->elements());
5585 bool has_elements = elements->length() > 0 &&
5586 elements->map() != isolate()->heap()->fixed_cow_array_map();
5587
5588 // Increase the offset so that subsequent objects end up right after
5589 // this object and its backing store.
5590 int object_offset = *offset;
5591 int object_size = object->map()->instance_size();
5592 int elements_size = has_elements ? elements->Size() : 0;
5593 int elements_offset = *offset + object_size;
5594 if (create_allocation_site_info) {
5595 elements_offset += AllocationSiteInfo::kSize;
5596 *offset += AllocationSiteInfo::kSize;
5597 }
5598
5599 *offset += object_size + elements_size;
5600
5601 // Copy object header.
5602 ASSERT(object->properties()->length() == 0);
5603 int inobject_properties = object->map()->inobject_properties();
5604 int header_size = object_size - inobject_properties * kPointerSize;
5605 for (int i = 0; i < header_size; i += kPointerSize) {
5606 if (has_elements && i == JSObject::kElementsOffset) {
5607 __ add(r2, result, Operand(elements_offset));
5608 } else {
5609 __ ldr(r2, FieldMemOperand(source, i));
5610 }
5611 __ str(r2, FieldMemOperand(result, object_offset + i));
5612 }
5613
5614 // Copy in-object properties.
5615 for (int i = 0; i < inobject_properties; i++) {
5616 int total_offset = object_offset + object->GetInObjectPropertyOffset(i);
5617 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i),
5618 isolate());
5619 if (value->IsJSObject()) {
5620 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
5621 __ add(r2, result, Operand(*offset));
5622 __ str(r2, FieldMemOperand(result, total_offset));
5623 __ LoadHeapObject(source, value_object);
5624 EmitDeepCopy(value_object, result, source, offset,
5625 DONT_TRACK_ALLOCATION_SITE);
5626 } else if (value->IsHeapObject()) {
5627 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value));
5628 __ str(r2, FieldMemOperand(result, total_offset));
5629 } else {
5630 __ mov(r2, Operand(value));
5631 __ str(r2, FieldMemOperand(result, total_offset));
5632 }
5633 }
5634
5635 // Build Allocation Site Info if desired
5636 if (create_allocation_site_info) {
5637 __ mov(r2, Operand(Handle<Map>(isolate()->heap()->
5638 allocation_site_info_map())));
5639 __ str(r2, FieldMemOperand(result, object_size));
5640 __ str(source, FieldMemOperand(result, object_size + kPointerSize));
5641 }
5642
5643 if (has_elements) {
5644 // Copy elements backing store header.
5645 __ LoadHeapObject(source, elements);
5646 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) {
5647 __ ldr(r2, FieldMemOperand(source, i));
5648 __ str(r2, FieldMemOperand(result, elements_offset + i));
5649 }
5650
5651 // Copy elements backing store content.
5652 int elements_length = has_elements ? elements->length() : 0;
5653 if (elements->IsFixedDoubleArray()) {
5654 Handle<FixedDoubleArray> double_array =
5655 Handle<FixedDoubleArray>::cast(elements);
5656 for (int i = 0; i < elements_length; i++) {
5657 int64_t value = double_array->get_representation(i);
5658 // We only support little endian mode...
5659 int32_t value_low = static_cast<int32_t>(value & 0xFFFFFFFF);
5660 int32_t value_high = static_cast<int32_t>(value >> 32);
5661 int total_offset =
5662 elements_offset + FixedDoubleArray::OffsetOfElementAt(i);
5663 __ mov(r2, Operand(value_low));
5664 __ str(r2, FieldMemOperand(result, total_offset));
5665 __ mov(r2, Operand(value_high));
5666 __ str(r2, FieldMemOperand(result, total_offset + 4));
5667 }
5668 } else if (elements->IsFixedArray()) {
5669 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
5670 for (int i = 0; i < elements_length; i++) {
5671 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i);
5672 Handle<Object> value(fast_elements->get(i), isolate());
5673 if (value->IsJSObject()) {
5674 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
5675 __ add(r2, result, Operand(*offset));
5676 __ str(r2, FieldMemOperand(result, total_offset));
5677 __ LoadHeapObject(source, value_object);
5678 EmitDeepCopy(value_object, result, source, offset,
5679 DONT_TRACK_ALLOCATION_SITE);
5680 } else if (value->IsHeapObject()) {
5681 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value));
5682 __ str(r2, FieldMemOperand(result, total_offset));
5683 } else {
5684 __ mov(r2, Operand(value));
5685 __ str(r2, FieldMemOperand(result, total_offset));
5686 }
5687 }
5688 } else {
5689 UNREACHABLE();
5690 }
5691 }
5692 }
5693
5694
5695 void LCodeGen::DoFastLiteral(LFastLiteral* instr) {
5696 int size = instr->hydrogen()->total_size();
5697 ElementsKind boilerplate_elements_kind =
5698 instr->hydrogen()->boilerplate()->GetElementsKind();
5699
5700 // Deopt if the array literal boilerplate ElementsKind is of a type different
5701 // than the expected one. The check isn't necessary if the boilerplate has
5702 // already been converted to TERMINAL_FAST_ELEMENTS_KIND.
5703 if (CanTransitionToMoreGeneralFastElementsKind(
5704 boilerplate_elements_kind, true)) {
5705 __ LoadHeapObject(r1, instr->hydrogen()->boilerplate());
5706 // Load map into r2.
5707 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset));
5708 // Load the map's "bit field 2".
5709 __ ldrb(r2, FieldMemOperand(r2, Map::kBitField2Offset));
5710 // Retrieve elements_kind from bit field 2.
5711 __ ubfx(r2, r2, Map::kElementsKindShift, Map::kElementsKindBitCount);
5712 __ cmp(r2, Operand(boilerplate_elements_kind));
5713 DeoptimizeIf(ne, instr->environment());
5714 }
5715
5716 // Allocate all objects that are part of the literal in one big
5717 // allocation. This avoids multiple limit checks.
5718 Label allocated, runtime_allocate;
5719 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT);
5720 __ jmp(&allocated);
5721
5722 __ bind(&runtime_allocate);
5723 __ mov(r0, Operand(Smi::FromInt(size)));
5724 __ push(r0);
5725 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
5726
5727 __ bind(&allocated);
5728 int offset = 0;
5729 __ LoadHeapObject(r1, instr->hydrogen()->boilerplate());
5730 EmitDeepCopy(instr->hydrogen()->boilerplate(), r0, r1, &offset,
5731 instr->hydrogen()->allocation_site_mode());
5732 ASSERT_EQ(size, offset);
5733 }
5734
5735
5736 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { 5572 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) {
5737 Handle<FixedArray> literals(instr->environment()->closure()->literals()); 5573 Handle<FixedArray> literals(instr->environment()->closure()->literals());
5738 Handle<FixedArray> constant_properties = 5574 Handle<FixedArray> constant_properties =
5739 instr->hydrogen()->constant_properties(); 5575 instr->hydrogen()->constant_properties();
5740 5576
5741 // Set up the parameters to the stub/runtime call. 5577 // Set up the parameters to the stub/runtime call.
5742 __ LoadHeapObject(r3, literals); 5578 __ LoadHeapObject(r3, literals);
5743 __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); 5579 __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
5744 __ mov(r1, Operand(constant_properties)); 5580 __ mov(r1, Operand(constant_properties));
5745 int flags = instr->hydrogen()->fast_elements() 5581 int flags = instr->hydrogen()->fast_elements()
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
6206 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); 6042 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize));
6207 __ ldr(result, FieldMemOperand(scratch, 6043 __ ldr(result, FieldMemOperand(scratch,
6208 FixedArray::kHeaderSize - kPointerSize)); 6044 FixedArray::kHeaderSize - kPointerSize));
6209 __ bind(&done); 6045 __ bind(&done);
6210 } 6046 }
6211 6047
6212 6048
6213 #undef __ 6049 #undef __
6214 6050
6215 } } // namespace v8::internal 6051 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-arm.cc ('k') | src/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698