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

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

Issue 19792007: Recognize Math's min and max function for doubles and inline the operation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { 2529 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) {
2530 PushArgumentInstr* push = call->PushArgumentAt(i); 2530 PushArgumentInstr* push = call->PushArgumentAt(i);
2531 push->ReplaceUsesWith(push->value()->definition()); 2531 push->ReplaceUsesWith(push->value()->definition());
2532 push->RemoveFromGraph(); 2532 push->RemoveFromGraph();
2533 } 2533 }
2534 // Manually replace call with global null constant. ReplaceCall can't 2534 // Manually replace call with global null constant. ReplaceCall can't
2535 // be used for definitions that are already in the graph. 2535 // be used for definitions that are already in the graph.
2536 call->ReplaceUsesWith(flow_graph_->constant_null()); 2536 call->ReplaceUsesWith(flow_graph_->constant_null());
2537 ASSERT(current_iterator()->Current() == call); 2537 ASSERT(current_iterator()->Current() == call);
2538 current_iterator()->RemoveCurrentFromGraph();; 2538 current_iterator()->RemoveCurrentFromGraph();;
2539 } else if ((recognized_kind == MethodRecognizer::kMathMin) ||
2540 (recognized_kind == MethodRecognizer::kMathMax)) {
2541 // We can handle only monomorphic min/max call sites with both arguments
2542 // being either doubles or Smi-s
2543 if (call->HasICData() && (call->ic_data()->NumberOfChecks() == 1)) {
2544 const ICData& ic_data = *call->ic_data();
2545 intptr_t result_cid = kIllegalCid;
2546 if (ICDataHasReceiverArgumentClassIds(ic_data, kDoubleCid, kDoubleCid)) {
2547 result_cid = kDoubleCid;
2548 } else if (ICDataHasReceiverArgumentClassIds(ic_data, kSmiCid, kSmiCid)) {
2549 // TODO(srdjan): Implement for Smi.
2550 result_cid = kIllegalCid;
2551 }
2552 if (result_cid != kIllegalCid) {
2553 MathMinMaxInstr* min_max = new MathMinMaxInstr(
2554 recognized_kind,
2555 new Value(call->ArgumentAt(0)),
2556 new Value(call->ArgumentAt(1)),
2557 call->deopt_id(),
2558 result_cid);
2559 const ICData& unary_checks =
2560 ICData::ZoneHandle(ic_data.AsUnaryClassChecks());
2561 AddCheckClass(min_max->left()->definition(),
2562 unary_checks,
2563 call->deopt_id(),
2564 call->env(),
2565 call);
2566 AddCheckClass(min_max->right()->definition(),
2567 unary_checks,
2568 call->deopt_id(),
2569 call->env(),
2570 call);
2571 ReplaceCall(call, min_max);
2572 }
2573 }
2539 } 2574 }
2540 } 2575 }
2541 2576
2542 2577
2543 bool FlowGraphOptimizer::TryInlineInstanceSetter(InstanceCallInstr* instr, 2578 bool FlowGraphOptimizer::TryInlineInstanceSetter(InstanceCallInstr* instr,
2544 const ICData& unary_ic_data) { 2579 const ICData& unary_ic_data) {
2545 ASSERT((unary_ic_data.NumberOfChecks() > 0) && 2580 ASSERT((unary_ic_data.NumberOfChecks() > 0) &&
2546 (unary_ic_data.num_args_tested() == 1)); 2581 (unary_ic_data.num_args_tested() == 1));
2547 if (FLAG_enable_type_checks) { 2582 if (FLAG_enable_type_checks) {
2548 // TODO(srdjan): Add assignable check node if --enable_type_checks. 2583 // TODO(srdjan): Add assignable check node if --enable_type_checks.
(...skipping 3725 matching lines...) Expand 10 before | Expand all | Expand 10 after
6274 const Object& value = instr->value()->definition()->constant_value(); 6309 const Object& value = instr->value()->definition()->constant_value();
6275 if (IsNonConstant(value)) { 6310 if (IsNonConstant(value)) {
6276 SetValue(instr, non_constant_); 6311 SetValue(instr, non_constant_);
6277 } else if (IsConstant(value)) { 6312 } else if (IsConstant(value)) {
6278 // TODO(kmillikin): Handle sqrt. 6313 // TODO(kmillikin): Handle sqrt.
6279 SetValue(instr, non_constant_); 6314 SetValue(instr, non_constant_);
6280 } 6315 }
6281 } 6316 }
6282 6317
6283 6318
6319 void ConstantPropagator::VisitMathMinMax(MathMinMaxInstr* instr) {
6320 const Object& left = instr->left()->definition()->constant_value();
6321 const Object& right = instr->right()->definition()->constant_value();
6322 if (IsNonConstant(left) || IsNonConstant(right)) {
6323 SetValue(instr, non_constant_);
6324 } else if (IsConstant(left) && IsConstant(right)) {
6325 // TODO(srdjan): Handle min and max.
6326 SetValue(instr, non_constant_);
6327 }
6328 }
6329
6330
6284 void ConstantPropagator::VisitUnboxDouble(UnboxDoubleInstr* instr) { 6331 void ConstantPropagator::VisitUnboxDouble(UnboxDoubleInstr* instr) {
6285 const Object& value = instr->value()->definition()->constant_value(); 6332 const Object& value = instr->value()->definition()->constant_value();
6286 if (IsNonConstant(value)) { 6333 if (IsNonConstant(value)) {
6287 SetValue(instr, non_constant_); 6334 SetValue(instr, non_constant_);
6288 } else if (IsConstant(value)) { 6335 } else if (IsConstant(value)) {
6289 // TODO(kmillikin): Handle conversion. 6336 // TODO(kmillikin): Handle conversion.
6290 SetValue(instr, non_constant_); 6337 SetValue(instr, non_constant_);
6291 } 6338 }
6292 } 6339 }
6293 6340
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
7195 7242
7196 // Insert materializations at environment uses. 7243 // Insert materializations at environment uses.
7197 const Class& cls = Class::Handle(alloc->constructor().Owner()); 7244 const Class& cls = Class::Handle(alloc->constructor().Owner());
7198 for (intptr_t i = 0; i < exits.length(); i++) { 7245 for (intptr_t i = 0; i < exits.length(); i++) {
7199 CreateMaterializationAt(exits[i], alloc, cls, *fields); 7246 CreateMaterializationAt(exits[i], alloc, cls, *fields);
7200 } 7247 }
7201 } 7248 }
7202 7249
7203 7250
7204 } // namespace dart 7251 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_type_propagator.cc » ('j') | runtime/vm/intermediate_language_arm.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698