OLD | NEW |
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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor( | 687 HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor( |
688 JSArrayBuilder* array_builder) { | 688 JSArrayBuilder* array_builder) { |
689 // Smi check and range check on the input arg. | 689 // Smi check and range check on the input arg. |
690 HValue* constant_one = graph()->GetConstant1(); | 690 HValue* constant_one = graph()->GetConstant1(); |
691 HValue* constant_zero = graph()->GetConstant0(); | 691 HValue* constant_zero = graph()->GetConstant0(); |
692 | 692 |
693 HInstruction* elements = Add<HArgumentsElements>(false); | 693 HInstruction* elements = Add<HArgumentsElements>(false); |
694 HInstruction* argument = Add<HAccessArgumentsAt>( | 694 HInstruction* argument = Add<HAccessArgumentsAt>( |
695 elements, constant_one, constant_zero); | 695 elements, constant_one, constant_zero); |
696 | 696 |
697 HConstant* max_alloc_length = | 697 return BuildAllocateArrayFromLength(array_builder, argument); |
698 Add<HConstant>(JSObject::kInitialMaxFastElementArray); | |
699 const int initial_capacity = JSArray::kPreallocatedArrayElements; | |
700 HConstant* initial_capacity_node = Add<HConstant>(initial_capacity); | |
701 | |
702 HInstruction* checked_arg = Add<HBoundsCheck>(argument, max_alloc_length); | |
703 IfBuilder if_builder(this); | |
704 if_builder.If<HCompareNumericAndBranch>(checked_arg, constant_zero, | |
705 Token::EQ); | |
706 if_builder.Then(); | |
707 Push(initial_capacity_node); // capacity | |
708 Push(constant_zero); // length | |
709 if_builder.Else(); | |
710 Push(checked_arg); // capacity | |
711 Push(checked_arg); // length | |
712 if_builder.End(); | |
713 | |
714 // Figure out total size | |
715 HValue* length = Pop(); | |
716 HValue* capacity = Pop(); | |
717 return array_builder->AllocateArray(capacity, length, true); | |
718 } | 698 } |
719 | 699 |
720 | 700 |
721 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor( | 701 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor( |
722 JSArrayBuilder* array_builder, ElementsKind kind) { | 702 JSArrayBuilder* array_builder, ElementsKind kind) { |
723 // We need to fill with the hole if it's a smi array in the multi-argument | 703 // We need to fill with the hole if it's a smi array in the multi-argument |
724 // case because we might have to bail out while copying arguments into | 704 // case because we might have to bail out while copying arguments into |
725 // the array because they aren't compatible with a smi array. | 705 // the array because they aren't compatible with a smi array. |
726 // If it's a double array, no problem, and if it's fast then no | 706 // If it's a double array, no problem, and if it's fast then no |
727 // problem either because doubles are boxed. | 707 // problem either because doubles are boxed. |
| 708 // |
| 709 // TODO(mvstanton): consider an instruction to memset fill the array |
| 710 // with zero in this case instead. |
728 HValue* length = GetArgumentsLength(); | 711 HValue* length = GetArgumentsLength(); |
729 bool fill_with_hole = IsFastSmiElementsKind(kind); | 712 JSArrayBuilder::FillMode fill_mode = IsFastSmiElementsKind(kind) |
| 713 ? JSArrayBuilder::FILL_WITH_HOLE |
| 714 : JSArrayBuilder::DONT_FILL_WITH_HOLE; |
730 HValue* new_object = array_builder->AllocateArray(length, | 715 HValue* new_object = array_builder->AllocateArray(length, |
731 length, | 716 length, |
732 fill_with_hole); | 717 fill_mode); |
733 HValue* elements = array_builder->GetElementsLocation(); | 718 HValue* elements = array_builder->GetElementsLocation(); |
734 ASSERT(elements != NULL); | 719 ASSERT(elements != NULL); |
735 | 720 |
736 // Now populate the elements correctly. | 721 // Now populate the elements correctly. |
737 LoopBuilder builder(this, | 722 LoopBuilder builder(this, |
738 context(), | 723 context(), |
739 LoopBuilder::kPostIncrement); | 724 LoopBuilder::kPostIncrement); |
740 HValue* start = graph()->GetConstant0(); | 725 HValue* start = graph()->GetConstant0(); |
741 HValue* key = builder.BeginBody(start, length, Token::LT); | 726 HValue* key = builder.BeginBody(start, length, Token::LT); |
742 HInstruction* argument_elements = Add<HArgumentsElements>(false); | 727 HInstruction* argument_elements = Add<HArgumentsElements>(false); |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 return js_function; | 1271 return js_function; |
1287 } | 1272 } |
1288 | 1273 |
1289 | 1274 |
1290 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { | 1275 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { |
1291 return DoGenerateCode(isolate, this); | 1276 return DoGenerateCode(isolate, this); |
1292 } | 1277 } |
1293 | 1278 |
1294 | 1279 |
1295 } } // namespace v8::internal | 1280 } } // namespace v8::internal |
OLD | NEW |