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

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

Issue 15507006: Improve constant propagation for Mint and Smi. (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 | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.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/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 5320 matching lines...) Expand 10 before | Expand all | Expand 10 after
5331 void ConstantPropagator::VisitAllocateContext(AllocateContextInstr* instr) { 5331 void ConstantPropagator::VisitAllocateContext(AllocateContextInstr* instr) {
5332 SetValue(instr, non_constant_); 5332 SetValue(instr, non_constant_);
5333 } 5333 }
5334 5334
5335 5335
5336 void ConstantPropagator::VisitCloneContext(CloneContextInstr* instr) { 5336 void ConstantPropagator::VisitCloneContext(CloneContextInstr* instr) {
5337 SetValue(instr, non_constant_); 5337 SetValue(instr, non_constant_);
5338 } 5338 }
5339 5339
5340 5340
5341 void ConstantPropagator::VisitBinarySmiOp(BinarySmiOpInstr* instr) { 5341 void ConstantPropagator::HandleBinaryOp(Definition* instr,
5342 const Object& left = instr->left()->definition()->constant_value(); 5342 Token::Kind op_kind,
5343 const Object& right = instr->right()->definition()->constant_value(); 5343 const Value& left_val,
5344 const Value& right_val) {
5345 const Object& left = left_val.definition()->constant_value();
5346 const Object& right = right_val.definition()->constant_value();
5344 if (IsNonConstant(left) || IsNonConstant(right)) { 5347 if (IsNonConstant(left) || IsNonConstant(right)) {
5348 // TODO(srdjan): Add arithemtic simplifications, e.g, add with 0.
5345 SetValue(instr, non_constant_); 5349 SetValue(instr, non_constant_);
5346 } else if (IsConstant(left) && IsConstant(right)) { 5350 } else if (IsConstant(left) && IsConstant(right)) {
5347 if (left.IsSmi() && right.IsSmi()) { 5351 if (left.IsInteger() && right.IsInteger()) {
5348 const Smi& left_smi = Smi::Cast(left); 5352 const Integer& left_int = Integer::Cast(left);
5349 const Smi& right_smi = Smi::Cast(right); 5353 const Integer& right_int = Integer::Cast(right);
5350 switch (instr->op_kind()) { 5354 switch (op_kind) {
5351 case Token::kADD: 5355 case Token::kADD:
5352 case Token::kSUB: 5356 case Token::kSUB:
5353 case Token::kMUL: 5357 case Token::kMUL:
5354 case Token::kTRUNCDIV: 5358 case Token::kTRUNCDIV:
5355 case Token::kMOD: { 5359 case Token::kMOD: {
5356 const Object& result = Integer::ZoneHandle( 5360 Instance& result = Integer::ZoneHandle(
5357 left_smi.ArithmeticOp(instr->op_kind(), right_smi)); 5361 left_int.ArithmeticOp(op_kind, right_int));
5362 result = result.Canonicalize();
5358 SetValue(instr, result); 5363 SetValue(instr, result);
5359 break; 5364 break;
5360 } 5365 }
5361 case Token::kSHL: 5366 case Token::kSHL:
5362 case Token::kSHR: { 5367 case Token::kSHR:
5363 const Object& result = Integer::ZoneHandle( 5368 if (left.IsSmi() && right.IsSmi()) {
5364 left_smi.ShiftOp(instr->op_kind(), right_smi)); 5369 Instance& result = Integer::ZoneHandle(
5370 Smi::Cast(left_int).ShiftOp(op_kind, Smi::Cast(right_int)));
5371 result = result.Canonicalize();
5372 SetValue(instr, result);
5373 } else {
5374 SetValue(instr, non_constant_);
5375 }
5376 break;
5377 case Token::kBIT_AND:
5378 case Token::kBIT_OR:
5379 case Token::kBIT_XOR: {
5380 Instance& result = Integer::ZoneHandle(
5381 left_int.BitOp(op_kind, right_int));
5382 result = result.Canonicalize();
5365 SetValue(instr, result); 5383 SetValue(instr, result);
5366 break; 5384 break;
5367 } 5385 }
5368 case Token::kBIT_AND: 5386 case Token::kDIV:
5369 case Token::kBIT_OR: 5387 SetValue(instr, non_constant_);
5370 case Token::kBIT_XOR: {
5371 const Object& result = Integer::ZoneHandle(
5372 left_smi.BitOp(instr->op_kind(), right_smi));
5373 SetValue(instr, result);
5374 break; 5388 break;
5375 }
5376 default: 5389 default:
5377 // TODO(kmillikin): support other smi operations. 5390 UNREACHABLE();
5378 SetValue(instr, non_constant_);
5379 } 5391 }
5380 } else { 5392 } else {
5381 // TODO(kmillikin): support other types. 5393 // TODO(kmillikin): support other types.
5382 SetValue(instr, non_constant_); 5394 SetValue(instr, non_constant_);
5383 } 5395 }
5384 } 5396 }
5385 } 5397 }
5386 5398
5387 5399
5400 void ConstantPropagator::VisitBinarySmiOp(BinarySmiOpInstr* instr) {
5401 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right());
5402 }
5403
5404
5388 void ConstantPropagator::VisitBoxInteger(BoxIntegerInstr* instr) { 5405 void ConstantPropagator::VisitBoxInteger(BoxIntegerInstr* instr) {
5389 // TODO(kmillikin): Handle box operation. 5406 // TODO(kmillikin): Handle box operation.
5390 SetValue(instr, non_constant_); 5407 SetValue(instr, non_constant_);
5391 } 5408 }
5392 5409
5393 5410
5394 void ConstantPropagator::VisitUnboxInteger(UnboxIntegerInstr* instr) { 5411 void ConstantPropagator::VisitUnboxInteger(UnboxIntegerInstr* instr) {
5395 // TODO(kmillikin): Handle unbox operation. 5412 // TODO(kmillikin): Handle unbox operation.
5396 SetValue(instr, non_constant_); 5413 SetValue(instr, non_constant_);
5397 } 5414 }
5398 5415
5399 5416
5400 void ConstantPropagator::VisitBinaryMintOp( 5417 void ConstantPropagator::VisitBinaryMintOp(
5401 BinaryMintOpInstr* instr) { 5418 BinaryMintOpInstr* instr) {
5402 // TODO(kmillikin): Handle binary operations. 5419 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right());
5403 SetValue(instr, non_constant_);
5404 } 5420 }
5405 5421
5406 5422
5407 void ConstantPropagator::VisitShiftMintOp( 5423 void ConstantPropagator::VisitShiftMintOp(
5408 ShiftMintOpInstr* instr) { 5424 ShiftMintOpInstr* instr) {
5409 // TODO(kmillikin): Handle shift operations. 5425 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right());
5410 SetValue(instr, non_constant_);
5411 } 5426 }
5412 5427
5413 5428
5414 void ConstantPropagator::VisitUnaryMintOp( 5429 void ConstantPropagator::VisitUnaryMintOp(
5415 UnaryMintOpInstr* instr) { 5430 UnaryMintOpInstr* instr) {
5416 // TODO(kmillikin): Handle unary operations. 5431 // TODO(kmillikin): Handle unary operations.
5417 SetValue(instr, non_constant_); 5432 SetValue(instr, non_constant_);
5418 } 5433 }
5419 5434
5420 5435
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
6496 6511
6497 // Insert materializations at environment uses. 6512 // Insert materializations at environment uses.
6498 const Class& cls = Class::Handle(alloc->constructor().Owner()); 6513 const Class& cls = Class::Handle(alloc->constructor().Owner());
6499 for (intptr_t i = 0; i < exits.length(); i++) { 6514 for (intptr_t i = 0; i < exits.length(); i++) {
6500 CreateMaterializationAt(exits[i], alloc, cls, *fields); 6515 CreateMaterializationAt(exits[i], alloc, cls, *fields);
6501 } 6516 }
6502 } 6517 }
6503 6518
6504 6519
6505 } // namespace dart 6520 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698