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

Unified Diff: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart

Issue 958603002: Added VariableUse expression to tree IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
diff --git a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
index 768ecaef3fcf99c11a69e911e4f57ac4dde2b46d..71cd69abfdfd6d57a3b9f3b05fe47105b2f35d0f 100644
--- a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
+++ b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
@@ -37,8 +37,8 @@ part of tree_ir.optimization;
* environment and the definition is recursively processed (in the
* new environment at the use site) before being propagated.
*
- * See [visitVariable] for the implementation of the heuristic for propagating
- * a definition.
+ * See [visitVariableUse] for the implementation of the heuristic for
+ * propagating a definition.
*
*
* IF-TO-CONDITIONAL CONVERSION:
@@ -157,9 +157,10 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
Expression visitExpression(Expression e) => e.processed ? e : e.accept(this);
- Expression visitVariable(Variable node) {
+ @override
+ Expression visitVariableUse(VariableUse node) {
// Propagate constant to use site.
- Expression constant = constantEnvironment[node];
+ Expression constant = constantEnvironment[node.variable];
if (constant != null) return constant;
// Propagate a variable's definition to its use site if:
@@ -168,10 +169,11 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
// 2. It was the most recent expression evaluated so that we do not
// reorder expressions with side effects.
if (!environment.isEmpty &&
- environment.last.variable == node &&
+ environment.last.variable == node.variable &&
environment.last.hasExactlyOneUse) {
return visitExpression(environment.removeLast().definition);
}
+
// If the definition could not be propagated, leave the variable use.
return node;
}
@@ -185,7 +187,7 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
return exp is Constant ||
exp is This ||
exp is ReifyTypeVar ||
- exp is Variable && constantEnvironment.containsKey(exp);
+ exp is VariableUse && constantEnvironment.containsKey(exp.variable);
}
Statement visitAssign(Assign node) {
@@ -537,8 +539,8 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
/// If non-null is returned, the caller must discard [e1] and [e2] and use
/// the resulting expression in the tree.
static Expression combineExpressions(Expression e1, Expression e2) {
- if (e1 is Variable && e1 == e2) {
- --e1.readCount; // Two references become one.
+ if (e1 is VariableUse && e2 is VariableUse && e1.variable == e2.variable) {
+ --e1.variable.readCount; // Two references become one.
return e1;
}
if (e1 is Constant && e2 is Constant && e1.value == e2.value) {

Powered by Google App Engine
This is Rietveld 408576698