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

Unified Diff: pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart

Issue 756383004: Refactored treatment of closure variables in dart2js CPS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
diff --git a/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart b/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
index 99e6aa5a02d3b4b83b10c6d8cd602ab3570d3099..eb39923f58d657892d10a6192eb2a049fffaabdc 100644
--- a/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
+++ b/pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart
@@ -49,9 +49,9 @@ class Builder extends cps_ir.Visitor<Node> {
final Map<Element, List<Variable>> element2variables =
<Element,List<Variable>>{};
- /// Like [element2variables], except for closure variables. Closure variables
- /// are not subject to SSA, so at most one variable is used per local.
- final Map<Local, Variable> local2closure = <Local, Variable>{};
+ /// Like [element2variables], except for closure variables.
+ final Map<cps_ir.ClosureVariable, Variable> local2closure =
+ <cps_ir.ClosureVariable, Variable>{};
// Continuations with more than one use are replaced with Tree labels. This
// is the mapping from continuations to labels.
@@ -72,14 +72,14 @@ class Builder extends cps_ir.Visitor<Node> {
/// variables.
Variable phiTempVar;
- Variable getClosureVariable(Local local) {
- if (local.executableContext != currentElement) {
- return parent.getClosureVariable(local);
+ Variable getClosureVariable(cps_ir.ClosureVariable irVariable) {
+ if (irVariable.host != currentElement) {
+ return parent.getClosureVariable(irVariable);
}
- Variable variable = local2closure[local];
+ Variable variable = local2closure[irVariable];
Johnni Winther 2014/12/08 13:15:13 This could be rewritten as a putIfAbsent.
asgerf 2014/12/08 13:44:00 Done.
if (variable == null) {
- variable = new Variable(currentElement, local);
- local2closure[local] = variable;
+ variable = new Variable(currentElement, irVariable.hint);
+ local2closure[irVariable] = variable;
}
return variable;
}
@@ -138,11 +138,19 @@ class Builder extends cps_ir.Visitor<Node> {
return new FieldDefinition(node.element, body);
}
+ Variable getFunctionParameter(cps_ir.Definition variable) {
+ if (variable is cps_ir.Parameter) {
+ return getVariable(variable);
+ } else {
+ return getClosureVariable(variable as cps_ir.ClosureVariable);
+ }
+ }
+
FunctionDefinition buildFunction(cps_ir.FunctionDefinition node) {
currentElement = node.element;
List<Variable> parameters = <Variable>[];
- for (cps_ir.Parameter p in node.parameters) {
- Variable parameter = getVariable(p);
+ for (cps_ir.Definition p in node.parameters) {
+ Variable parameter = getFunctionParameter(p);
assert(parameter != null);
++parameter.writeCount; // Being a parameter counts as a write.
parameters.add(parameter);
@@ -348,18 +356,18 @@ class Builder extends cps_ir.Visitor<Node> {
}
Expression visitGetClosureVariable(cps_ir.GetClosureVariable node) {
- return getClosureVariable(node.variable);
+ return getClosureVariable(node.variable.definition);
}
Statement visitSetClosureVariable(cps_ir.SetClosureVariable node) {
- Variable variable = getClosureVariable(node.variable);
+ Variable variable = getClosureVariable(node.variable.definition);
Expression value = getVariableReference(node.value);
return new Assign(variable, value, visit(node.body),
isDeclaration: node.isDeclaration);
}
Statement visitDeclareFunction(cps_ir.DeclareFunction node) {
- Variable variable = getClosureVariable(node.variable);
+ Variable variable = getClosureVariable(node.variable.definition);
FunctionDefinition function = makeSubFunction(node.definition);
return new FunctionDeclaration(variable, function, visit(node.body));
}

Powered by Google App Engine
This is Rietveld 408576698