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

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

Issue 12852007: Improve code for !identical(a, b): (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 | « runtime/vm/intermediate_language.h ('k') | runtime/vm/token.h » ('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/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/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flow_graph_allocator.h" 9 #include "vm/flow_graph_allocator.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 instantiator_type_arguments()->BindTo(null_constant); 1236 instantiator_type_arguments()->BindTo(null_constant);
1237 } 1237 }
1238 return this; 1238 return this;
1239 } 1239 }
1240 1240
1241 1241
1242 Instruction* BranchInstr::Canonicalize(FlowGraphOptimizer* optimizer) { 1242 Instruction* BranchInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1243 // Only handle strict-compares. 1243 // Only handle strict-compares.
1244 if (comparison()->IsStrictCompare()) { 1244 if (comparison()->IsStrictCompare()) {
1245 Definition* replacement = comparison()->Canonicalize(optimizer); 1245 Definition* replacement = comparison()->Canonicalize(optimizer);
1246 if (replacement == comparison() || replacement == NULL) return this; 1246 if ((replacement == comparison()) || (replacement == NULL)) {
1247 return this;
1248 }
1247 ComparisonInstr* comp = replacement->AsComparison(); 1249 ComparisonInstr* comp = replacement->AsComparison();
1248 if ((comp == NULL) || comp->CanDeoptimize()) return this; 1250 if ((comp == NULL) || comp->CanDeoptimize()) {
1251 return this;
1252 }
1249 1253
1250 // Check that comparison is not serving as a pending deoptimization target 1254 // Check that comparison is not serving as a pending deoptimization target
1251 // for conversions. 1255 // for conversions.
1252 for (intptr_t i = 0; i < comp->InputCount(); i++) { 1256 for (intptr_t i = 0; i < comp->InputCount(); i++) {
1253 if (comp->RequiredInputRepresentation(i) != 1257 if (comp->RequiredInputRepresentation(i) !=
1254 comp->InputAt(i)->definition()->representation()) { 1258 comp->InputAt(i)->definition()->representation()) {
1255 return this; 1259 return this;
1256 } 1260 }
1257 } 1261 }
1258 1262
(...skipping 12 matching lines...) Expand all
1271 ASSERT(comp->input_use_list() == NULL); 1275 ASSERT(comp->input_use_list() == NULL);
1272 comp->ClearSSATempIndex(); 1276 comp->ClearSSATempIndex();
1273 comp->ClearTempIndex(); 1277 comp->ClearTempIndex();
1274 } 1278 }
1275 } 1279 }
1276 return this; 1280 return this;
1277 } 1281 }
1278 1282
1279 1283
1280 Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) { 1284 Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1281 if (!right()->BindsToConstant()) return this; 1285 if (!right()->BindsToConstant()) {
1286 return this;
1287 }
1282 const Object& right_constant = right()->BoundConstant(); 1288 const Object& right_constant = right()->BoundConstant();
1283 Definition* left_defn = left()->definition(); 1289 Definition* left_defn = left()->definition();
1284 // TODO(fschneider): Handle other cases: e === false and e !== true/false. 1290 // TODO(fschneider): Handle other cases: e === false and e !== true/false.
1285 // Handles e === true. 1291 // Handles e === true.
1286 if ((kind() == Token::kEQ_STRICT) && 1292 if ((kind() == Token::kEQ_STRICT) &&
1287 (right_constant.raw() == Bool::True().raw()) && 1293 (right_constant.raw() == Bool::True().raw()) &&
1288 (left()->Type()->ToCid() == kBoolCid)) { 1294 (left()->Type()->ToCid() == kBoolCid)) {
1289 // Return left subexpression as the replacement for this instruction. 1295 // Return left subexpression as the replacement for this instruction.
1290 return left_defn; 1296 return left_defn;
1291 } 1297 }
1298 // x = (a === b); y = x !== true; -> y = a !== b.
1299 // In order to merge two strict comares, 'left_strict' must have only one use.
1300 // Do not check left's cid as it is required to be a strict compare.
1301 StrictCompareInstr* left_strict = left_defn->AsStrictCompare();
1302 if ((kind() == Token::kNE_STRICT) &&
1303 (right_constant.raw() == Bool::True().raw()) &&
1304 (left_strict != NULL) &&
1305 (left_strict->HasOnlyUse(left()))) {
1306 left_strict->set_kind(Token::NegateComparison(left_strict->kind()));
1307 return left_strict;
1308 }
1309
1292 return this; 1310 return this;
1293 } 1311 }
1294 1312
1295 1313
1296 Instruction* CheckClassInstr::Canonicalize(FlowGraphOptimizer* optimizer) { 1314 Instruction* CheckClassInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1297 // TODO(vegorov): Replace class checks with null checks when ToNullableCid 1315 // TODO(vegorov): Replace class checks with null checks when ToNullableCid
1298 // matches. 1316 // matches.
1299 1317
1300 const intptr_t value_cid = value()->Type()->ToCid(); 1318 const intptr_t value_cid = value()->Type()->ToCid();
1301 if (value_cid == kDynamicCid) { 1319 if (value_cid == kDynamicCid) {
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 default: 2360 default:
2343 UNREACHABLE(); 2361 UNREACHABLE();
2344 } 2362 }
2345 return kPowRuntimeEntry; 2363 return kPowRuntimeEntry;
2346 } 2364 }
2347 2365
2348 2366
2349 #undef __ 2367 #undef __
2350 2368
2351 } // namespace dart 2369 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | runtime/vm/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698