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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/constant_propagation.dart

Issue 758953002: cps-ir: Optimize identical used with constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add an assert. Created 6 years 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/js_backend_cps_ir_control_flow.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 // Conditions. 600 // Conditions.
601 601
602 void visitIsTrue(IsTrue node) { 602 void visitIsTrue(IsTrue node) {
603 Branch branch = node.parent; 603 Branch branch = node.parent;
604 visitBranch(branch); 604 visitBranch(branch);
605 } 605 }
606 606
607 // JavaScript specific nodes. 607 // JavaScript specific nodes.
608 608
609 void visitIdentical(Identical node) { 609 void visitIdentical(Identical node) {
610 setValue(node, _ConstnessLattice.NonConst); 610 _ConstnessLattice leftConst = getValue(node.left.definition);
karlklose 2014/11/26 08:16:00 Indentation is correct, the highlighting hides the
611 _ConstnessLattice rightConst = getValue(node.left.definition);
612 ConstantValue leftValue = leftConst.constant;
613 ConstantValue rightValue = rightConst.constant;
614 if (leftConst.isUnknown || rightConst.isUnknown) {
615 // Come back later.
616 return;
617 } else if (!leftConst.isConstant || !rightConst.isConstant) {
618 setValue(node, _ConstnessLattice.NonConst);
619 } else if (leftValue.isPrimitive && rightValue.isPrimitive) {
620 assert(leftConst.isConstant && rightConst.isConstant);
621 PrimitiveConstantValue left = leftValue;
622 PrimitiveConstantValue right = rightValue;
623 ConstantValue result =
624 new BoolConstantValue(left.primitiveValue == right.primitiveValue);
625 setValue(node, new _ConstnessLattice(result));
626 }
611 } 627 }
612 } 628 }
613 629
614 /// Represents the constant-state of a variable at some point in the program. 630 /// Represents the constant-state of a variable at some point in the program.
615 /// UNKNOWN: may be some as yet undetermined constant. 631 /// UNKNOWN: may be some as yet undetermined constant.
616 /// CONSTANT: is a constant as stored in the local field. 632 /// CONSTANT: is a constant as stored in the local field.
617 /// NONCONST: not a constant. 633 /// NONCONST: not a constant.
618 class _ConstnessLattice { 634 class _ConstnessLattice {
619 static const int UNKNOWN = 0; 635 static const int UNKNOWN = 0;
620 static const int CONSTANT = 1; 636 static const int CONSTANT = 1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 return that; 679 return that;
664 } 680 }
665 681
666 if (this.constant == that.constant) { 682 if (this.constant == that.constant) {
667 return this; 683 return this;
668 } 684 }
669 685
670 return NonConst; 686 return NonConst;
671 } 687 }
672 } 688 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/js_backend_cps_ir_control_flow.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698