Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: src/compiler/js-typed-lowering.cc

Issue 516853002: Preliminary lowering of typed array loads in TF. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/graph-inl.h" 5 #include "src/compiler/graph-inl.h"
6 #include "src/compiler/js-typed-lowering.h" 6 #include "src/compiler/js-typed-lowering.h"
7 #include "src/compiler/node-aux-data-inl.h" 7 #include "src/compiler/node-aux-data-inl.h"
8 #include "src/compiler/node-properties-inl.h" 8 #include "src/compiler/node-properties-inl.h"
9 #include "src/types.h" 9 #include "src/types.h"
10 10
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 ReplaceEagerly(input, inv); 492 ReplaceEagerly(input, inv);
493 // TODO(titzer): Ugly. ReplaceEagerly smashes all uses. Smash it back here. 493 // TODO(titzer): Ugly. ReplaceEagerly smashes all uses. Smash it back here.
494 cmp->ReplaceInput(0, input); 494 cmp->ReplaceInput(0, input);
495 return Changed(inv); 495 return Changed(inv);
496 } 496 }
497 // TODO(turbofan): js-typed-lowering of ToBoolean(string) 497 // TODO(turbofan): js-typed-lowering of ToBoolean(string)
498 return NoChange(); 498 return NoChange();
499 } 499 }
500 500
501 501
502 FieldAccess JSTypedLowering::FieldAccessForElements() {
titzer 2014/08/28 09:45:09 Let's pull these out to an AccessHelper class.
Michael Starzinger 2014/08/28 10:38:40 Done. I called it just "Access" but I am happy to
titzer 2014/08/28 11:09:03 Maybe AccessBuilder...to prevent confusion between
503 return {kTaggedBase, JSTypedArray::kElementsOffset,
504 graph()->zone()->isolate()->factory()->empty_string(),
505 Type::Internal(), kMachAnyTagged};
506 }
507
508
509 FieldAccess JSTypedLowering::FieldAccessForExternalPointer() {
510 return {kTaggedBase, ExternalArray::kExternalPointerOffset,
511 graph()->zone()->isolate()->factory()->empty_string(),
512 Type::UntaggedPtr(), kMachPtr};
513 }
514
515
516 static ElementAccess ElementAccessForTypedArray(BaseTaggedness taggedness,
517 ExternalArrayType type,
518 int header_size) {
519 switch (type) {
520 case kExternalInt8Array:
521 return {taggedness, header_size, Type::Signed32(), kMachInt8};
522 case kExternalUint8Array:
523 case kExternalUint8ClampedArray:
524 return {taggedness, header_size, Type::Unsigned32(), kMachUint8};
525 case kExternalInt16Array:
526 return {taggedness, header_size, Type::Signed32(), kMachInt16};
527 case kExternalUint16Array:
528 return {taggedness, header_size, Type::Unsigned32(), kMachUint16};
529 case kExternalInt32Array:
530 return {taggedness, header_size, Type::Signed32(), kMachInt32};
531 case kExternalUint32Array:
532 return {taggedness, header_size, Type::Unsigned32(), kMachUint32};
533 case kExternalFloat32Array:
534 return {taggedness, header_size, Type::Number(), kRepFloat32};
535 case kExternalFloat64Array:
536 return {taggedness, header_size, Type::Number(), kRepFloat64};
537 }
538 UNREACHABLE();
539 return {kUntaggedBase, 0, Type::None(), kMachNone};
540 }
541
542
543 Reduction JSTypedLowering::ReduceJSPropertyLoad(Node* node) {
544 Node* key = NodeProperties::GetValueInput(node, 1);
545 Node* base = NodeProperties::GetValueInput(node, 0);
546 Type* key_type = NodeProperties::GetBounds(key).upper;
547 Type* base_type = NodeProperties::GetBounds(base).upper;
548 // TODO(mstarzinger): This lowering is not correct if:
549 // a) The typed array turns external (i.e. MaterializeArrayBuffer)
550 // b) The typed array or it's buffer is neutered.
551 // c) The index is out of bounds.
552 if (base_type->IsConstant() && key_type->Is(Type::Integral32()) &&
553 base_type->AsConstant()->Value()->IsJSTypedArray()) {
554 // JSLoadProperty(typed-array, int32)
555 JSTypedArray* array = JSTypedArray::cast(*base_type->AsConstant()->Value());
556 ElementsKind elements_kind = array->map()->elements_kind();
557 ExternalArrayType type = array->type();
558 ElementAccess element_access;
559 Node* elements =
560 graph()->NewNode(simplified()->LoadField(FieldAccessForElements()),
561 base, NodeProperties::GetEffectInput(node));
562 if (IsExternalArrayElementsKind(elements_kind)) {
563 elements = graph()->NewNode(
564 simplified()->LoadField(FieldAccessForExternalPointer()), elements,
565 NodeProperties::GetEffectInput(node));
566 element_access = ElementAccessForTypedArray(kUntaggedBase, type, 0);
titzer 2014/08/28 09:45:10 Maybe instead of passing the header size, you pass
Michael Starzinger 2014/08/28 10:38:40 Done.
567 } else {
568 DCHECK(IsFixedTypedArrayElementsKind(elements_kind));
569 int offset = FixedTypedArrayBase::kDataOffset;
570 element_access = ElementAccessForTypedArray(kTaggedBase, type, offset);
571 }
572 Node* value =
573 graph()->NewNode(simplified()->LoadElement(element_access), elements,
574 key, NodeProperties::GetEffectInput(node));
575 return ReplaceEagerly(node, value);
576 }
577 return NoChange();
578 }
579
580
502 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) { 581 static Reduction ReplaceWithReduction(Node* node, Reduction reduction) {
503 if (reduction.Changed()) { 582 if (reduction.Changed()) {
504 NodeProperties::ReplaceWithValue(node, reduction.replacement()); 583 NodeProperties::ReplaceWithValue(node, reduction.replacement());
505 return reduction; 584 return reduction;
506 } 585 }
507 return Reducer::NoChange(); 586 return Reducer::NoChange();
508 } 587 }
509 588
510 589
511 Reduction JSTypedLowering::Reduce(Node* node) { 590 Reduction JSTypedLowering::Reduce(Node* node) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 645 }
567 case IrOpcode::kJSToBoolean: 646 case IrOpcode::kJSToBoolean:
568 return ReplaceWithReduction(node, 647 return ReplaceWithReduction(node,
569 ReduceJSToBooleanInput(node->InputAt(0))); 648 ReduceJSToBooleanInput(node->InputAt(0)));
570 case IrOpcode::kJSToNumber: 649 case IrOpcode::kJSToNumber:
571 return ReplaceWithReduction(node, 650 return ReplaceWithReduction(node,
572 ReduceJSToNumberInput(node->InputAt(0))); 651 ReduceJSToNumberInput(node->InputAt(0)));
573 case IrOpcode::kJSToString: 652 case IrOpcode::kJSToString:
574 return ReplaceWithReduction(node, 653 return ReplaceWithReduction(node,
575 ReduceJSToStringInput(node->InputAt(0))); 654 ReduceJSToStringInput(node->InputAt(0)));
655 case IrOpcode::kJSLoadProperty:
656 return ReduceJSPropertyLoad(node);
576 default: 657 default:
577 break; 658 break;
578 } 659 }
579 return NoChange(); 660 return NoChange();
580 } 661 }
581 } 662 }
582 } 663 }
583 } // namespace v8::internal::compiler 664 } // namespace v8::internal::compiler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698