OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/js-typed-lowering.h" | 5 #include "src/compiler/js-typed-lowering.h" |
6 | 6 |
7 #include "src/ast/modules.h" | 7 #include "src/ast/modules.h" |
8 #include "src/builtins/builtins-utils.h" | 8 #include "src/builtins/builtins-utils.h" |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/compilation-dependencies.h" | 10 #include "src/compilation-dependencies.h" |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 } | 1247 } |
1248 return NoChange(); | 1248 return NoChange(); |
1249 } | 1249 } |
1250 | 1250 |
1251 Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { | 1251 Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { |
1252 Node* key = NodeProperties::GetValueInput(node, 1); | 1252 Node* key = NodeProperties::GetValueInput(node, 1); |
1253 Node* base = NodeProperties::GetValueInput(node, 0); | 1253 Node* base = NodeProperties::GetValueInput(node, 0); |
1254 Node* value = NodeProperties::GetValueInput(node, 2); | 1254 Node* value = NodeProperties::GetValueInput(node, 2); |
1255 Type* key_type = NodeProperties::GetType(key); | 1255 Type* key_type = NodeProperties::GetType(key); |
1256 Type* value_type = NodeProperties::GetType(value); | 1256 Type* value_type = NodeProperties::GetType(value); |
| 1257 |
| 1258 if (!value_type->Is(Type::PlainPrimitive())) return NoChange(); |
| 1259 |
1257 HeapObjectMatcher mbase(base); | 1260 HeapObjectMatcher mbase(base); |
1258 if (mbase.HasValue() && mbase.Value()->IsJSTypedArray()) { | 1261 if (mbase.HasValue() && mbase.Value()->IsJSTypedArray()) { |
1259 Handle<JSTypedArray> const array = | 1262 Handle<JSTypedArray> const array = |
1260 Handle<JSTypedArray>::cast(mbase.Value()); | 1263 Handle<JSTypedArray>::cast(mbase.Value()); |
1261 if (!array->GetBuffer()->was_neutered()) { | 1264 if (!array->GetBuffer()->was_neutered()) { |
1262 array->GetBuffer()->set_is_neuterable(false); | 1265 array->GetBuffer()->set_is_neuterable(false); |
1263 BufferAccess const access(array->type()); | 1266 BufferAccess const access(array->type()); |
1264 size_t const k = | 1267 size_t const k = |
1265 ElementSizeLog2Of(access.machine_type().representation()); | 1268 ElementSizeLog2Of(access.machine_type().representation()); |
1266 double const byte_length = array->byte_length()->Number(); | 1269 double const byte_length = array->byte_length()->Number(); |
1267 CHECK_LT(k, arraysize(shifted_int32_ranges_)); | 1270 CHECK_LT(k, arraysize(shifted_int32_ranges_)); |
1268 if (access.external_array_type() != kExternalUint8ClampedArray && | 1271 if (access.external_array_type() != kExternalUint8ClampedArray && |
1269 key_type->Is(shifted_int32_ranges_[k]) && byte_length <= kMaxInt) { | 1272 key_type->Is(shifted_int32_ranges_[k]) && byte_length <= kMaxInt) { |
1270 // JSLoadProperty(typed-array, int32) | 1273 // JSLoadProperty(typed-array, int32) |
1271 Handle<FixedTypedArrayBase> elements = | 1274 Handle<FixedTypedArrayBase> elements = |
1272 Handle<FixedTypedArrayBase>::cast(handle(array->elements())); | 1275 Handle<FixedTypedArrayBase>::cast(handle(array->elements())); |
1273 Node* buffer = jsgraph()->PointerConstant(elements->external_pointer()); | 1276 Node* buffer = jsgraph()->PointerConstant(elements->external_pointer()); |
1274 Node* length = jsgraph()->Constant(byte_length); | 1277 Node* length = jsgraph()->Constant(byte_length); |
1275 Node* context = NodeProperties::GetContextInput(node); | 1278 Node* context = NodeProperties::GetContextInput(node); |
1276 Node* effect = NodeProperties::GetEffectInput(node); | 1279 Node* effect = NodeProperties::GetEffectInput(node); |
1277 Node* control = NodeProperties::GetControlInput(node); | 1280 Node* control = NodeProperties::GetControlInput(node); |
1278 // Convert to a number first. | 1281 // Convert to a number first. |
1279 if (!value_type->Is(Type::Number())) { | 1282 if (!value_type->Is(Type::Number())) { |
1280 Reduction number_reduction = ReduceJSToNumberInput(value); | 1283 Reduction number_reduction = ReduceJSToNumberInput(value); |
1281 if (number_reduction.Changed()) { | 1284 if (number_reduction.Changed()) { |
1282 value = number_reduction.replacement(); | 1285 value = number_reduction.replacement(); |
1283 } else { | 1286 } else { |
1284 Node* frame_state_for_to_number = | 1287 value = |
1285 NodeProperties::FindFrameStateBefore(node); | 1288 graph()->NewNode(simplified()->PlainPrimitiveToNumber(), value); |
1286 value = effect = | |
1287 graph()->NewNode(javascript()->ToNumber(), value, context, | |
1288 frame_state_for_to_number, effect, control); | |
1289 control = graph()->NewNode(common()->IfSuccess(), value); | |
1290 } | 1289 } |
1291 } | 1290 } |
1292 // Check if we can avoid the bounds check. | 1291 // Check if we can avoid the bounds check. |
1293 if (key_type->Min() >= 0 && key_type->Max() < array->length_value()) { | 1292 if (key_type->Min() >= 0 && key_type->Max() < array->length_value()) { |
1294 RelaxControls(node); | 1293 RelaxControls(node); |
1295 node->ReplaceInput(0, buffer); | 1294 node->ReplaceInput(0, buffer); |
1296 DCHECK_EQ(key, node->InputAt(1)); | 1295 DCHECK_EQ(key, node->InputAt(1)); |
1297 node->ReplaceInput(2, value); | 1296 node->ReplaceInput(2, value); |
1298 node->ReplaceInput(3, effect); | 1297 node->ReplaceInput(3, effect); |
1299 node->ReplaceInput(4, control); | 1298 node->ReplaceInput(4, control); |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2317 } | 2316 } |
2318 | 2317 |
2319 | 2318 |
2320 CompilationDependencies* JSTypedLowering::dependencies() const { | 2319 CompilationDependencies* JSTypedLowering::dependencies() const { |
2321 return dependencies_; | 2320 return dependencies_; |
2322 } | 2321 } |
2323 | 2322 |
2324 } // namespace compiler | 2323 } // namespace compiler |
2325 } // namespace internal | 2324 } // namespace internal |
2326 } // namespace v8 | 2325 } // namespace v8 |
OLD | NEW |