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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor( | 688 HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor( |
689 JSArrayBuilder* array_builder) { | 689 JSArrayBuilder* array_builder) { |
690 // Smi check and range check on the input arg. | 690 // Smi check and range check on the input arg. |
691 HValue* constant_one = graph()->GetConstant1(); | 691 HValue* constant_one = graph()->GetConstant1(); |
692 HValue* constant_zero = graph()->GetConstant0(); | 692 HValue* constant_zero = graph()->GetConstant0(); |
693 | 693 |
694 HInstruction* elements = Add<HArgumentsElements>(false); | 694 HInstruction* elements = Add<HArgumentsElements>(false); |
695 HInstruction* argument = Add<HAccessArgumentsAt>( | 695 HInstruction* argument = Add<HAccessArgumentsAt>( |
696 elements, constant_one, constant_zero); | 696 elements, constant_one, constant_zero); |
697 | 697 |
698 HConstant* max_alloc_length = | 698 return BuildAllocateArrayFromLength(array_builder, argument); |
699 Add<HConstant>(JSObject::kInitialMaxFastElementArray); | |
700 const int initial_capacity = JSArray::kPreallocatedArrayElements; | |
701 HConstant* initial_capacity_node = Add<HConstant>(initial_capacity); | |
702 | |
703 HInstruction* checked_arg = Add<HBoundsCheck>(argument, max_alloc_length); | |
704 IfBuilder if_builder(this); | |
705 if_builder.If<HCompareNumericAndBranch>(checked_arg, constant_zero, | |
706 Token::EQ); | |
707 if_builder.Then(); | |
708 Push(initial_capacity_node); // capacity | |
709 Push(constant_zero); // length | |
710 if_builder.Else(); | |
711 Push(checked_arg); // capacity | |
712 Push(checked_arg); // length | |
713 if_builder.End(); | |
714 | |
715 // Figure out total size | |
716 HValue* length = Pop(); | |
717 HValue* capacity = Pop(); | |
718 return array_builder->AllocateArray(capacity, length, true); | |
719 } | 699 } |
720 | 700 |
721 | 701 |
722 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor( | 702 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor( |
723 JSArrayBuilder* array_builder, ElementsKind kind) { | 703 JSArrayBuilder* array_builder, ElementsKind kind) { |
724 // We need to fill with the hole if it's a smi array in the multi-argument | 704 // We need to fill with the hole if it's a smi array in the multi-argument |
725 // case because we might have to bail out while copying arguments into | 705 // case because we might have to bail out while copying arguments into |
726 // the array because they aren't compatible with a smi array. | 706 // the array because they aren't compatible with a smi array. |
727 // If it's a double array, no problem, and if it's fast then no | 707 // If it's a double array, no problem, and if it's fast then no |
728 // problem either because doubles are boxed. | 708 // problem either because doubles are boxed. |
729 HValue* length = GetArgumentsLength(); | 709 HValue* length = GetArgumentsLength(); |
730 bool fill_with_hole = IsFastSmiElementsKind(kind); | 710 JSArrayBuilder::FillMode fill_mode = IsFastSmiElementsKind(kind) |
711 ? JSArrayBuilder::FILL_WITH_HOLE | |
712 : JSArrayBuilder::DONT_FILL_WITH_HOLE; | |
Toon Verwaest
2013/11/11 13:59:28
Technically we don't need to fill this in with the
mvstanton
2013/11/13 14:12:52
I've added a TODO for this, it's a neat idea.
| |
731 HValue* new_object = array_builder->AllocateArray(length, | 713 HValue* new_object = array_builder->AllocateArray(length, |
732 length, | 714 length, |
733 fill_with_hole); | 715 fill_mode); |
734 HValue* elements = array_builder->GetElementsLocation(); | 716 HValue* elements = array_builder->GetElementsLocation(); |
735 ASSERT(elements != NULL); | 717 ASSERT(elements != NULL); |
736 | 718 |
737 // Now populate the elements correctly. | 719 // Now populate the elements correctly. |
738 LoopBuilder builder(this, | 720 LoopBuilder builder(this, |
739 context(), | 721 context(), |
740 LoopBuilder::kPostIncrement); | 722 LoopBuilder::kPostIncrement); |
741 HValue* start = graph()->GetConstant0(); | 723 HValue* start = graph()->GetConstant0(); |
742 HValue* key = builder.BeginBody(start, length, Token::LT); | 724 HValue* key = builder.BeginBody(start, length, Token::LT); |
743 HInstruction* argument_elements = Add<HArgumentsElements>(false); | 725 HInstruction* argument_elements = Add<HArgumentsElements>(false); |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 return js_function; | 1239 return js_function; |
1258 } | 1240 } |
1259 | 1241 |
1260 | 1242 |
1261 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { | 1243 Handle<Code> FastNewClosureStub::GenerateCode(Isolate* isolate) { |
1262 return DoGenerateCode(isolate, this); | 1244 return DoGenerateCode(isolate, this); |
1263 } | 1245 } |
1264 | 1246 |
1265 | 1247 |
1266 } } // namespace v8::internal | 1248 } } // namespace v8::internal |
OLD | NEW |