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/intermediate_language.cc

Issue 783683002: Better constant folding of length-loads in checked mode. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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
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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cpu.h" 8 #include "vm/cpu.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_allocator.h" 10 #include "vm/flow_graph_allocator.h"
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 } 1819 }
1820 1820
1821 1821
1822 Definition* LoadFieldInstr::Canonicalize(FlowGraph* flow_graph) { 1822 Definition* LoadFieldInstr::Canonicalize(FlowGraph* flow_graph) {
1823 if (!HasUses()) return NULL; 1823 if (!HasUses()) return NULL;
1824 if (!IsImmutableLengthLoad()) return this; 1824 if (!IsImmutableLengthLoad()) return this;
1825 1825
1826 // For fixed length arrays if the array is the result of a known constructor 1826 // For fixed length arrays if the array is the result of a known constructor
1827 // call we can replace the length load with the length argument passed to 1827 // call we can replace the length load with the length argument passed to
1828 // the constructor. 1828 // the constructor.
1829 StaticCallInstr* call = instance()->definition()->AsStaticCall(); 1829 StaticCallInstr* call =
1830 instance()->definition()->OriginalDefinition()->AsStaticCall();
1830 if (call != NULL) { 1831 if (call != NULL) {
1831 if (call->is_known_list_constructor() && 1832 if (call->is_known_list_constructor() &&
1832 IsFixedLengthArrayCid(call->Type()->ToCid())) { 1833 IsFixedLengthArrayCid(call->Type()->ToCid())) {
1833 return call->ArgumentAt(1); 1834 return call->ArgumentAt(1);
1834 } 1835 }
1835 if (call->is_native_list_factory()) { 1836 if (call->is_native_list_factory()) {
1836 return call->ArgumentAt(0); 1837 return call->ArgumentAt(0);
1837 } 1838 }
1838 } 1839 }
1839 1840
1840 CreateArrayInstr* create_array = instance()->definition()->AsCreateArray(); 1841 CreateArrayInstr* create_array =
1842 instance()->definition()->OriginalDefinition()->AsCreateArray();
1841 if ((create_array != NULL) && 1843 if ((create_array != NULL) &&
1842 (recognized_kind() == MethodRecognizer::kObjectArrayLength)) { 1844 (recognized_kind() == MethodRecognizer::kObjectArrayLength)) {
1843 return create_array->num_elements()->definition(); 1845 return create_array->num_elements()->definition();
1844 } 1846 }
1845 1847
1846 // For arrays with guarded lengths, replace the length load 1848 // For arrays with guarded lengths, replace the length load
1847 // with a constant. 1849 // with a constant.
1848 LoadFieldInstr* load_array = instance()->definition()->AsLoadField(); 1850 LoadFieldInstr* load_array =
1851 instance()->definition()->OriginalDefinition()->AsLoadField();
1849 if (load_array != NULL) { 1852 if (load_array != NULL) {
1850 const Field* field = load_array->field(); 1853 const Field* field = load_array->field();
1851 if ((field != NULL) && (field->guarded_list_length() >= 0)) { 1854 if ((field != NULL) && (field->guarded_list_length() >= 0)) {
1852 return flow_graph->GetConstant( 1855 return flow_graph->GetConstant(
1853 Smi::Handle(Smi::New(field->guarded_list_length()))); 1856 Smi::Handle(Smi::New(field->guarded_list_length())));
1854 } 1857 }
1855 } 1858 }
1856 return this; 1859 return this;
1857 } 1860 }
1858 1861
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
3438 case Token::kTRUNCDIV: return 0; 3441 case Token::kTRUNCDIV: return 0;
3439 case Token::kMOD: return 1; 3442 case Token::kMOD: return 1;
3440 default: UNIMPLEMENTED(); return -1; 3443 default: UNIMPLEMENTED(); return -1;
3441 } 3444 }
3442 } 3445 }
3443 3446
3444 3447
3445 #undef __ 3448 #undef __
3446 3449
3447 } // namespace dart 3450 } // namespace dart
OLDNEW
« runtime/vm/flow_graph_optimizer.cc ('K') | « runtime/vm/flow_graph_optimizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698