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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 301 } |
302 | 302 |
303 // -------------------------- Visitor overrides ------------------------------ | 303 // -------------------------- Visitor overrides ------------------------------ |
304 | 304 |
305 void visitNode(Node node) { | 305 void visitNode(Node node) { |
306 compiler.internalError(NO_LOCATION_SPANNABLE, | 306 compiler.internalError(NO_LOCATION_SPANNABLE, |
307 "_ConstPropagationVisitor is stale, add missing visit overrides"); | 307 "_ConstPropagationVisitor is stale, add missing visit overrides"); |
308 } | 308 } |
309 | 309 |
310 void visitFunctionDefinition(FunctionDefinition node) { | 310 void visitFunctionDefinition(FunctionDefinition node) { |
311 node.parameters.forEach(visitParameter); | 311 node.parameters.forEach(visit); |
312 setReachable(node.body); | 312 setReachable(node.body); |
313 } | 313 } |
314 | 314 |
315 void visitFieldDefinition(FieldDefinition node) { | 315 void visitFieldDefinition(FieldDefinition node) { |
316 if (node.hasInitializer) { | 316 if (node.hasInitializer) { |
317 setReachable(node.body); | 317 setReachable(node.body); |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 // Expressions. | 321 // Expressions. |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 setReachable(node.definition); | 579 setReachable(node.definition); |
580 ConstantValue constant = | 580 ConstantValue constant = |
581 new FunctionConstantValue(node.definition.element); | 581 new FunctionConstantValue(node.definition.element); |
582 setValue(node, new _ConstnessLattice(constant)); | 582 setValue(node, new _ConstnessLattice(constant)); |
583 } | 583 } |
584 | 584 |
585 void visitGetClosureVariable(GetClosureVariable node) { | 585 void visitGetClosureVariable(GetClosureVariable node) { |
586 setValue(node, _ConstnessLattice.NonConst); | 586 setValue(node, _ConstnessLattice.NonConst); |
587 } | 587 } |
588 | 588 |
| 589 void visitClosureVariable(ClosureVariable node) { |
| 590 } |
| 591 |
589 void visitParameter(Parameter node) { | 592 void visitParameter(Parameter node) { |
590 if (node.parent is FunctionDefinition) { | 593 if (node.parent is FunctionDefinition) { |
591 // Functions may escape and thus their parameters must be initialized to | 594 // Functions may escape and thus their parameters must be initialized to |
592 // NonConst. | 595 // NonConst. |
593 setValue(node, _ConstnessLattice.NonConst); | 596 setValue(node, _ConstnessLattice.NonConst); |
594 } else if (node.parent is Continuation) { | 597 } else if (node.parent is Continuation) { |
595 // Continuations on the other hand are local, and parameters are | 598 // Continuations on the other hand are local, and parameters are |
596 // initialized to Unknown. | 599 // initialized to Unknown. |
597 setValue(node, _ConstnessLattice.Unknown); | 600 setValue(node, _ConstnessLattice.Unknown); |
598 } else { | 601 } else { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 return that; | 696 return that; |
694 } | 697 } |
695 | 698 |
696 if (this.constant == that.constant) { | 699 if (this.constant == that.constant) { |
697 return this; | 700 return this; |
698 } | 701 } |
699 | 702 |
700 return NonConst; | 703 return NonConst; |
701 } | 704 } |
702 } | 705 } |
OLD | NEW |