From: bmeurer@chromium.org Date: Fri, 10 Oct 2014 08:10:29 +0000 (+0000) Subject: [turbofan] Fix typed lowering of typed array loads/stores. X-Git-Tag: upstream/4.7.83~6445 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb37b6c54eb90bab459c140c9965c89b6196d1f4;p=platform%2Fupstream%2Fv8.git [turbofan] Fix typed lowering of typed array loads/stores. R=jarin@chromium.org Review URL: https://codereview.chromium.org/646483003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24514 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc index 05e8ede..557b027 100644 --- a/src/compiler/js-typed-lowering.cc +++ b/src/compiler/js-typed-lowering.cc @@ -541,21 +541,24 @@ Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) { Handle::cast(base_type->AsConstant()->Value()); if (IsExternalArrayElementsKind(array->map()->elements_kind())) { ExternalArrayType type = array->type(); - uint32_t length; - CHECK(array->length()->ToUint32(&length)); - Node* elements = graph()->NewNode( - simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, - graph()->start()); - Node* pointer = graph()->NewNode( - simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), - elements, elements); - Node* effect = NodeProperties::GetEffectInput(node); - Node* control = NodeProperties::GetControlInput(node); - Node* load = graph()->NewNode( - simplified()->LoadElement( - AccessBuilder::ForTypedArrayElement(type, true)), - pointer, key, jsgraph()->Uint32Constant(length), effect, control); - return ReplaceEagerly(node, load); + uint32_t byte_length; + if (array->byte_length()->ToUint32(&byte_length)) { + Node* elements = graph()->NewNode( + simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, + graph()->start()); + Node* pointer = graph()->NewNode( + simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), + elements, elements); + Node* length = jsgraph()->Uint32Constant( + static_cast(byte_length / array->element_size())); + Node* effect = NodeProperties::GetEffectInput(node); + Node* control = NodeProperties::GetControlInput(node); + Node* load = graph()->NewNode( + simplified()->LoadElement( + AccessBuilder::ForTypedArrayElement(type, true)), + pointer, key, length, effect, control); + return ReplaceEagerly(node, load); + } } } return NoChange(); @@ -577,22 +580,24 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { Handle::cast(base_type->AsConstant()->Value()); if (IsExternalArrayElementsKind(array->map()->elements_kind())) { ExternalArrayType type = array->type(); - uint32_t length; - CHECK(array->length()->ToUint32(&length)); - Node* elements = graph()->NewNode( - simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, - graph()->start()); - Node* pointer = graph()->NewNode( - simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), - elements, elements); - Node* effect = NodeProperties::GetEffectInput(node); - Node* control = NodeProperties::GetControlInput(node); - Node* store = - graph()->NewNode(simplified()->StoreElement( - AccessBuilder::ForTypedArrayElement(type, true)), - pointer, key, jsgraph()->Uint32Constant(length), - value, effect, control); - return ReplaceEagerly(node, store); + uint32_t byte_length; + if (array->byte_length()->ToUint32(&byte_length)) { + Node* elements = graph()->NewNode( + simplified()->LoadField(AccessBuilder::ForJSObjectElements()), base, + graph()->start()); + Node* pointer = graph()->NewNode( + simplified()->LoadField(AccessBuilder::ForExternalArrayPointer()), + elements, elements); + Node* length = jsgraph()->Uint32Constant( + static_cast(byte_length / array->element_size())); + Node* effect = NodeProperties::GetEffectInput(node); + Node* control = NodeProperties::GetControlInput(node); + Node* store = graph()->NewNode( + simplified()->StoreElement( + AccessBuilder::ForTypedArrayElement(type, true)), + pointer, key, length, value, effect, control); + return ReplaceEagerly(node, store); + } } } return NoChange(); diff --git a/src/factory.cc b/src/factory.cc index 25d8cd8..60ea691 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1731,6 +1731,19 @@ ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) { } +size_t GetExternalArrayElementSize(ExternalArrayType type) { + switch (type) { +#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ + case kExternal##Type##Array: \ + return size; + TYPED_ARRAYS(TYPED_ARRAY_CASE) + } + UNREACHABLE(); + return 0; +#undef TYPED_ARRAY_CASE +} + + JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { Context* native_context = isolate->context()->native_context(); switch (type) { @@ -1769,7 +1782,9 @@ Handle Factory::NewJSTypedArray(ExternalArrayType type, array->set_weak_next(buffer->weak_first_view()); buffer->set_weak_first_view(*array); array->set_byte_offset(Smi::FromInt(0)); - array->set_byte_length(buffer->byte_length()); + Handle byte_length_handle = + NewNumberFromSize(length * GetExternalArrayElementSize(type)); + array->set_byte_length(*byte_length_handle); Handle length_handle = NewNumberFromSize(length); array->set_length(*length_handle); Handle elements =