Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart b/sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart |
| index b334cb8d8a322acfa714173381e8d90b5a89323c..06d6731d3f72765ce63e4afc29d3fe0931f2e81f 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart |
| @@ -191,6 +191,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| // used to determine if a join-point continuation needs to be passed |
| // arguments, and what the arguments are. |
| final Map<Element, int> variableIndex; |
| + final List<Element> index2variable; |
| final List<ir.Parameter> freeVars; |
| final List<ir.Primitive> assignedVars; |
| @@ -201,6 +202,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| variableIndex = <Element, int>{}, |
| freeVars = null, |
| assignedVars = <ir.Primitive>[], |
| + index2variable = <Element>[], |
| super(elements, compiler); |
| /// Construct a delimited visitor. |
| @@ -214,6 +216,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| growable: false), |
| assignedVars = new List<ir.Primitive>.generate( |
| parent.assignedVars.length, (_) => null), |
| + index2variable = new List<Element>.from(parent.index2variable), |
| super(parent.elements, parent.compiler); |
| /** |
| @@ -240,6 +243,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| parameters.add(parameter); |
| variableIndex[parameterElement] = assignedVars.length; |
| assignedVars.add(parameter); |
| + index2variable.add(parameterElement); |
| }); |
| visit(function.body); |
| @@ -345,7 +349,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| // left and right subterms we will still have a join continuation with |
| // possibly arguments passed to it. Such singly-used continuations |
| // are eliminated by the shrinking conversions. |
| - parameters.add(new ir.Parameter(null)); |
| + parameters.add(new ir.Parameter(index2variable[i])); |
| ir.Primitive reachingDefinition = |
| assignedVars[i] == null ? freeVars[i] : assignedVars[i]; |
| leftArguments.add( |
| @@ -395,7 +399,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| // If not, no value needs to be passed to the join point. |
| if (reachingAssignment == null) continue; |
| - parameters.add(new ir.Parameter(null)); |
| + parameters.add(new ir.Parameter(index2variable[i])); |
| ir.Definition entryAssignment = assignedVars[i]; |
| entryArguments.add( |
| entryAssignment == null ? freeVars[i] : entryAssignment); |
| @@ -628,16 +632,22 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| assert(!definition.arguments.isEmpty); |
| assert(definition.arguments.tail.isEmpty); |
| ir.Primitive initialValue = visit(definition.arguments.head); |
| + // If a temporary was introduced for the initializer expression, |
|
Kevin Millikin (Google)
2014/06/10 11:33:01
Hmm, the comment says "If" but the code is uncondi
asgerf
2014/06/10 12:22:24
The 'if' I mention is inside the method (if elemen
|
| + // do not use a separate variable for it. |
| + useElementForVariable(initialValue, element); |
| variableIndex[element] = assignedVars.length; |
| assignedVars.add(initialValue); |
| + index2variable.add(element); |
| } else { |
| assert(definition is ast.Identifier); |
| // The initial value is null. |
| // TODO(kmillikin): Consider pooling constants. |
| ir.Constant constant = new ir.Constant(constantSystem.createNull()); |
| + useElementForVariable(constant, element); |
| add(new ir.LetPrim(constant)); |
| variableIndex[element] = assignedVars.length; |
| assignedVars.add(constant); |
| + index2variable.add(element); |
| } |
| } |
| return null; |
| @@ -1088,6 +1098,7 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| assert(!node.arguments.isEmpty); |
| assert(node.arguments.tail.isEmpty); |
| ir.Primitive result = visit(node.arguments.head); |
| + useElementForVariable(result, element); |
| assignedVars[variableIndex[element]] = result; |
| return result; |
| } else if (Elements.isStaticOrTopLevel(element)) { |
| @@ -1177,6 +1188,16 @@ class IrBuilder extends ResolvedVisitor<ir.Primitive> { |
| return v; |
| } |
| + /// Associates [primitive] with the given [element]. |
| + /// This is used as a hint when choosing variables names later when |
| + /// translating out of the IR again. |
| + void useElementForVariable(ir.Primitive primitive, Element element) { |
|
Kevin Millikin (Google)
2014/06/10 11:33:01
This works better as a method on Primitive, doesn'
asgerf
2014/06/10 12:22:24
Yes, good idea.
|
| + // Use the first assigned element |
| + if (primitive.element != null) return; |
| + |
| + primitive.element = element; |
| + } |
| + |
| static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted"; |
| ir.Primitive giveup() => throw ABORT_IRNODE_BUILDER; |