Chromium Code Reviews| Index: frog/leg/ssa/builder.dart |
| diff --git a/frog/leg/ssa/builder.dart b/frog/leg/ssa/builder.dart |
| index ba2ee880d03ebc76fe3c48fcd0cde53ab7aaa347..859aa4aff6bd5c4711fd50ae177ae77a23462f88 100644 |
| --- a/frog/leg/ssa/builder.dart |
| +++ b/frog/leg/ssa/builder.dart |
| @@ -854,12 +854,9 @@ class SsaBuilder implements Visitor { |
| if (localsHandler.hasValueForDirectLocal(member)) { |
| value = localsHandler.readLocal(member); |
| } else { |
| - var fieldValue = |
| + Constant fieldValue = |
| compiler.compileTimeConstantHandler.compileVariable(member); |
| - // TODO(floitsch): this constant should be treated like all |
| - // other constants and should be at the top of the graph. |
| - value = new HLiteral.internal(fieldValue, HType.UNKNOWN); |
| - add(value); |
| + value = graph.addNewConstant(fieldValue); |
| } |
| constructorArguments.add(value); |
| } |
| @@ -1300,20 +1297,21 @@ class SsaBuilder implements Visitor { |
| visit(node.receiver); |
| assert(op.token.kind !== PLUS_TOKEN); |
| HInstruction operand = pop(); |
| + // See if we can constant-fold right away. This avoids rewrites later on. |
|
kasperl
2012/03/05 13:53:16
Nice. I wonder if there's anyway of avoiding to cr
floitsch
2012/03/05 15:43:24
We could, but I'm not sure it wins us that much. A
|
| + if (operand is HConstant) { |
| + HConstant typedOperand = operand; |
| + Constant constant = typedOperand.constant; |
| + Constant folded = constant.unaryFold(op.source.stringValue); |
| + if (folded !== null) { |
| + stack.add(graph.addNewConstant(folded)); |
| + return; |
| + } |
| + } |
| HInstruction target = |
| new HStatic(interceptors.getPrefixOperatorInterceptor(op)); |
| add(target); |
| switch (op.source.stringValue) { |
| - case "-": |
| - // TODO(kasperl): Avoid calling visit(node.receiver) above. |
| - if ((operand is HLiteral) && (operand.value is double)) { |
| - stack.add(graph.addNewLiteralDouble(-operand.value)); |
| - } else if ((operand is HLiteral) && (operand.value is int)) { |
| - stack.add(graph.addNewLiteralInt(-operand.value)); |
| - } else { |
| - push(new HNegate(target, operand)); |
| - } |
| - break; |
| + case "-": push(new HNegate(target, operand)); break; |
| case "~": push(new HBitNot(target, operand)); break; |
| default: unreachable(); |
| } |
| @@ -1621,12 +1619,8 @@ class SsaBuilder implements Visitor { |
| if (foundIndex != -1) { |
| list.add(namedArguments[foundIndex]); |
| } else { |
| - // TODO(kasperl): This needs more work. Ideally these |
| - // constants should be treated like any other constant and |
| - // canonicalized by the graph methods. |
| - var constant = compiler.compileVariable(parameter); |
| - push(new HLiteral.internal(constant, HType.UNKNOWN)); |
| - list.add(pop()); |
| + Constant constant = compiler.compileVariable(parameter); |
| + list.add(graph.addNewConstant(constant)); |
| } |
| } |
| } |
| @@ -1861,7 +1855,7 @@ class SsaBuilder implements Visitor { |
| index = pop(); |
| } else { |
| index = pop(); |
| - value = graph.addNewLiteralInt(1); |
| + value = graph.addNewConstant(new IntConstant(1)); |
| } |
| HStatic indexMethod = new HStatic(interceptors.getIndexInterceptor()); |
| add(indexMethod); |
| @@ -1902,7 +1896,7 @@ class SsaBuilder implements Visitor { |
| visit(node.argumentsNode); |
| right = pop(); |
| } else { |
| - right = graph.addNewLiteralInt(1); |
| + right = graph.addNewConstant(new IntConstant(1)); |
| } |
| visitBinary(left, op, right); |
| HInstruction operation = pop(); |
| @@ -1916,19 +1910,19 @@ class SsaBuilder implements Visitor { |
| } |
| void visitLiteralInt(LiteralInt node) { |
| - stack.add(graph.addNewLiteralInt(node.value)); |
| + stack.add(graph.addNewConstant(new IntConstant(node.value))); |
| } |
| void visitLiteralDouble(LiteralDouble node) { |
| - stack.add(graph.addNewLiteralDouble(node.value)); |
| + stack.add(graph.addNewConstant(new DoubleConstant(node.value))); |
| } |
| void visitLiteralBool(LiteralBool node) { |
| - stack.add(graph.addNewLiteralBool(node.value)); |
| + stack.add(graph.addNewConstant(new BoolConstant(node.value))); |
| } |
| void visitLiteralString(LiteralString node) { |
| - stack.add(graph.addNewLiteralString(node.dartString)); |
| + stack.add(graph.addNewConstant(new StringConstant(node.dartString))); |
| } |
| void visitLiteralStringJuxtaposition(LiteralStringJuxtaposition node) { |
| @@ -1936,7 +1930,7 @@ class SsaBuilder implements Visitor { |
| } |
| void visitLiteralNull(LiteralNull node) { |
| - stack.add(graph.addNewLiteralNull()); |
| + stack.add(graph.addNewConstant(const NullConstant())); |
| } |
| visitNodeList(NodeList node) { |
| @@ -1957,7 +1951,7 @@ class SsaBuilder implements Visitor { |
| visitReturn(Return node) { |
| HInstruction value; |
| if (node.expression === null) { |
| - value = graph.addNewLiteralNull(); |
| + value = graph.addNewConstant(const NullConstant()); |
| } else { |
| visit(node.expression); |
| value = pop(); |
| @@ -1969,7 +1963,7 @@ class SsaBuilder implements Visitor { |
| if (node.expression === null) { |
| HInstruction exception = rethrowableException; |
| if (exception === null) { |
| - exception = graph.addNewLiteralNull(); |
| + exception = graph.addNewConstant(const NullConstant()); |
| compiler.reportError(node, |
| 'throw without expression outside catch block'); |
| } |
| @@ -1991,7 +1985,7 @@ class SsaBuilder implements Visitor { |
| link = link.tail) { |
| Node definition = link.head; |
| if (definition is Identifier) { |
| - HInstruction initialValue = graph.addNewLiteralNull(); |
| + HInstruction initialValue = graph.addNewConstant(const NullConstant()); |
| localsHandler.updateLocal(elements[definition], initialValue); |
| } else { |
| assert(definition is SendSet); |
| @@ -2300,7 +2294,7 @@ class SsaBuilder implements Visitor { |
| VariableDefinitions declaration = catchBlock.formals.nodes.head; |
| HInstruction condition = null; |
| if (declaration.type == null) { |
| - condition = graph.addNewLiteralTrue(); |
| + condition = graph.addNewConstant(new BoolConstant(true)); |
| stack.add(condition); |
| } else { |
| Element typeElement = elements[declaration.type]; |
| @@ -2370,7 +2364,7 @@ class SsaBuilder implements Visitor { |
| generateUnimplemented(String reason, [bool isExpression = false]) { |
| DartString string = new DartString.literal(reason); |
| - HInstruction message = graph.addNewLiteralString(string); |
| + HInstruction message = graph.addNewConstant(new StringConstant(string)); |
| // Normally, we would call [close] here. However, then we hit |
| // another unimplemented feature: aborting loop body. Simply |
| @@ -2378,7 +2372,7 @@ class SsaBuilder implements Visitor { |
| // isn't a control flow instruction. So we inline parts of [add]. |
| current.addAfter(current.last, new HThrow(message)); |
| if (isExpression) { |
| - stack.add(graph.addNewLiteralNull()); |
| + stack.add(graph.addNewConstant(const NullConstant())); |
| } |
| } |
| } |