| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 import '../resolution/tree_elements.dart' show TreeElements; | 32 import '../resolution/tree_elements.dart' show TreeElements; |
| 33 import '../tree/tree.dart' as ast; | 33 import '../tree/tree.dart' as ast; |
| 34 import '../types/types.dart'; | 34 import '../types/types.dart'; |
| 35 import '../universe/call_structure.dart' show CallStructure; | 35 import '../universe/call_structure.dart' show CallStructure; |
| 36 import '../universe/selector.dart' show Selector; | 36 import '../universe/selector.dart' show Selector; |
| 37 import '../universe/side_effects.dart' show SideEffects; | 37 import '../universe/side_effects.dart' show SideEffects; |
| 38 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; | 38 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
| 39 import '../util/util.dart'; | 39 import '../util/util.dart'; |
| 40 import '../world.dart' show ClassWorld; | 40 import '../world.dart' show ClassWorld; |
| 41 | 41 |
| 42 import 'context.dart'; |
| 42 import 'graph_builder.dart'; | 43 import 'graph_builder.dart'; |
| 43 import 'locals_handler.dart'; | 44 import 'locals_handler.dart'; |
| 44 import 'nodes.dart'; | 45 import 'nodes.dart'; |
| 45 import 'optimize.dart'; | 46 import 'optimize.dart'; |
| 46 import 'ssa_branch_builder.dart'; | 47 import 'ssa_branch_builder.dart'; |
| 47 import 'types.dart'; | 48 import 'types.dart'; |
| 48 | 49 |
| 49 /// A synthetic local variable only used with the SSA graph. | 50 /// A synthetic local variable only used with the SSA graph. |
| 50 /// | 51 /// |
| 51 /// For instance used for holding return value of function or the exception of a | 52 /// For instance used for holding return value of function or the exception of a |
| (...skipping 20 matching lines...) Expand all Loading... |
| 72 String get name => 'SSA builder'; | 73 String get name => 'SSA builder'; |
| 73 | 74 |
| 74 SsaBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) | 75 SsaBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) |
| 75 : emitter = backend.emitter, | 76 : emitter = backend.emitter, |
| 76 backend = backend, | 77 backend = backend, |
| 77 compiler = backend.compiler, | 78 compiler = backend.compiler, |
| 78 super(backend.compiler.measurer); | 79 super(backend.compiler.measurer); |
| 79 | 80 |
| 80 DiagnosticReporter get reporter => compiler.reporter; | 81 DiagnosticReporter get reporter => compiler.reporter; |
| 81 | 82 |
| 82 HGraph build(CodegenWorkItem work) { | 83 HGraph build(CodegenWorkItem work, SsaCompilationContext context) { |
| 83 return measure(() { | 84 return measure(() { |
| 84 Element element = work.element.implementation; | 85 Element element = work.element.implementation; |
| 85 return reporter.withCurrentElement(element, () { | 86 return reporter.withCurrentElement(element, () { |
| 86 SsaBuilder builder = new SsaBuilder( | 87 SsaBuilder builder = new SsaBuilder( |
| 87 work.element.implementation, | 88 work.element.implementation, |
| 88 work.resolvedAst, | 89 work.resolvedAst, |
| 89 work.compilationContext, | 90 context, |
| 90 work.registry, | 91 work.registry, |
| 91 backend, | 92 backend, |
| 92 emitter.nativeEmitter, | 93 emitter.nativeEmitter, |
| 93 sourceInformationFactory); | 94 sourceInformationFactory); |
| 94 HGraph graph = builder.build(); | 95 HGraph graph = builder.build(); |
| 95 | 96 |
| 96 // Default arguments are handled elsewhere, but we must ensure | 97 // Default arguments are handled elsewhere, but we must ensure |
| 97 // that the default values are computed during codegen. | 98 // that the default values are computed during codegen. |
| 98 if (!identical(element.kind, ElementKind.FIELD)) { | 99 if (!identical(element.kind, ElementKind.FIELD)) { |
| 99 FunctionElement function = element; | 100 FunctionElement function = element; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 if (element.isClassMember) { | 111 if (element.isClassMember) { |
| 111 String className = element.enclosingClass.name; | 112 String className = element.enclosingClass.name; |
| 112 String memberName = element.name; | 113 String memberName = element.name; |
| 113 name = "$className.$memberName"; | 114 name = "$className.$memberName"; |
| 114 if (element.isGenerativeConstructorBody) { | 115 if (element.isGenerativeConstructorBody) { |
| 115 name = "$name (body)"; | 116 name = "$name (body)"; |
| 116 } | 117 } |
| 117 } else { | 118 } else { |
| 118 name = "${element.name}"; | 119 name = "${element.name}"; |
| 119 } | 120 } |
| 120 compiler.tracer.traceCompilation(name, work.compilationContext); | 121 compiler.tracer.traceCompilation(name); |
| 121 compiler.tracer.traceGraph('builder', graph); | 122 compiler.tracer.traceGraph('builder', graph); |
| 122 } | 123 } |
| 123 return graph; | 124 return graph; |
| 124 }); | 125 }); |
| 125 }); | 126 }); |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| 129 // Represents a single break/continue instruction. | 130 // Represents a single break/continue instruction. |
| 130 class JumpHandlerEntry { | 131 class JumpHandlerEntry { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 final Element target; | 364 final Element target; |
| 364 | 365 |
| 365 ResolvedAst resolvedAst; | 366 ResolvedAst resolvedAst; |
| 366 | 367 |
| 367 /// Used to report information about inlining (which occurs while building the | 368 /// Used to report information about inlining (which occurs while building the |
| 368 /// SSA graph), when dump-info is enabled. | 369 /// SSA graph), when dump-info is enabled. |
| 369 final InfoReporter infoReporter; | 370 final InfoReporter infoReporter; |
| 370 | 371 |
| 371 /// If not null, the builder will store in [context] data that is used later | 372 /// If not null, the builder will store in [context] data that is used later |
| 372 /// during the optimization phases. | 373 /// during the optimization phases. |
| 373 final JavaScriptItemCompilationContext context; | 374 final SsaCompilationContext context; |
| 374 | 375 |
| 375 /// Registry used to enqueue work during codegen, may be null to avoid | 376 /// Registry used to enqueue work during codegen, may be null to avoid |
| 376 /// enqueing any work. | 377 /// enqueing any work. |
| 377 // TODO(sigmund,johnniwinther): get rid of registry entirely. We should be | 378 // TODO(sigmund,johnniwinther): get rid of registry entirely. We should be |
| 378 // able to return the impact as a result after building and avoid enqueing | 379 // able to return the impact as a result after building and avoid enqueing |
| 379 // things here. Later the codegen task can decide whether to enqueue | 380 // things here. Later the codegen task can decide whether to enqueue |
| 380 // something. In the past this didn't matter as much because the SSA graph was | 381 // something. In the past this didn't matter as much because the SSA graph was |
| 381 // used only for codegen, but currently we want to experiment using it for | 382 // used only for codegen, but currently we want to experiment using it for |
| 382 // code-analysis too. | 383 // code-analysis too. |
| 383 final CodegenRegistry registry; | 384 final CodegenRegistry registry; |
| (...skipping 7169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7553 const _LoopTypeVisitor(); | 7554 const _LoopTypeVisitor(); |
| 7554 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; | 7555 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; |
| 7555 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; | 7556 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; |
| 7556 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; | 7557 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; |
| 7557 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; | 7558 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; |
| 7558 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 7559 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
| 7559 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 7560 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
| 7560 int visitSwitchStatement(ast.SwitchStatement node) => | 7561 int visitSwitchStatement(ast.SwitchStatement node) => |
| 7561 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; | 7562 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; |
| 7562 } | 7563 } |
| OLD | NEW |