| OLD | NEW |
| 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 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
| 7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 8 : this.backend = backend, | 8 : this.backend = backend, |
| 9 super(backend.compiler); | 9 super(backend.compiler); |
| 10 String get name() => 'SSA code generator'; | 10 String get name() => 'SSA code generator'; |
| 11 NativeEmitter get nativeEmitter() => backend.emitter.nativeEmitter; | 11 NativeEmitter get nativeEmitter() => backend.emitter.nativeEmitter; |
| 12 | 12 |
| 13 | 13 |
| 14 js.Fun buildJavaScriptFunction(FunctionElement element, | 14 js.Fun buildJavaScriptFunction(FunctionElement element, |
| 15 List<js.Parameter> parameters, | 15 List<js.Parameter> parameters, |
| 16 js.Block body) { | 16 js.Block body) { |
| 17 FunctionExpression expression = element.cachedNode; | 17 FunctionExpression expression = element.cachedNode; |
| 18 js.Fun result = new js.Fun(parameters, body); | 18 js.Fun result = new js.Fun(parameters, body); |
| 19 result.sourcePosition = expression.getBeginToken(); | 19 result.sourcePosition = expression.getBeginToken(); |
| 20 result.endSourcePosition = expression.getEndToken(); | 20 result.endSourcePosition = expression.getEndToken(); |
| 21 return result; | 21 return result; |
| 22 } | 22 } |
| 23 | 23 |
| 24 CodeBuffer prettyPrint(js.Node node, Element positionElement) { | 24 CodeBuffer prettyPrint(js.Node node, Element positionElement) { |
| 25 return js.prettyPrint(node, compiler, positionElement); | 25 return js.prettyPrint(node, compiler, positionElement); |
| 26 } | 26 } |
| 27 | 27 |
| 28 CodeBuffer generateCode(WorkItem work, HGraph graph) { |
| 29 if (work.element.isField()) { |
| 30 return generateLazyInitializer(work, graph); |
| 31 } else { |
| 32 return generateMethod(work, graph); |
| 33 } |
| 34 } |
| 35 |
| 36 CodeBuffer generateLazyInitializer(work, graph) { |
| 37 return measure(() { |
| 38 compiler.tracer.traceGraph("codegen", graph); |
| 39 List<js.Parameter> parameters = <js.Parameter>[]; |
| 40 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator( |
| 41 backend, work, parameters, new Map<Element, String>()); |
| 42 codegen.visitGraph(graph); |
| 43 js.Block body = codegen.body; |
| 44 Element element = work.element; |
| 45 js.Fun fun = new js.Fun(parameters, body); |
| 46 return prettyPrint(fun, element); |
| 47 }); |
| 48 } |
| 49 |
| 28 CodeBuffer generateMethod(WorkItem work, HGraph graph) { | 50 CodeBuffer generateMethod(WorkItem work, HGraph graph) { |
| 29 return measure(() { | 51 return measure(() { |
| 30 compiler.tracer.traceGraph("codegen", graph); | 52 compiler.tracer.traceGraph("codegen", graph); |
| 31 Map<Element, String> parameterNames = getParameterNames(work); | 53 Map<Element, String> parameterNames = getParameterNames(work); |
| 32 parameterNames.forEach((element, name) { | 54 parameterNames.forEach((element, name) { |
| 33 compiler.enqueuer.codegen.addToWorkList(element); | 55 compiler.enqueuer.codegen.addToWorkList(element); |
| 34 }); | 56 }); |
| 35 List<js.Parameter> parameters = <js.Parameter>[]; | 57 List<js.Parameter> parameters = <js.Parameter>[]; |
| 36 parameterNames.forEach((element, name) { | 58 parameterNames.forEach((element, name) { |
| 37 parameters.add(new js.Parameter(name)); | 59 parameters.add(new js.Parameter(name)); |
| (...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1930 backend.registerNonCallStaticUse(node); | 1952 backend.registerNonCallStaticUse(node); |
| 1931 break; | 1953 break; |
| 1932 } | 1954 } |
| 1933 } | 1955 } |
| 1934 } | 1956 } |
| 1935 }); | 1957 }); |
| 1936 world.registerStaticUse(node.element); | 1958 world.registerStaticUse(node.element); |
| 1937 push(new js.VariableUse(compiler.namer.isolateAccess(node.element))); | 1959 push(new js.VariableUse(compiler.namer.isolateAccess(node.element))); |
| 1938 } | 1960 } |
| 1939 | 1961 |
| 1962 void visitLazyStatic(HLazyStatic node) { |
| 1963 Element element = node.element; |
| 1964 world.registerStaticUse(element); |
| 1965 String lazyGetter = compiler.namer.isolateLazyInitializerAccess(element); |
| 1966 js.VariableUse target = new js.VariableUse(lazyGetter); |
| 1967 js.Call call = new js.Call(target, <js.Expression>[]); |
| 1968 push(call, node); |
| 1969 } |
| 1970 |
| 1940 void visitStaticStore(HStaticStore node) { | 1971 void visitStaticStore(HStaticStore node) { |
| 1941 world.registerStaticUse(node.element); | 1972 world.registerStaticUse(node.element); |
| 1942 js.VariableUse variableUse = | 1973 js.VariableUse variableUse = |
| 1943 new js.VariableUse(compiler.namer.isolateAccess(node.element)); | 1974 new js.VariableUse(compiler.namer.isolateAccess(node.element)); |
| 1944 use(node.inputs[0]); | 1975 use(node.inputs[0]); |
| 1945 push(new js.Assignment(variableUse, pop()), node); | 1976 push(new js.Assignment(variableUse, pop()), node); |
| 1946 } | 1977 } |
| 1947 | 1978 |
| 1948 void visitStringConcat(HStringConcat node) { | 1979 void visitStringConcat(HStringConcat node) { |
| 1949 if (isEmptyString(node.left)) { | 1980 if (isEmptyString(node.left)) { |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2438 for (; i < maxBailoutParameters; i++) { | 2469 for (; i < maxBailoutParameters; i++) { |
| 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); |
| 2479 } else if (element.isField()) { |
| 2480 String bailoutName = namer.isolateLazyInitializerBailoutAccess(element); |
| 2481 bailoutTarget = new js.VariableUse(bailoutName); |
| 2448 } else { | 2482 } else { |
| 2449 bailoutTarget = new js.VariableUse(namer.isolateBailoutAccess(element)); | 2483 bailoutTarget = new js.VariableUse(namer.isolateBailoutAccess(element)); |
| 2450 } | 2484 } |
| 2451 js.Call call = new js.Call(bailoutTarget, arguments); | 2485 js.Call call = new js.Call(bailoutTarget, arguments); |
| 2452 attachLocation(call, guard); | 2486 attachLocation(call, guard); |
| 2453 return new js.Return(call); | 2487 return new js.Return(call); |
| 2454 } | 2488 } |
| 2455 | 2489 |
| 2456 void visitTypeGuard(HTypeGuard node) { | 2490 void visitTypeGuard(HTypeGuard node) { |
| 2457 HInstruction input = node.guarded; | 2491 HInstruction input = node.guarded; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2901 if (leftType.canBeNull() && rightType.canBeNull()) { | 2935 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2902 if (left.isConstantNull() || right.isConstantNull() || | 2936 if (left.isConstantNull() || right.isConstantNull() || |
| 2903 (leftType.isPrimitive() && leftType == rightType)) { | 2937 (leftType.isPrimitive() && leftType == rightType)) { |
| 2904 return '=='; | 2938 return '=='; |
| 2905 } | 2939 } |
| 2906 return null; | 2940 return null; |
| 2907 } else { | 2941 } else { |
| 2908 return '==='; | 2942 return '==='; |
| 2909 } | 2943 } |
| 2910 } | 2944 } |
| OLD | NEW |