| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of dart2js.optimizers; | 5 part of dart2js.optimizers; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Propagates constants throughout the IR, and replaces branches with fixed | 8 * Propagates constants throughout the IR, and replaces branches with fixed |
| 9 * jumps as well as side-effect free expressions with known constant results. | 9 * jumps as well as side-effect free expressions with known constant results. |
| 10 * Should be followed by the [ShrinkingReducer] pass. | 10 * Should be followed by the [ShrinkingReducer] pass. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 assert(continuation.parameters.length == 1); | 76 assert(continuation.parameters.length == 1); |
| 77 | 77 |
| 78 // Set up the replacement structure. | 78 // Set up the replacement structure. |
| 79 | 79 |
| 80 PrimitiveConstantValue primitiveConstant = cell.constant; | 80 PrimitiveConstantValue primitiveConstant = cell.constant; |
| 81 ConstantExpression constExp = | 81 ConstantExpression constExp = |
| 82 new PrimitiveConstantExpression(primitiveConstant); | 82 new PrimitiveConstantExpression(primitiveConstant); |
| 83 Constant constant = new Constant(constExp); | 83 Constant constant = new Constant(constExp); |
| 84 LetPrim letPrim = new LetPrim(constant); | 84 LetPrim letPrim = new LetPrim(constant); |
| 85 InvokeContinuation invoke = | 85 InvokeContinuation invoke = |
| 86 new InvokeContinuation(continuation, <Definition>[constant]); | 86 new InvokeContinuation(continuation, <Primitive>[constant]); |
| 87 | 87 |
| 88 invoke.parent = constant.parent = letPrim; | 88 invoke.parent = constant.parent = letPrim; |
| 89 letPrim.body = invoke; | 89 letPrim.body = invoke; |
| 90 | 90 |
| 91 // Replace the method invocation. | 91 // Replace the method invocation. |
| 92 | 92 |
| 93 InteriorNode parent = node.parent; | 93 InteriorNode parent = node.parent; |
| 94 letPrim.parent = parent; | 94 letPrim.parent = parent; |
| 95 parent.body = letPrim; | 95 parent.body = letPrim; |
| 96 | 96 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 117 return; | 117 return; |
| 118 } | 118 } |
| 119 | 119 |
| 120 Continuation successor = (trueReachable) ? | 120 Continuation successor = (trueReachable) ? |
| 121 node.trueContinuation.definition : node.falseContinuation.definition; | 121 node.trueContinuation.definition : node.falseContinuation.definition; |
| 122 | 122 |
| 123 // Replace the branch by a continuation invocation. | 123 // Replace the branch by a continuation invocation. |
| 124 | 124 |
| 125 assert(successor.parameters.isEmpty); | 125 assert(successor.parameters.isEmpty); |
| 126 InvokeContinuation invoke = | 126 InvokeContinuation invoke = |
| 127 new InvokeContinuation(successor, <Definition>[]); | 127 new InvokeContinuation(successor, <Primitive>[]); |
| 128 | 128 |
| 129 InteriorNode parent = node.parent; | 129 InteriorNode parent = node.parent; |
| 130 invoke.parent = parent; | 130 invoke.parent = parent; |
| 131 parent.body = invoke; | 131 parent.body = invoke; |
| 132 | 132 |
| 133 // Unlink all removed references. | 133 // Unlink all removed references. |
| 134 | 134 |
| 135 node.trueContinuation.unlink(); | 135 node.trueContinuation.unlink(); |
| 136 node.falseContinuation.unlink(); | 136 node.falseContinuation.unlink(); |
| 137 IsTrue isTrue = node.condition; | 137 IsTrue isTrue = node.condition; |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 return that; | 657 return that; |
| 658 } | 658 } |
| 659 | 659 |
| 660 if (this.constant == that.constant) { | 660 if (this.constant == that.constant) { |
| 661 return this; | 661 return this; |
| 662 } | 662 } |
| 663 | 663 |
| 664 return NonConst; | 664 return NonConst; |
| 665 } | 665 } |
| 666 } | 666 } |
| OLD | NEW |