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

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

Issue 102973007: Constant propagation in LoadIndexed when inputs are array/string and index constants. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | tests/language/guess_cid_test.dart » ('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/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 6612 matching lines...) Expand 10 before | Expand all | Expand 10 after
6623 } 6623 }
6624 6624
6625 6625
6626 void ConstantPropagator::VisitStringInterpolate(StringInterpolateInstr* instr) { 6626 void ConstantPropagator::VisitStringInterpolate(StringInterpolateInstr* instr) {
6627 SetValue(instr, non_constant_); 6627 SetValue(instr, non_constant_);
6628 return; 6628 return;
6629 } 6629 }
6630 6630
6631 6631
6632 void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) { 6632 void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) {
6633 SetValue(instr, non_constant_); 6633 const Object& array_obj = instr->array()->definition()->constant_value();
6634 const Object& index_obj = instr->index()->definition()->constant_value();
6635 if (IsNonConstant(array_obj) || IsNonConstant(index_obj)) {
6636 SetValue(instr, non_constant_);
6637 } else if (IsConstant(array_obj) && IsConstant(index_obj)) {
6638 // Need index to be Smi and array to be either String or an immutable array.
6639 if (!index_obj.IsSmi()) {
6640 // Should not occur.
6641 SetValue(instr, non_constant_);
6642 return;
6643 }
6644 const intptr_t index = Smi::Cast(index_obj).Value();
6645 if (index >= 0) {
6646 if (array_obj.IsString()) {
6647 const String& str = String::Cast(array_obj);
6648 if (str.Length() > index) {
6649 SetValue(instr, Smi::Handle(Smi::New(str.CharAt(index))));
6650 return;
6651 }
6652 } else if (array_obj.IsArray()) {
6653 const Array& a = Array::Cast(array_obj);
6654 if ((a.Length() > index) && a.IsImmutable()) {
Cutch 2013/12/18 05:21:19 Is IsImmutable needed for a constant array?
srdjan 2013/12/18 16:40:01 I believe it could be possible for constant propag
6655 Instance& result = Instance::Handle();
6656 result ^= a.At(index);
6657 SetValue(instr, result);
6658 return;
6659 }
6660 }
6661 }
6662 SetValue(instr, non_constant_);
6663 }
6634 } 6664 }
6635 6665
6636 6666
6637 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) { 6667 void ConstantPropagator::VisitStoreIndexed(StoreIndexedInstr* instr) {
6638 SetValue(instr, instr->value()->definition()->constant_value()); 6668 SetValue(instr, instr->value()->definition()->constant_value());
6639 } 6669 }
6640 6670
6641 6671
6642 void ConstantPropagator::VisitStoreInstanceField( 6672 void ConstantPropagator::VisitStoreInstanceField(
6643 StoreInstanceFieldInstr* instr) { 6673 StoreInstanceFieldInstr* instr) {
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after
8072 } 8102 }
8073 8103
8074 // Insert materializations at environment uses. 8104 // Insert materializations at environment uses.
8075 for (intptr_t i = 0; i < exits.length(); i++) { 8105 for (intptr_t i = 0; i < exits.length(); i++) {
8076 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 8106 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
8077 } 8107 }
8078 } 8108 }
8079 8109
8080 8110
8081 } // namespace dart 8111 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/guess_cid_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698