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

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, 9 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 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 5742 matching lines...) Expand 10 before | Expand all | Expand 10 after
5753 FastCloneShallowArrayStub::Mode mode = 5753 FastCloneShallowArrayStub::Mode mode =
5754 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS 5754 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS
5755 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS 5755 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
5756 : FastCloneShallowArrayStub::CLONE_ELEMENTS; 5756 : FastCloneShallowArrayStub::CLONE_ELEMENTS;
5757 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); 5757 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length);
5758 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); 5758 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr);
5759 } 5759 }
5760 } 5760 }
5761 5761
5762 5762
5763 void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
5764 Register result,
5765 Register source,
5766 int* offset,
5767 AllocationSiteMode mode) {
5768 ASSERT(!source.is(r2));
5769 ASSERT(!result.is(r2));
5770
5771 bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE &&
5772 object->map()->CanTrackAllocationSite();
5773
5774 // Only elements backing stores for non-COW arrays need to be copied.
5775 Handle<FixedArrayBase> elements(object->elements());
5776 bool has_elements = elements->length() > 0 &&
5777 elements->map() != isolate()->heap()->fixed_cow_array_map();
5778
5779 // Increase the offset so that subsequent objects end up right after
5780 // this object and its backing store.
5781 int object_offset = *offset;
5782 int object_size = object->map()->instance_size();
5783 int elements_size = has_elements ? elements->Size() : 0;
5784 int elements_offset = *offset + object_size;
5785 if (create_allocation_site_info) {
5786 elements_offset += AllocationSiteInfo::kSize;
5787 *offset += AllocationSiteInfo::kSize;
5788 }
5789
5790 *offset += object_size + elements_size;
5791
5792 // Copy object header.
5793 ASSERT(object->properties()->length() == 0);
5794 int inobject_properties = object->map()->inobject_properties();
5795 int header_size = object_size - inobject_properties * kPointerSize;
5796 for (int i = 0; i < header_size; i += kPointerSize) {
5797 if (has_elements && i == JSObject::kElementsOffset) {
5798 __ add(r2, result, Operand(elements_offset));
5799 } else {
5800 __ ldr(r2, FieldMemOperand(source, i));
5801 }
5802 __ str(r2, FieldMemOperand(result, object_offset + i));
5803 }
5804
5805 // Copy in-object properties.
5806 for (int i = 0; i < inobject_properties; i++) {
5807 int total_offset = object_offset + object->GetInObjectPropertyOffset(i);
5808 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i),
5809 isolate());
5810 if (value->IsJSObject()) {
5811 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
5812 __ add(r2, result, Operand(*offset));
5813 __ str(r2, FieldMemOperand(result, total_offset));
5814 __ LoadHeapObject(source, value_object);
5815 EmitDeepCopy(value_object, result, source, offset,
5816 DONT_TRACK_ALLOCATION_SITE);
5817 } else if (value->IsHeapObject()) {
5818 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value));
5819 __ str(r2, FieldMemOperand(result, total_offset));
5820 } else {
5821 __ mov(r2, Operand(value));
5822 __ str(r2, FieldMemOperand(result, total_offset));
5823 }
5824 }
5825
5826 // Build Allocation Site Info if desired
5827 if (create_allocation_site_info) {
5828 __ mov(r2, Operand(Handle<Map>(isolate()->heap()->
5829 allocation_site_info_map())));
5830 __ str(r2, FieldMemOperand(result, object_size));
5831 __ str(source, FieldMemOperand(result, object_size + kPointerSize));
5832 }
5833
5834 if (has_elements) {
5835 // Copy elements backing store header.
5836 __ LoadHeapObject(source, elements);
5837 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) {
5838 __ ldr(r2, FieldMemOperand(source, i));
5839 __ str(r2, FieldMemOperand(result, elements_offset + i));
5840 }
5841
5842 // Copy elements backing store content.
5843 int elements_length = has_elements ? elements->length() : 0;
5844 if (elements->IsFixedDoubleArray()) {
5845 Handle<FixedDoubleArray> double_array =
5846 Handle<FixedDoubleArray>::cast(elements);
5847 for (int i = 0; i < elements_length; i++) {
5848 int64_t value = double_array->get_representation(i);
5849 // We only support little endian mode...
5850 int32_t value_low = static_cast<int32_t>(value & 0xFFFFFFFF);
5851 int32_t value_high = static_cast<int32_t>(value >> 32);
5852 int total_offset =
5853 elements_offset + FixedDoubleArray::OffsetOfElementAt(i);
5854 __ mov(r2, Operand(value_low));
5855 __ str(r2, FieldMemOperand(result, total_offset));
5856 __ mov(r2, Operand(value_high));
5857 __ str(r2, FieldMemOperand(result, total_offset + 4));
5858 }
5859 } else if (elements->IsFixedArray()) {
5860 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
5861 for (int i = 0; i < elements_length; i++) {
5862 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i);
5863 Handle<Object> value(fast_elements->get(i), isolate());
5864 if (value->IsJSObject()) {
5865 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
5866 __ add(r2, result, Operand(*offset));
5867 __ str(r2, FieldMemOperand(result, total_offset));
5868 __ LoadHeapObject(source, value_object);
5869 EmitDeepCopy(value_object, result, source, offset,
5870 DONT_TRACK_ALLOCATION_SITE);
5871 } else if (value->IsHeapObject()) {
5872 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value));
5873 __ str(r2, FieldMemOperand(result, total_offset));
5874 } else {
5875 __ mov(r2, Operand(value));
5876 __ str(r2, FieldMemOperand(result, total_offset));
5877 }
5878 }
5879 } else {
5880 UNREACHABLE();
5881 }
5882 }
5883 }
5884
5885
5886 void LCodeGen::DoFastLiteral(LFastLiteral* instr) {
5887 int size = instr->hydrogen()->total_size();
5888 ElementsKind boilerplate_elements_kind =
5889 instr->hydrogen()->boilerplate()->GetElementsKind();
5890
5891 // Deopt if the array literal boilerplate ElementsKind is of a type different
5892 // than the expected one. The check isn't necessary if the boilerplate has
5893 // already been converted to TERMINAL_FAST_ELEMENTS_KIND.
5894 if (CanTransitionToMoreGeneralFastElementsKind(
5895 boilerplate_elements_kind, true)) {
5896 __ LoadHeapObject(r1, instr->hydrogen()->boilerplate());
5897 // Load map into r2.
5898 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset));
5899 // Load the map's "bit field 2".
5900 __ ldrb(r2, FieldMemOperand(r2, Map::kBitField2Offset));
5901 // Retrieve elements_kind from bit field 2.
5902 __ ubfx(r2, r2, Map::kElementsKindShift, Map::kElementsKindBitCount);
5903 __ cmp(r2, Operand(boilerplate_elements_kind));
5904 DeoptimizeIf(ne, instr->environment());
5905 }
5906
5907 // Allocate all objects that are part of the literal in one big
5908 // allocation. This avoids multiple limit checks.
5909 Label allocated, runtime_allocate;
5910 __ Allocate(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT);
5911 __ jmp(&allocated);
5912
5913 __ bind(&runtime_allocate);
5914 __ mov(r0, Operand(Smi::FromInt(size)));
5915 __ push(r0);
5916 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
5917
5918 __ bind(&allocated);
5919 int offset = 0;
5920 __ LoadHeapObject(r1, instr->hydrogen()->boilerplate());
5921 EmitDeepCopy(instr->hydrogen()->boilerplate(), r0, r1, &offset,
5922 instr->hydrogen()->allocation_site_mode());
5923 ASSERT_EQ(size, offset);
5924 }
5925
5926
5927 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { 5763 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) {
5928 Handle<FixedArray> literals(instr->environment()->closure()->literals()); 5764 Handle<FixedArray> literals(instr->environment()->closure()->literals());
5929 Handle<FixedArray> constant_properties = 5765 Handle<FixedArray> constant_properties =
5930 instr->hydrogen()->constant_properties(); 5766 instr->hydrogen()->constant_properties();
5931 5767
5932 // Set up the parameters to the stub/runtime call. 5768 // Set up the parameters to the stub/runtime call.
5933 __ LoadHeapObject(r3, literals); 5769 __ LoadHeapObject(r3, literals);
5934 __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); 5770 __ mov(r2, Operand(Smi::FromInt(instr->hydrogen()->literal_index())));
5935 __ mov(r1, Operand(constant_properties)); 5771 __ mov(r1, Operand(constant_properties));
5936 int flags = instr->hydrogen()->fast_elements() 5772 int flags = instr->hydrogen()->fast_elements()
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
6397 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); 6233 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize));
6398 __ ldr(result, FieldMemOperand(scratch, 6234 __ ldr(result, FieldMemOperand(scratch,
6399 FixedArray::kHeaderSize - kPointerSize)); 6235 FixedArray::kHeaderSize - kPointerSize));
6400 __ bind(&done); 6236 __ bind(&done);
6401 } 6237 }
6402 6238
6403 6239
6404 #undef __ 6240 #undef __
6405 6241
6406 } } // namespace v8::internal 6242 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-arm.cc ('k') | src/hydrogen.h » ('j') | src/hydrogen.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698