Chromium Code Reviews| Index: lib/compiler/implementation/ssa/builder.dart |
| diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart |
| index 941cbbb59f6e0a97536267ef8efdb9173040c870..610f9a4fc4088155d95c26ab6da20b4db0d45ec3 100644 |
| --- a/lib/compiler/implementation/ssa/builder.dart |
| +++ b/lib/compiler/implementation/ssa/builder.dart |
| @@ -153,7 +153,7 @@ class SsaBuilderTask extends CompilerTask { |
| HGraph build(WorkItem work) { |
| return measure(() { |
| - FunctionElement element = work.element; |
| + Element element = work.element; |
| HInstruction.idCounter = 0; |
| SsaBuilder builder = new SsaBuilder(this, work); |
| HGraph graph; |
| @@ -165,26 +165,32 @@ class SsaBuilderTask extends CompilerTask { |
| kind === ElementKind.GETTER || |
| kind === ElementKind.SETTER) { |
| graph = builder.buildMethod(work.element); |
| + } else if (kind === ElementKind.FIELD) { |
| + graph = builder.buildLazyInitializer(work.element); |
| } |
| assert(graph.isValid()); |
| - bool inLoop = functionsCalledInLoop.contains(element); |
| - if (!inLoop) { |
| - Selector selector = selectorsCalledInLoop[element.name]; |
| - inLoop = selector !== null && selector.applies(element, compiler); |
| - } |
| - graph.calledInLoop = inLoop; |
| - |
| - // If there is an estimate of the parameter types assume these types when |
| - // compiling. |
| - List<HType> parameterTypes = |
| - backend.optimisticParameterTypesWithRecompilationOnTypeChange( |
| - element); |
| - if (parameterTypes != null) { |
| - FunctionSignature signature = element.computeSignature(compiler); |
| - int i = 0; |
| - signature.forEachParameter((Element param) { |
| - builder.parameters[param].guaranteedType = parameterTypes[i++]; |
| - }); |
| + if (kind !== ElementKind.FIELD) { |
| + bool inLoop = functionsCalledInLoop.contains(element); |
| + if (!inLoop) { |
| + Selector selector = selectorsCalledInLoop[element.name]; |
| + inLoop = selector !== null && selector.applies(element, compiler); |
| + } |
| + graph.calledInLoop = inLoop; |
| + |
| + // If there is an estimate of the parameter types assume these types |
| + // when compiling. |
| + List<HType> parameterTypes = |
| + backend.optimisticParameterTypesWithRecompilationOnTypeChange( |
| + element); |
| + if (parameterTypes != null) { |
| + FunctionElement functionElement = element; |
| + FunctionSignature signature = |
| + functionElement.computeSignature(compiler); |
| + int i = 0; |
| + signature.forEachParameter((Element param) { |
| + builder.parameters[param].guaranteedType = parameterTypes[i++]; |
| + }); |
| + } |
| } |
| if (compiler.tracer.enabled) { |
| @@ -860,6 +866,20 @@ class SsaBuilder extends ResolvedVisitor implements Visitor { |
| return closeFunction(); |
| } |
| + HGraph buildLazyInitializer(VariableElement variable) { |
| + HBasicBlock block = graph.addNewBlock(); |
| + open(graph.entry); |
| + close(new HGoto()).addSuccessor(block); |
| + open(block); |
| + SendSet node = variable.parseNode(compiler); |
| + Link<Node> link = node.arguments; |
| + assert(!link.isEmpty() && link.tail.isEmpty()); |
| + visit(link.head); |
| + close(new HReturn(pop())).addSuccessor(graph.exit); |
| + graph.finalize(); |
| + return graph; |
| + } |
| + |
| /** |
| * Returns the constructor body associated with the given constructor or |
| * creates a new constructor body, if none can be found. |
| @@ -1051,7 +1071,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor { |
| if (value === null) { |
| // The field has no value in the initializer list. Initialize it |
| // with the declaration-site constant (if any). |
| - Constant fieldValue = compiler.constantHandler.compileVariable(member); |
| + Constant fieldValue = compiler.compileConstant(member); |
| value = graph.addConstant(fieldValue); |
| } |
| constructorArguments.add(value); |
| @@ -1768,10 +1788,18 @@ class SsaBuilder extends ResolvedVisitor implements Visitor { |
| void generateGetter(Send send, Element element) { |
| if (Elements.isStaticOrTopLevelField(element)) { |
| + Constant value; |
| if (element.kind == ElementKind.FIELD && !element.isAssignable()) { |
|
kasperl
2012/08/16 14:41:37
isField?
floitsch
2012/08/16 22:52:33
Done.
|
| - // A static final. Get its constant value and inline it. |
| - Constant value = compiler.constantHandler.compileVariable(element); |
| + // A static final or const. Get its constant value and inline it if |
| + // the value can be compiled eagerly. |
| + value = compiler.compileVariable(element); |
| + } |
| + if (value != null) { |
| stack.add(graph.addConstant(value)); |
| + } else if (element.kind == ElementKind.FIELD && |
| + compiler.isLazilyInitialized(element)) { |
| + assert(element.kind == ElementKind.FIELD); |
|
kasperl
2012/08/16 14:41:37
Seems like a completely trivial assert given the c
floitsch
2012/08/16 22:52:33
Done.
|
| + push(new HLazyStatic(element)); |
| } else { |
| Selector selector = elements.getSelector(send); |
| push(new HStatic(element)); |
| @@ -1975,7 +2003,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor { |
| } |
| HInstruction compileConstant(Element constantElement) { |
| - Constant constant = compiler.compileVariable(constantElement); |
| + Constant constant = compiler.compileConstant(constantElement); |
| return graph.addConstant(constant); |
| } |