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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 14566020: - Correctly handle negative constant indices when (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/flow_graph_builder.h" 9 #include "vm/flow_graph_builder.h"
10 #include "vm/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 Definition** array, 684 Definition** array,
685 Definition** index) { 685 Definition** index) {
686 // Insert class check and index smi checks and attach a copy of the 686 // Insert class check and index smi checks and attach a copy of the
687 // original environment because the operation can still deoptimize. 687 // original environment because the operation can still deoptimize.
688 AddReceiverCheck(call); 688 AddReceiverCheck(call);
689 InsertBefore(call, 689 InsertBefore(call,
690 new CheckSmiInstr(new Value(*index), call->deopt_id()), 690 new CheckSmiInstr(new Value(*index), call->deopt_id()),
691 call->env(), 691 call->env(),
692 Definition::kEffect); 692 Definition::kEffect);
693 693
694 // If both index and array are constants, then do a compile-time check. 694 // Insert array length load and bounds check.
695 // TODO(srdjan): Remove once constant propagation handles bounds checks. 695 const bool is_immutable =
696 bool skip_check = false; 696 CheckArrayBoundInstr::IsFixedLengthArrayType(class_id);
697 if ((*array)->IsConstant() && (*index)->IsConstant()) { 697 LoadFieldInstr* length =
698 const ImmutableArray& constant_array = 698 new LoadFieldInstr(new Value(*array),
699 ImmutableArray::Cast((*array)->AsConstant()->value()); 699 CheckArrayBoundInstr::LengthOffsetFor(class_id),
700 const Object& constant_index = (*index)->AsConstant()->value(); 700 Type::ZoneHandle(Type::SmiType()),
701 skip_check = constant_index.IsSmi() && 701 is_immutable);
702 (Smi::Cast(constant_index).Value() < constant_array.Length()); 702 length->set_result_cid(kSmiCid);
703 } 703 length->set_recognized_kind(
704 if (!skip_check) { 704 LoadFieldInstr::RecognizedKindFromArrayCid(class_id));
705 // Insert array length load and bounds check. 705 InsertBefore(call, length, NULL, Definition::kValue);
706 const bool is_immutable = 706 InsertBefore(call,
707 CheckArrayBoundInstr::IsFixedLengthArrayType(class_id); 707 new CheckArrayBoundInstr(new Value(length),
708 LoadFieldInstr* length = 708 new Value(*index),
709 new LoadFieldInstr(new Value(*array), 709 class_id,
710 CheckArrayBoundInstr::LengthOffsetFor(class_id), 710 call),
711 Type::ZoneHandle(Type::SmiType()), 711 call->env(),
712 is_immutable); 712 Definition::kEffect);
713 length->set_result_cid(kSmiCid);
714 length->set_recognized_kind(
715 LoadFieldInstr::RecognizedKindFromArrayCid(class_id));
716 InsertBefore(call, length, NULL, Definition::kValue);
717 713
718 InsertBefore(call,
719 new CheckArrayBoundInstr(new Value(length),
720 new Value(*index),
721 class_id,
722 call),
723 call->env(),
724 Definition::kEffect);
725 }
726 if (class_id == kGrowableObjectArrayCid) { 714 if (class_id == kGrowableObjectArrayCid) {
727 // Insert data elements load. 715 // Insert data elements load.
728 LoadFieldInstr* elements = 716 LoadFieldInstr* elements =
729 new LoadFieldInstr(new Value(*array), 717 new LoadFieldInstr(new Value(*array),
730 GrowableObjectArray::data_offset(), 718 GrowableObjectArray::data_offset(),
731 Type::ZoneHandle(Type::DynamicType())); 719 Type::ZoneHandle(Type::DynamicType()));
732 elements->set_result_cid(kArrayCid); 720 elements->set_result_cid(kArrayCid);
733 InsertBefore(call, elements, NULL, Definition::kValue); 721 InsertBefore(call, elements, NULL, Definition::kValue);
734 *array = elements; 722 *array = elements;
735 return kArrayCid; 723 return kArrayCid;
(...skipping 5770 matching lines...) Expand 10 before | Expand all | Expand 10 after
6506 6494
6507 // Insert materializations at environment uses. 6495 // Insert materializations at environment uses.
6508 const Class& cls = Class::Handle(alloc->constructor().Owner()); 6496 const Class& cls = Class::Handle(alloc->constructor().Owner());
6509 for (intptr_t i = 0; i < exits.length(); i++) { 6497 for (intptr_t i = 0; i < exits.length(); i++) {
6510 CreateMaterializationAt(exits[i], alloc, cls, *fields); 6498 CreateMaterializationAt(exits[i], alloc, cls, *fields);
6511 } 6499 }
6512 } 6500 }
6513 6501
6514 6502
6515 } // namespace dart 6503 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698