| Index: lib/compiler/implementation/ssa/builder.dart
|
| diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart
|
| index e8517ce475764335c6489bd52a864f9fbc6c4a97..21957fd7baba7b16e91bb3565eef335fd843358f 100644
|
| --- a/lib/compiler/implementation/ssa/builder.dart
|
| +++ b/lib/compiler/implementation/ssa/builder.dart
|
| @@ -157,7 +157,9 @@ class SsaBuilderTask extends CompilerTask {
|
| return measure(() {
|
| FunctionElement element = work.element;
|
| HInstruction.idCounter = 0;
|
| - SsaBuilder builder = new SsaBuilder(this, work);
|
| + ConstantSystem constantSystem =
|
| + compiler.constantHandler.constantSystem;
|
| + SsaBuilder builder = new SsaBuilder(constantSystem, this, work);
|
| HGraph graph;
|
| ElementKind kind = element.kind;
|
| if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
|
| @@ -802,6 +804,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| final SsaBuilderTask builder;
|
| final Interceptors interceptors;
|
| final WorkItem work;
|
| + final ConstantSystem constantSystem;
|
| bool methodInterceptionEnabled;
|
| HGraph graph;
|
| LocalsHandler localsHandler;
|
| @@ -832,7 +835,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| Compiler get compiler => builder.compiler;
|
| CodeEmitterTask get emitter => builder.emitter;
|
|
|
| - SsaBuilder(SsaBuilderTask builder, WorkItem work)
|
| + SsaBuilder(this.constantSystem, SsaBuilderTask builder, WorkItem work)
|
| : this.builder = builder,
|
| this.work = work,
|
| interceptors = builder.interceptors,
|
| @@ -930,7 +933,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| returnElement = new Element(const SourceString("result"),
|
| ElementKind.VARIABLE,
|
| function);
|
| - localsHandler.updateLocal(returnElement, graph.addConstantNull());
|
| + Constant constantNull = constantSystem.createNull();
|
| + localsHandler.updateLocal(returnElement, graph.addConstant(constantNull));
|
| elements = compiler.enqueuer.resolution.getCachedElements(function);
|
| FunctionSignature signature = function.computeSignature(compiler);
|
| int index = 0;
|
| @@ -1112,7 +1116,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| SendSet assignment = node.asSendSet();
|
| HInstruction value;
|
| if (assignment === null) {
|
| - value = graph.addConstantNull();
|
| + value = graph.addConstant(constantSystem.createNull());
|
| } else {
|
| Node right = assignment.arguments.head;
|
| TreeElements savedElements = elements;
|
| @@ -1594,7 +1598,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| }
|
| HInstruction buildCondition() {
|
| if (node.condition === null) {
|
| - return graph.addConstantBool(true);
|
| + return graph.addConstant(constantSystem.createBool(true));
|
| }
|
| visit(node.condition);
|
| return popBoolified();
|
| @@ -1782,7 +1786,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| String value = op.source.stringValue;
|
| if (value === '?') {
|
| // TODO(ahe): Implement argument definition test.
|
| - stack.add(graph.addConstantBool(true));
|
| + stack.add(graph.addConstant(constantSystem.createBool(true)));
|
| return;
|
| }
|
| assert(node.argumentsNode is Prefix);
|
| @@ -1804,7 +1808,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| // See if we can constant-fold right away. This avoids rewrites later on.
|
| if (operand is HConstant) {
|
| HConstant constant = operand;
|
| - Constant folded = result.operation.fold(constant.constant);
|
| + Constant folded =
|
| + result.operation(constantSystem).fold(constant.constant);
|
| if (folded !== null) {
|
| stack.add(graph.addConstant(folded));
|
| return;
|
| @@ -2087,7 +2092,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| // compiler and answer true to any is check involving a type variable
|
| // -- both is T and is !T -- until we have a proper implementation of
|
| // reified generics.
|
| - stack.add(graph.addConstantBool(true));
|
| + stack.add(graph.addConstant(constantSystem.createBool(true)));
|
| } else {
|
| HInstruction instruction;
|
| if (typeInfo !== null) {
|
| @@ -2416,10 +2421,12 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| String name = identifier.source.slowToString();
|
| // TODO(ahe): Add the arguments to this list.
|
| push(new HLiteralList([]));
|
| + Constant nameConstant =
|
| + constantSystem.createString(new DartString.literal(name), node);
|
| var inputs = <HInstruction>[
|
| target,
|
| self,
|
| - graph.addConstantString(new DartString.literal(name), node),
|
| + graph.addConstant(nameConstant),
|
| pop()];
|
| push(new HInvokeSuper(inputs));
|
| }
|
| @@ -2487,8 +2494,9 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| }
|
| } else {
|
| // The type variable is a type (e.g. int).
|
| - return graph.addConstantString(
|
| - new LiteralDartString('$argument'), currentNode);
|
| + return graph.addConstant(
|
| + constantSystem.createString(new LiteralDartString('$argument'),
|
| + currentNode));
|
| }
|
| }
|
|
|
| @@ -2542,7 +2550,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| Selector selector = elements.getSelector(node);
|
| Element element = elements[node];
|
| if (element === compiler.assertMethod && !compiler.enableUserAssertions) {
|
| - stack.add(graph.addConstantNull());
|
| + stack.add(graph.addConstant(constantSystem.createNull()));
|
| return;
|
| }
|
| compiler.ensure(element.kind !== ElementKind.GENERATIVE_CONSTRUCTOR);
|
| @@ -2605,7 +2613,9 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
|
|
| void generateRuntimeError(Node node, String message) {
|
| DartString messageObject = new DartString.literal(message);
|
| - HInstruction errorMessage = graph.addConstantString(messageObject, node);
|
| + Constant messageConstant =
|
| + constantSystem.createString(messageObject, node);
|
| + HInstruction errorMessage = graph.addConstant(messageConstant);
|
| Element helper = interceptors.getThrowRuntimeError();
|
| pushInvokeHelper1(helper, errorMessage);
|
| }
|
| @@ -2619,10 +2629,14 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| Element helper =
|
| compiler.findHelper(const SourceString('throwNoSuchMethod'));
|
| DartString receiverLiteral = new DartString.literal('');
|
| - HInstruction receiver = graph.addConstantString(receiverLiteral, node);
|
| + Constant receiverConstant =
|
| + constantSystem.createString(receiverLiteral, node);
|
| + HInstruction receiver = graph.addConstant(receiverConstant);
|
| String constructorName = 'constructor ${message.arguments[0]}';
|
| DartString nameLiteral = new DartString.literal(constructorName);
|
| - HInstruction name = graph.addConstantString(nameLiteral, node.send);
|
| + Constant nameConstant =
|
| + constantSystem.createString(nameLiteral, node.send);
|
| + HInstruction name = graph.addConstant(nameConstant);
|
| List<HInstruction> inputs = <HInstruction>[];
|
| node.send.arguments.forEach((argumentNode) {
|
| visit(argumentNode);
|
| @@ -2691,7 +2705,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| index = pop();
|
| } else {
|
| index = pop();
|
| - value = graph.addConstantInt(1);
|
| + value = graph.addConstant(constantSystem.createInt(1));
|
| }
|
| HStatic indexMethod = new HStatic(interceptors.getIndexInterceptor());
|
| add(indexMethod);
|
| @@ -2741,7 +2755,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| visit(node.argumentsNode);
|
| right = pop();
|
| } else {
|
| - right = graph.addConstantInt(1);
|
| + right = graph.addConstant(constantSystem.createInt(1));
|
| }
|
| visitBinary(left, op, right);
|
| HInstruction operation = pop();
|
| @@ -2761,25 +2775,27 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| }
|
|
|
| void visitLiteralInt(LiteralInt node) {
|
| - stack.add(graph.addConstantInt(node.value));
|
| + stack.add(graph.addConstant(constantSystem.createInt(node.value)));
|
| }
|
|
|
| void visitLiteralDouble(LiteralDouble node) {
|
| - stack.add(graph.addConstantDouble(node.value));
|
| + stack.add(graph.addConstant(constantSystem.createDouble(node.value)));
|
| }
|
|
|
| void visitLiteralBool(LiteralBool node) {
|
| - stack.add(graph.addConstantBool(node.value));
|
| + stack.add(graph.addConstant(constantSystem.createBool(node.value)));
|
| }
|
|
|
| void visitLiteralString(LiteralString node) {
|
| - stack.add(graph.addConstantString(node.dartString, node));
|
| + Constant constant = constantSystem.createString(node.dartString, node);
|
| + stack.add(graph.addConstant(constant));
|
| }
|
|
|
| void visitStringJuxtaposition(StringJuxtaposition node) {
|
| if (!node.isInterpolation) {
|
| // This is a simple string with no interpolations.
|
| - stack.add(graph.addConstantString(node.dartString, node));
|
| + Constant constant = constantSystem.createString(node.dartString, node);
|
| + stack.add(graph.addConstant(constant));
|
| return;
|
| }
|
| StringBuilderVisitor stringBuilder = new StringBuilderVisitor(this, node);
|
| @@ -2788,7 +2804,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| }
|
|
|
| void visitLiteralNull(LiteralNull node) {
|
| - stack.add(graph.addConstantNull());
|
| + stack.add(graph.addConstant(constantSystem.createNull()));
|
| }
|
|
|
| visitNodeList(NodeList node) {
|
| @@ -2828,7 +2844,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| }
|
| HInstruction value;
|
| if (node.expression === null) {
|
| - value = graph.addConstantNull();
|
| + value = graph.addConstant(constantSystem.createNull());
|
| } else {
|
| visit(node.expression);
|
| value = pop();
|
| @@ -2844,7 +2860,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| if (node.expression === null) {
|
| HInstruction exception = rethrowableException;
|
| if (exception === null) {
|
| - exception = graph.addConstantNull();
|
| + exception = graph.addConstant(constantSystem.createNull());
|
| compiler.reportError(node,
|
| 'throw without expression outside catch block');
|
| }
|
| @@ -2866,7 +2882,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| link = link.tail) {
|
| Node definition = link.head;
|
| if (definition is Identifier) {
|
| - HInstruction initialValue = graph.addConstantNull();
|
| + HInstruction initialValue =
|
| + graph.addConstant(constantSystem.createNull());
|
| localsHandler.updateLocal(elements[definition], initialValue);
|
| } else {
|
| assert(definition is SendSet);
|
| @@ -3464,7 +3481,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| VariableDefinitions declaration = catchBlock.formals.nodes.head;
|
| HInstruction condition = null;
|
| if (declaration.type == null) {
|
| - condition = graph.addConstantBool(true);
|
| + condition = graph.addConstant(constantSystem.createBool(true));
|
| stack.add(condition);
|
| } else {
|
| // TODO(aprelev@gmail.com): Once old catch syntax is removed
|
| @@ -3575,7 +3592,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
|
| /** HACK HACK HACK */
|
| void hackAroundPossiblyAbortingBody(Node statement, void body()) {
|
| visitCondition() {
|
| - stack.add(graph.addConstantBool(true));
|
| + stack.add(graph.addConstant(constantSystem.createBool(true)));
|
| }
|
| buildBody() {
|
| // TODO(lrn): Make sure to take continue into account.
|
| @@ -3863,8 +3880,10 @@ class SsaBranchBuilder {
|
| }
|
|
|
| handleIf(visitCondition, visitThen, null);
|
| + HConstant notIsAnd =
|
| + builder.graph.addConstant(builder.constantSystem.createBool(!isAnd));
|
| HPhi result = new HPhi.manyInputs(null,
|
| - <HInstruction>[boolifiedRight, builder.graph.addConstantBool(!isAnd)]);
|
| + <HInstruction>[boolifiedRight, notIsAnd]);
|
| builder.current.addPhi(result);
|
| builder.stack.add(result);
|
| }
|
|
|