| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library cps_ir.optimization.inline; | 5 library cps_ir.optimization.inline; |
| 6 | 6 |
| 7 import 'cps_fragment.dart'; | 7 import 'cps_fragment.dart'; |
| 8 import 'cps_ir_builder.dart' show ThisParameterLocal; | 8 import 'cps_ir_builder.dart' show ThisParameterLocal; |
| 9 import 'cps_ir_nodes.dart'; | 9 import 'cps_ir_nodes.dart'; |
| 10 import 'optimizers.dart'; | 10 import 'optimizers.dart'; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 visitor.countArgument(invoke.receiver, function.thisParameter); | 213 visitor.countArgument(invoke.receiver, function.thisParameter); |
| 214 for (int i = 0; i < invoke.arguments.length; ++i) { | 214 for (int i = 0; i < invoke.arguments.length; ++i) { |
| 215 visitor.countArgument(invoke.arguments[i], function.parameters[i]); | 215 visitor.countArgument(invoke.arguments[i], function.parameters[i]); |
| 216 } | 216 } |
| 217 return visitor.size; | 217 return visitor.size; |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Inlining a function incurs a cost equal to the number of primitives and | 220 // Inlining a function incurs a cost equal to the number of primitives and |
| 221 // non-jump tail expressions. | 221 // non-jump tail expressions. |
| 222 // TODO(kmillikin): Tune the size computation and size bound. | 222 // TODO(kmillikin): Tune the size computation and size bound. |
| 223 processLetPrim(LetPrim node) => ++size; | 223 processLetPrim(LetPrim node) { |
| 224 if (node.primitive is! Refinement) { |
| 225 ++size; |
| 226 } |
| 227 } |
| 224 processLetMutable(LetMutable node) => ++size; | 228 processLetMutable(LetMutable node) => ++size; |
| 225 processBranch(Branch node) => ++size; | 229 processBranch(Branch node) => ++size; |
| 226 processThrow(Throw nose) => ++size; | 230 processThrow(Throw nose) => ++size; |
| 227 processRethrow(Rethrow node) => ++size; | 231 processRethrow(Rethrow node) => ++size; |
| 228 } | 232 } |
| 229 | 233 |
| 230 class InliningVisitor extends TrampolineRecursiveVisitor { | 234 class InliningVisitor extends TrampolineRecursiveVisitor { |
| 231 final Inliner _inliner; | 235 final Inliner _inliner; |
| 232 | 236 |
| 233 // A successful inlining attempt returns the [Primitive] that represents the | 237 // A successful inlining attempt returns the [Primitive] that represents the |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 // We cannot inline a constructor invocation containing type arguments | 527 // We cannot inline a constructor invocation containing type arguments |
| 524 // because CreateInstance in the body does not know the type arguments. | 528 // because CreateInstance in the body does not know the type arguments. |
| 525 // We would incorrectly instantiate a class like A instead of A<B>. | 529 // We would incorrectly instantiate a class like A instead of A<B>. |
| 526 // TODO(kmillikin): try to fix this. | 530 // TODO(kmillikin): try to fix this. |
| 527 GenericType generic = node.dartType; | 531 GenericType generic = node.dartType; |
| 528 if (generic.typeArguments.any((DartType t) => !t.isDynamic)) return null; | 532 if (generic.typeArguments.any((DartType t) => !t.isDynamic)) return null; |
| 529 } | 533 } |
| 530 return tryInlining(node, node.target, null); | 534 return tryInlining(node, node.target, null); |
| 531 } | 535 } |
| 532 } | 536 } |
| OLD | NEW |