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

Unified Diff: lib/compiler/implementation/ssa/builder.dart

Issue 10855174: Lazy implementation of final variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix tests. Created 8 years, 4 months 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: 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);
}

Powered by Google App Engine
This is Rietveld 408576698