OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/hydrogen.h" | 5 #include "src/hydrogen.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 9857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9868 Add<HStoreNamedField>(elements, | 9868 Add<HStoreNamedField>(elements, |
9869 HObjectAccess::ForExternalArrayExternalPointer(), | 9869 HObjectAccess::ForExternalArrayExternalPointer(), |
9870 typed_array_start); | 9870 typed_array_start); |
9871 | 9871 |
9872 return elements; | 9872 return elements; |
9873 } | 9873 } |
9874 | 9874 |
9875 | 9875 |
9876 HValue* HOptimizedGraphBuilder::BuildAllocateFixedTypedArray( | 9876 HValue* HOptimizedGraphBuilder::BuildAllocateFixedTypedArray( |
9877 ExternalArrayType array_type, size_t element_size, | 9877 ExternalArrayType array_type, size_t element_size, |
9878 ElementsKind fixed_elements_kind, | 9878 ElementsKind fixed_elements_kind, HValue* byte_length, HValue* length, |
9879 HValue* byte_length, HValue* length) { | 9879 bool initialize) { |
9880 STATIC_ASSERT( | 9880 STATIC_ASSERT( |
9881 (FixedTypedArrayBase::kHeaderSize & kObjectAlignmentMask) == 0); | 9881 (FixedTypedArrayBase::kHeaderSize & kObjectAlignmentMask) == 0); |
9882 HValue* total_size; | 9882 HValue* total_size; |
9883 | 9883 |
9884 // if fixed array's elements are not aligned to object's alignment, | 9884 // if fixed array's elements are not aligned to object's alignment, |
9885 // we need to align the whole array to object alignment. | 9885 // we need to align the whole array to object alignment. |
9886 if (element_size % kObjectAlignment != 0) { | 9886 if (element_size % kObjectAlignment != 0) { |
9887 total_size = BuildObjectSizeAlignment( | 9887 total_size = BuildObjectSizeAlignment( |
9888 byte_length, FixedTypedArrayBase::kHeaderSize); | 9888 byte_length, FixedTypedArrayBase::kHeaderSize); |
9889 } else { | 9889 } else { |
(...skipping 18 matching lines...) Expand all Loading... |
9908 #endif | 9908 #endif |
9909 | 9909 |
9910 AddStoreMapConstant(elements, fixed_typed_array_map); | 9910 AddStoreMapConstant(elements, fixed_typed_array_map); |
9911 | 9911 |
9912 Add<HStoreNamedField>(elements, | 9912 Add<HStoreNamedField>(elements, |
9913 HObjectAccess::ForFixedArrayLength(), | 9913 HObjectAccess::ForFixedArrayLength(), |
9914 length); | 9914 length); |
9915 | 9915 |
9916 HValue* filler = Add<HConstant>(static_cast<int32_t>(0)); | 9916 HValue* filler = Add<HConstant>(static_cast<int32_t>(0)); |
9917 | 9917 |
9918 { | 9918 if (initialize) { |
9919 LoopBuilder builder(this, context(), LoopBuilder::kPostIncrement); | 9919 LoopBuilder builder(this, context(), LoopBuilder::kPostIncrement); |
9920 | 9920 |
9921 HValue* key = builder.BeginBody( | 9921 HValue* key = builder.BeginBody( |
9922 Add<HConstant>(static_cast<int32_t>(0)), | 9922 Add<HConstant>(static_cast<int32_t>(0)), |
9923 length, Token::LT); | 9923 length, Token::LT); |
9924 Add<HStoreKeyed>(elements, key, filler, fixed_elements_kind); | 9924 Add<HStoreKeyed>(elements, key, filler, fixed_elements_kind); |
9925 | 9925 |
9926 builder.EndBody(); | 9926 builder.EndBody(); |
9927 } | 9927 } |
9928 return elements; | 9928 return elements; |
9929 } | 9929 } |
9930 | 9930 |
9931 | 9931 |
9932 void HOptimizedGraphBuilder::GenerateTypedArrayInitialize( | 9932 void HOptimizedGraphBuilder::GenerateTypedArrayInitialize( |
9933 CallRuntime* expr) { | 9933 CallRuntime* expr) { |
9934 ZoneList<Expression*>* arguments = expr->arguments(); | 9934 ZoneList<Expression*>* arguments = expr->arguments(); |
9935 | 9935 |
9936 static const int kObjectArg = 0; | 9936 static const int kObjectArg = 0; |
9937 static const int kArrayIdArg = 1; | 9937 static const int kArrayIdArg = 1; |
9938 static const int kBufferArg = 2; | 9938 static const int kBufferArg = 2; |
9939 static const int kByteOffsetArg = 3; | 9939 static const int kByteOffsetArg = 3; |
9940 static const int kByteLengthArg = 4; | 9940 static const int kByteLengthArg = 4; |
9941 static const int kArgsLength = 5; | 9941 static const int kInitializeArg = 5; |
| 9942 static const int kArgsLength = 6; |
9942 DCHECK(arguments->length() == kArgsLength); | 9943 DCHECK(arguments->length() == kArgsLength); |
9943 | 9944 |
9944 | 9945 |
9945 CHECK_ALIVE(VisitForValue(arguments->at(kObjectArg))); | 9946 CHECK_ALIVE(VisitForValue(arguments->at(kObjectArg))); |
9946 HValue* obj = Pop(); | 9947 HValue* obj = Pop(); |
9947 | 9948 |
9948 if (!arguments->at(kArrayIdArg)->IsLiteral()) { | 9949 if (!arguments->at(kArrayIdArg)->IsLiteral()) { |
9949 // This should never happen in real use, but can happen when fuzzing. | 9950 // This should never happen in real use, but can happen when fuzzing. |
9950 // Just bail out. | 9951 // Just bail out. |
9951 Bailout(kNeedSmiLiteral); | 9952 Bailout(kNeedSmiLiteral); |
(...skipping 28 matching lines...) Expand all Loading... |
9980 } else { | 9981 } else { |
9981 CHECK_ALIVE(VisitForValue(arguments->at(kByteOffsetArg))); | 9982 CHECK_ALIVE(VisitForValue(arguments->at(kByteOffsetArg))); |
9982 byte_offset = Pop(); | 9983 byte_offset = Pop(); |
9983 is_zero_byte_offset = false; | 9984 is_zero_byte_offset = false; |
9984 DCHECK(buffer != NULL); | 9985 DCHECK(buffer != NULL); |
9985 } | 9986 } |
9986 | 9987 |
9987 CHECK_ALIVE(VisitForValue(arguments->at(kByteLengthArg))); | 9988 CHECK_ALIVE(VisitForValue(arguments->at(kByteLengthArg))); |
9988 HValue* byte_length = Pop(); | 9989 HValue* byte_length = Pop(); |
9989 | 9990 |
| 9991 CHECK(arguments->at(kInitializeArg)->IsLiteral()); |
| 9992 bool initialize = static_cast<Literal*>(arguments->at(kInitializeArg)) |
| 9993 ->value() |
| 9994 ->BooleanValue(); |
| 9995 |
9990 NoObservableSideEffectsScope scope(this); | 9996 NoObservableSideEffectsScope scope(this); |
9991 IfBuilder byte_offset_smi(this); | 9997 IfBuilder byte_offset_smi(this); |
9992 | 9998 |
9993 if (!is_zero_byte_offset) { | 9999 if (!is_zero_byte_offset) { |
9994 byte_offset_smi.If<HIsSmiAndBranch>(byte_offset); | 10000 byte_offset_smi.If<HIsSmiAndBranch>(byte_offset); |
9995 byte_offset_smi.Then(); | 10001 byte_offset_smi.Then(); |
9996 } | 10002 } |
9997 | 10003 |
9998 ExternalArrayType array_type = | 10004 ExternalArrayType array_type = |
9999 kExternalInt8Array; // Bogus initialization. | 10005 kExternalInt8Array; // Bogus initialization. |
(...skipping 27 matching lines...) Expand all Loading... |
10027 | 10033 |
10028 HValue* elements; | 10034 HValue* elements; |
10029 if (buffer != NULL) { | 10035 if (buffer != NULL) { |
10030 elements = BuildAllocateExternalElements( | 10036 elements = BuildAllocateExternalElements( |
10031 array_type, is_zero_byte_offset, buffer, byte_offset, length); | 10037 array_type, is_zero_byte_offset, buffer, byte_offset, length); |
10032 Handle<Map> obj_map = TypedArrayMap( | 10038 Handle<Map> obj_map = TypedArrayMap( |
10033 isolate(), array_type, external_elements_kind); | 10039 isolate(), array_type, external_elements_kind); |
10034 AddStoreMapConstant(obj, obj_map); | 10040 AddStoreMapConstant(obj, obj_map); |
10035 } else { | 10041 } else { |
10036 DCHECK(is_zero_byte_offset); | 10042 DCHECK(is_zero_byte_offset); |
10037 elements = BuildAllocateFixedTypedArray( | 10043 elements = BuildAllocateFixedTypedArray(array_type, element_size, |
10038 array_type, element_size, fixed_elements_kind, | 10044 fixed_elements_kind, byte_length, |
10039 byte_length, length); | 10045 length, initialize); |
10040 } | 10046 } |
10041 Add<HStoreNamedField>( | 10047 Add<HStoreNamedField>( |
10042 obj, HObjectAccess::ForElementsPointer(), elements); | 10048 obj, HObjectAccess::ForElementsPointer(), elements); |
10043 } | 10049 } |
10044 | 10050 |
10045 if (!is_zero_byte_offset) { | 10051 if (!is_zero_byte_offset) { |
10046 byte_offset_smi.Else(); | 10052 byte_offset_smi.Else(); |
10047 { // byte_offset is not Smi. | 10053 { // byte_offset is not Smi. |
10048 Push(obj); | 10054 Push(obj); |
10049 CHECK_ALIVE(VisitForValue(arguments->at(kArrayIdArg))); | 10055 CHECK_ALIVE(VisitForValue(arguments->at(kArrayIdArg))); |
10050 Push(buffer); | 10056 Push(buffer); |
10051 Push(byte_offset); | 10057 Push(byte_offset); |
10052 Push(byte_length); | 10058 Push(byte_length); |
| 10059 CHECK_ALIVE(VisitForValue(arguments->at(kInitializeArg))); |
10053 PushArgumentsFromEnvironment(kArgsLength); | 10060 PushArgumentsFromEnvironment(kArgsLength); |
10054 Add<HCallRuntime>(expr->name(), expr->function(), kArgsLength); | 10061 Add<HCallRuntime>(expr->name(), expr->function(), kArgsLength); |
10055 } | 10062 } |
10056 } | 10063 } |
10057 byte_offset_smi.End(); | 10064 byte_offset_smi.End(); |
10058 } | 10065 } |
10059 | 10066 |
10060 | 10067 |
10061 void HOptimizedGraphBuilder::GenerateMaxSmi(CallRuntime* expr) { | 10068 void HOptimizedGraphBuilder::GenerateMaxSmi(CallRuntime* expr) { |
10062 DCHECK(expr->arguments()->length() == 0); | 10069 DCHECK(expr->arguments()->length() == 0); |
(...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13147 if (ShouldProduceTraceOutput()) { | 13154 if (ShouldProduceTraceOutput()) { |
13148 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 13155 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
13149 } | 13156 } |
13150 | 13157 |
13151 #ifdef DEBUG | 13158 #ifdef DEBUG |
13152 graph_->Verify(false); // No full verify. | 13159 graph_->Verify(false); // No full verify. |
13153 #endif | 13160 #endif |
13154 } | 13161 } |
13155 | 13162 |
13156 } } // namespace v8::internal | 13163 } } // namespace v8::internal |
OLD | NEW |