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

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

Issue 22842014: Fold equals and not equals comparisons for constant strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « no previous file | no next file » | 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 6033 matching lines...) Expand 10 before | Expand all | Expand 10 after
6044 const Object& left = instr->left()->definition()->constant_value(); 6044 const Object& left = instr->left()->definition()->constant_value();
6045 const Object& right = instr->right()->definition()->constant_value(); 6045 const Object& right = instr->right()->definition()->constant_value();
6046 6046
6047 if (instr->left()->definition() == instr->right()->definition()) { 6047 if (instr->left()->definition() == instr->right()->definition()) {
6048 // Fold x == x, and x != x to true/false for numbers and checked strict 6048 // Fold x == x, and x != x to true/false for numbers and checked strict
6049 // comparisons. 6049 // comparisons.
6050 if (instr->IsCheckedStrictEqual() || 6050 if (instr->IsCheckedStrictEqual() ||
6051 RawObject::IsIntegerClassId(instr->operation_cid())) { 6051 RawObject::IsIntegerClassId(instr->operation_cid())) {
6052 return SetValue(instr, 6052 return SetValue(instr,
6053 (instr->kind() == Token::kEQ) 6053 (instr->kind() == Token::kEQ)
6054 ? Bool::True() 6054 ? Bool::True()
6055 : Bool::False()); 6055 : Bool::False());
6056 } 6056 }
6057 } 6057 }
6058 6058
6059 if (IsNonConstant(left) || IsNonConstant(right)) { 6059 if (IsNonConstant(left) || IsNonConstant(right)) {
6060 SetValue(instr, non_constant_); 6060 SetValue(instr, non_constant_);
6061 } else if (IsConstant(left) && IsConstant(right)) { 6061 } else if (IsConstant(left) && IsConstant(right)) {
6062 if (left.IsInteger() && right.IsInteger()) { 6062 if (left.IsInteger() && right.IsInteger()) {
6063 const bool result = CompareIntegers(instr->kind(), 6063 const bool result = CompareIntegers(instr->kind(),
6064 Integer::Cast(left), 6064 Integer::Cast(left),
6065 Integer::Cast(right)); 6065 Integer::Cast(right));
6066 SetValue(instr, result ? Bool::True() : Bool::False()); 6066 SetValue(instr, result ? Bool::True() : Bool::False());
6067 } else if (left.IsString() && right.IsString()) {
srdjan 2013/08/26 16:00:39 I believe all constant strings must be canonicaliz
6068 const bool result = String::Cast(left).Equals(String::Cast(right));
6069 SetValue(instr,
6070 ((instr->kind() == Token::kEQ) == result)
6071 ? Bool::True()
6072 : Bool::False());
6067 } else { 6073 } else {
6068 SetValue(instr, non_constant_); 6074 SetValue(instr, non_constant_);
6069 } 6075 }
6070 } 6076 }
6071 } 6077 }
6072 6078
6073 6079
6074 void ConstantPropagator::VisitRelationalOp(RelationalOpInstr* instr) { 6080 void ConstantPropagator::VisitRelationalOp(RelationalOpInstr* instr) {
6075 const Object& left = instr->left()->definition()->constant_value(); 6081 const Object& left = instr->left()->definition()->constant_value();
6076 const Object& right = instr->right()->definition()->constant_value(); 6082 const Object& right = instr->right()->definition()->constant_value();
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
7535 } 7541 }
7536 7542
7537 // Insert materializations at environment uses. 7543 // Insert materializations at environment uses.
7538 for (intptr_t i = 0; i < exits.length(); i++) { 7544 for (intptr_t i = 0; i < exits.length(); i++) {
7539 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 7545 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
7540 } 7546 }
7541 } 7547 }
7542 7548
7543 7549
7544 } // namespace dart 7550 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698