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

Side by Side Diff: src/x64/lithium-codegen-x64.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/ia32/lithium-ia32.cc ('k') | src/x64/lithium-x64.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 5186 matching lines...) Expand 10 before | Expand all | Expand 10 after
5197 FastCloneShallowArrayStub::Mode mode = 5197 FastCloneShallowArrayStub::Mode mode =
5198 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS 5198 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS
5199 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS 5199 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
5200 : FastCloneShallowArrayStub::CLONE_ELEMENTS; 5200 : FastCloneShallowArrayStub::CLONE_ELEMENTS;
5201 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); 5201 FastCloneShallowArrayStub stub(mode, allocation_site_mode, length);
5202 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr); 5202 CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr);
5203 } 5203 }
5204 } 5204 }
5205 5205
5206 5206
5207 void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
5208 Register result,
5209 Register source,
5210 int* offset,
5211 AllocationSiteMode mode) {
5212 ASSERT(!source.is(rcx));
5213 ASSERT(!result.is(rcx));
5214
5215 bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE &&
5216 object->map()->CanTrackAllocationSite();
5217
5218 // Only elements backing stores for non-COW arrays need to be copied.
5219 Handle<FixedArrayBase> elements(object->elements());
5220 bool has_elements = elements->length() > 0 &&
5221 elements->map() != isolate()->heap()->fixed_cow_array_map();
5222
5223 // Increase the offset so that subsequent objects end up right after
5224 // this object and its backing store.
5225 int object_offset = *offset;
5226 int object_size = object->map()->instance_size();
5227 int elements_size = has_elements ? elements->Size() : 0;
5228 int elements_offset = *offset + object_size;
5229 if (create_allocation_site_info) {
5230 elements_offset += AllocationSiteInfo::kSize;
5231 *offset += AllocationSiteInfo::kSize;
5232 }
5233
5234 *offset += object_size + elements_size;
5235
5236 // Copy object header.
5237 ASSERT(object->properties()->length() == 0);
5238 int inobject_properties = object->map()->inobject_properties();
5239 int header_size = object_size - inobject_properties * kPointerSize;
5240 for (int i = 0; i < header_size; i += kPointerSize) {
5241 if (has_elements && i == JSObject::kElementsOffset) {
5242 __ lea(rcx, Operand(result, elements_offset));
5243 } else {
5244 __ movq(rcx, FieldOperand(source, i));
5245 }
5246 __ movq(FieldOperand(result, object_offset + i), rcx);
5247 }
5248
5249 // Copy in-object properties.
5250 for (int i = 0; i < inobject_properties; i++) {
5251 int total_offset = object_offset + object->GetInObjectPropertyOffset(i);
5252 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i),
5253 isolate());
5254 if (value->IsJSObject()) {
5255 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
5256 __ lea(rcx, Operand(result, *offset));
5257 __ movq(FieldOperand(result, total_offset), rcx);
5258 __ LoadHeapObject(source, value_object);
5259 EmitDeepCopy(value_object, result, source, offset,
5260 DONT_TRACK_ALLOCATION_SITE);
5261 } else if (value->IsHeapObject()) {
5262 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value));
5263 __ movq(FieldOperand(result, total_offset), rcx);
5264 } else {
5265 __ movq(rcx, value, RelocInfo::NONE64);
5266 __ movq(FieldOperand(result, total_offset), rcx);
5267 }
5268 }
5269
5270 // Build Allocation Site Info if desired
5271 if (create_allocation_site_info) {
5272 __ LoadRoot(kScratchRegister, Heap::kAllocationSiteInfoMapRootIndex);
5273 __ movq(FieldOperand(result, object_size), kScratchRegister);
5274 __ movq(FieldOperand(result, object_size + kPointerSize), source);
5275 }
5276
5277 if (has_elements) {
5278 // Copy elements backing store header.
5279 __ LoadHeapObject(source, elements);
5280 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) {
5281 __ movq(rcx, FieldOperand(source, i));
5282 __ movq(FieldOperand(result, elements_offset + i), rcx);
5283 }
5284
5285 // Copy elements backing store content.
5286 int elements_length = elements->length();
5287 if (elements->IsFixedDoubleArray()) {
5288 Handle<FixedDoubleArray> double_array =
5289 Handle<FixedDoubleArray>::cast(elements);
5290 for (int i = 0; i < elements_length; i++) {
5291 int64_t value = double_array->get_representation(i);
5292 int total_offset =
5293 elements_offset + FixedDoubleArray::OffsetOfElementAt(i);
5294 __ movq(rcx, value, RelocInfo::NONE64);
5295 __ movq(FieldOperand(result, total_offset), rcx);
5296 }
5297 } else if (elements->IsFixedArray()) {
5298 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
5299 for (int i = 0; i < elements_length; i++) {
5300 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i);
5301 Handle<Object> value(fast_elements->get(i), isolate());
5302 if (value->IsJSObject()) {
5303 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
5304 __ lea(rcx, Operand(result, *offset));
5305 __ movq(FieldOperand(result, total_offset), rcx);
5306 __ LoadHeapObject(source, value_object);
5307 EmitDeepCopy(value_object, result, source, offset,
5308 DONT_TRACK_ALLOCATION_SITE);
5309 } else if (value->IsHeapObject()) {
5310 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value));
5311 __ movq(FieldOperand(result, total_offset), rcx);
5312 } else {
5313 __ movq(rcx, value, RelocInfo::NONE64);
5314 __ movq(FieldOperand(result, total_offset), rcx);
5315 }
5316 }
5317 } else {
5318 UNREACHABLE();
5319 }
5320 }
5321 }
5322
5323
5324 void LCodeGen::DoFastLiteral(LFastLiteral* instr) {
5325 int size = instr->hydrogen()->total_size();
5326 ElementsKind boilerplate_elements_kind =
5327 instr->hydrogen()->boilerplate()->GetElementsKind();
5328
5329 // Deopt if the array literal boilerplate ElementsKind is of a type different
5330 // than the expected one. The check isn't necessary if the boilerplate has
5331 // already been converted to TERMINAL_FAST_ELEMENTS_KIND.
5332 if (CanTransitionToMoreGeneralFastElementsKind(
5333 boilerplate_elements_kind, true)) {
5334 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate());
5335 __ movq(rcx, FieldOperand(rbx, HeapObject::kMapOffset));
5336 // Load the map's "bit field 2".
5337 __ movb(rcx, FieldOperand(rcx, Map::kBitField2Offset));
5338 // Retrieve elements_kind from bit field 2.
5339 __ and_(rcx, Immediate(Map::kElementsKindMask));
5340 __ cmpb(rcx, Immediate(boilerplate_elements_kind <<
5341 Map::kElementsKindShift));
5342 DeoptimizeIf(not_equal, instr->environment());
5343 }
5344
5345 // Allocate all objects that are part of the literal in one big
5346 // allocation. This avoids multiple limit checks.
5347 Label allocated, runtime_allocate;
5348 __ Allocate(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT);
5349 __ jmp(&allocated);
5350
5351 __ bind(&runtime_allocate);
5352 __ Push(Smi::FromInt(size));
5353 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr);
5354
5355 __ bind(&allocated);
5356 int offset = 0;
5357 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate());
5358 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset,
5359 instr->hydrogen()->allocation_site_mode());
5360 ASSERT_EQ(size, offset);
5361 }
5362
5363
5364 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { 5207 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) {
5365 Handle<FixedArray> literals(instr->environment()->closure()->literals()); 5208 Handle<FixedArray> literals(instr->environment()->closure()->literals());
5366 Handle<FixedArray> constant_properties = 5209 Handle<FixedArray> constant_properties =
5367 instr->hydrogen()->constant_properties(); 5210 instr->hydrogen()->constant_properties();
5368 5211
5369 int flags = instr->hydrogen()->fast_elements() 5212 int flags = instr->hydrogen()->fast_elements()
5370 ? ObjectLiteral::kFastElements 5213 ? ObjectLiteral::kFastElements
5371 : ObjectLiteral::kNoFlags; 5214 : ObjectLiteral::kNoFlags;
5372 flags |= instr->hydrogen()->has_function() 5215 flags |= instr->hydrogen()->has_function()
5373 ? ObjectLiteral::kHasFunction 5216 ? ObjectLiteral::kHasFunction
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
5845 FixedArray::kHeaderSize - kPointerSize)); 5688 FixedArray::kHeaderSize - kPointerSize));
5846 __ bind(&done); 5689 __ bind(&done);
5847 } 5690 }
5848 5691
5849 5692
5850 #undef __ 5693 #undef __
5851 5694
5852 } } // namespace v8::internal 5695 } } // namespace v8::internal
5853 5696
5854 #endif // V8_TARGET_ARCH_X64 5697 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/x64/lithium-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698