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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10855174: Lazy implementation of final variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase and merge. Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 6
7 final JavaScriptBackend backend; 7 final JavaScriptBackend backend;
8 8
9 SsaCodeGeneratorTask(JavaScriptBackend backend) 9 SsaCodeGeneratorTask(JavaScriptBackend backend)
10 : this.backend = backend, 10 : this.backend = backend,
11 super(backend.compiler); 11 super(backend.compiler);
12 String get name => 'SSA code generator'; 12 String get name => 'SSA code generator';
13 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; 13 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter;
14 14
15 15
16 js.Fun buildJavaScriptFunction(FunctionElement element, 16 js.Fun buildJavaScriptFunction(FunctionElement element,
17 List<js.Parameter> parameters, 17 List<js.Parameter> parameters,
18 js.Block body) { 18 js.Block body) {
19 FunctionExpression expression = element.cachedNode; 19 FunctionExpression expression = element.cachedNode;
20 js.Fun result = new js.Fun(parameters, body); 20 js.Fun result = new js.Fun(parameters, body);
21 result.sourcePosition = expression.getBeginToken(); 21 result.sourcePosition = expression.getBeginToken();
22 result.endSourcePosition = expression.getEndToken(); 22 result.endSourcePosition = expression.getEndToken();
23 return result; 23 return result;
24 } 24 }
25 25
26 CodeBuffer prettyPrint(js.Node node, Element positionElement) { 26 CodeBuffer prettyPrint(js.Node node, Element positionElement) {
27 return js.prettyPrint(node, compiler, positionElement); 27 return js.prettyPrint(node, compiler, positionElement);
28 } 28 }
29 29
30 CodeBuffer generateCode(WorkItem work, HGraph graph) {
31 if (work.element.isField()) {
32 return generateLazyInitializer(work, graph);
33 } else {
34 return generateMethod(work, graph);
35 }
36 }
37
38 CodeBuffer generateLazyInitializer(work, graph) {
39 return measure(() {
40 compiler.tracer.traceGraph("codegen", graph);
41 List<js.Parameter> parameters = <js.Parameter>[];
42 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator(
43 backend, work, parameters, new Map<Element, String>());
44 codegen.visitGraph(graph);
45 js.Block body = codegen.body;
46 Element element = work.element;
47 js.Fun fun = new js.Fun(parameters, body);
48 return prettyPrint(fun, element);
49 });
50 }
51
30 CodeBuffer generateMethod(WorkItem work, HGraph graph) { 52 CodeBuffer generateMethod(WorkItem work, HGraph graph) {
31 return measure(() { 53 return measure(() {
32 JavaScriptItemCompilationContext context = work.compilationContext; 54 JavaScriptItemCompilationContext context = work.compilationContext;
33 HTypeMap types = context.types; 55 HTypeMap types = context.types;
34 graph.exit.predecessors.forEach((block) { 56 graph.exit.predecessors.forEach((block) {
35 assert(block.last is HGoto || block.last is HReturn); 57 assert(block.last is HGoto || block.last is HReturn);
36 if (block.last is HReturn) { 58 if (block.last is HReturn) {
37 backend.registerReturnType(work.element, types[block.last.inputs[0]]); 59 backend.registerReturnType(work.element, types[block.last.inputs[0]]);
38 } else { 60 } else {
39 backend.registerReturnType(work.element, HType.NULL); 61 backend.registerReturnType(work.element, HType.NULL);
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 backend.registerNonCallStaticUse(node); 1987 backend.registerNonCallStaticUse(node);
1966 break; 1988 break;
1967 } 1989 }
1968 } 1990 }
1969 } 1991 }
1970 }); 1992 });
1971 world.registerStaticUse(node.element); 1993 world.registerStaticUse(node.element);
1972 push(new js.VariableUse(compiler.namer.isolateAccess(node.element))); 1994 push(new js.VariableUse(compiler.namer.isolateAccess(node.element)));
1973 } 1995 }
1974 1996
1997 void visitLazyStatic(HLazyStatic node) {
1998 Element element = node.element;
1999 world.registerStaticUse(element);
2000 String lazyGetter = compiler.namer.isolateLazyInitializerAccess(element);
2001 js.VariableUse target = new js.VariableUse(lazyGetter);
2002 js.Call call = new js.Call(target, <js.Expression>[]);
2003 push(call, node);
2004 }
2005
1975 void visitStaticStore(HStaticStore node) { 2006 void visitStaticStore(HStaticStore node) {
1976 world.registerStaticUse(node.element); 2007 world.registerStaticUse(node.element);
1977 js.VariableUse variableUse = 2008 js.VariableUse variableUse =
1978 new js.VariableUse(compiler.namer.isolateAccess(node.element)); 2009 new js.VariableUse(compiler.namer.isolateAccess(node.element));
1979 use(node.inputs[0]); 2010 use(node.inputs[0]);
1980 push(new js.Assignment(variableUse, pop()), node); 2011 push(new js.Assignment(variableUse, pop()), node);
1981 } 2012 }
1982 2013
1983 void visitStringConcat(HStringConcat node) { 2014 void visitStringConcat(HStringConcat node) {
1984 if (isEmptyString(node.left)) { 2015 if (isEmptyString(node.left)) {
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 arguments.add(new js.LiteralNumber('0')); 2470 arguments.add(new js.LiteralNumber('0'));
2440 } 2471 }
2441 2472
2442 js.Expression bailoutTarget; 2473 js.Expression bailoutTarget;
2443 if (element.isInstanceMember()) { 2474 if (element.isInstanceMember()) {
2444 // TODO(ngeoffray): This does not work in case we come from a 2475 // TODO(ngeoffray): This does not work in case we come from a
2445 // super call. We must make bailout names unique. 2476 // super call. We must make bailout names unique.
2446 String bailoutName = namer.getBailoutName(element); 2477 String bailoutName = namer.getBailoutName(element);
2447 bailoutTarget = new js.PropertyAccess.field(new js.This(), bailoutName); 2478 bailoutTarget = new js.PropertyAccess.field(new js.This(), bailoutName);
2448 } else { 2479 } else {
2480 assert(!element.isField());
2449 bailoutTarget = new js.VariableUse(namer.isolateBailoutAccess(element)); 2481 bailoutTarget = new js.VariableUse(namer.isolateBailoutAccess(element));
2450 } 2482 }
2451 js.Call call = new js.Call(bailoutTarget, arguments); 2483 js.Call call = new js.Call(bailoutTarget, arguments);
2452 attachLocation(call, guard); 2484 attachLocation(call, guard);
2453 return new js.Return(call); 2485 return new js.Return(call);
2454 } 2486 }
2455 2487
2456 void visitTypeGuard(HTypeGuard node) { 2488 void visitTypeGuard(HTypeGuard node) {
2457 HInstruction input = node.guarded; 2489 HInstruction input = node.guarded;
2458 Element indexingBehavior = compiler.jsIndexingBehaviorInterface; 2490 Element indexingBehavior = compiler.jsIndexingBehaviorInterface;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
2900 if (leftType.canBeNull() && rightType.canBeNull()) { 2932 if (leftType.canBeNull() && rightType.canBeNull()) {
2901 if (left.isConstantNull() || right.isConstantNull() || 2933 if (left.isConstantNull() || right.isConstantNull() ||
2902 (leftType.isPrimitive() && leftType == rightType)) { 2934 (leftType.isPrimitive() && leftType == rightType)) {
2903 return '=='; 2935 return '==';
2904 } 2936 }
2905 return null; 2937 return null;
2906 } else { 2938 } else {
2907 return '==='; 2939 return '===';
2908 } 2940 }
2909 } 2941 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/builder.dart ('k') | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698