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

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
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)) {
5345 SetValue(instr, non_constant_); 5348 SetValue(instr, non_constant_);
Kevin Millikin (Google) 2013/05/22 07:50:35 I think this is where we would support arithmetic
srdjan 2013/05/22 15:13:33 Added comment: // TODO(srdjan): Add arithemtic sim
5346 } else if (IsConstant(left) && IsConstant(right)) { 5349 } else if (IsConstant(left) && IsConstant(right)) {
5347 if (left.IsSmi() && right.IsSmi()) { 5350 if (left.IsInteger() && right.IsInteger()) {
5348 const Smi& left_smi = Smi::Cast(left); 5351 const Integer& left_int = Integer::Cast(left);
5349 const Smi& right_smi = Smi::Cast(right); 5352 const Integer& right_int = Integer::Cast(right);
5350 switch (instr->op_kind()) { 5353 switch (op_kind) {
5351 case Token::kADD: 5354 case Token::kADD:
5352 case Token::kSUB: 5355 case Token::kSUB:
5353 case Token::kMUL: 5356 case Token::kMUL:
5354 case Token::kTRUNCDIV: 5357 case Token::kTRUNCDIV:
5355 case Token::kMOD: { 5358 case Token::kMOD: {
5356 const Object& result = Integer::ZoneHandle( 5359 Instance& result = Integer::ZoneHandle(
5357 left_smi.ArithmeticOp(instr->op_kind(), right_smi)); 5360 left_int.ArithmeticOp(op_kind, right_int));
5361 result = result.Canonicalize();
5358 SetValue(instr, result); 5362 SetValue(instr, result);
5359 break; 5363 break;
5360 } 5364 }
5361 case Token::kSHL: 5365 case Token::kSHL:
5362 case Token::kSHR: { 5366 case Token::kSHR: {
Kevin Millikin (Google) 2013/05/22 07:50:35 I'm not sure about the official VM style, but I us
srdjan 2013/05/22 15:13:33 Removed braces.
5363 const Object& result = Integer::ZoneHandle( 5367 if (left.IsSmi() && right.IsSmi()) {
5364 left_smi.ShiftOp(instr->op_kind(), right_smi)); 5368 Instance& result = Integer::ZoneHandle(
5365 SetValue(instr, result); 5369 Smi::Cast(left_int).ShiftOp(op_kind, Smi::Cast(right_int)));
5370 result = result.Canonicalize();
5371 SetValue(instr, result);
5372 } else {
5373 SetValue(instr, non_constant_);
5374 }
5366 break; 5375 break;
5367 } 5376 }
5368 case Token::kBIT_AND: 5377 case Token::kBIT_AND:
5369 case Token::kBIT_OR: 5378 case Token::kBIT_OR:
5370 case Token::kBIT_XOR: { 5379 case Token::kBIT_XOR: {
5371 const Object& result = Integer::ZoneHandle( 5380 Instance& result = Integer::ZoneHandle(
5372 left_smi.BitOp(instr->op_kind(), right_smi)); 5381 left_int.BitOp(op_kind, right_int));
5382 result = result.Canonicalize();
5373 SetValue(instr, result); 5383 SetValue(instr, result);
5374 break; 5384 break;
5375 } 5385 }
5376 default: 5386 default:
5377 // TODO(kmillikin): support other smi operations. 5387 // TODO(kmillikin): support other smi operations.
Kevin Millikin (Google) 2013/05/22 07:50:35 This comment is a bit out of date now. I think th
srdjan 2013/05/22 15:13:33 Done.
5378 SetValue(instr, non_constant_); 5388 SetValue(instr, non_constant_);
5379 } 5389 }
5380 } else { 5390 } else {
5381 // TODO(kmillikin): support other types. 5391 // TODO(kmillikin): support other types.
5382 SetValue(instr, non_constant_); 5392 SetValue(instr, non_constant_);
5383 } 5393 }
5384 } 5394 }
5385 } 5395 }
5386 5396
5387 5397
5398 void ConstantPropagator::VisitBinarySmiOp(BinarySmiOpInstr* instr) {
5399 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right());
5400 }
5401
5402
5388 void ConstantPropagator::VisitBoxInteger(BoxIntegerInstr* instr) { 5403 void ConstantPropagator::VisitBoxInteger(BoxIntegerInstr* instr) {
5389 // TODO(kmillikin): Handle box operation. 5404 // TODO(kmillikin): Handle box operation.
5390 SetValue(instr, non_constant_); 5405 SetValue(instr, non_constant_);
5391 } 5406 }
5392 5407
5393 5408
5394 void ConstantPropagator::VisitUnboxInteger(UnboxIntegerInstr* instr) { 5409 void ConstantPropagator::VisitUnboxInteger(UnboxIntegerInstr* instr) {
5395 // TODO(kmillikin): Handle unbox operation. 5410 // TODO(kmillikin): Handle unbox operation.
5396 SetValue(instr, non_constant_); 5411 SetValue(instr, non_constant_);
5397 } 5412 }
5398 5413
5399 5414
5400 void ConstantPropagator::VisitBinaryMintOp( 5415 void ConstantPropagator::VisitBinaryMintOp(
5401 BinaryMintOpInstr* instr) { 5416 BinaryMintOpInstr* instr) {
5402 // TODO(kmillikin): Handle binary operations. 5417 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right());
5403 SetValue(instr, non_constant_);
5404 } 5418 }
5405 5419
5406 5420
5407 void ConstantPropagator::VisitShiftMintOp( 5421 void ConstantPropagator::VisitShiftMintOp(
5408 ShiftMintOpInstr* instr) { 5422 ShiftMintOpInstr* instr) {
5409 // TODO(kmillikin): Handle shift operations. 5423 HandleBinaryOp(instr, instr->op_kind(), *instr->left(), *instr->right());
5410 SetValue(instr, non_constant_);
5411 } 5424 }
5412 5425
5413 5426
5414 void ConstantPropagator::VisitUnaryMintOp( 5427 void ConstantPropagator::VisitUnaryMintOp(
5415 UnaryMintOpInstr* instr) { 5428 UnaryMintOpInstr* instr) {
5416 // TODO(kmillikin): Handle unary operations. 5429 // TODO(kmillikin): Handle unary operations.
5417 SetValue(instr, non_constant_); 5430 SetValue(instr, non_constant_);
5418 } 5431 }
5419 5432
5420 5433
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
6494 6507
6495 // Insert materializations at environment uses. 6508 // Insert materializations at environment uses.
6496 const Class& cls = Class::Handle(alloc->constructor().Owner()); 6509 const Class& cls = Class::Handle(alloc->constructor().Owner());
6497 for (intptr_t i = 0; i < exits.length(); i++) { 6510 for (intptr_t i = 0; i < exits.length(); i++) {
6498 CreateMaterializationAt(exits[i], alloc, cls, *fields); 6511 CreateMaterializationAt(exits[i], alloc, cls, *fields);
6499 } 6512 }
6500 } 6513 }
6501 6514
6502 6515
6503 } // namespace dart 6516 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698